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

Refer to the B-Rep Geometry Exploration Example.

base_explorer.py

1#!/usr/bin/env python3
2
3# $Id$
4
5# Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
6# Copyright (C) 2014-2023, CADEX. All rights reserved.
7
8# This file is part of the CAD Exchanger software.
9
10# You may use this file under the terms of the BSD license as follows:
11
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions are met:
14# * Redistributions of source code must retain the above copyright notice,
15# this list of conditions and the following disclaimer.
16# * Redistributions in binary form must reproduce the above copyright notice,
17# this list of conditions and the following disclaimer in the documentation
18# and/or other materials provided with the distribution.
19
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31
32
33import sys
34from pathlib import Path
35import os
36
37
38import cadexchanger.CadExCore as cadex
39
40sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
41
42class BaseExplorer:
43 def __init__(self):
44 super().__init__()
45 self.myNestingLevel = 0
46
47 @classmethod
48 def PrintElementary(cls, theGeometry):
49 cls.PrintDomain(theGeometry)
50 aPosition = theGeometry.Position()
51 aLoc = aPosition.Location()
52 anAxis = aPosition.Axis()
53 aXDir = aPosition.XDirection()
54 aYDir = aPosition.YDirection()
55 cls.PrintNamedParameter("Location", aLoc)
56 cls.PrintNamedParameter("Axis", anAxis)
57 cls.PrintNamedParameter("X Direction", aXDir)
58 cls.PrintNamedParameter("Y Direction", aYDir)
59
60 @classmethod
61 def PrintElementary2d(cls, theGeometry):
62 cls.PrintDomain(theGeometry)
63 aPosition = theGeometry.Position()
64 aLoc = aPosition.Location()
65 aXDir = aPosition.XDirection()
66 aYDir = aPosition.YDirection()
67 cls.PrintNamedParameter("Location", aLoc)
68 cls.PrintNamedParameter("X Direction", aXDir)
69 cls.PrintNamedParameter("Y Direction", aYDir)
70
71 @classmethod
72 def PrintRange(cls, aName: str, aFirstParameter: float, aLastParameter: float):
73 print(f"{aName} = [{aFirstParameter}, {aLastParameter}]; ", end="")
74
75 @classmethod
76 def PrintCurveDomain(cls, theCurve):
77 cls.PrintRange("Domain", theCurve.UMin(), theCurve.UMax())
78
79 @classmethod
80 def PrintSurfaceDomain(cls, theSurface):
81 cls.PrintRange("Domain U", theSurface.UMin(), theSurface.UMax())
82 cls.PrintRange("V", theSurface.VMin(), theSurface.VMax())
83
84 @classmethod
85 def PrintDomain(cls, theValue):
86 if isinstance(theValue, cadex.ModelData_Curve) or isinstance(theValue, cadex.ModelData_Curve2d):
87 cls.PrintCurveDomain(theValue)
88 elif isinstance(theValue, cadex.ModelData_Surface):
89 cls.PrintSurfaceDomain(theValue)
90
91 @classmethod
92 def Print3dParameter(cls, thePoint):
93 print(f"({thePoint.X()}, {thePoint.Y()}, {thePoint.Z()}); ", end="")
94
95 @classmethod
96 def Print2dParameter(cls, thePoint):
97 print(f"({thePoint.X()}, {thePoint.Y()}); ", end="")
98
99 @classmethod
100 def Print1dParameter(cls, theValue):
101 print(f"{theValue}; ", end="")
102
103 @classmethod
104 def PrintParameter(cls, theValue):
105 if isinstance(theValue, cadex.ModelData_Point) or isinstance(theValue, cadex.ModelData_Direction):
106 cls.Print3dParameter(theValue)
107 elif isinstance(theValue, cadex.ModelData_Point2d) or isinstance(theValue, cadex.ModelData_Direction2d):
108 cls.Print2dParameter(theValue)
109 elif isinstance(theValue, float):
110 cls.Print1dParameter(theValue)
111
112 @classmethod
113 def PrintNamedParameter(cls, theName, TheValue):
114 print(f"{theName} = ", end="")
115 cls.PrintParameter(TheValue)
116
117 @classmethod
118 def PrintName(cls, theName: str):
119 print(f"{theName}: ", end="")
120
121 @classmethod
122 def Print2dCollection(cls, theName: str, theFinalIndex: int, thePrintElement):
123 if theName:
124 print(f"{theName} = ", end="")
125
126 print("[", end="")
127 for i in range(1, theFinalIndex + 1):
128 if(i > 3):
129 print("...", end="")
130 break
131 thePrintElement(i)
132
133 print("]; ", end="")
134
135
136 @classmethod
137 def Print3dCollection(cls, theName: str, theFinalIndex1: int, theFinalIndex2: int, thePrintElement):
138 def PrintString(i: int):
139 cls.Print2dCollection(None, theFinalIndex2, lambda j: thePrintElement(i, j))
140 cls.Print2dCollection(theName, theFinalIndex1, PrintString)
141
142 @classmethod
143 def PrintOrientation(cls, theOrientation):
144 print("Orientation = ", end="")
145 if theOrientation == cadex.ModelData_SO_Forward:
146 print("Forward", end="")
147 elif theOrientation == cadex.ModelData_SO_Reversed:
148 print("Reversed", end="")
149 else:
150 print("Undefined")
151 print("; ", end="")
152
153 def PrintTabulation(self):
154 print("--- " * self.myNestingLevel, end="")
Base class for 2D curves.
Definition: ModelData_Curve2d.hxx:42
Base class for 3D curves.
Definition: ModelData_Curve.hxx:44
Defines a 2D direction.
Definition: ModelData_Direction2d.hxx:176
Defines a 3D direction.
Definition: ModelData_Direction.hxx:180
Defines a 2D point.
Definition: ModelData_Point2d.hxx:193
Defines a 3D point.
Definition: ModelData_Point.hxx:295
Base class for geometrical surfaces.
Definition: ModelData_Surface.hxx:44

curve_explorer.py

1#!/usr/bin/env python3
2
3# $Id$
4
5# Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
6# Copyright (C) 2014-2023, CADEX. All rights reserved.
7
8# This file is part of the CAD Exchanger software.
9
10# You may use this file under the terms of the BSD license as follows:
11
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions are met:
14# * Redistributions of source code must retain the above copyright notice,
15# this list of conditions and the following disclaimer.
16# * Redistributions in binary form must reproduce the above copyright notice,
17# this list of conditions and the following disclaimer in the documentation
18# and/or other materials provided with the distribution.
19
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31
32
33import sys
34from pathlib import Path
35import os
36
37
38import cadexchanger.CadExCore as cadex
39from base_explorer import BaseExplorer
40
41
42class CurveExplorer(BaseExplorer):
43 # Prints curve type name and prints shape info in some cases
44 @classmethod
45 def PrintCurveInfo(cls, theCurve: cadex.ModelData_Curve):
46 if theCurve.Type() == cadex.ModelData_CT_Line:
47 cls.PrintLine(cadex.ModelData_Line.Cast(theCurve))
48 elif theCurve.Type() == cadex.ModelData_CT_Circle:
49 cls.PrintCircle(cadex.ModelData_Circle.Cast(theCurve))
50 elif theCurve.Type() == cadex.ModelData_CT_Ellipse:
51 cls.PrintEllipse(cadex.ModelData_Ellipse.Cast(theCurve))
52 elif theCurve.Type() == cadex.ModelData_CT_Hyperbola:
53 cls.PrintHyperbola(cadex.ModelData_Hyperbola.Cast(theCurve))
54 elif theCurve.Type() == cadex.ModelData_CT_Parabola:
55 cls.PrintParabola(cadex.ModelData_Parabola.Cast(theCurve))
56 elif theCurve.Type() == cadex.ModelData_CT_Bezier:
57 cls.PrintBezierCurve(cadex.ModelData_BezierCurve.Cast(theCurve))
58 elif theCurve.Type() == cadex.ModelData_CT_BSpline:
59 cls.PrintBSplineCurve(cadex.ModelData_BSplineCurve.Cast(theCurve))
60 elif theCurve.Type() == cadex.ModelData_CT_Offset:
61 cls.PrintOffsetCurve(cadex.ModelData_OffsetCurve.Cast(theCurve))
62 elif theCurve.Type() == cadex.ModelData_CT_Trimmed:
63 cls.PrintTrimmedCurve(cadex.ModelData_TrimmedCurve.Cast(theCurve))
64
65 @classmethod
66 def PrintLine(cls, theLine: cadex.ModelData_Line):
67 cls.PrintName("Line")
68 aLoc = theLine.Location()
69 aDir = theLine.Direction()
70 cls.PrintDomain(theLine)
71 cls.PrintNamedParameter("Location", aLoc)
72 cls.PrintNamedParameter("Direction", aDir)
73
74 @classmethod
75 def PrintCircle(cls, theCircle: cadex.ModelData_Circle):
76 cls.PrintName("Circle")
77 aRadius = theCircle.Radius()
78 cls.PrintElementary(theCircle)
79 cls.PrintNamedParameter("Radius", aRadius)
80
81 @classmethod
82 def PrintEllipse(cls, theEllipse: cadex.ModelData_Ellipse):
83 cls.PrintName("Ellipse")
84 aMajorRadius = theEllipse.MajorRadius()
85 aMinorRadius = theEllipse.MinorRadius()
86 cls.PrintElementary(theEllipse)
87 cls.PrintNamedParameter("Major Radius", aMajorRadius)
88 cls.PrintNamedParameter("Minor Radius", aMinorRadius)
89
90 @classmethod
91 def PrintHyperbola(cls, theHyperbola: cadex.ModelData_Hyperbola):
92 cls.PrintName("Hyperbola")
93 aMajorRadius = theHyperbola.MajorRadius()
94 aMinorRadius = theHyperbola.MinorRadius()
95 cls.PrintElementary(theHyperbola)
96 cls.PrintNamedParameter("Major Radius", aMajorRadius)
97 cls.PrintNamedParameter("Minor Radius", aMinorRadius)
98
99 @classmethod
100 def PrintParabola(cls, theParabola: cadex.ModelData_Parabola):
101 cls.PrintName("Parabola")
102 aFocal = theParabola.Focal()
103 cls.PrintElementary(theParabola)
104 cls.PrintNamedParameter("Focal", aFocal)
105
106 @classmethod
107 def PrintBezierCurve(cls, theBezier: cadex.ModelData_BezierCurve):
108 cls.PrintName("Bezier Curve")
109 aDegree = theBezier.Degree()
110 aNumberOfPoles = theBezier.NumberOfPoles()
111 cls.PrintDomain(theBezier)
112 cls.PrintNamedParameter("Degree", aDegree)
113 cls.PrintNamedParameter("Number Of Poles", aNumberOfPoles)
114
115 def PrintPole(i):
116 aPole = theBezier.Pole(i)
117 cls.PrintParameter(aPole)
118
119 cls.Print2dCollection("Poles", aNumberOfPoles, PrintPole)
120
121 def PrintWeight(i):
122 aWeight = theBezier.Weight(i)
123 cls.PrintParameter(aWeight)
124
125 cls.Print2dCollection("Weights", aNumberOfPoles, PrintWeight)
126
127 @classmethod
128 def PrintBSplineCurve(cls, theBSpline: cadex.ModelData_BSplineCurve):
129 cls.PrintName("BSpline Curve")
130 aDegree = theBSpline.Degree()
131 aNumberOfKnots = theBSpline.NumberOfKnots()
132 aNumberOfPoles = theBSpline.NumberOfPoles()
133 cls.PrintDomain(theBSpline)
134 cls.PrintNamedParameter("Degree", aDegree)
135 cls.PrintNamedParameter("Number Of Knots", aNumberOfKnots)
136 cls.PrintNamedParameter("Number Of Poles", aNumberOfPoles)
137
138 def PrintKnot(i):
139 aKnot = theBSpline.Knot(i)
140 cls.PrintParameter(aKnot)
141
142 cls.Print2dCollection("Knots", aNumberOfKnots, PrintKnot)
143
144 def PrintMultiplicity(i):
145 aMultiplicity = theBSpline.Multiplicity(i)
146 cls.PrintParameter(aMultiplicity)
147
148 cls.Print2dCollection("Multiplicities", aNumberOfKnots, PrintMultiplicity)
149
150 def PrintPole(i):
151 aPole = theBSpline.Pole(i)
152 cls.PrintParameter(aPole)
153
154 cls.Print2dCollection("Poles", aNumberOfPoles, PrintPole)
155
156 def PrintWeight(i):
157 aWeight = theBSpline.Weight(i)
158 cls.PrintParameter(aWeight)
159
160 cls.Print2dCollection("Weights", aNumberOfPoles, PrintWeight)
161
162 @classmethod
163 def PrintOffsetCurve(cls, theOffset: cadex.ModelData_OffsetCurve):
164 cls.PrintName("Offset Curve")
165 aDir = theOffset.Direction()
166 anOffset = theOffset.Offset()
167 cls.PrintDomain(theOffset)
168 cls.PrintNamedParameter("Direction", aDir)
169 cls.PrintNamedParameter("Offset", anOffset)
170 print("Basis Curve = ", end="")
171 cls.PrintCurveInfo(theOffset.BasisCurve())
172
173 @classmethod
174 def PrintTrimmedCurve(cls, theTrimmed: cadex.ModelData_TrimmedCurve):
175 cls.PrintName("Trimmed Curve")
176 cls.PrintDomain(theTrimmed)
177 print("Basis Curve = ", end="")
178 cls.PrintCurveInfo(theTrimmed.BasisCurve())

pcurve_explorer.py

1#!/usr/bin/env python3
2
3# $Id$
4
5# Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
6# Copyright (C) 2014-2023, CADEX. All rights reserved.
7
8# This file is part of the CAD Exchanger software.
9
10# You may use this file under the terms of the BSD license as follows:
11
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions are met:
14# * Redistributions of source code must retain the above copyright notice,
15# this list of conditions and the following disclaimer.
16# * Redistributions in binary form must reproduce the above copyright notice,
17# this list of conditions and the following disclaimer in the documentation
18# and/or other materials provided with the distribution.
19
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31
32
33import sys
34from pathlib import Path
35import os
36
37
38import cadexchanger.CadExCore as cadex
39from base_explorer import BaseExplorer
40
41
42class PCurveExplorer(BaseExplorer):
43
44# Prints 2d curve type name and prints shape info in some cases
45 @classmethod
46 def PrintPCurveInfo(cls, theCurve):
47 if theCurve.Type() == cadex.ModelData_CT_Line:
48 cls.PrintLine(cadex.ModelData_Line2d.Cast(theCurve))
49 elif theCurve.Type() == cadex.ModelData_CT_Circle:
50 cls.PrintCircle(cadex.ModelData_Circle2d.Cast(theCurve))
51 elif theCurve.Type() == cadex.ModelData_CT_Ellipse:
52 cls.PrintEllipse(cadex.ModelData_Ellipse2d.Cast(theCurve))
53 elif theCurve.Type() == cadex.ModelData_CT_Hyperbola:
54 cls.PrintHyperbola(cadex.ModelData_Hyperbola2d.Cast(theCurve))
55 elif theCurve.Type() == cadex.ModelData_CT_Parabola:
56 cls.PrintParabola(cadex.ModelData_Parabola2d.Cast(theCurve))
57 elif theCurve.Type() == cadex.ModelData_CT_Bezier:
58 cls.PrintBezierCurve(cadex.ModelData_BezierCurve2d.Cast(theCurve))
59 elif theCurve.Type() == cadex.ModelData_CT_BSpline:
60 cls.PrintBSplineCurve(cadex.ModelData_BSplineCurve2d.Cast(theCurve))
61 elif theCurve.Type() == cadex.ModelData_CT_Offset:
62 cls.PrintOffsetCurve(cadex.ModelData_OffsetCurve2d.Cast(theCurve))
63 elif theCurve.Type() == cadex.ModelData_CT_Trimmed:
64 cls.PrintTrimmedCurve(cadex.ModelData_TrimmedCurve2d.Cast(theCurve))
65
66
67 @classmethod
68 def PrintLine(cls, theLine: cadex.ModelData_Line2d):
69 cls.PrintName("Line 2d")
70 aLoc = theLine.Location()
71 aDir = theLine.Direction()
72 cls.PrintDomain(theLine)
73 cls.PrintNamedParameter("Location", aLoc)
74 cls.PrintNamedParameter("Direction", aDir)
75
76 @classmethod
77 def PrintCircle(cls, theCircle: cadex.ModelData_Circle2d):
78 cls.PrintName("Circle 2d")
79 aRadius = theCircle.Radius()
80 cls.PrintElementary2d(theCircle)
81 cls.PrintNamedParameter("Radius", aRadius)
82
83 @classmethod
84 def PrintEllipse(cls, theEllipse: cadex.ModelData_Ellipse2d):
85 cls.PrintName("Ellipse 2d")
86 aMajorRadius = theEllipse.MajorRadius()
87 aMinorRadius = theEllipse.MinorRadius()
88 cls.PrintElementary2d(theEllipse)
89 cls.PrintNamedParameter("Major Radius", aMajorRadius)
90 cls.PrintNamedParameter("Minor Radius", aMinorRadius)
91
92 @classmethod
93 def PrintHyperbola(cls, theHyperbola: cadex.ModelData_Hyperbola2d):
94 cls.PrintName("Hyperbola 2d")
95 aMajorRadius = theHyperbola.MajorRadius()
96 aMinorRadius = theHyperbola.MinorRadius()
97 cls.PrintElementary2d(theHyperbola)
98 cls.PrintNamedParameter("Major Radius", aMajorRadius)
99 cls.PrintNamedParameter("Minor Radius", aMinorRadius)
100
101 @classmethod
102 def PrintParabola(cls, theParabola: cadex.ModelData_Parabola2d):
103 cls.PrintName("Parabola 2d")
104 aFocal = theParabola.Focal()
105 cls.PrintElementary2d(theParabola)
106 cls.PrintNamedParameter("Focal", aFocal)
107
108 @classmethod
109 def PrintBezierCurve(cls, theBezier: cadex.ModelData_BezierCurve2d):
110 cls.PrintName("Bezier Curve 2d")
111 aDegree = theBezier.Degree()
112 aNumberOfPoles = theBezier.NumberOfPoles()
113 cls.PrintDomain(theBezier)
114 cls.PrintNamedParameter("Degree", aDegree)
115 cls.PrintNamedParameter("Number Of Poles", aNumberOfPoles)
116
117 def PrintPole(i):
118 aPole = theBezier.Pole(i)
119 cls.PrintNamedParameter(aPole)
120
121 cls.Print2dCollection("Poles", aNumberOfPoles, PrintPole)
122
123 def PrintWeight(i):
124 aWeight = theBezier.Weight(i)
125 cls.PrintNamedParameter(aWeight)
126
127 cls.Print2dCollection("Weights", aNumberOfPoles, PrintWeight)
128
129
130 @classmethod
131 def PrintBSplineCurve(cls, theBSpline: cadex.ModelData_BSplineCurve2d):
132 cls.PrintName("BSpline Curve 2d")
133 aDegree = theBSpline.Degree()
134 aNumberOfKnots = theBSpline.NumberOfKnots()
135 aNumberOfPoles = theBSpline.NumberOfPoles()
136 cls.PrintDomain(theBSpline)
137 cls.PrintNamedParameter("Degree", aDegree)
138 cls.PrintNamedParameter("Number Of Knots", aNumberOfKnots)
139 cls.PrintNamedParameter("Number Of Poles", aNumberOfPoles)
140
141 def PrintKnot(i):
142 aKnot = theBSpline.Knot(i)
143 cls.PrintParameter(aKnot)
144
145 cls.Print2dCollection("Knots", aNumberOfKnots, PrintKnot)
146
147 def PrintMultiplicity(i):
148 aMultiplicity = theBSpline.Multiplicity(i)
149 cls.PrintParameter(aMultiplicity)
150
151 cls.Print2dCollection("Multiplicities", aNumberOfKnots, PrintMultiplicity)
152
153 def PrintPole(i):
154 aPole = theBSpline.Pole(i)
155 cls.PrintParameter(aPole)
156
157 cls.Print2dCollection("Poles", aNumberOfPoles, PrintPole)
158
159 def PrintWeight(i):
160 aWeight = theBSpline.Weight(i)
161 cls.PrintParameter(aWeight)
162
163 cls.Print2dCollection("Weights", aNumberOfPoles, PrintWeight)
164
165 @classmethod
166 def PrintOffsetCurve(cls, theOffset: cadex.ModelData_OffsetCurve2d):
167 cls.PrintName("Offset Curve 2d")
168 anOffset = theOffset.Offset()
169 cls.PrintDomain(theOffset)
170 cls.PrintParameter("Offset", anOffset)
171 print("Basis Curve = ", end="")
172 cls.PrintPCurveInfo(theOffset.BasisCurve())
173
174 @classmethod
175 def PrintTrimmedCurve(cls, theTrimmed: cadex.ModelData_TrimmedCurve2d):
176 cls.PrintName("Trimmed Curve 2d")
177 cls.PrintDomain(theTrimmed)
178 print("Basis Curve = ", end="")
179 cls.PrintPCurveInfo(theTrimmed.BasisCurve())

shape_explorer.py

1#!/usr/bin/env python3
2
3# $Id$
4
5# Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
6# Copyright (C) 2014-2023, CADEX. All rights reserved.
7
8# This file is part of the CAD Exchanger software.
9
10# You may use this file under the terms of the BSD license as follows:
11
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions are met:
14# * Redistributions of source code must retain the above copyright notice,
15# this list of conditions and the following disclaimer.
16# * Redistributions in binary form must reproduce the above copyright notice,
17# this list of conditions and the following disclaimer in the documentation
18# and/or other materials provided with the distribution.
19
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31
32
33import sys
34from pathlib import Path
35import os
36
37
38import cadexchanger.CadExCore as cadex
39from base_explorer import BaseExplorer
40from surface_explorer import SurfaceExplorer
41from curve_explorer import CurveExplorer
42from pcurve_explorer import PCurveExplorer
43
44class ShapeExplorer(cadex.ModelData_Model_VoidElementVisitor, BaseExplorer):
45 def __init__(self):
46 BaseExplorer.__init__(self)
47 cadex.ModelData_Model_VoidElementVisitor.__init__(self)
48
49 def VisitPart(self, thePart: cadex.ModelData_Part):
50 aBRep = thePart.BRepRepresentation()
51 if aBRep:
52 print(f"Part = \"{thePart.Name()}\"")
53 self.ExploreBRep(aBRep)
54
55 def ExploreBRep(self, theBRep: cadex.ModelData_BRepRepresentation):
56 # Get() method retrieves bodies listed in B-Rep representation by calling data providers flushing
57 # Flushing isn't an elementary process so it can take a significant time(seconds, minutes depending on a model structure)
58 aBodyList = theBRep.Get()
59
60 # Iterate over bodies
61 for i, aBody in enumerate(aBodyList):
62 print(f"Body {i}: {self.BodyType(aBody)}")
63 self.ExploreShape(aBody)
64
65
66 # Recursive iterating over the Shape until reaching vertices
67 def ExploreShape(self, theShape: cadex.ModelData_Shape):
68 if theShape.Type() == cadex.ModelData_ST_Face:
69 self.myCurrentFace = cadex.ModelData_Face.Cast(theShape)
70 self.myNestingLevel += 1
71 for aShape in cadex.ModelData_Shape_Iterator(theShape):
72 self.PrintShape(aShape)
73 self.ExploreShape(aShape)
74
75 if theShape.Type() == cadex.ModelData_ST_Face:
76 self.myCurrentFace = None
77
78 self.myNestingLevel -= 1
79
80 # Returns body type name
81 def BodyType(self, theBody: cadex.ModelData_Body) -> str:
82 if theBody.BodyType() == cadex.ModelData_BT_Solid:
83 return "Solid"
84 if theBody.BodyType() == cadex.ModelData_BT_Sheet:
85 return "Sheet"
86 if theBody.BodyType() == cadex.ModelData_BT_Wireframe:
87 return "Wireframe"
88 if theBody.BodyType() == cadex.ModelData_BT_Acorn:
89 return "Acorn"
90 return "Undefined"
91
92 # Returns shape type name and prints shape info in some cases
93 def PrintShape(self, theShape: cadex.ModelData_Shape):
94 self.PrintTabulation()
95
96 if theShape.Type() == cadex.ModelData_ST_Solid:
97 print("Solid", end="")
98 elif theShape.Type() == cadex.ModelData_ST_Shell:
99 self.PrintShell(cadex.ModelData_Shell.Cast(theShape))
100 elif theShape.Type() == cadex.ModelData_ST_Wire:
101 self.PrintWire(cadex.ModelData_Wire.Cast(theShape))
102 elif theShape.Type() == cadex.ModelData_ST_Face:
103 self.PrintFace(cadex.ModelData_Face.Cast(theShape))
104 elif theShape.Type() == cadex.ModelData_ST_Edge:
105 self.PrintEdge(cadex.ModelData_Edge.Cast(theShape))
106 elif theShape.Type() == cadex.ModelData_ST_Vertex:
107 self.PrintVertex(cadex.ModelData_Vertex.Cast(theShape))
108 else:
109 print("Undefined", end="")
110
111 print()
112
113 def PrintShell(self, theShell: cadex.ModelData_Shell):
114 self.PrintName("Shell")
115 self.myNestingLevel += 1
116 self.PrintOrientation(theShell.Orientation())
117 self.myNestingLevel -= 1
118
119 def PrintWire(self, theWire: cadex.ModelData_Wire):
120 self.PrintName("Wire")
121 self.myNestingLevel += 1
122 self.PrintOrientation(theWire.Orientation())
123 self.myNestingLevel -= 1
124
125 def PrintFace(self, theFace: cadex.ModelData_Face):
126 self.PrintName("Face")
127 self.myNestingLevel += 1
128 self.PrintOrientation(theFace.Orientation())
129 print()
130 aSurface = theFace.Surface()
131 self.PrintTabulation()
132 print("Surface: ")
133 SurfaceExplorer.PrintSurface(aSurface)
134 self.myNestingLevel -= 1
135
136 def PrintEdge(self, theEdge: cadex.ModelData_Edge):
137 self.PrintName("Edge")
138 self.myNestingLevel += 1
139 if theEdge.IsDegenerated():
140 print("Degenerated: ", end="")
141 self.PrintOrientation(theEdge.Orientation())
142 self.PrintNamedParameter("Tolerance", theEdge.Tolerance())
143
144 if not theEdge.IsDegenerated():
145 aCurve, first, second = theEdge.Curve()
146 print()
147 self.PrintTabulation()
148 self.PrintName("Curve")
149 self.PrintRange("Edge Range", first, second)
150 CurveExplorer.PrintCurveInfo(aCurve)
151
152 if self.myCurrentFace:
153 aPCurve, first, second = theEdge.PCurve(self.myCurrentFace)
154 print()
155 self.PrintTabulation()
156 self.PrintName("PCurve")
157 self.PrintRange("Edge Range", first, second)
158 PCurveExplorer.PrintPCurveInfo(aPCurve)
159
160 self.myNestingLevel -= 1
161
162 def PrintVertex(self, theVertex:cadex.ModelData_Vertex):
163 self.PrintName("Vertex")
164 aLoc = theVertex.Point()
165 aTolerance = theVertex.Tolerance()
166 self.PrintOrientation(theVertex.Orientation())
167 self.PrintNamedParameter("Tolerance", aTolerance)
168 self.PrintNamedParameter("Location", aLoc)
static const ModelData_Edge & Cast(const ModelData_Shape &theShape)
Casts a base class object to ModelData_Edge.
Definition: ModelData_Edge.cxx:688
static const ModelData_Face & Cast(const ModelData_Shape &theShape)
Cast operator.
Definition: ModelData_Face.cxx:282
static const ModelData_Shell & Cast(const ModelData_Shape &theShape)
Definition: ModelData_Shell.cxx:88
static const ModelData_Vertex & Cast(const ModelData_Shape &theShape)
Definition: ModelData_Vertex.cxx:94
static const ModelData_Wire & Cast(const ModelData_Shape &theShape)
Definition: ModelData_Wire.cxx:88

surface_explorer.py

1#!/usr/bin/env python3
2
3# $Id$
4
5# Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
6# Copyright (C) 2014-2023, CADEX. All rights reserved.
7
8# This file is part of the CAD Exchanger software.
9
10# You may use this file under the terms of the BSD license as follows:
11
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions are met:
14# * Redistributions of source code must retain the above copyright notice,
15# this list of conditions and the following disclaimer.
16# * Redistributions in binary form must reproduce the above copyright notice,
17# this list of conditions and the following disclaimer in the documentation
18# and/or other materials provided with the distribution.
19
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31
32
33import sys
34from pathlib import Path
35import os
36
37
38import cadexchanger.CadExCore as cadex
39from base_explorer import BaseExplorer
40from curve_explorer import CurveExplorer
41
42class SurfaceExplorer(BaseExplorer):
43 def __init__():
44 super().__init__()
45
46 @classmethod
47 def PrintSurface(cls, theSurface: cadex.ModelData_Surface):
48 if theSurface.Type() == cadex.ModelData_ST_Plane:
49 cls.PrintPlane(cadex.ModelData_Plane.Cast(theSurface))
50 elif theSurface.Type() == cadex.ModelData_ST_Cylinder:
51 cls.PrintCylinder(cadex.ModelData_CylindricalSurface.Cast(theSurface))
52 elif theSurface.Type() == cadex.ModelData_ST_Cone:
53 cls.PrintCone(cadex.ModelData_ConicalSurface.Cast(theSurface))
54 elif theSurface.Type() == cadex.ModelData_ST_Sphere:
55 cls.PrintSphere(cadex.ModelData_SphericalSurface.Cast(theSurface))
56 elif theSurface.Type() == cadex.ModelData_ST_Torus:
57 cls.PrintTorus(cadex.ModelData_ToroidalSurface.Cast(theSurface))
58 elif theSurface.Type() == cadex.ModelData_ST_LinearExtrusion:
59 cls.PrintLinearExtrusion(cadex.ModelData_SurfaceOfLinearExtrusion.Cast(theSurface))
60 elif theSurface.Type() == cadex.ModelData_ST_Revolution:
61 cls.PrintRevolution(cadex.ModelData_SurfaceOfRevolution.Cast(theSurface))
62 elif theSurface.Type() == cadex.ModelData_ST_Bezier:
63 cls.PrintBezierSurface(cadex.ModelData_BezierSurface.Cast(theSurface))
64 elif theSurface.Type() == cadex.ModelData_ST_BSpline:
65 cls.PrintBSplineSurface(cadex.ModelData_BSplineSurface.Cast(theSurface))
66 elif theSurface.Type() == cadex.ModelData_ST_Offset:
67 cls.PrintOffsetSurface(cadex.ModelData_OffsetSurface.Cast(theSurface))
68 elif theSurface.Type() == cadex.ModelData_ST_Trimmed:
69 cls.PrintTrimmedSurface(cadex.ModelData_RectangularTrimmedSurface.Cast(theSurface))
70
71
72 @classmethod
73 def PrintPlane(cls, thePlane: cadex.ModelData_Plane):
74 cls.PrintName("Plane")
75 cls.PrintElementary(thePlane)
76
77 @classmethod
78 def PrintCylinder(cls, theCylinder: cadex.ModelData_CylindricalSurface):
79 cls.PrintName("Cylinder")
80 aRadius = theCylinder.Radius()
81 cls.PrintElementary(theCylinder)
82 cls.PrintNamedParameter("Radius", aRadius)
83
84 @classmethod
85 def PrintCone(cls, theCone: cadex.ModelData_ConicalSurface):
86 cls.PrintName("Cone")
87 aRadius = theCone.Radius()
88 aSemiAngle = theCone.SemiAngle()
89 cls.PrintElementary(theCone)
90 cls.PrintNamedParameter("Radius", aRadius)
91 cls.PrintNamedParameter("Semi-Angle", aSemiAngle)
92
93 @classmethod
94 def PrintSphere(cls, theSphere: cadex.ModelData_SphericalSurface):
95 cls.PrintName("Sphere")
96 aRadius = theSphere.Radius()
97 cls.PrintElementary(theSphere)
98 cls.PrintNamedParameter("Radius", aRadius)
99
100 @classmethod
101 def PrintTorus(cls, theTorus: cadex.ModelData_ToroidalSurface):
102 cls.PrintName("Torus")
103 aMajorRadius = theTorus.MajorRadius()
104 aMinorRadius = theTorus.MinorRadius()
105 cls.PrintElementary(theTorus)
106 cls.PrintNamedParameter("Major Radius", aMajorRadius)
107 cls.PrintNamedParameter("Minor Radius", aMinorRadius)
108
109 @classmethod
110 def PrintLinearExtrusion(cls, theLinearExtrusion: cadex.ModelData_SurfaceOfLinearExtrusion):
111 cls.PrintName("Linear Extrusion Surface")
112 aDir = theLinearExtrusion.Direction()
113 cls.PrintDomain(theLinearExtrusion)
114 cls.PrintNamedParameter("Direction", aDir)
115 print("Basis Curve = ", end="")
116 CurveExplorer.PrintCurveInfo(theLinearExtrusion.BasisCurve())
117
118 @classmethod
119 def PrintRevolution(cls, theRevolution: cadex.ModelData_SurfaceOfRevolution):
120 cls.PrintName("Revolution Surface")
121 aDir = theRevolution.Direction()
122 aLoc = theRevolution.Location()
123 print(cls.PrintDomain(theRevolution), end="")
124 cls.PrintNamedParameter("Location", aLoc)
125 cls.PrintNamedParameter("Direction", aDir)
126 print("Basis Curve = ", end="")
127 CurveExplorer.PrintCurveInfo(theRevolution.BasisCurve())
128
129 @classmethod
130 def PrintBezierSurface(cls, theBezier: cadex.ModelData_BezierSurface):
131 cls.PrintName("Bezier Surface")
132 aUDegree = theBezier.UDegree()
133 aVDegree = theBezier.VDegree()
134 aNumberOfUPoles = theBezier.NumberOfUPoles()
135 aNumberOfVPoles = theBezier.NumberOfVPoles()
136 cls.PrintDomain(theBezier)
137 cls.PrintNamedParameter("UKnots Degree", aUDegree)
138 cls.PrintNamedParameter("VKnots Degree", aVDegree)
139 cls.PrintNamedParameter("Number Of UKnots Poles", aNumberOfUPoles)
140 cls.PrintNamedParameter("Number Of VKnots Poles", aNumberOfVPoles)
141
142 def PrintPole(i, j):
143 aPole = theBezier.Pole(i, j)
144 cls.PrintParameter(aPole)
145
146 cls.PrintCollection("Poles", aNumberOfUPoles, aNumberOfVPoles, PrintPole)
147
148 def PrintWeight(i,j):
149 aWeight = theBezier.Weight(i, j)
150 cls.PrintParameter(aWeight)
151
152 cls.PrintCollection("Weights", aNumberOfUPoles, aNumberOfVPoles, PrintWeight)
153
154 @classmethod
155 def PrintBSplineSurface(cls, theBSpline: cadex.ModelData_BSplineSurface):
156 cls.PrintName("BSpline Surface")
157
158 aUDegree = theBSpline.UDegree()
159 aVDegree = theBSpline.VDegree()
160 aNumberOfUKnots = theBSpline.NumberOfUKnots()
161 aNumberOfVKnots = theBSpline.NumberOfVKnots()
162 aNumberOfUPoles = theBSpline.NumberOfUPoles()
163 aNumberOfVPoles = theBSpline.NumberOfVPoles()
164 cls.PrintDomain(theBSpline)
165 cls.PrintNamedParameter("UKnots Degree", aUDegree)
166 cls.PrintNamedParameter("VKnots Degree", aVDegree)
167 cls.PrintNamedParameter("Number Of UKnots ", aNumberOfUKnots)
168 cls.PrintNamedParameter("Number Of VKnots ", aNumberOfVKnots)
169 cls.PrintNamedParameter("Number Of UKnots Poles", aNumberOfUPoles)
170 cls.PrintNamedParameter("Number Of VKnots Poles", aNumberOfVPoles)
171
172 def PrintUKnot(i):
173 aKnot = theBSpline.UKnot(i)
174 cls.PrintParameter(aKnot)
175
176 cls.Print2dCollection("UKnots ", aNumberOfUKnots, PrintUKnot)
177
178 def PrintVKnot(i):
179 aKnot = theBSpline.VKnot(i)
180 cls.PrintParameter(aKnot)
181
182 cls.Print2dCollection("VKnots ", aNumberOfVKnots, PrintVKnot)
183
184 def PrintUMultiplicity(i):
185 aUMultiplicity = theBSpline.UMultiplicity(i)
186 cls.PrintParameter(aUMultiplicity)
187
188 cls.Print2dCollection("UKnots Multiplicities", aNumberOfUKnots, PrintUMultiplicity)
189
190 def PrintVMultiplicity(i):
191 aVMultiplicity = theBSpline.VMultiplicity(i)
192 cls.PrintParameter(aVMultiplicity)
193
194 cls.Print2dCollection("VKnots Multiplicities", aNumberOfVKnots, PrintVMultiplicity)
195
196 def PrintPole(i, j):
197 aPole = theBSpline.Pole(i, j)
198 cls.PrintParameter(aPole)
199
200 cls.Print3dCollection("Poles", aNumberOfUPoles, aNumberOfVPoles, PrintPole)
201
202 def PrintWeight(i,j):
203 aWeight = theBSpline.Weight(i, j)
204 cls.PrintParameter(aWeight)
205
206 cls.Print3dCollection("Weights", aNumberOfUPoles, aNumberOfVPoles, PrintWeight)
207
208 @classmethod
209 def PrintOffsetSurface(cls, theOffset: cadex.ModelData_OffsetSurface):
210 cls.PrintName("Offset Surface")
211 anOffset = theOffset.Offset()
212 cls.PrintDomain(theOffset)
213 cls.PrintNamedParameter("Offset", anOffset)
214 print("Basis Surface = ", end="")
215 cls.PrintSurface(theOffset.BasisSurface())
216
217 @classmethod
218 def PrintTrimmedSurface(cls, theTrimmed: cadex.ModelData_RectangularTrimmedSurface):
219 cls.PrintName("Trimmed Surface")
220 cls.PrintDomain(theTrimmed)
221 print("Basis Surface = ", end="")
222 cls.PrintSurface(theTrimmed.BasisSurface())

brepgeometry.py

1#!/usr/bin/env python3
2
3# $Id$
4
5# Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
6# Copyright (C) 2014-2023, CADEX. All rights reserved.
7
8# This file is part of the CAD Exchanger software.
9
10# You may use this file under the terms of the BSD license as follows:
11
12# Redistribution and use in source and binary forms, with or without
13# modification, are permitted provided that the following conditions are met:
14# * Redistributions of source code must retain the above copyright notice,
15# this list of conditions and the following disclaimer.
16# * Redistributions in binary form must reproduce the above copyright notice,
17# this list of conditions and the following disclaimer in the documentation
18# and/or other materials provided with the distribution.
19
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30# POSSIBILITY OF SUCH DAMAGE.
31
32
33import sys
34from pathlib import Path
35import os
36
37import cadexchanger.CadExCore as cadex
38
39sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
40import cadex_license as license
41from shape_explorer import ShapeExplorer
42
43def main(theSource: str):
44 aKey = license.Value()
45
46 if not cadex.LicenseManager.Activate(aKey):
47 print("Failed to activate CAD Exchanger license.")
48 return 1
49
50 aModel = cadex.ModelData_Model()
51
52 if not cadex.ModelData_ModelReader().Read(cadex.Base_UTF16String(theSource), aModel):
53 print("Failed to read the file " + theSource)
54 return 1
55
56 # Explore B-Rep representation of model parts
57 aVisitor = ShapeExplorer()
58 aModel.AcceptElementVisitor(aVisitor)
59
60 print("Completed")
61 return 0
62
63if __name__ == "__main__":
64 if len(sys.argv) != 2:
65 print("Usage: " + os.path.abspath(Path(__file__).resolve()) + " <input_file>, where:")
66 print(" <input_file> is a name of the XML file to be read")
67 sys.exit(1)
68
69 aSource = os.path.abspath(sys.argv[1])
70
71 sys.exit(main(aSource))
72
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33