#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
typedef ModelData::OrientedShapeHash HasherType;
typedef ModelData::OrientedShapeEqual EqualerType;
#else
typedef ModelData::UnorientedShapeHash HasherType;
typedef ModelData::UnorientedShapeEqual EqualerType;
#endif
typedef unordered_set<ModelData::Shape, HasherType, EqualerType> ShapeSetType;
class PartBRepVisitor : public ModelData::ModelElementVoidVisitor
{
public:
PartBRepVisitor() : myNestingLevel (0)
{}
void PrintUniqueShapesCount()
{
cout << endl << "Total unique shapes count: " << myShapeSet.size() << endl;
}
protected:
void operator() (const ModelData::Part& thePart) override
{
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;
for (ModelData::ShapeIterator j (aBody); j.HasNext();) {
const ModelData::Shape& aShape = j.Next();
ExploreShape (aShape);
}
}
myNestingLevel--;
}
void ExploreShape (const ModelData::Shape theShape)
{
myShapeSet.insert (theShape);
++myNestingLevel;
ModelData::ShapeIterator aShapeIt (theShape);
while (aShapeIt.HasNext()) {
const ModelData::Shape& aShape = aShapeIt.Next();
PrintShapeInfo (aShape);
ExploreShape (aShape);
}
--myNestingLevel;
}
string PrintBodyType (const ModelData::Body& theBody)
{
if (theBody.IsOfType<ModelData::SheetBody>()) {
return "Sheet";
} else if (theBody.IsOfType<ModelData::SolidBody>()) {
return "Solid";
} else if (theBody.IsOfType<ModelData::WireframeBody>()) {
return "Wireframe";
}
return "Undefined";
}
void PrintShapeInfo (const ModelData::Shape& theShape)
{
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;
}
void PrintWireInfo (const ModelData::Wire& theWire)
{
++myNestingLevel;
PrintOrientation (theWire.Orientation());
--myNestingLevel;
}
void PrintFaceInfo (const ModelData::Face& theFace)
{
++myNestingLevel;
PrintOrientation (theFace.Orientation());
cout << endl;
Geom::Surface aSurface = theFace.Surface();
PrintTabulation();
cout << "Surface: " << PrintSurfaceType (aSurface);
--myNestingLevel;
}
const char* PrintSurfaceType (const Geom::Surface& theSurface)
{
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";
}
void PrintEdgeInfo (const ModelData::Edge& theEdge)
{
++myNestingLevel;
if (theEdge.IsDegenerated()) {
cout << "(Degenerated)";
}
PrintOrientation (theEdge.Orientation());
cout << "Tolerance = " << theEdge.Tolerance();
if (!theEdge.IsDegenerated()) {
double aFirstParam, aLastParam;
Geom::Curve aCurve = theEdge.Curve (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";
}
void PrintVertexInfo (const ModelData::Vertex& theVertex)
{
PrintOrientation (theVertex.Orientation());
cout << "Tolerance = " << theVertex.Tolerance();
}
static void PrintOrientation (const ModelData::ShapeOrientation& theOrientation)
{
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];
ModelData::Model aModel;
if (!ModelData::ModelReader().Read (aSource, aModel)) {
cerr << "Failed to read the file " << aSource << endl;
return 1;
}
PartBRepVisitor aVisitor;
aModel.Accept (aVisitor);
aVisitor.PrintUniqueShapesCount();
return 0;
}
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.