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];
Model aModel = new Model();
if (!new ModelReader().Read(new UTF16String(aSource), aModel))
{
Console.WriteLine("Failed to read the file " + aSource);
return 1;
}
PartBRepVisitor aVisitor = new PartBRepVisitor();
aModel.Accept(aVisitor);
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();
}
}
class PartBRepVisitor : ModelElementVoidVisitor
{
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;
ShapeIterator aFaceIt = new ShapeIterator(aBody);
for (var j = new ShapeIterator (aBody); j.HasNext();)
{
var aShape = j.Next();
ExploreShape(aShape);
}
}
myNestingLevel--;
}
private void ExploreShape(Shape theShape)
{
myShapeSet.Add(theShape);
++myNestingLevel;
ShapeIterator aShapeIt = new ShapeIterator(theShape);
while (aShapeIt.HasNext())
{
Shape aShape = aShapeIt.Next();
PrintShapeInfo(aShape);
ExploreShape(aShape);
}
--myNestingLevel;
}
private string PrintBodyType(Body theBody)
{
if (SheetBody.CompareType(theBody))
{
return "Sheet";
}
else if (SolidBody.CompareType(theBody))
{
return "Solid";
}
else if (WireframeBody.CompareType(theBody))
{
return "Wireframe";
}
return "Undefined";
}
private void PrintShapeInfo(Shape theShape)
{
PrintTabulation();
switch (theShape.Type())
{
case ShapeType.Solid: Console.Write("Solid"); break;
case ShapeType.Shell: Console.Write("Shell"); break;
case ShapeType.Wire:
Console.Write("Wire");
PrintWireInfo(Wire.Cast(theShape));
break;
case ShapeType.Face:
Console.Write("Face");
PrintFaceInfo(Face.Cast(theShape));
break;
case ShapeType.Edge:
Console.Write("Edge");
PrintEdgeInfo(Edge.Cast(theShape));
break;
case ShapeType.Vertex:
Console.Write("Vertex");
PrintVertexInfo(Vertex.Cast(theShape));
break;
default: Console.Write("Undefined"); break;
}
Console.WriteLine();
}
private void PrintOrientationInfo(Shape theShape)
{
Console.Write(". Orientation: ");
switch (theShape.Orientation())
{
case ShapeOrientation.Forward: Console.Write("Forward"); break;
case ShapeOrientation.Reversed: Console.Write("Reversed"); break;
default:
break;
}
}
private void PrintWireInfo(Wire theWire)
{
++myNestingLevel;
PrintOrientationInfo(theWire);
--myNestingLevel;
}
public void PrintFaceInfo(Face theFace)
{
++myNestingLevel;
PrintOrientationInfo(theFace);
Console.WriteLine();
Surface aSurface = theFace.Surface();
PrintTabulation();
Console.Write("Surface: " + PrintSurfaceType(aSurface));
--myNestingLevel;
}
private string PrintSurfaceType(Surface theSurface)
{
switch (theSurface.Type())
{
case SurfaceType.Plane: return "Plane";
case SurfaceType.Cylinder: return "Cylinder";
case SurfaceType.Cone: return "Cone";
case SurfaceType.Sphere: return "Sphere";
case SurfaceType.Torus: return "Torus";
case SurfaceType.LinearExtrusion: return "LinearExtrusion";
case SurfaceType.Revolution: return "Revolution";
case SurfaceType.Bezier: return "Bezier";
case SurfaceType.BSpline: return "BSpline";
case SurfaceType.Offset: return "Offset";
default:
break;
}
return "Undefined";
}
private void PrintEdgeInfo(Edge theEdge)
{
++myNestingLevel;
if (theEdge.IsDegenerated())
{
Console.Write("(Degenerated)");
}
PrintOrientationInfo(theEdge);
Console.Write(". Tolerance " + theEdge.Tolerance());
if (!theEdge.IsDegenerated())
{
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)
{
switch (theCurve.Type())
{
case CurveType.Line: return "Line";
case CurveType.Circle: return "Circle";
case CurveType.Ellipse: return "Ellipse";
case CurveType.Hyperbola: return "Hyperbola";
case CurveType.Parabola: return "Parabola";
case CurveType.Bezier: return "Bezier";
case CurveType.BSpline: return "BSpline";
case CurveType.Offset: return "Offset";
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;
}
}
Contains classes, types, enums, and functions related to geometric entities.
Defines classes, types, enums, and functions related to topological entities and scene graph elements...
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.