Hide menu
Loading...
Searching...
No Matches
Model Explore Helper Implementation

Implementation of classes that help to explore model BRep representation of a part in Manufacturing Toolkit examples.

Overview

This helper using to explore the model, BRep representation of a part and process specific shapes using MTK tools.

Implementation

To explore the model and process parts, it's need to create an inheritor from the VoidElementVisitor and override the part processing method void operator() (const ModelData_Part& thePart). For this purpose, two classes were created: ShapeProcessor and SolidProcessor.
ShapeProcessor is used to explore ModelData_BRepRepresentation and process each unique ModelData_Solid or ModelData_Shell by passing it to virtual method void ProcessSolid (const ModelData_Solid& theSolid) or void ProcessShell (const ModelData_Shell& theShell). These methods should be overridden in child classes.

class ShapeProcessor : public ModelData_Model::VoidElementVisitor
{
public:
void operator() (const ModelData_Part& thePart) override
{
auto aPartName = thePart.Name().IsEmpty() ? "noname" : thePart.Name();
auto aBRep = thePart.BRepRepresentation();
if (aBRep) {
const auto& aBodyList = aBRep.Get();
for (size_t i = 0, n = aBodyList.Size(); i < n; ++i) {
const auto& aBody = aBodyList[i];
ModelData_Shape::Iterator aShapeIt (aBody);
while (aShapeIt.HasNext()) {
const auto& aShape = aShapeIt.Next();
if (aShape.Type() == ModelData_ST_Solid) {
cout << "Part #" << myPartIndex++ << " [\"" << aPartName << "\"] - solid #" << std::to_string (i) << " has:" << endl;
ProcessSolid (ModelData_Solid::Cast (aShape));
} else if (aShape.Type() == ModelData_ST_Shell) {
cout << "Part #" << myPartIndex++ << " [\"" << aPartName << "\"] - shell #" << std::to_string (i) << " has:" << endl;
ProcessShell (ModelData_Shell::Cast (aShape));
}
}
}
}
}
virtual void ProcessSolid (const ModelData_Solid& theSolid) = 0;
virtual void ProcessShell (const ModelData_Shell& theShell) = 0;
private:
size_t myPartIndex = 0;
};

SolidProcessor is used to explore ModelData_BRepRepresentation and process each unique ModelData_Solid by passing it to virtual method void ProcessSolid (const ModelData_Solid& theSolid). This method should be overridden in child classes.

class SolidProcessor : public ModelData_Model::VoidElementVisitor
{
public:
void operator() (const ModelData_Part& thePart) override
{
auto aPartName = thePart.Name().IsEmpty() ? "noname" : thePart.Name();
auto aBRep = thePart.BRepRepresentation();
if (aBRep) {
const auto& aBodyList = aBRep.Get();
for (size_t i = 0, n = aBodyList.Size(); i < n; ++i) {
const auto& aBody = aBodyList[i];
ModelData_Shape::Iterator aShapeIt (aBody);
while (aShapeIt.HasNext()) {
const auto& aShape = aShapeIt.Next();
if (aShape.Type() == ModelData_ST_Solid) {
cout << "Part #" << myPartIndex++ << " [\"" << aPartName << "\"] - solid #" << std::to_string (i) << " has:" << endl;
ProcessSolid (ModelData_Solid::Cast (aShape));
}
}
}
}
}
virtual void ProcessSolid (const ModelData_Solid& theSolid) = 0;
private:
size_t myPartIndex = 0;
};

Files