using System;
using System.Collections.Generic;
namespace brep_topology
{
class Program
{
static int Main(string[] args)
{
string aKey = MTKLicenseKey.Value();
{
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;
}
}
{
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 int myNestingLevel;
}
}
Base class for 3D curves.
Definition Curve.cs:84
cadex.Geom.CurveType Type()
Definition Curve.cs:123
Base class for geometrical surfaces.
Definition Surface.cs:96
cadex.Geom.SurfaceType Type()
Returns a surface type.
Definition Surface.cs:134
Activates the license key.
Definition LicenseManager.cs:48
Provides a base body class.
Definition Body.cs:19
Defines an edge.
Definition Edge.cs:146
bool IsDegenerated()
Returns true if the edge is degenerated.
Definition Edge.cs:422
cadex.Geom.Curve Curve(out double theFirstParameter, out double theLastParameter)
Returns edge 3D curve and its limits.
Definition Edge.cs:261
static cadex.ModelData.Edge Cast(cadex.ModelData.Shape theShape)
Casts a base class object to Edge.
Definition Edge.cs:448
double Tolerance()
Returns edge tolerance.
Definition Edge.cs:415
Defines a topological face.
Definition Face.cs:120
static cadex.ModelData.Face Cast(cadex.ModelData.Shape theShape)
Cast operator.
Definition Face.cs:250
cadex.Geom.Surface Surface()
Returns underlying surface.
Definition Face.cs:216
cadex.UTF16String Name()
Returns a name.
Definition ModelElement.cs:67
Element visitor with empty implementation.
Definition ModelElementVoidVisitor.cs:20
Provides MTK data model.
Definition Model.cs:30
void Accept(cadex.ModelData.ModelElementVisitor theVisitor)
Accepts a visitor.
Definition Model.cs:179
Reads supported formats, see Import section.
Definition ModelReader.cs:17
Defines a leaf node in the scene graph hierarchy.
Definition Part.cs:23
Base class of topological shapes.
Definition Shape.cs:178
cadex.ModelData.ShapeOrientation Orientation()
Returns orientation flag.
Definition Shape.cs:230
cadex.ModelData.ShapeType Type()
Returns a shape type. For a null object returns Undefined.
Definition Shape.cs:222
Iterates over subshapes in a shape.
Definition ShapeIterator.cs:58
Provides a sheet body composed of faces and shells.
Definition SheetBody.cs:19
Provides a solid body composed of solids.
Definition SolidBody.cs:19
Hasher for Shape using 'IsSame' relationship.
Definition UnorientedShapeHash.cs:19
Defines topological vertex.
Definition Vertex.cs:32
double Tolerance()
Returns vertex tolerance.
Definition Vertex.cs:89
Defines a connected set of edges.
Definition Wire.cs:30
Provides a wireframe body composed of edges and wires.
Definition WireframeBody.cs:19
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition UTF16String.cs:17
Definition ArrayDouble2.cs:12
Contains classes, types, enums, and functions related to geometric entities.
Definition Axis1d.cs:12
SurfaceType
Defines surface type.
Definition SurfaceType.cs:17
CurveType
Defines curve type.
Definition CurveType.cs:17
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
Definition AngleUnit.cs:12
ShapeType
Defines shape type.
Definition ShapeType.cs:17
ShapeOrientation
Defines shape orientation.
Definition ShapeOrientation.cs:17
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition BaseObject.cs:12