using cadex.Collections;
using System;
using System.Collections.Generic;
namespace brep_topology
{
class Program
{
static int Main(string[] args)
{
string aKey = MTKLicenseKey.Value();
if (!LicenseManager.Activate(aKey))
{
Console.WriteLine("Failed to activate Manufacturing Toolkit license.");
return 1;
}
if (args.Length != 1)
{
Console.WriteLine("Usage: " +
$"{System.Reflection.Assembly.GetExecutingAssembly().Location} <input_file>, where:");
Console.WriteLine($" <input_file> is a name of the file to be read");
Console.WriteLine($"");
return 1;
}
string aSource = args[0];
{
Console.WriteLine("Failed to read the file " + aSource);
return 1;
}
PartBRepVisitor aVisitor = new PartBRepVisitor();
aVisitor.PrintUniqueShapesCount();
return 0;
}
}
class UnorintedShapeHasher : IEqualityComparer<Shape>
{
public bool Equals(
Shape theFirstShape,
Shape theSecondShape)
{
return theFirstShape.
IsSame(theSecondShape);
}
public int GetHashCode(
Shape theShape)
{
return (
int)theShape.
Id();
}
}
{
public PartBRepVisitor()
{
myNestingLevel = 0;
}
public void PrintUniqueShapesCount()
{
Console.WriteLine();
Console.WriteLine("Total unique shapes count: " + myShapeSet.Count);
}
public override void Apply(
Part thePart)
{
Console.WriteLine(
"Part = \"" + thePart.
Name() +
"\"" );
var aBodies = thePart.
Bodies();
if (!aBodies.IsEmpty)
{
ExploreBRep(aBodies);
}
}
private void ExploreBRep(BodyList theBodies)
{
myNestingLevel++;
int i = 0;
foreach (var aBody in theBodies)
{
PrintTabulation();
Console.WriteLine("Body " + i + ": -type " + PrintBodyType(aBody));
++i;
{
var aShape = j.Next();
ExploreShape(aShape);
}
}
myNestingLevel--;
}
private void ExploreShape(
Shape theShape)
{
myShapeSet.Add(theShape);
++myNestingLevel;
while (aShapeIt.HasNext())
{
Shape aShape = aShapeIt.
Next();
PrintShapeInfo(aShape);
ExploreShape(aShape);
}
--myNestingLevel;
}
private string PrintBodyType(
Body theBody)
{
{
return "Sheet";
}
{
return "Solid";
}
{
return "Wireframe";
}
return "Undefined";
}
private void PrintShapeInfo(
Shape theShape)
{
PrintTabulation();
{
case ShapeType.Solid: Console.Write(
"Solid");
break;
case ShapeType.Shell: Console.Write(
"Shell");
break;
Console.Write("Wire");
PrintWireInfo(
Wire.
Cast(theShape));
break;
Console.Write("Face");
break;
Console.Write("Edge");
break;
Console.Write("Vertex");
PrintVertexInfo(
Vertex.
Cast(theShape));
break;
default: Console.Write("Undefined"); break;
}
Console.WriteLine();
}
private void PrintOrientationInfo(
Shape theShape)
{
Console.Write(". Orientation: ");
{
default:
break;
}
}
private void PrintWireInfo(
Wire theWire)
{
++myNestingLevel;
PrintOrientationInfo(theWire);
--myNestingLevel;
}
public void PrintFaceInfo(
Face theFace)
{
++myNestingLevel;
PrintOrientationInfo(theFace);
Console.WriteLine();
PrintTabulation();
Console.Write("Surface: " + PrintSurfaceType(aSurface));
--myNestingLevel;
}
private string PrintSurfaceType(
Surface theSurface)
{
switch (theSurface.
Type())
{
case SurfaceType.LinearExtrusion:
return "LinearExtrusion";
default:
break;
}
return "Undefined";
}
private void PrintEdgeInfo(
Edge theEdge)
{
++myNestingLevel;
{
Console.Write("(Degenerated)");
}
PrintOrientationInfo(theEdge);
Console.Write(
". Tolerance " + theEdge.
Tolerance());
{
Console.WriteLine();
double aParamFirst = 0.0, aParamLast = 0.0;
Curve aCurve = theEdge.
Curve(out aParamFirst, out aParamLast);
PrintTabulation();
Console.Write("Curve: " + PrintCurveType(aCurve));
}
--myNestingLevel;
}
private string PrintCurveType(
Curve theCurve)
{
{
case CurveType.Hyperbola:
return "Hyperbola";
default:
break;
}
return "Undefined";
}
private void PrintVertexInfo(
Vertex theVertex)
{
PrintOrientationInfo(theVertex);
Console.Write(
". Tolerance " + theVertex.
Tolerance());
}
private void PrintTabulation()
{
for (int i = 0; i < myNestingLevel; ++i)
{
Console.Write("- ");
}
}
private HashSet<Shape> myShapeSet = new HashSet<Shape>(new UnorintedShapeHasher());
private int myNestingLevel;
}
}
size_t Id() const
Return unique identifier of public object.
Definition BaseObject.cxx:50
Base class for 3D curves.
Definition Curve.hxx:39
CurveType Type() const
Definition Curve.cxx:434
Base class for geometrical surfaces.
Definition Surface.hxx:40
SurfaceType Type() const
Returns a surface type.
Definition Surface.cxx:495
Provides a base body class.
Definition Body.hxx:30
Defines an edge.
Definition Edge.hxx:33
Geom::Curve Curve(double &theFirstParameter, double &theLastParameter) const
Returns edge 3D curve and its limits.
Definition Edge.cxx:408
double Tolerance() const
Returns edge tolerance.
Definition Edge.cxx:682
bool IsDegenerated() const
Returns true if the edge is degenerated.
Definition Edge.cxx:689
static const Edge & Cast(const Shape &theShape)
Casts a base class object to Edge.
Definition Edge.cxx:714
Defines a topological face.
Definition Face.hxx:33
Geom::Surface Surface() const
Returns underlying surface.
Definition Face.cxx:324
static const Face & Cast(const Shape &theShape)
Cast operator.
Definition Face.cxx:355
UTF16String Name() const
Returns a name.
Definition ModelElement.cxx:55
Element visitor with empty implementation.
Definition ModelElementVisitor.hxx:64
Provides MTK data model.
Definition Model.hxx:40
void Accept(ModelElementVisitor &theVisitor) const
Accepts a visitor.
Definition Model.cxx:274
Reads STEP and native format.
Definition ModelReader.hxx:33
Defines a leaf node in the scene graph hiearchy.
Definition Part.hxx:34
Base class of topological shapes.
Definition Shape.hxx:38
bool IsSame(const Shape &theOther) const
Returns true if the shape shares the same geometry and subshape graph.
Definition Shape.cxx:322
ShapeOrientation Orientation() const
Returns orientation flag.
Definition Shape.cxx:271
ShapeType Type() const
Returns a shape type. For a null object returns Undefined.
Definition Shape.cxx:259
Iterates over subshapes in a shape.
Definition ShapeIterator.hxx:32
Provides a sheet body composed of faces and shells.
Definition SheetBody.hxx:34
Provides a solid body composed of solids.
Definition SolidBody.hxx:30
Defines topological vertex.
Definition Vertex.hxx:30
double Tolerance() const
Returns vertex tolerance.
Definition Vertex.cxx:117
Defines a connected set of edges.
Definition Wire.hxx:32
Provides a wireframe body composed of edges and wires.
Definition WireframeBody.hxx:34
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition UTF16String.hxx:30
Contains classes, types, enums, and functions related to geometric entities.
SurfaceType
Defines surface type.
Definition SurfaceType.hxx:27
CurveType
Defines curve type.
Definition CurveType.hxx:27
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
ShapeType
Defines shape type.
Definition ShapeType.hxx:27
ShapeOrientation
Defines shape orientation.
Definition ShapeOrientation.hxx:27
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition LicenseManager_LicenseError.hxx:30