Hide menu
Loading...
Searching...
No Matches
exploring/brepgeometry/brepgeometry.java

Refer to the B-Rep Geometry Exploration Example.

base_explorer.java

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, 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.
//
// ****************************************************************************
import java.util.function.Consumer;
import java.util.function.BiConsumer;
import cadex.*;
public class base_explorer {
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) {
System.out.print(aName + " = [" + aFirstParameter + ", " + aLastParameter + "]; ");
}
public static void PrintDomain(final ModelData_Curve theCurve) {
PrintRange("Domain", theCurve.UMin(), theCurve.UMax());
}
public static void PrintDomain(final ModelData_Curve2d theCurve) {
PrintRange("Domain", theCurve.UMin(), theCurve.UMax());
}
public static void PrintDomain(final ModelData_Surface theSurface) {
PrintRange("Domain U", theSurface.UMin(), theSurface.UMax());
PrintRange("V", theSurface.VMin(), theSurface.VMax());
}
public static void PrintParameter(ModelData_Point theValue) {
System.out.print("(" + theValue.X() + ", " + theValue.Y() + ", " + theValue.Z() + "); ");
}
public static void PrintParameter(ModelData_Direction theValue) {
System.out.print("(" + theValue.X() + ", " + theValue.Y() + ", " + theValue.Z() + "); ");
}
public static void PrintParameter(ModelData_Point2d theValue) {
System.out.print("(" + theValue.X() + ", " + theValue.Y() + "); ");
}
public static void PrintParameter(ModelData_Direction2d theValue) {
System.out.print("(" + theValue.X() + ", " + theValue.Y() + "); ");
}
public static void PrintParameter(double theValue) {
System.out.print(theValue + "; ");
}
public static void PrintParameter(String theName, ModelData_Point theValue) {
System.out.print(theName + " = ");
PrintParameter(theValue);
}
public static void PrintParameter(String theName, ModelData_Direction theValue) {
System.out.print(theName + " = ");
PrintParameter(theValue);
}
public static void PrintParameter(String theName, double theValue) {
System.out.print(theName + " = ");
PrintParameter(theValue);
}
public static void PrintParameter(String theName, ModelData_Point2d theValue) {
System.out.print(theName + " = ");
PrintParameter(theValue);
}
public static void PrintParameter(String theName, ModelData_Direction2d theValue) {
System.out.print(theName + " = ");
PrintParameter(theValue);
}
public static void PrintName(String theName) {
System.out.print(theName + ": ");
}
public static void PrintCollection(String theName,
int theFinalIndex,
Consumer<Integer> thePrintElement) {
if (theName != null) {
System.out.print(theName + " = ");
}
System.out.print("[");
for (Integer i = 1; i <= theFinalIndex; ++i) {
if (i > 3) {
System.out.print("...");
break;
}
thePrintElement.accept(i);
}
System.out.print("]; ");
}
public static void PrintCollection(String theName,
int theFinalIndex1,
int theFinalIndex2,
BiConsumer<Integer, Integer> thePrintElement) {
PrintCollection(theName, theFinalIndex1, (Integer i) ->
{
PrintCollection(null, theFinalIndex2, (Integer j) -> {thePrintElement.accept(i, j); });
});
}
public static void PrintOrientation(final ModelData_ShapeOrientation theOrientation) {
System.out.print("Orientation = ");
switch (theOrientation) {
case ModelData_SO_Forward: System.out.print("Forward"); break;
case ModelData_SO_Reversed: System.out.print("Reversed"); break;
default: System.out.print("Undefined"); break;
}
System.out.print("; ");
}
public void PrintTabulation() {
for (int i = 0; i < myNestingLevel; ++i) {
System.out.print("--- ");
}
}
public int myNestingLevel = 0;
}
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22

curve_explorer.java

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, 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.
//
// ****************************************************************************
import cadex.*;
public class curve_explorer extends base_explorer {
public static void PrintCurveInfo(final ModelData_Curve theCurve) {
switch (theCurve.Type()) {
case ModelData_CT_Line:
PrintLine(ModelData_Line.Cast(theCurve));
break;
case ModelData_CT_Circle:
PrintCircle(ModelData_Circle.Cast(theCurve));
break;
case ModelData_CT_Ellipse:
PrintEllipse(ModelData_Ellipse.Cast(theCurve));
break;
case ModelData_CT_Hyperbola:
PrintHyperbola(ModelData_Hyperbola.Cast(theCurve));
break;
case ModelData_CT_Parabola:
PrintParabola(ModelData_Parabola.Cast(theCurve));
break;
case ModelData_CT_Bezier:
PrintBezierCurve(ModelData_BezierCurve.Cast(theCurve));
break;
case ModelData_CT_BSpline:
PrintBSplineCurve(ModelData_BSplineCurve.Cast(theCurve));
break;
case ModelData_CT_Offset:
PrintOffsetCurve(ModelData_OffsetCurve.Cast(theCurve));
break;
case ModelData_CT_Trimmed:
PrintTrimmedCurve(ModelData_TrimmedCurve.Cast(theCurve));
break;
default:
break;
}
}
public static void PrintLine(final 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(final ModelData_Circle theCircle) {
PrintName("Circle");
double aRadius = theCircle.Radius();
PrintElementary(theCircle);
PrintParameter("Radius", aRadius);
}
public static void PrintEllipse(final 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(final 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(final ModelData_Parabola theParabola) {
PrintName("Parabola");
double aFocal = theParabola.Focal();
PrintElementary(theParabola);
PrintParameter("Focal", aFocal);
}
public static void PrintBezierCurve(final 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, (Integer i) ->
{
ModelData_Point aPole = theBezier.Pole(i);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfPoles, (Integer i) ->
{
double aWeight = theBezier.Weight(i);
PrintParameter(aWeight);
});
}
public static void PrintBSplineCurve(final 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, (Integer i) ->
{
double aKnot = theBSpline.Knot(i);
PrintParameter(aKnot);
});
PrintCollection("Multiplicities", aNumberOfKnots, (Integer i) ->
{
int aMultiplicity = theBSpline.Multiplicity(i);
PrintParameter(aMultiplicity);
});
PrintCollection("Poles", aNumberOfPoles, (Integer i) ->
{
ModelData_Point aPole = theBSpline.Pole(i);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfPoles, (Integer i) ->
{
double aWeight = theBSpline.Weight(i);
PrintParameter(aWeight);
});
}
public static void PrintOffsetCurve(final ModelData_OffsetCurve theOffset) {
PrintName("Offset Curve");
final ModelData_Direction aDir = theOffset.Direction();
double anOffset = theOffset.Offset();
PrintDomain(theOffset);
PrintParameter("Direction", aDir);
PrintParameter("Offset", anOffset);
System.out.print("Basis Curve = ");
PrintCurveInfo(theOffset.BasisCurve());
}
public static void PrintTrimmedCurve(final ModelData_TrimmedCurve theTrimmed) {
PrintName("Trimmed Curve");
PrintDomain(theTrimmed);
System.out.print("Basis Curve = ");
PrintCurveInfo(theTrimmed.BasisCurve());
}
}

pcurve_explorer.java

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, 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.
//
// ****************************************************************************
import cadex.*;
public class pcurve_explorer extends base_explorer {
public static void PrintPCurveInfo(ModelData_Curve2d theCurve) {
switch (theCurve.Type()) {
case ModelData_CT_Line:
PrintLine(ModelData_Line2d.Cast(theCurve));
break;
case ModelData_CT_Circle:
PrintCircle(ModelData_Circle2d.Cast(theCurve));
break;
case ModelData_CT_Ellipse:
PrintEllipse(ModelData_Ellipse2d.Cast(theCurve));
break;
case ModelData_CT_Hyperbola:
PrintHyperbola(ModelData_Hyperbola2d.Cast(theCurve));
break;
case ModelData_CT_Parabola:
PrintParabola(ModelData_Parabola2d.Cast(theCurve));
break;
case ModelData_CT_Bezier:
PrintBezierCurve(ModelData_BezierCurve2d.Cast(theCurve));
break;
case ModelData_CT_BSpline:
PrintBSplineCurve(ModelData_BSplineCurve2d.Cast(theCurve));
break;
case ModelData_CT_Offset:
PrintOffsetCurve(ModelData_OffsetCurve2d.Cast(theCurve));
break;
case 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, (Integer i) -> {
ModelData_Point2d aPole = theBezier.Pole(i);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfPoles, (Integer 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, (Integer i) ->
{
double aKnot = theBSpline.Knot(i);
PrintParameter(aKnot);
});
PrintCollection("Multiplicities", aNumberOfKnots, (Integer i) -> {
int aMultiplicity = theBSpline.Multiplicity(i);
PrintParameter(aMultiplicity);
});
PrintCollection("Poles", aNumberOfPoles, (Integer i) -> {
ModelData_Point2d aPole = theBSpline.Pole(i);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfPoles, (Integer 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);
System.out.print("Basis Curve = ");
PrintPCurveInfo(theOffset.BasisCurve());
}
public static void PrintTrimmedCurve(ModelData_TrimmedCurve2d theTrimmed) {
PrintName("Trimmed Curve 2d");
PrintDomain(theTrimmed);
System.out.print("Basis Curve = ");
PrintPCurveInfo(theTrimmed.BasisCurve());
}
}

shape_explorer.java

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, 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.
//
// ****************************************************************************
import cadex.*;
public class shape_explorer extends ModelData_Model.VoidElementVisitor {
@Override
public void Apply(ModelData_Part thePart) {
ModelData_BRepRepresentation aBRep = thePart.BRepRepresentation();
if (aBRep != null) {
System.out.println("Part = \"" + thePart.Name() + "\"");
ExploreBRep (aBRep);
}
}
private void ExploreBRep (final 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)
final ModelData_BodyList aBodyList = theBRep.Get();
// Iterate over bodies
for (int i = 0; i < aBodyList.Size(); ++i){
final ModelData_Body aBody = aBodyList.Element(i);
System.out.println("Body " + i + ": " + BodyType(aBody));
ExploreShape(aBody);
}
}
// Recursive iterating over the Shape until reaching vertices
private void ExploreShape (final 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 final String BodyType (final ModelData_Body theBody) {
switch (theBody.BodyType()) {
case ModelData_BT_Solid: return "Solid";
case ModelData_BT_Sheet: return "Sheet";
case ModelData_BT_Wireframe: return "Wireframe";
case ModelData_BT_Acorn: return "Acorn";
default:
break;
}
return "Undefined";
}
// Returns shape type name and prints shape info in some cases
private void PrintShape (final ModelData_Shape theShape) {
myBase.PrintTabulation();
switch (theShape.Type()) {
case ModelData_ST_Solid: System.out.print("Solid"); break;
case ModelData_ST_Shell: PrintShell (ModelData_Shell.Cast (theShape)); break;
case ModelData_ST_Wire: PrintWire (ModelData_Wire.Cast (theShape)); break;
case ModelData_ST_Face: PrintFace (ModelData_Face.Cast (theShape)); break;
case ModelData_ST_Edge: PrintEdge (ModelData_Edge.Cast (theShape)); break;
case ModelData_ST_Vertex: PrintVertex(ModelData_Vertex.Cast (theShape)); break;
default: System.out.print("Undefined"); break;
}
System.out.println("");
}
private void PrintShell (final ModelData_Shell theWire) {
myBase.PrintName("Shell");
++myBase.myNestingLevel;
myBase.PrintOrientation(theWire.Orientation());
--myBase.myNestingLevel;
}
private void PrintWire(final ModelData_Wire theWire) {
myBase.PrintName("Wire");
++myBase.myNestingLevel;
myBase.PrintOrientation(theWire.Orientation());
--myBase.myNestingLevel;
}
private void PrintFace (final ModelData_Face theFace) {
myBase.PrintName("Face");
++myBase.myNestingLevel;
myBase.PrintOrientation (theFace.Orientation());
System.out.println("");
ModelData_Surface aSurface = theFace.Surface();
myBase.PrintTabulation();
myBase.PrintName("Surface");
surface_explorer.PrintSurface (aSurface);
--myBase.myNestingLevel;
}
private void PrintEdge (final ModelData_Edge theEdge) {
myBase.PrintName("Edge");
++myBase.myNestingLevel;
if (theEdge.IsDegenerated()) {
System.out.print("Degenerated: ");
}
myBase.PrintOrientation(theEdge.Orientation());
myBase.PrintParameter("Tolerance", theEdge.Tolerance());
if (!theEdge.IsDegenerated()) {
double[] aFirstParameter = {0}, aLastParameter = {0};
ModelData_Curve aCurve = theEdge.Curve(aFirstParameter, aLastParameter);
System.out.println("");
myBase.PrintTabulation();
myBase.PrintName("Curve");
myBase.PrintRange("Edge Range", aFirstParameter[0], aLastParameter[0]);
curve_explorer.PrintCurveInfo(aCurve);
}
if (myCurrentFace != null) {
double[] aFirstParameter2d = {0}, aLastParameter2d = {0};
final ModelData_Curve2d aPCurve = theEdge.PCurve(myCurrentFace,
aFirstParameter2d,
aLastParameter2d);
System.out.println("");
myBase.PrintTabulation();
myBase.PrintName("PCurve");
myBase.PrintRange("Edge Range", aFirstParameter2d[0], aLastParameter2d[0]);
pcurve_explorer.PrintPCurveInfo(aPCurve);
}
--myBase.myNestingLevel;
}
private void PrintVertex(final ModelData_Vertex theVertex) {
myBase.PrintName ("Vertex");
ModelData_Point aLoc = theVertex.Point();
double aTolerance = theVertex.Tolerance();
myBase.PrintOrientation(theVertex.Orientation());
myBase.PrintParameter("Tolerance", aTolerance);
myBase.PrintParameter("Location", aLoc);
}
private base_explorer myBase = new base_explorer();
private ModelData_Face myCurrentFace = null;
}

surface_explorer.java

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, 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.
//
// ****************************************************************************
import cadex.*;
public class surface_explorer extends base_explorer {
public static void PrintSurface(ModelData_Surface theSurface) {
switch (theSurface.Type()) {
case ModelData_ST_Plane:
PrintPlane(ModelData_Plane.Cast(theSurface));
break;
case ModelData_ST_Cylinder:
PrintCylinder(ModelData_CylindricalSurface.Cast(theSurface));
break;
case ModelData_ST_Cone:
PrintCone(ModelData_ConicalSurface.Cast(theSurface));
break;
case ModelData_ST_Sphere:
PrintSphere(ModelData_SphericalSurface.Cast(theSurface));
break;
case ModelData_ST_Torus:
PrintTorus(ModelData_ToroidalSurface.Cast(theSurface));
break;
case ModelData_ST_LinearExtrusion:
PrintLinearExtrusion(ModelData_SurfaceOfLinearExtrusion.Cast(theSurface));
break;
case ModelData_ST_Revolution:
PrintRevolution(ModelData_SurfaceOfRevolution.Cast(theSurface));
break;
case ModelData_ST_Bezier:
PrintBezierSurface(ModelData_BezierSurface.Cast(theSurface));
break;
case ModelData_ST_BSpline:
PrintBSplineSurface(ModelData_BSplineSurface.Cast(theSurface));
break;
case ModelData_ST_Offset:
PrintOffsetSurface(ModelData_OffsetSurface.Cast(theSurface));
break;
case 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);
System.out.print("Basis Curve = ");
curve_explorer.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);
System.out.print("Basis Curve = ");
curve_explorer.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, (Integer i, Integer j) -> {
ModelData_Point aPole = theBezier.Pole(i, j);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfUPoles, aNumberOfVPoles, (Integer i, Integer 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, (Integer i) -> {
double aKnot = theBSpline.UKnot(i);
PrintParameter(aKnot);
});
PrintCollection("V Knots", aNumberOfVKnots, (Integer i) -> {
double aKnot = theBSpline.VKnot(i);
PrintParameter(aKnot);
});
PrintCollection("U Multiplicities", aNumberOfUKnots, (Integer i) -> {
int aUMultiplicity = theBSpline.UMultiplicity(i);
PrintParameter(aUMultiplicity);
});
PrintCollection("V Multiplicities", aNumberOfVKnots, (Integer i) -> {
int aVMultiplicity = theBSpline.VMultiplicity(i);
PrintParameter(aVMultiplicity);
});
PrintCollection("Poles", aNumberOfUPoles, aNumberOfVPoles, (Integer i, Integer j) -> {
ModelData_Point aPole = theBSpline.Pole(i, j);
PrintParameter(aPole);
});
PrintCollection("Weights", aNumberOfUPoles, aNumberOfVPoles, (Integer i, Integer 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);
System.out.print("Basis Surface = ");
PrintSurface(theOffset.BasisSurface());
}
public static void PrintTrimmedSurface(ModelData_RectangularTrimmedSurface theTrimmed) {
PrintName("Trimmed Surface");
PrintDomain(theTrimmed);
System.out.print("Basis Surface = ");
PrintSurface(theTrimmed.BasisSurface());
}
}

brepgeometry.java

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, 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.
//
// ****************************************************************************
import cadex.*;
public class brepgeometry {
static {
try {
System.loadLibrary("CadExCore");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String[] args) {
String aKey = LicenseKey.Value();
// Activate the license (aKey must be defined in LicenseKey.java)
if (!LicenseManager.Activate(aKey)) {
System.out.println("Failed to activate CAD Exchanger license.");
System.exit(1);
}
if (args.length != 1) {
System.out.println("Usage: " + " <input_file>, where:");
System.out.println(" <input_file> is a name of the XML file to be read");
System.exit(1);
}
String aSource = args[0];
ModelData_Model aModel = new ModelData_Model();
if (!new ModelData_ModelReader().Read(new Base_UTF16String(aSource), aModel)) {
System.out.println("Failed to read the file");
System.exit(1);
}
shape_explorer aVisitor = new shape_explorer();
aModel.Accept(aVisitor);
}
}