#include <cadex/LicenseManager_Activate.h>
#include <cadex/ModelData/Body.hxx>
#include <cadex/ModelData/Edge.hxx>
#include <cadex/ModelData/Face.hxx>
#include <cadex/ModelData/Model.hxx>
#include <cadex/ModelData/ModelElementVisitor.hxx>
#include <cadex/ModelData/ModelReader.hxx>
#include <cadex/ModelData/Part.hxx>
#include <cadex/ModelData/Shape.hxx>
#include <cadex/ModelData/SheetBody.hxx>
#include <cadex/ModelData/Shell.hxx>
#include <cadex/ModelData/SolidBody.hxx>
#include <cadex/ModelData/Vertex.hxx>
#include <cadex/ModelData/Wire.hxx>
#include <cadex/ModelData/WireframeBody.hxx>
#include <iostream>
#include <unordered_set>
#include "../../mtk_license.cxx"
using namespace std;
#define ShapesOrientationIsUsed 0
#if ShapesOrientationIsUsed
#else
#endif
typedef unordered_set<ModelData::Shape, HasherType, EqualerType> ShapeSetType;
{
public:
PartBRepVisitor() :
myNestingLevel (0)
{}
void PrintUniqueShapesCount()
{
cout << endl << "Total unique shapes count: " << myShapeSet.size() << endl;
}
protected:
{
cout <<
"Part = \"" << thePart.
Name() <<
"\"" << endl;
const auto& aBodies = thePart.
Bodies();
if (!aBodies.empty()) {
ExploreBRep (aBodies);
}
}
private:
void ExploreBRep (const std::vector<ModelData::Body>& theBodies)
{
myNestingLevel++;
for (size_t i = 0; i < theBodies.size(); ++i) {
const auto& aBody = theBodies[i];
PrintTabulation();
cout << "Body " << i << " " << PrintBodyType (aBody) << endl;
ExploreShape (aShape);
}
}
myNestingLevel--;
}
{
myShapeSet.insert (theShape);
++myNestingLevel;
while (aShapeIt.HasNext()) {
PrintShapeInfo (aShape);
ExploreShape (aShape);
}
--myNestingLevel;
}
{
return "Sheet";
return "Solid";
return "Wireframe";
}
return "Undefined";
}
{
PrintTabulation();
switch (theShape.
Type()) {
case ModelData::ShapeType::Solid: cout << "Solid"; break;
case ModelData::ShapeType::Shell: cout << "Shell"; break;
case ModelData::ShapeType::Wire:
cout << "Wire";
PrintWireInfo (ModelData::Wire::Cast (theShape));
break;
case ModelData::ShapeType::Face:
cout << "Face";
PrintFaceInfo (ModelData::Face::Cast (theShape));
break;
case ModelData::ShapeType::Edge:
cout << "Edge";
PrintEdgeInfo (ModelData::Edge::Cast (theShape));
break;
case ModelData::ShapeType::Vertex:
cout << "Vertex";
PrintVertexInfo (ModelData::Vertex::Cast (theShape));
break;
default: cout << "Undefined"; break;
}
cout << endl;
}
{
++myNestingLevel;
--myNestingLevel;
}
{
++myNestingLevel;
cout << endl;
PrintTabulation();
cout << "Surface: " << PrintSurfaceType (aSurface);
--myNestingLevel;
}
{
switch (theSurface.
Type()) {
case Geom::SurfaceType::Plane: return "Plane";
case Geom::SurfaceType::Cylinder: return "Cylinder";
case Geom::SurfaceType::Cone: return "Cone";
case Geom::SurfaceType::Sphere: return "Sphere";
case Geom::SurfaceType::Torus: return "Torus";
case Geom::SurfaceType::LinearExtrusion: return "LinearExtrusion";
case Geom::SurfaceType::Revolution: return "Revolution";
case Geom::SurfaceType::Bezier: return "Bezier";
case Geom::SurfaceType::BSpline: return "BSpline";
case Geom::SurfaceType::Offset: return "Offset";
default: break;
}
return "Undefined";
}
{
++myNestingLevel;
cout << "(Degenerated)";
}
cout <<
"Tolerance = " << theEdge.
Tolerance();
double aFirstParam, aLastParam;
cout << endl;
PrintTabulation();
cout << "Curve: " << PrintCurvetype (aCurve);
}
--myNestingLevel;
}
const char* PrintCurvetype (
const Geom::Curve& theCurve)
{
switch (theCurve.
Type()) {
case Geom::CurveType::Line: return "Line";
case Geom::CurveType::Circle: return "Circle";
case Geom::CurveType::Ellipse: return "Ellipse";
case Geom::CurveType::Hyperbola: return "Hyperbola";
case Geom::CurveType::Parabola: return "Parabola";
case Geom::CurveType::Bezier: return "Bezier";
case Geom::CurveType::BSpline: return "BSpline";
case Geom::CurveType::Offset: return "Offset";
default: break;
}
return "Undefined";
}
{
cout <<
"Tolerance = " << theVertex.
Tolerance();
}
{
cout << "Orientation = ";
switch (theOrientation) {
case ModelData::ShapeOrientation::Forward: cout << "Forward"; break;
case ModelData::ShapeOrientation::Reversed: cout << "Reversed"; break;
default: cout << "Undefined"; break;
}
cout << "; ";
}
void PrintTabulation()
{
for (size_t i = 0; i < myNestingLevel; ++i) {
cout << "- ";
}
}
size_t myNestingLevel;
ShapeSetType myShapeSet;
};
int main (int argc, char* argv[])
{
auto aKey = MTKLicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
cerr << "Failed to activate Manufacturing Toolkit license." << endl;
return 1;
}
if (argc != 2) {
cerr << "Usage: " << argv[0] << " <input_file>, where:" << endl;
cerr << " <input_file> is a name of the file to be read" << endl;
return 1;
}
const char* aSource = argv[1];
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
PartBRepVisitor aVisitor;
aVisitor.PrintUniqueShapesCount();
return 0;
}
Base class for 3D curves.
Definition Curve.cs:84
Base class for geometrical surfaces.
Definition Surface.cs:97
cadex.Geom.SurfaceType Type()
Returns a surface type.
Definition Surface.cs:135
Provides a base body class.
Definition Body.cs:19
Defines an edge.
Definition Edge.cs:146
bool IsDegenerated()
A degenerated edge has no 3D curve.
Definition Edge.cs:422
cadex.Geom.Curve Curve(out double theFirstParameter, out double theLastParameter)
Returns null curve for a degenerated edge (see IsDegenerated()).
Definition Edge.cs:261
double Tolerance()
Returns edge tolerance.
Definition Edge.cs:415
Defines a topological face.
Definition Face.cs:120
cadex.Geom.Surface Surface()
Returns underlying surface.
Definition Face.cs:226
cadex.UTF16String Name()
Returns empty string if the model element has no name (by default).
Definition ModelElement.cs:67
Element visitor with empty implementation.
Definition ModelElementVoidVisitor.cs:20
Provides MTK data model.
Definition Model.cs:31
void Accept(cadex.ModelData.ModelElementVisitor theVisitor)
Accepts a visitor.
Definition Model.cs:176
Reads supported formats, see Import section.
Definition ModelReader.cs:17
Compares shapes using 'IsEqual' relationship.
Definition OrientedShapeEqual.cs:19
Hasher for Shape using 'IsEqual' relationship.
Definition OrientedShapeHash.cs:19
Defines a leaf node in the scene graph hierarchy.
Definition Part.cs:23
Base class of topological shapes.
Definition Shape.cs:180
cadex.ModelData.ShapeOrientation Orientation()
Returns orientation flag.
Definition Shape.cs:230
cadex.ModelData.ShapeType Type()
Returns a shape type. For a null object returns Undefined.
Definition Shape.cs:224
Iterates over subshapes in a shape.
Definition ShapeIterator.cs:58
Provides a sheet body composed of faces and shells.
Definition SheetBody.cs:19
Provides a solid body composed of solids.
Definition SolidBody.cs:19
Compares shapes using 'IsSame' relationship.
Definition UnorientedShapeEqual.cs:19
Hasher for Shape using 'IsSame' relationship.
Definition UnorientedShapeHash.cs:19
Defines topological vertex.
Definition Vertex.cs:32
double Tolerance()
Returns vertex tolerance.
Definition Vertex.cs:89
Defines a connected set of edges.
Definition Wire.cs:30
Provides a wireframe body composed of edges and wires.
Definition WireframeBody.cs:19
ShapeOrientation
Defines shape orientation.
Definition ShapeOrientation.cs:17
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition BaseObject.cs:12