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.
abstract class ShapeProcessor : ModelElementVoidVisitor
{
public override void Apply(ModelData.Part thePart)
{
var aPartName = thePart.Name().IsEmpty() ? new UTF16String("noname") : thePart.Name();
var aBodyVec = thePart.Bodies();
if (aBodyVec.Count != 0)
{
for (int i = 0; i < aBodyVec.Count; ++i)
{
Body aBody = aBodyVec[i];
var aShapeIt = new ModelData.ShapeIterator(aBody);
while (aShapeIt.HasNext())
{
var aShape = aShapeIt.Next();
if (aShape.Type() == ShapeType.Solid)
{
Console.Write($"Part #{myPartIndex} [\"{aPartName}\"] - solid #{i} has:\n");
ProcessSolid(Solid.Cast(aShape));
}
else if (aShape.Type() == ShapeType.Shell)
{
Console.Write($"Part #{myPartIndex} [\"{aPartName}\"] - shell #{i} has:\n");
ProcessShell(Shell.Cast(aShape));
}
}
++myPartIndex;
}
}
}
public abstract void ProcessSolid(ModelData.Solid theSolid);
public abstract void ProcessShell(ModelData.Shell theShell);
private uint myPartIndex = 0;
}
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.
abstract class SolidProcessor : ModelElementVoidVisitor
{
public override void Apply(ModelData.Part thePart)
{
var aPartName = thePart.Name().IsEmpty() ? new UTF16String ("noname") : thePart.Name();
var aBodyVec = thePart.Bodies();
if (aBodyVec.Count != 0)
{
for (int i = 0; i < aBodyVec.Count; ++i)
{
Body aBody = aBodyVec[i];
var aShapeIt = new ModelData.ShapeIterator(aBody);
while (aShapeIt.HasNext())
{
var aShape = aShapeIt.Next();
if (aShape.Type() == ShapeType.Solid)
{
Console.Write ($"Part #{myPartIndex} [\"{aPartName}\"] - solid #{i} has:\n");
ProcessSolid(ModelData.Solid.Cast(aShape));
}
}
++myPartIndex;
}
}
}
public abstract void ProcessSolid(ModelData.Solid theSolid);
private uint myPartIndex = 0;
}
Files