Hide menu
exploring/brepgeometry/Program.cs

Refer to the B-Rep Geometry Exploration Example.

base_explorer.cs

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2022, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
using cadex;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace brepgeometry
{
class BaseExplorer
{
public static void PrintElementary(ModelData_Conic theGeometry)
{
PrintDomain(theGeometry);
ModelData_Axis2Placement aPosition = theGeometry.Position();
ModelData_Point aLoc = aPosition.Location();
ModelData_Direction anAxis = aPosition.Axis();
ModelData_Direction aXDir = aPosition.XDirection();
ModelData_Direction aYDir = aPosition.YDirection();
PrintParameter("Location", aLoc);
PrintParameter("Axis", anAxis);
PrintParameter("X Direction", aXDir);
PrintParameter("Y Direction", aYDir);
}
public static void PrintElementary(ModelData_ElementarySurface theGeometry)
{
PrintDomain(theGeometry);
ModelData_Axis3Placement aPosition = theGeometry.Position();
ModelData_Point aLoc = aPosition.Location();
ModelData_Direction anAxis = aPosition.Axis();
ModelData_Direction aXDir = aPosition.XDirection();
ModelData_Direction aYDir = aPosition.YDirection();
PrintParameter("Location", aLoc);
PrintParameter("Axis", anAxis);
PrintParameter("X Direction", aXDir);
PrintParameter("Y Direction", aYDir);
}
public static void PrintElementary2d(ModelData_Conic2d theGeometry)
{
PrintDomain(theGeometry);
ModelData_Axis2Placement2d aPosition = theGeometry.Position();
ModelData_Point2d aLoc = aPosition.Location();
ModelData_Direction2d aXDir = aPosition.XDirection();
ModelData_Direction2d aYDir = aPosition.YDirection();
PrintParameter("Location", aLoc);
PrintParameter("X Direction", aXDir);
PrintParameter("Y Direction", aYDir);
}
public static void PrintRange(string aName, double aFirstParameter, double aLastParameter)
{
Console.Write("{0} = [{1}, {2}]; ", aName, aFirstParameter, aLastParameter);
}
public static void PrintDomain(ModelData_Curve theCurve)
{
PrintRange("Domain", theCurve.UMin(), theCurve.UMax());
}
public static void PrintDomain(ModelData_Curve2d theCurve)
{
PrintRange("Domain", theCurve.UMin(), theCurve.UMax());
}
public static void PrintDomain(ModelData_Surface theSurface)
{
PrintRange("Domain U", theSurface.UMin(), theSurface.UMax());
PrintRange("V", theSurface.VMin(), theSurface.VMax());
}
public static void PrintParameter(ModelData_Point theValue)
{
Console.Write("({0}, {1}); ", theValue.X(), theValue.Y());
}
public static void PrintParameter(ModelData_Direction theValue)
{
Console.Write("({0}, {1}, {2}); ", theValue.X(), theValue.Y(), theValue.Z());
}
public static void PrintParameter(ModelData_Point2d theValue)
{
Console.Write("({0}, {1}); ", theValue.X(), theValue.Y());
}
public static void PrintParameter(ModelData_Direction2d theValue)
{
Console.Write("({0}, {1}); ", theValue.X(), theValue.Y());
}
public static void PrintParameter(double theValue)
{
Console.Write("{0}; ", theValue);
}
public static void PrintParameter(string theName, ModelData_Point theValue)
{
Console.Write("{0} = ", theName);
PrintParameter(theValue);
}
public static void PrintParameter(string theName, ModelData_Direction theValue)
{
Console.Write("{0} = ", theName);
PrintParameter(theValue);
}
public static void PrintParameter(string theName, double theValue)
{
Console.Write("{0} = ", theName);
PrintParameter(theValue);
}
public static void PrintParameter(string theName, ModelData_Point2d theValue)
{
Console.Write("{0} = ", theName);
PrintParameter(theValue);
}
public static void PrintParameter(string theName, ModelData_Direction2d theValue)
{
Console.Write("{0} = ", theName);
PrintParameter(theValue);
}
public static void PrintName(string theName)
{
Console.Write("{0}: ", theName);
}
public delegate void myPrint1dElement(int i);
public static void PrintCollection(string theName,
int theFinalIndex,
myPrint1dElement thePrintElement)
{
if (theName != null)
{
Console.Write("{0} = ", theName);
}
Console.Write("[");
for (int i = 1; i <= theFinalIndex; ++i)
{
if (i > 3)
{
Console.Write("...");
break;
}
thePrintElement(i);
}
Console.Write("]; ");
}
public delegate void myPrint2dElement(int i, int j);
public static void PrintCollection(string theName,
int theFinalIndex1,
int theFinalIndex2,
myPrint2dElement thePrintElement)
{
PrintCollection(theName, theFinalIndex1, (int i) =>
{
PrintCollection(null, theFinalIndex2, (int j) => { thePrintElement(i, j); });
});
}
public static void PrintOrientation(ModelData_ShapeOrientation theOrientation)
{
Console.Write("Orientation = ");
switch (theOrientation)
{
case ModelData_ShapeOrientation.ModelData_SO_Forward: Console.Write("Forward"); break;
case ModelData_ShapeOrientation.ModelData_SO_Reversed: Console.Write("Reversed"); break;
default: Console.Write("Undefined"); break;
}
Console.Write("; ");
}
public void PrintTabulation()
{
for (uint i = 0; i < myNestingLevel; ++i)
{
Console.Write("--- ");
}
}
public uint myNestingLevel = 0;
}
}

curve_explorer.cs

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2022, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
using cadex;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace brepgeometry
{
class CurveExplorer : BaseExplorer
{
// Prints curve type name and prints shape info in some cases
public static void PrintCurveInfo(ModelData_Curve theCurve)
{
switch (theCurve.Type())
{
case ModelData_CurveType.ModelData_CT_Line:
PrintLine(ModelData_Line.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Circle:
PrintCircle(ModelData_Circle.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Ellipse:
PrintEllipse(ModelData_Ellipse.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Hyperbola:
PrintHyperbola(ModelData_Hyperbola.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Parabola:
PrintParabola(ModelData_Parabola.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Bezier:
PrintBezierCurve(ModelData_BezierCurve.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_BSpline:
PrintBSplineCurve(ModelData_BSplineCurve.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Offset:
PrintOffsetCurve(ModelData_OffsetCurve.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Trimmed:
PrintTrimmedCurve(ModelData_TrimmedCurve.Cast(theCurve));
break;
default:
break;
}
}
public static void PrintLine(ModelData_Line theLine)
{
PrintName("Line");
ModelData_Point aLoc = theLine.Location();
ModelData_Direction aDir = theLine.Direction();
PrintDomain(theLine);
PrintParameter("Location", aLoc);
PrintParameter("Direction", aDir);
}
public static void PrintCircle(ModelData_Circle theCircle)
{
PrintName("Circle");
double aRadius = theCircle.Radius();
PrintElementary(theCircle);
PrintParameter("Radius", aRadius);
}
public static void PrintEllipse(ModelData_Ellipse theEllipse)
{
PrintName("Ellipse");
double aMajorRadius = theEllipse.MajorRadius();
double aMinorRadius = theEllipse.MinorRadius();
PrintElementary(theEllipse);
PrintParameter("Major Radius", aMajorRadius);
PrintParameter("Minor Radius", aMinorRadius);
}
public static void PrintHyperbola(ModelData_Hyperbola theHyperbola)
{
PrintName("Hyperbola");
double aMajorRadius = theHyperbola.MajorRadius();
double aMinorRadius = theHyperbola.MinorRadius();
PrintElementary(theHyperbola);
PrintParameter("Major Radius", aMajorRadius);
PrintParameter("Minor Radius", aMinorRadius);
}
public static void PrintParabola(ModelData_Parabola theParabola)
{
PrintName("Parabola");
double aFocal = theParabola.Focal();
PrintElementary(theParabola);
PrintParameter("Focal", aFocal);
}
public static void PrintBezierCurve(ModelData_BezierCurve theBezier)
{
PrintName("Bezier Curve");
int aDegree = theBezier.Degree();
int aNumberOfPoles = theBezier.NumberOfPoles();
PrintDomain(theBezier);
PrintParameter("Degree", aDegree);
PrintParameter("Number Of Poles", aNumberOfPoles);
PrintCollection("Poles", aNumberOfPoles, (int i) =>
{
ModelData_Point aPole = theBezier.Pole(i);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfPoles, (int i) =>
{
double aWeight = theBezier.Weight(i);
PrintParameter(aWeight);
});
}
public static void PrintBSplineCurve(ModelData_BSplineCurve theBSpline)
{
PrintName("BSpline Curve");
int aDegree = theBSpline.Degree();
int aNumberOfKnots = theBSpline.NumberOfKnots();
int aNumberOfPoles = theBSpline.NumberOfPoles();
PrintDomain(theBSpline);
PrintParameter("Degree", aDegree);
PrintParameter("Number Of Knots", aNumberOfKnots);
PrintParameter("Number Of Poles", aNumberOfPoles);
PrintCollection("Knots", aNumberOfKnots, (int i) =>
{
double aKnot = theBSpline.Knot(i);
PrintParameter(aKnot);
});
PrintCollection("Multiplicities", aNumberOfKnots, (int i) =>
{
int aMultiplicity = theBSpline.Multiplicity(i);
PrintParameter(aMultiplicity);
});
PrintCollection("Poles", aNumberOfPoles, (int i) =>
{
ModelData_Point aPole = theBSpline.Pole(i);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfPoles, (int i) =>
{
double aWeight = theBSpline.Weight(i);
PrintParameter(aWeight);
});
}
public static void PrintOffsetCurve(ModelData_OffsetCurve theOffset)
{
PrintName("Offset Curve");
ModelData_Direction aDir = theOffset.Direction();
double anOffset = theOffset.Offset();
PrintDomain(theOffset);
PrintParameter("Direction", aDir);
PrintParameter("Offset", anOffset);
Console.Write("Basis Curve = ");
PrintCurveInfo(theOffset.BasisCurve());
}
public static void PrintTrimmedCurve(ModelData_TrimmedCurve theTrimmed)
{
PrintName("Trimmed Curve");
PrintDomain(theTrimmed);
Console.Write("Basis Curve = ");
PrintCurveInfo(theTrimmed.BasisCurve());
}
}
}

pcurve_explorer.cs

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2022, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
using cadex;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace brepgeometry
{
class PCurveExplorer : BaseExplorer
{
// Prints 2d curve type name and prints shape info in some cases
public static void PrintPCurveInfo(ModelData_Curve2d theCurve)
{
switch (theCurve.Type())
{
case ModelData_CurveType.ModelData_CT_Line:
PrintLine(ModelData_Line2d.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Circle:
PrintCircle(ModelData_Circle2d.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Ellipse:
PrintEllipse(ModelData_Ellipse2d.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Hyperbola:
PrintHyperbola(ModelData_Hyperbola2d.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Parabola:
PrintParabola(ModelData_Parabola2d.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Bezier:
PrintBezierCurve(ModelData_BezierCurve2d.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_BSpline:
PrintBSplineCurve(ModelData_BSplineCurve2d.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Offset:
PrintOffsetCurve(ModelData_OffsetCurve2d.Cast(theCurve));
break;
case ModelData_CurveType.ModelData_CT_Trimmed:
PrintTrimmedCurve(ModelData_TrimmedCurve2d.Cast(theCurve));
break;
default:
break;
}
}
public static void PrintLine(ModelData_Line2d theLine)
{
PrintName("Line 2d");
ModelData_Point2d aLoc = theLine.Location();
ModelData_Direction2d aDir = theLine.Direction();
PrintDomain(theLine);
PrintParameter("Location", aLoc);
PrintParameter("Direction", aDir);
}
public static void PrintCircle(ModelData_Circle2d theCircle)
{
PrintName("Circle 2d");
double aRadius = theCircle.Radius();
PrintElementary2d(theCircle);
PrintParameter("Radius", aRadius);
}
public static void PrintEllipse(ModelData_Ellipse2d theEllipse)
{
PrintName("Ellipse 2d");
double aMajorRadius = theEllipse.MajorRadius();
double aMinorRadius = theEllipse.MinorRadius();
PrintElementary2d(theEllipse);
PrintParameter("Major Radius", aMajorRadius);
PrintParameter("Minor Radius", aMinorRadius);
}
public static void PrintHyperbola(ModelData_Hyperbola2d theHyperbola)
{
PrintName("Hyperbola 2d");
double aMajorRadius = theHyperbola.MajorRadius();
double aMinorRadius = theHyperbola.MinorRadius();
PrintElementary2d(theHyperbola);
PrintParameter("Major Radius", aMajorRadius);
PrintParameter("Minor Radius", aMinorRadius);
}
public static void PrintParabola(ModelData_Parabola2d theParabola)
{
PrintName("Parabola 2d");
double aFocal = theParabola.Focal();
PrintElementary2d(theParabola);
PrintParameter("Focal", aFocal);
}
public static void PrintBezierCurve(ModelData_BezierCurve2d theBezier)
{
PrintName("Bezier Curve 2d");
int aDegree = theBezier.Degree();
int aNumberOfPoles = theBezier.NumberOfPoles();
PrintDomain(theBezier);
PrintParameter("Degree", aDegree);
PrintParameter("Number Of Poles", aNumberOfPoles);
PrintCollection("Poles", aNumberOfPoles, (int i) => {
ModelData_Point2d aPole = theBezier.Pole(i);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfPoles, (int i) => {
double aWeight = theBezier.Weight(i);
PrintParameter(aWeight);
});
}
public static void PrintBSplineCurve(ModelData_BSplineCurve2d theBSpline)
{
PrintName("BSpline Curve 2d");
int aDegree = theBSpline.Degree();
int aNumberOfKnots = theBSpline.NumberOfKnots();
int aNumberOfPoles = theBSpline.NumberOfPoles();
PrintDomain(theBSpline);
PrintParameter("Degree", aDegree);
PrintParameter("Number Of Knots", aNumberOfKnots);
PrintParameter("Number Of Poles", aNumberOfPoles);
PrintCollection("Knots", aNumberOfKnots, (int i) =>
{
double aKnot = theBSpline.Knot(i);
PrintParameter(aKnot);
});
PrintCollection("Multiplicities", aNumberOfKnots, (int i) => {
int aMultiplicity = theBSpline.Multiplicity(i);
PrintParameter(aMultiplicity);
});
PrintCollection("Poles", aNumberOfPoles, (int i) => {
ModelData_Point2d aPole = theBSpline.Pole(i);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfPoles, (int i) => {
double aWeight = theBSpline.Weight(i);
PrintParameter(aWeight);
});
}
public static void PrintOffsetCurve(ModelData_OffsetCurve2d theOffset)
{
PrintName("Offset Curve 2d");
double anOffset = theOffset.Offset();
PrintDomain(theOffset);
PrintParameter("Offset", anOffset);
Console.Write("Basis Curve = ");
PrintPCurveInfo(theOffset.BasisCurve());
}
public static void PrintTrimmedCurve(ModelData_TrimmedCurve2d theTrimmed)
{
PrintName("Trimmed Curve 2d");
PrintDomain(theTrimmed);
Console.Write("Basis Curve = ");
PrintPCurveInfo(theTrimmed.BasisCurve());
}
}
}

shape_explorer.cs

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2022, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
using cadex;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace brepgeometry
{
class ShapeExplorer : ModelData_Model.VoidElementVisitor
{
public override void Apply(ModelData_Part thePart)
{
ModelData_BRepRepresentation aBRep = thePart.BRepRepresentation();
if (aBRep != null)
{
Console.WriteLine("Part = \"{0}\"", thePart.Name());
ExploreBRep(aBRep);
}
}
private void ExploreBRep(ModelData_BRepRepresentation theBRep)
{
// Get() method retrieves bodies listed in B-Rep representation by calling data providers flushing
// Flushing isn't an elementary process so it can take a significant time (seconds, minutes depending on a model structure)
ModelData_BodyList aBodyList = theBRep.Get();
// Iterate over bodies
for (uint i = 0; i < aBodyList.Size(); ++i)
{
ModelData_Body aBody = aBodyList.Access(i);
Console.WriteLine("Body {0}: -type {1}", i, BodyType(aBody));
ExploreShape(aBody);
}
}
// Recursive iterating over the Shape until reaching vertices
private void ExploreShape(ModelData_Shape theShape)
{
if (theShape.Type() == ModelData_ShapeType.ModelData_ST_Face)
{
myCurrentFace = ModelData_Face.Cast(theShape);
}
++myBase.myNestingLevel;
ModelData_Shape.Iterator aShapeIt = new ModelData_Shape.Iterator(theShape);
while (aShapeIt.HasNext())
{
ModelData_Shape aShape = aShapeIt.Next();
PrintShape(aShape);
ExploreShape(aShape);
}
if (theShape.Type() == ModelData_ShapeType.ModelData_ST_Face)
{
myCurrentFace = null;
}
--myBase.myNestingLevel;
}
// Returns body type name
private string BodyType(ModelData_Body theBody)
{
switch (theBody.BodyType())
{
case ModelData_BodyType.ModelData_BT_Solid: return "Solid";
case ModelData_BodyType.ModelData_BT_Sheet: return "Sheet";
case ModelData_BodyType.ModelData_BT_Wireframe: return "Wireframe";
case ModelData_BodyType.ModelData_BT_Acorn: return "Acorn";
}
return "Undefined";
}
// Prints shape type name and prints shape info in some cases
private void PrintShape(ModelData_Shape theShape)
{
myBase.PrintTabulation();
switch (theShape.Type())
{
case ModelData_ShapeType.ModelData_ST_Solid:
Console.Write("Solid");
break;
case ModelData_ShapeType.ModelData_ST_Shell:
PrintShell(ModelData_Shell.Cast(theShape));
break;
case ModelData_ShapeType.ModelData_ST_Wire:
PrintWire(ModelData_Wire.Cast(theShape));
break;
case ModelData_ShapeType.ModelData_ST_Face:
PrintFace(ModelData_Face.Cast(theShape));
break;
case ModelData_ShapeType.ModelData_ST_Edge:
PrintEdge(ModelData_Edge.Cast(theShape));
break;
case ModelData_ShapeType.ModelData_ST_Vertex:
PrintVertex(ModelData_Vertex.Cast(theShape));
break;
default: Console.Write("Undefined"); break;
}
Console.WriteLine();
}
private void PrintShell(ModelData_Shell theWire)
{
BaseExplorer.PrintName("Shell");
++myBase.myNestingLevel;
BaseExplorer.PrintOrientation(theWire.Orientation());
--myBase.myNestingLevel;
}
private void PrintWire(ModelData_Wire theWire)
{
BaseExplorer.PrintName("Wire");
++myBase.myNestingLevel;
BaseExplorer.PrintOrientation(theWire.Orientation());
--myBase.myNestingLevel;
}
private void PrintFace(ModelData_Face theFace)
{
BaseExplorer.PrintName("Face");
++myBase.myNestingLevel;
BaseExplorer.PrintOrientation(theFace.Orientation());
Console.WriteLine();
ModelData_Surface aSurface = theFace.Surface();
myBase.PrintTabulation();
BaseExplorer.PrintName("Surface");
SurfaceExplorer.PrintSurface(aSurface);
--myBase.myNestingLevel;
}
private void PrintEdge(ModelData_Edge theEdge)
{
BaseExplorer.PrintName("Edge");
++myBase.myNestingLevel;
if (theEdge.IsDegenerated())
{
Console.Write("Degenerated: ");
}
BaseExplorer.PrintOrientation(theEdge.Orientation());
BaseExplorer.PrintParameter("Tolerance", theEdge.Tolerance());
if (!theEdge.IsDegenerated())
{
double aFirstParameter = 0, aLastParameter = 0;
ModelData_Curve aCurve = theEdge.Curve(ref aFirstParameter, ref aLastParameter);
Console.WriteLine();
myBase.PrintTabulation();
BaseExplorer.PrintName("Curve");
BaseExplorer.PrintRange("Edge Range", aFirstParameter, aLastParameter);
CurveExplorer.PrintCurveInfo(aCurve);
}
if (myCurrentFace != null)
{
double aFirstParameter2d = 0, aLastParameter2d = 0;
ModelData_Curve2d aPCurve = theEdge.PCurve(myCurrentFace,
ref aFirstParameter2d,
ref aLastParameter2d);
Console.WriteLine();
myBase.PrintTabulation();
BaseExplorer.PrintName("PCurve");
BaseExplorer.PrintRange("Edge Range", aFirstParameter2d, aLastParameter2d);
PCurveExplorer.PrintPCurveInfo(aPCurve);
}
--myBase.myNestingLevel;
}
private void PrintVertex(ModelData_Vertex theVertex)
{
BaseExplorer.PrintName("Vertex");
ModelData_Point aLoc = theVertex.Point();
double aTolerance = theVertex.Tolerance();
BaseExplorer.PrintOrientation(theVertex.Orientation());
BaseExplorer.PrintParameter("Tolerance", aTolerance);
BaseExplorer.PrintParameter("Location", aLoc);
}
private BaseExplorer myBase = new BaseExplorer();
private ModelData_Face myCurrentFace = null;
}
}

surface_explorer.cs

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2022, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
using cadex;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace brepgeometry
{
class SurfaceExplorer : BaseExplorer
{
// Prints surface type name and prints shape info in some cases
public static void PrintSurface(ModelData_Surface theSurface)
{
switch (theSurface.Type())
{
case ModelData_SurfaceType.ModelData_ST_Plane:
PrintPlane(ModelData_Plane.Cast(theSurface));
break;
case ModelData_SurfaceType.ModelData_ST_Cylinder:
PrintCylinder(ModelData_CylindricalSurface.Cast(theSurface));
break;
case ModelData_SurfaceType.ModelData_ST_Cone:
PrintCone(ModelData_ConicalSurface.Cast(theSurface));
break;
case ModelData_SurfaceType.ModelData_ST_Sphere:
PrintSphere(ModelData_SphericalSurface.Cast(theSurface));
break;
case ModelData_SurfaceType.ModelData_ST_Torus:
PrintTorus(ModelData_ToroidalSurface.Cast(theSurface));
break;
case ModelData_SurfaceType.ModelData_ST_LinearExtrusion:
PrintLinearExtrusion(ModelData_SurfaceOfLinearExtrusion.Cast(theSurface));
break;
case ModelData_SurfaceType.ModelData_ST_Revolution:
PrintRevolution(ModelData_SurfaceOfRevolution.Cast(theSurface));
break;
case ModelData_SurfaceType.ModelData_ST_Bezier:
PrintBezierSurface(ModelData_BezierSurface.Cast(theSurface));
break;
case ModelData_SurfaceType.ModelData_ST_BSpline:
PrintBSplineSurface(ModelData_BSplineSurface.Cast(theSurface));
break;
case ModelData_SurfaceType.ModelData_ST_Offset:
PrintOffsetSurface(ModelData_OffsetSurface.Cast(theSurface));
break;
case ModelData_SurfaceType.ModelData_ST_Trimmed:
PrintTrimmedSurface(ModelData_RectangularTrimmedSurface.Cast(theSurface));
break;
default:
break;
}
}
public static void PrintPlane(ModelData_Plane thePlane)
{
PrintName("Plane");
PrintElementary(thePlane);
}
public static void PrintCylinder(ModelData_CylindricalSurface theCylinder)
{
PrintName("Cylinder");
double aRadius = theCylinder.Radius();
PrintElementary(theCylinder);
PrintParameter("Radius", aRadius);
}
public static void PrintCone(ModelData_ConicalSurface theCone)
{
PrintName("Cone");
double aRadius = theCone.Radius();
double aSemiAngle = theCone.SemiAngle();
PrintElementary(theCone);
PrintParameter("Radius", aRadius);
PrintParameter("Semi-Angle", aSemiAngle);
}
public static void PrintSphere(ModelData_SphericalSurface theSphere)
{
PrintName("Sphere");
double aRadius = theSphere.Radius();
PrintElementary(theSphere);
PrintParameter("Radius", aRadius);
}
public static void PrintTorus(ModelData_ToroidalSurface theTorus)
{
PrintName("Torus");
double aMajorRadius = theTorus.MajorRadius();
double aMinorRadius = theTorus.MinorRadius();
PrintElementary(theTorus);
PrintParameter("Major Radius", aMajorRadius);
PrintParameter("Minor Radius", aMinorRadius);
}
public static void PrintLinearExtrusion(ModelData_SurfaceOfLinearExtrusion theLinearExtrusion)
{
PrintName("Linear Extrusion Surface");
ModelData_Direction aDir = theLinearExtrusion.Direction();
PrintDomain(theLinearExtrusion);
PrintParameter("Direction", aDir);
Console.Write("Basis Curve = ");
CurveExplorer.PrintCurveInfo(theLinearExtrusion.BasisCurve());
}
public static void PrintRevolution(ModelData_SurfaceOfRevolution theRevolution)
{
PrintName("Revolution Surface");
ModelData_Direction aDir = theRevolution.Direction();
ModelData_Point aLoc = theRevolution.Location();
PrintDomain(theRevolution);
PrintParameter("Location", aLoc);
PrintParameter("Direction", aDir);
Console.Write("Basis Curve = ");
CurveExplorer.PrintCurveInfo(theRevolution.BasisCurve());
}
public static void PrintBezierSurface(ModelData_BezierSurface theBezier)
{
PrintName("Bezier Surface");
int aUDegree = theBezier.UDegree();
int aVDegree = theBezier.VDegree();
int aNumberOfUPoles = theBezier.NumberOfUPoles();
int aNumberOfVPoles = theBezier.NumberOfVPoles();
PrintDomain(theBezier);
PrintParameter("U Degree", aUDegree);
PrintParameter("V Degree", aVDegree);
PrintParameter("Number Of U Poles", aNumberOfUPoles);
PrintParameter("Number Of V Poles", aNumberOfVPoles);
PrintCollection("Poles", aNumberOfUPoles, aNumberOfVPoles, (int i, int j) => {
ModelData_Point aPole = theBezier.Pole(i, j);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfUPoles, aNumberOfVPoles, (int i, int j) => {
double aWeight = theBezier.Weight(i, j);
PrintParameter(aWeight);
});
}
public static void PrintBSplineSurface(ModelData_BSplineSurface theBSpline)
{
PrintName("BSpline Surface");
int aUDegree = theBSpline.UDegree();
int aVDegree = theBSpline.VDegree();
int aNumberOfUKnots = theBSpline.NumberOfUKnots();
int aNumberOfVKnots = theBSpline.NumberOfVKnots();
int aNumberOfUPoles = theBSpline.NumberOfUPoles();
int aNumberOfVPoles = theBSpline.NumberOfVPoles();
PrintDomain(theBSpline);
PrintParameter("U Degree", aUDegree);
PrintParameter("V Degree", aVDegree);
PrintParameter("Number Of U Knots", aNumberOfUKnots);
PrintParameter("Number Of V Knots", aNumberOfVKnots);
PrintParameter("Number Of U Poles", aNumberOfUPoles);
PrintParameter("Number Of V Poles", aNumberOfVPoles);
PrintCollection("U Knots", aNumberOfUKnots, (int i) => {
double aKnot = theBSpline.UKnot(i);
PrintParameter(aKnot);
});
PrintCollection("V Knots", aNumberOfVKnots, (int i) => {
double aKnot = theBSpline.VKnot(i);
PrintParameter(aKnot);
});
PrintCollection("U Multiplicities", aNumberOfUKnots, (int i) => {
int aUMultiplicity = theBSpline.UMultiplicity(i);
PrintParameter(aUMultiplicity);
});
PrintCollection("V Multiplicities", aNumberOfVKnots, (int i) => {
int aVMultiplicity = theBSpline.VMultiplicity(i);
PrintParameter(aVMultiplicity);
});
PrintCollection("Poles", aNumberOfUPoles, aNumberOfVPoles, (int i, int j) => {
ModelData_Point aPole = theBSpline.Pole(i, j);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfUPoles, aNumberOfVPoles, (int i, int j) => {
double aWeight = theBSpline.Weight(i, j);
PrintParameter(aWeight);
});
}
public static void PrintOffsetSurface(ModelData_OffsetSurface theOffset)
{
PrintName("Offset Surface");
double anOffset = theOffset.Offset();
PrintDomain(theOffset);
PrintParameter("Offset", anOffset);
Console.Write("Basis Surface = ");
PrintSurface(theOffset.BasisSurface());
}
public static void PrintTrimmedSurface(ModelData_RectangularTrimmedSurface theTrimmed)
{
PrintName("Trimmed Surface");
PrintDomain(theTrimmed);
Console.Write("Basis Surface = ");
PrintSurface(theTrimmed.BasisSurface());
}
}
}

Program.cs

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2022, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
using cadex;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace brepgeometry
{
class Program
{
// For more information see https://stackoverflow.com/questions/8836093/how-can-i-specify-a-dllimport-path-at-runtime
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);
static int Main(string[] args)
{
// Add runtime path to CAD Exchanger libraries (e.g. compiled with Visual Studio 2015)
SetDllDirectory("../../../../../../win64/vc14.1/bin");
string aKey = LicenseKey.Value();
// Activate the license (aKey must be defined in cadex_license.cs)
if (!LicenseManager.Activate(aKey))
{
Console.WriteLine("Failed to activate CAD Exchanger 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 XML file to be read");
return 1;
}
string aSource = args[0];
ModelData_Model aModel = new ModelData_Model();
if (!new ModelData_ModelReader().Read(new Base_UTF16String(aSource), aModel))
{
Console.WriteLine("Failed to read the file " + aSource);
return 1;
}
// Explore B-Rep representation of model parts
ShapeExplorer aVisitor = new ShapeExplorer();
aModel.Accept(aVisitor);
return 0;
}
}
}
ModelData_ShapeType
Defines shape type.
Definition: ModelData_ShapeType.hxx:24
ModelData_CurveType
Defines curve type.
Definition: ModelData_CurveType.hxx:24
ModelData_ShapeOrientation
Defines shape orientation.
Definition: ModelData_ShapeOrientation.hxx:24
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22
ModelData_SurfaceType
Defines surface type.
Definition: ModelData_SurfaceType.hxx:24
ModelData_BodyType
Defines a body type.
Definition: ModelData_BodyType.hxx:24