Implementation of classes that help to explore model BRep representation of a part in Manufacturing Toolkit examples.
Overview
This helper is used to explore the model, BRep representation of a ModelData_Part and process specific shapes using MTK tools.
Implementation
To explore the model and process ModelData_Part s, it's need to create an inheritor from the ModelData_ModelElementVoidVisitor 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 BRep representation 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(mtk.ModelData_ModelElementVoidVisitor):
def __init__(self):
super().__init__()
self.myPartIndex = 0
def __call__(self, thePart: mtk.ModelData_Part):
aPartName = "noname" if thePart.Name().IsEmpty() else thePart.Name()
aBodyList = thePart.Bodies()
i = 0
for aBody in aBodyList:
aShapeIt = mtk.ModelData_ShapeIterator(aBody)
for aShape in aShapeIt:
if aShape.Type() == mtk.ShapeType_Solid:
print("Part #", self.myPartIndex, " [\"", aPartName, "\"] - solid #", i, " has:", sep="")
i += 1
self.ProcessSolid(mtk.ModelData_Solid.Cast(aShape))
elif aShape.Type() == mtk.ShapeType_Shell:
print("Part #", self.myPartIndex, " [\"", aPartName, "\"] - shell #", i, " has:", sep="")
i += 1
self.ProcessShell(mtk.Shell.Cast (aShape))
self.myPartIndex += 1
@abstractmethod
def ProcessSolid(self, theSolid: mtk.ModelData_Solid):
pass
@abstractmethod
def ProcessShell(self, theShell: mtk.ModelData_Shell):
pass
SolidProcessor
is used to explore BRep representation 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(mtk.ModelData_ModelElementVoidVisitor):
def __init__(self):
super().__init__()
self.myPartIndex = 0
def __call__(self, thePart: mtk.ModelData_Part):
aPartName = "noname" if thePart.Name().IsEmpty() else thePart.Name()
aBodyList = thePart.Bodies()
i = 0
for aBody in aBodyList:
aShapeIt = mtk.ShapeIterator(aBody)
for aShape in aShapeIt:
if aShape.Type() == mtk.ShapeType_Solid:
print("SHAPE")
print("Part #", self.myPartIndex, " [\"", aPartName, "\"] - solid #", i, " has:", sep="")
i += 1
self.ProcessSolid (mtk.ModelData_Solid.Cast (aShape))
self.myPartIndex += 1
@abstractmethod
def ProcessSolid(self, theSolid: mtk.ModelData_Solid):
pass
Files