Refer to the B-Rep Geometry Exploration Example.
base_explorer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32import sys
33from pathlib import Path
34import os
35
36import manufacturingtoolkit.CadExMTK as mtk
37
38sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
39
40class BaseExplorer:
41 def __init__(self):
42 super().__init__()
43 self.myNestingLevel = 0
44
45 @classmethod
46 def PrintElementary(cls, theGeometry):
47 cls.PrintDomain(theGeometry)
48 aPosition = theGeometry.Position()
49 aLoc = aPosition.Location()
50 anAxis = aPosition.Axis()
51 aXDir = aPosition.XDirection()
52 aYDir = aPosition.YDirection()
53 cls.PrintNamedParameter("Location", aLoc)
54 cls.PrintNamedParameter("Axis", anAxis)
55 cls.PrintNamedParameter("X Direction", aXDir)
56 cls.PrintNamedParameter("Y Direction", aYDir)
57
58 @classmethod
59 def PrintElementary2d(cls, theGeometry):
60 cls.PrintDomain(theGeometry)
61 aPosition = theGeometry.Position()
62 aLoc = aPosition.Location()
63 aXDir = aPosition.XDirection()
64 aYDir = aPosition.YDirection()
65 cls.PrintNamedParameter("Location", aLoc)
66 cls.PrintNamedParameter("X Direction", aXDir)
67 cls.PrintNamedParameter("Y Direction", aYDir)
68
69 @classmethod
70 def PrintRange(cls, aName: str, aFirstParameter: float, aLastParameter: float):
71 print(f"{aName} = [{aFirstParameter}, {aLastParameter}]; ", end="")
72
73 @classmethod
74 def PrintCurveDomain(cls, theCurve):
75 cls.PrintRange("Domain", theCurve.UMin(), theCurve.UMax())
76
77 @classmethod
78 def PrintSurfaceDomain(cls, theSurface):
79 cls.PrintRange("Domain U", theSurface.UMin(), theSurface.UMax())
80 cls.PrintRange("V", theSurface.VMin(), theSurface.VMax())
81
82 @classmethod
83 def PrintDomain(cls, theValue):
84 if isinstance(theValue, mtk.Geom_Curve) or isinstance(theValue, mtk.Geom_Curve2d):
85 cls.PrintCurveDomain(theValue)
86 elif isinstance(theValue, mtk.Geom_Surface):
87 cls.PrintSurfaceDomain(theValue)
88
89 @classmethod
90 def Print3dParameter(cls, thePoint):
91 print(f"({thePoint.X()}, {thePoint.Y()}, {thePoint.Z()}); ", end="")
92
93 @classmethod
94 def Print2dParameter(cls, thePoint):
95 print(f"({thePoint.X()}, {thePoint.Y()}); ", end="")
96
97 @classmethod
98 def Print1dParameter(cls, theValue):
99 print(f"{theValue}; ", end="")
100
101 @classmethod
102 def PrintParameter(cls, theValue):
103 if isinstance(theValue, mtk.Geom_Point) or isinstance(theValue, mtk.Geom_Direction):
104 cls.Print3dParameter(theValue)
105 elif isinstance(theValue, mtk.Geom_Point2d) or isinstance(theValue, mtk.Geom_Direction2d):
106 cls.Print2dParameter(theValue)
107 elif isinstance(theValue, float):
108 cls.Print1dParameter(theValue)
109
110 @classmethod
111 def PrintNamedParameter(cls, theName, TheValue):
112 print(f"{theName} = ", end="")
113 cls.PrintParameter(TheValue)
114
115 @classmethod
116 def PrintName(cls, theName: str):
117 print(f"{theName}: ", end="")
118
119 @classmethod
120 def Print2dCollection(cls, theName: str, theFinalIndex: int, thePrintElement):
121 if theName:
122 print(f"{theName} = ", end="")
123
124 print("[", end="")
125 for i in range(1, theFinalIndex + 1):
126 if(i > 3):
127 print("...", end="")
128 break
129 thePrintElement(i)
130
131 print("]; ", end="")
132
133
134 @classmethod
135 def Print3dCollection(cls, theName: str, theFinalIndex1: int, theFinalIndex2: int, thePrintElement):
136 def PrintString(i: int):
137 cls.Print2dCollection(None, theFinalIndex2, lambda j: thePrintElement(i, j))
138 cls.Print2dCollection(theName, theFinalIndex1, PrintString)
139
140 @classmethod
141 def PrintOrientation(cls, theOrientation):
142 print("Orientation = ", end="")
143 if theOrientation == mtk.ShapeOrientation_Forward:
144 print("Forward", end="")
145 elif theOrientation == mtk.ShapeOrientation_Reversed:
146 print("Reversed", end="")
147 else:
148 print("Undefined")
149 print("; ", end="")
150
151 def PrintTabulation(self):
152 print("--- " * self.myNestingLevel, end="")
curve_explorer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32import sys
33from pathlib import Path
34import os
35
36import manufacturingtoolkit.CadExMTK as mtk
37from base_explorer import BaseExplorer
38
39class CurveExplorer(BaseExplorer):
40
41 @classmethod
42 def PrintCurveInfo(cls, theCurve: mtk.Geom_Curve):
43 if theCurve.Type() == mtk.CurveType_Line:
44 cls.PrintLine(mtk.Geom_Line.Cast(theCurve))
45 elif theCurve.Type() == mtk.CurveType_Circle:
46 cls.PrintCircle(mtk.Geom_Circle.Cast(theCurve))
47 elif theCurve.Type() == mtk.CurveType_Ellipse:
48 cls.PrintEllipse(mtk.Geom_Ellipse.Cast(theCurve))
49 elif theCurve.Type() == mtk.CurveType_Hyperbola:
50 cls.PrintHyperbola(mtk.Geom_Hyperbola.Cast(theCurve))
51 elif theCurve.Type() == mtk.CurveType_Parabola:
52 cls.PrintParabola(mtk.Geom_Parabola.Cast(theCurve))
53 elif theCurve.Type() == mtk.CurveType_Bezier:
54 cls.PrintBezierCurve(mtk.Geom_BezierCurve.Cast(theCurve))
55 elif theCurve.Type() == mtk.CurveType_BSpline:
56 cls.PrintBSplineCurve(mtk.Geom_BSplineCurve.Cast(theCurve))
57 elif theCurve.Type() == mtk.CurveType_Offset:
58 cls.PrintOffsetCurve(mtk.Geom_OffsetCurve.Cast(theCurve))
59
60 @classmethod
61 def PrintLine(cls, theLine: mtk.Geom_Line):
62 cls.PrintName("Line")
63 aLoc = theLine.Location()
64 aDir = theLine.Direction()
65 cls.PrintDomain(theLine)
66 cls.PrintNamedParameter("Location", aLoc)
67 cls.PrintNamedParameter("Direction", aDir)
68
69 @classmethod
70 def PrintCircle(cls, theCircle: mtk.Geom_Circle):
71 cls.PrintName("Circle")
72 aRadius = theCircle.Radius()
73 cls.PrintElementary(theCircle)
74 cls.PrintNamedParameter("Radius", aRadius)
75
76 @classmethod
77 def PrintEllipse(cls, theEllipse: mtk.Geom_Ellipse):
78 cls.PrintName("Ellipse")
79 aMajorRadius = theEllipse.MajorRadius()
80 aMinorRadius = theEllipse.MinorRadius()
81 cls.PrintElementary(theEllipse)
82 cls.PrintNamedParameter("Major Radius", aMajorRadius)
83 cls.PrintNamedParameter("Minor Radius", aMinorRadius)
84
85 @classmethod
86 def PrintHyperbola(cls, theHyperbola: mtk.Geom_Hyperbola):
87 cls.PrintName("Hyperbola")
88 aMajorRadius = theHyperbola.MajorRadius()
89 aMinorRadius = theHyperbola.MinorRadius()
90 cls.PrintElementary(theHyperbola)
91 cls.PrintNamedParameter("Major Radius", aMajorRadius)
92 cls.PrintNamedParameter("Minor Radius", aMinorRadius)
93
94 @classmethod
95 def PrintParabola(cls, theParabola: mtk.Geom_Parabola):
96 cls.PrintName("Parabola")
97 aFocal = theParabola.Focal()
98 cls.PrintElementary(theParabola)
99 cls.PrintNamedParameter("Focal", aFocal)
100
101 @classmethod
102 def PrintBezierCurve(cls, theBezier: mtk.Geom_BezierCurve):
103 cls.PrintName("Bezier Curve")
104 aDegree = theBezier.Degree()
105 aNumberOfPoles = theBezier.NumberOfPoles()
106 cls.PrintDomain(theBezier)
107 cls.PrintNamedParameter("Degree", aDegree)
108 cls.PrintNamedParameter("Number Of Poles", aNumberOfPoles)
109
110 def PrintPole(i):
111 aPole = theBezier.Pole(i)
112 cls.PrintParameter(aPole)
113
114 cls.Print2dCollection("Poles", aNumberOfPoles, PrintPole)
115
116 def PrintWeight(i):
117 aWeight = theBezier.Weight(i)
118 cls.PrintParameter(aWeight)
119
120 cls.Print2dCollection("Weights", aNumberOfPoles, PrintWeight)
121
122 @classmethod
123 def PrintBSplineCurve(cls, theBSpline: mtk.Geom_BSplineCurve):
124 cls.PrintName("BSpline Curve")
125 aDegree = theBSpline.Degree()
126 aNumberOfKnots = theBSpline.NumberOfKnots()
127 aNumberOfPoles = theBSpline.NumberOfPoles()
128 cls.PrintDomain(theBSpline)
129 cls.PrintNamedParameter("Degree", aDegree)
130 cls.PrintNamedParameter("Number Of Knots", aNumberOfKnots)
131 cls.PrintNamedParameter("Number Of Poles", aNumberOfPoles)
132
133 def PrintKnot(i):
134 aKnot = theBSpline.Knot(i)
135 cls.PrintParameter(aKnot)
136
137 cls.Print2dCollection("Knots", aNumberOfKnots, PrintKnot)
138
139 def PrintMultiplicity(i):
140 aMultiplicity = theBSpline.Multiplicity(i)
141 cls.PrintParameter(aMultiplicity)
142
143 cls.Print2dCollection("Multiplicities", aNumberOfKnots, PrintMultiplicity)
144
145 def PrintPole(i):
146 aPole = theBSpline.Pole(i)
147 cls.PrintParameter(aPole)
148
149 cls.Print2dCollection("Poles", aNumberOfPoles, PrintPole)
150
151 def PrintWeight(i):
152 aWeight = theBSpline.Weight(i)
153 cls.PrintParameter(aWeight)
154
155 cls.Print2dCollection("Weights", aNumberOfPoles, PrintWeight)
156
157 @classmethod
158 def PrintOffsetCurve(cls, theOffset: mtk.Geom_OffsetCurve):
159 cls.PrintName("Offset Curve")
160 aDir = theOffset.Direction()
161 anOffset = theOffset.Offset()
162 cls.PrintDomain(theOffset)
163 cls.PrintNamedParameter("Direction", aDir)
164 cls.PrintNamedParameter("Offset", anOffset)
165 print("Basis Curve = ", end="")
166 cls.PrintCurveInfo(theOffset.BasisCurve())
pcurve_explorer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32import sys
33from pathlib import Path
34import os
35
36import manufacturingtoolkit.CadExMTK as mtk
37from base_explorer import BaseExplorer
38
39class PCurveExplorer(BaseExplorer):
40
41
42 @classmethod
43 def PrintPCurveInfo(cls, theCurve):
44 if theCurve.Type() == mtk.CurveType_Line:
45 cls.PrintLine(mtk.Geom_Line2d.Cast(theCurve))
46 elif theCurve.Type() == mtk.CurveType_Circle:
47 cls.PrintCircle(mtk.Geom_Circle2d.Cast(theCurve))
48 elif theCurve.Type() == mtk.CurveType_Ellipse:
49 cls.PrintEllipse(mtk.Geom_Ellipse2d.Cast(theCurve))
50 elif theCurve.Type() == mtk.CurveType_Hyperbola:
51 cls.PrintHyperbola(mtk.Geom_Hyperbola2d.Cast(theCurve))
52 elif theCurve.Type() == mtk.CurveType_Parabola:
53 cls.PrintParabola(mtk.Geom_Parabola2d.Cast(theCurve))
54 elif theCurve.Type() == mtk.CurveType_Bezier:
55 cls.PrintBezierCurve(mtk.Geom_BezierCurve2d.Cast(theCurve))
56 elif theCurve.Type() == mtk.CurveType_BSpline:
57 cls.PrintBSplineCurve(mtk.Geom_BSplineCurve2d.Cast(theCurve))
58 elif theCurve.Type() == mtk.CurveType_Offset:
59 cls.PrintOffsetCurve(mtk.Geom_OffsetCurve2d.Cast(theCurve))
60
61 @classmethod
62 def PrintLine(cls, theLine: mtk.Geom_Line2d):
63 cls.PrintName("Line 2d")
64 aLoc = theLine.Location()
65 aDir = theLine.Direction()
66 cls.PrintDomain(theLine)
67 cls.PrintNamedParameter("Location", aLoc)
68 cls.PrintNamedParameter("Direction", aDir)
69
70 @classmethod
71 def PrintCircle(cls, theCircle: mtk.Geom_Circle2d):
72 cls.PrintName("Circle 2d")
73 aRadius = theCircle.Radius()
74 cls.PrintElementary2d(theCircle)
75 cls.PrintNamedParameter("Radius", aRadius)
76
77 @classmethod
78 def PrintEllipse(cls, theEllipse: mtk.Geom_Ellipse2d):
79 cls.PrintName("Ellipse 2d")
80 aMajorRadius = theEllipse.MajorRadius()
81 aMinorRadius = theEllipse.MinorRadius()
82 cls.PrintElementary2d(theEllipse)
83 cls.PrintNamedParameter("Major Radius", aMajorRadius)
84 cls.PrintNamedParameter("Minor Radius", aMinorRadius)
85
86 @classmethod
87 def PrintHyperbola(cls, theHyperbola: mtk.Geom_Hyperbola2d):
88 cls.PrintName("Hyperbola 2d")
89 aMajorRadius = theHyperbola.MajorRadius()
90 aMinorRadius = theHyperbola.MinorRadius()
91 cls.PrintElementary2d(theHyperbola)
92 cls.PrintNamedParameter("Major Radius", aMajorRadius)
93 cls.PrintNamedParameter("Minor Radius", aMinorRadius)
94
95 @classmethod
96 def PrintParabola(cls, theParabola: mtk.Geom_Parabola2d):
97 cls.PrintName("Parabola 2d")
98 aFocal = theParabola.Focal()
99 cls.PrintElementary2d(theParabola)
100 cls.PrintNamedParameter("Focal", aFocal)
101
102 @classmethod
103 def PrintBezierCurve(cls, theBezier: mtk.Geom_BezierCurve2d):
104 cls.PrintName("Bezier Curve 2d")
105 aDegree = theBezier.Degree()
106 aNumberOfPoles = theBezier.NumberOfPoles()
107 cls.PrintDomain(theBezier)
108 cls.PrintNamedParameter("Degree", aDegree)
109 cls.PrintNamedParameter("Number Of Poles", aNumberOfPoles)
110
111 def PrintPole(i):
112 aPole = theBezier.Pole(i)
113 cls.PrintNamedParameter(aPole)
114
115 cls.Print2dCollection("Poles", aNumberOfPoles, PrintPole)
116
117 def PrintWeight(i):
118 aWeight = theBezier.Weight(i)
119 cls.PrintNamedParameter(aWeight)
120
121 cls.Print2dCollection("Weights", aNumberOfPoles, PrintWeight)
122
123 @classmethod
124 def PrintBSplineCurve(cls, theBSpline: mtk.Geom_BSplineCurve2d):
125 cls.PrintName("BSpline Curve 2d")
126 aDegree = theBSpline.Degree()
127 aNumberOfKnots = theBSpline.NumberOfKnots()
128 aNumberOfPoles = theBSpline.NumberOfPoles()
129 cls.PrintDomain(theBSpline)
130 cls.PrintNamedParameter("Degree", aDegree)
131 cls.PrintNamedParameter("Number Of Knots", aNumberOfKnots)
132 cls.PrintNamedParameter("Number Of Poles", aNumberOfPoles)
133
134 def PrintKnot(i):
135 aKnot = theBSpline.Knot(i)
136 cls.PrintParameter(aKnot)
137
138 cls.Print2dCollection("Knots", aNumberOfKnots, PrintKnot)
139
140 def PrintMultiplicity(i):
141 aMultiplicity = theBSpline.Multiplicity(i)
142 cls.PrintParameter(aMultiplicity)
143
144 cls.Print2dCollection("Multiplicities", aNumberOfKnots, PrintMultiplicity)
145
146 def PrintPole(i):
147 aPole = theBSpline.Pole(i)
148 cls.PrintParameter(aPole)
149
150 cls.Print2dCollection("Poles", aNumberOfPoles, PrintPole)
151
152 def PrintWeight(i):
153 aWeight = theBSpline.Weight(i)
154 cls.PrintParameter(aWeight)
155
156 cls.Print2dCollection("Weights", aNumberOfPoles, PrintWeight)
157
158 @classmethod
159 def PrintOffsetCurve(cls, theOffset: mtk.Geom_OffsetCurve2d):
160 cls.PrintName("Offset Curve 2d")
161 anOffset = theOffset.Offset()
162 cls.PrintDomain(theOffset)
163 cls.PrintParameter("Offset", anOffset)
164 print("Basis Curve = ", end="")
165 cls.PrintPCurveInfo(theOffset.BasisCurve())
shape_explorer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32import sys
33from pathlib import Path
34import os
35
36import manufacturingtoolkit.CadExMTK as mtk
37from base_explorer import BaseExplorer
38from surface_explorer import SurfaceExplorer
39from curve_explorer import CurveExplorer
40from pcurve_explorer import PCurveExplorer
41
42class ShapeExplorer(mtk.ModelData_ModelElementVoidVisitor, BaseExplorer):
43 def __init__(self):
44 BaseExplorer.__init__(self)
45 mtk.ModelData_ModelElementVoidVisitor.__init__(self)
46
47 def VisitPart(self, thePart: mtk.ModelData_Part):
48 aBodies = thePart.Bodies()
49 if thePart.NumberOfBodies() > 0:
50 print(f"Part = \"{thePart.Name()}\"")
51 self.ExploreBRep(aBodies)
52
53 def ExploreBRep(self, theBodies: mtk.Collections_BodyList):
54 for i, aBody in enumerate(theBodies):
55 print(f"Body {i}: {self.BodyType(aBody)}")
56 aShapeIt = mtk.ModelData_ShapeIterator(aBody)
57 for aShape in aShapeIt:
58 self.ExploreShape(aShape)
59
60
61 def ExploreShape(self, theShape: mtk.ModelData_Shape):
62 if theShape.Type() == mtk.ShapeType_Face:
63 self.myCurrentFace = mtk.ModelData_Face.Cast(theShape)
64 self.myNestingLevel += 1
65 for aShape in mtk.ModelData_ShapeIterator(theShape):
66 self.PrintShape(aShape)
67 self.ExploreShape(aShape)
68
69 if theShape.Type() == mtk.ShapeType_Face:
70 self.myCurrentFace = None
71
72 self.myNestingLevel -= 1
73
74
75 def BodyType(self, theBody: mtk.ModelData_Body) -> str:
76 if mtk.ModelData_SolidBody.CompareType(theBody):
77 return "Solid"
78 if mtk.ModelData_SheetBody.CompareType(theBody):
79 return "Sheet"
80 if mtk.ModelData_WireframeBody.CompareType(theBody):
81 return "Wireframe"
82 return "Undefined"
83
84
85 def PrintShape(self, theShape: mtk.ModelData_Shape):
86 self.PrintTabulation()
87 aType = theShape.Type()
88 if aType == mtk.ShapeType_Solid:
89 print("Solid", end="")
90 elif aType == mtk.ShapeType_Shell:
91 self.PrintShell(mtk.ModelData_Shell.Cast(theShape))
92 elif aType == mtk.ShapeType_Wire:
93 self.PrintWire(mtk.ModelData_Wire.Cast(theShape))
94 elif aType == mtk.ShapeType_Face:
95 self.PrintFace(mtk.ModelData_Face.Cast(theShape))
96 elif aType == mtk.ShapeType_Edge:
97 self.PrintEdge(mtk.ModelData_Edge.Cast(theShape))
98 elif aType == mtk.ShapeType_Vertex:
99 self.PrintVertex(mtk.ModelData_Vertex.Cast(theShape))
100 else:
101 print("Undefined", end="")
102
103 print()
104
105 def PrintShell(self, theShell: mtk.ModelData_Shell):
106 self.PrintName("Shell")
107 self.myNestingLevel += 1
108 self.PrintOrientation(theShell.Orientation())
109 self.myNestingLevel -= 1
110
111 def PrintWire(self, theWire: mtk.ModelData_Wire):
112 self.PrintName("Wire")
113 self.myNestingLevel += 1
114 self.PrintOrientation(theWire.Orientation())
115 self.myNestingLevel -= 1
116
117 def PrintFace(self, theFace: mtk.ModelData_Face):
118 self.PrintName("Face")
119 self.myNestingLevel += 1
120 self.PrintOrientation(theFace.Orientation())
121 print()
122 aSurface = theFace.Surface()
123 self.PrintTabulation()
124 print("Surface: ")
125 SurfaceExplorer.PrintSurface(aSurface)
126 self.myNestingLevel -= 1
127
128 def PrintEdge(self, theEdge: mtk.ModelData_Edge):
129 self.PrintName("Edge")
130 self.myNestingLevel += 1
131 if theEdge.IsDegenerated():
132 print("Degenerated: ", end="")
133 self.PrintOrientation(theEdge.Orientation())
134 self.PrintNamedParameter("Tolerance", theEdge.Tolerance())
135
136 if not theEdge.IsDegenerated():
137 aCurve, first, second = theEdge.Curve()
138 print()
139 self.PrintTabulation()
140 self.PrintName("Curve")
141 self.PrintRange("Edge Range", first, second)
142 CurveExplorer.PrintCurveInfo(aCurve)
143
144 if self.myCurrentFace:
145 aPCurve, first, second = theEdge.PCurve(self.myCurrentFace)
146 print()
147 self.PrintTabulation()
148 self.PrintName("PCurve")
149 self.PrintRange("Edge Range", first, second)
150 PCurveExplorer.PrintPCurveInfo(aPCurve)
151
152 self.myNestingLevel -= 1
153
154 def PrintVertex(self, theVertex:mtk.ModelData_Vertex):
155 self.PrintName("Vertex")
156 aLoc = theVertex.Point()
157 aTolerance = theVertex.Tolerance()
158 self.PrintOrientation(theVertex.Orientation())
159 self.PrintNamedParameter("Tolerance", aTolerance)
160 self.PrintNamedParameter("Location", aLoc)
surface_explorer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32import sys
33from pathlib import Path
34import os
35
36import manufacturingtoolkit.CadExMTK as mtk
37from base_explorer import BaseExplorer
38from curve_explorer import CurveExplorer
39
40class SurfaceExplorer(BaseExplorer):
41 def __init__():
42 super().__init__()
43
44 @classmethod
45 def PrintSurface(cls, theSurface: mtk.Geom_Surface):
46 if theSurface.Type() == mtk.SurfaceType_Plane:
47 cls.PrintPlane(mtk.Geom_Plane.Cast(theSurface))
48 elif theSurface.Type() == mtk.SurfaceType_Cylinder:
49 cls.PrintCylinder(mtk.Geom_CylindricalSurface.Cast(theSurface))
50 elif theSurface.Type() == mtk.SurfaceType_Cone:
51 cls.PrintCone(mtk.Geom_ConicalSurface.Cast(theSurface))
52 elif theSurface.Type() == mtk.SurfaceType_Sphere:
53 cls.PrintSphere(mtk.Geom_SphericalSurface.Cast(theSurface))
54 elif theSurface.Type() == mtk.SurfaceType_Torus:
55 cls.PrintTorus(mtk.Geom_ToroidalSurface.Cast(theSurface))
56 elif theSurface.Type() == mtk.SurfaceType_LinearExtrusion:
57 cls.PrintLinearExtrusion(mtk.Geom_SurfaceOfLinearExtrusion.Cast(theSurface))
58 elif theSurface.Type() == mtk.SurfaceType_Revolution:
59 cls.PrintRevolution(mtk.Geom_SurfaceOfRevolution.Cast(theSurface))
60 elif theSurface.Type() == mtk.SurfaceType_Bezier:
61 cls.PrintBezierSurface(mtk.Geom_BezierSurface.Cast(theSurface))
62 elif theSurface.Type() == mtk.SurfaceType_BSpline:
63 cls.PrintBSplineSurface(mtk.Geom_BSplineSurface.Cast(theSurface))
64 elif theSurface.Type() == mtk.SurfaceType_Offset:
65 cls.PrintOffsetSurface(mtk.Geom_OffsetSurface.Cast(theSurface))
66
67 @classmethod
68 def PrintPlane(cls, thePlane: mtk.Geom_Plane):
69 cls.PrintName("Plane")
70 cls.PrintElementary(thePlane)
71
72 @classmethod
73 def PrintCylinder(cls, theCylinder: mtk.Geom_CylindricalSurface):
74 cls.PrintName("Cylinder")
75 aRadius = theCylinder.Radius()
76 cls.PrintElementary(theCylinder)
77 cls.PrintNamedParameter("Radius", aRadius)
78
79 @classmethod
80 def PrintCone(cls, theCone: mtk.Geom_ConicalSurface):
81 cls.PrintName("Cone")
82 aRadius = theCone.Radius()
83 aSemiAngle = theCone.SemiAngle()
84 cls.PrintElementary(theCone)
85 cls.PrintNamedParameter("Radius", aRadius)
86 cls.PrintNamedParameter("Semi-Angle", aSemiAngle)
87
88 @classmethod
89 def PrintSphere(cls, theSphere: mtk.Geom_SphericalSurface):
90 cls.PrintName("Sphere")
91 aRadius = theSphere.Radius()
92 cls.PrintElementary(theSphere)
93 cls.PrintNamedParameter("Radius", aRadius)
94
95 @classmethod
96 def PrintTorus(cls, theTorus: mtk.Geom_ToroidalSurface):
97 cls.PrintName("Torus")
98 aMajorRadius = theTorus.MajorRadius()
99 aMinorRadius = theTorus.MinorRadius()
100 cls.PrintElementary(theTorus)
101 cls.PrintNamedParameter("Major Radius", aMajorRadius)
102 cls.PrintNamedParameter("Minor Radius", aMinorRadius)
103
104 @classmethod
105 def PrintLinearExtrusion(cls, theLinearExtrusion: mtk.Geom_SurfaceOfLinearExtrusion):
106 cls.PrintName("Linear Extrusion Surface")
107 aDir = theLinearExtrusion.Direction()
108 cls.PrintDomain(theLinearExtrusion)
109 cls.PrintNamedParameter("Direction", aDir)
110 print("Basis Curve = ", end="")
111 CurveExplorer.PrintCurveInfo(theLinearExtrusion.BasisCurve())
112
113 @classmethod
114 def PrintRevolution(cls, theRevolution: mtk.Geom_SurfaceOfRevolution):
115 cls.PrintName("Revolution Surface")
116 aDir = theRevolution.Direction()
117 aLoc = theRevolution.Location()
118 print(cls.PrintDomain(theRevolution), end="")
119 cls.PrintNamedParameter("Location", aLoc)
120 cls.PrintNamedParameter("Direction", aDir)
121 print("Basis Curve = ", end="")
122 CurveExplorer.PrintCurveInfo(theRevolution.BasisCurve())
123
124 @classmethod
125 def PrintBezierSurface(cls, theBezier: mtk.Geom_BezierSurface):
126 cls.PrintName("Bezier Surface")
127 aUDegree = theBezier.UDegree()
128 aVDegree = theBezier.VDegree()
129 aNumberOfUPoles = theBezier.NumberOfUPoles()
130 aNumberOfVPoles = theBezier.NumberOfVPoles()
131 cls.PrintDomain(theBezier)
132 cls.PrintNamedParameter("UKnots Degree", aUDegree)
133 cls.PrintNamedParameter("VKnots Degree", aVDegree)
134 cls.PrintNamedParameter("Number Of UKnots Poles", aNumberOfUPoles)
135 cls.PrintNamedParameter("Number Of VKnots Poles", aNumberOfVPoles)
136
137 def PrintPole(i, j):
138 aPole = theBezier.Pole(i, j)
139 cls.PrintParameter(aPole)
140
141 cls.PrintCollection("Poles", aNumberOfUPoles, aNumberOfVPoles, PrintPole)
142
143 def PrintWeight(i,j):
144 aWeight = theBezier.Weight(i, j)
145 cls.PrintParameter(aWeight)
146
147 cls.PrintCollection("Weights", aNumberOfUPoles, aNumberOfVPoles, PrintWeight)
148
149 @classmethod
150 def PrintBSplineSurface(cls, theBSpline: mtk.Geom_BSplineSurface):
151 cls.PrintName("BSpline Surface")
152
153 aUDegree = theBSpline.UDegree()
154 aVDegree = theBSpline.VDegree()
155 aNumberOfUKnots = theBSpline.NumberOfUKnots()
156 aNumberOfVKnots = theBSpline.NumberOfVKnots()
157 aNumberOfUPoles = theBSpline.NumberOfUPoles()
158 aNumberOfVPoles = theBSpline.NumberOfVPoles()
159 cls.PrintDomain(theBSpline)
160 cls.PrintNamedParameter("UKnots Degree", aUDegree)
161 cls.PrintNamedParameter("VKnots Degree", aVDegree)
162 cls.PrintNamedParameter("Number Of UKnots ", aNumberOfUKnots)
163 cls.PrintNamedParameter("Number Of VKnots ", aNumberOfVKnots)
164 cls.PrintNamedParameter("Number Of UKnots Poles", aNumberOfUPoles)
165 cls.PrintNamedParameter("Number Of VKnots Poles", aNumberOfVPoles)
166
167 def PrintUKnot(i):
168 aKnot = theBSpline.UKnot(i)
169 cls.PrintParameter(aKnot)
170
171 cls.Print2dCollection("UKnots ", aNumberOfUKnots, PrintUKnot)
172
173 def PrintVKnot(i):
174 aKnot = theBSpline.VKnot(i)
175 cls.PrintParameter(aKnot)
176
177 cls.Print2dCollection("VKnots ", aNumberOfVKnots, PrintVKnot)
178
179 def PrintUMultiplicity(i):
180 aUMultiplicity = theBSpline.UMultiplicity(i)
181 cls.PrintParameter(aUMultiplicity)
182
183 cls.Print2dCollection("UKnots Multiplicities", aNumberOfUKnots, PrintUMultiplicity)
184
185 def PrintVMultiplicity(i):
186 aVMultiplicity = theBSpline.VMultiplicity(i)
187 cls.PrintParameter(aVMultiplicity)
188
189 cls.Print2dCollection("VKnots Multiplicities", aNumberOfVKnots, PrintVMultiplicity)
190
191 def PrintPole(i, j):
192 aPole = theBSpline.Pole(i, j)
193 cls.PrintParameter(aPole)
194
195 cls.Print3dCollection("Poles", aNumberOfUPoles, aNumberOfVPoles, PrintPole)
196
197 def PrintWeight(i,j):
198 aWeight = theBSpline.Weight(i, j)
199 cls.PrintParameter(aWeight)
200
201 cls.Print3dCollection("Weights", aNumberOfUPoles, aNumberOfVPoles, PrintWeight)
202
203 @classmethod
204 def PrintOffsetSurface(cls, theOffset: mtk.Geom_OffsetSurface):
205 cls.PrintName("Offset Surface")
206 anOffset = theOffset.Offset()
207 cls.PrintDomain(theOffset)
208 cls.PrintNamedParameter("Offset", anOffset)
209 print("Basis Surface = ", end="")
210 cls.PrintSurface(theOffset.BasisSurface())
brep_geometry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32import sys
33from pathlib import Path
34import os
35
36import manufacturingtoolkit.CadExMTK as mtk
37from shape_explorer import ShapeExplorer
38
39sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
40
41import mtk_license as license
42
43def main(theSource: str):
44 aKey = license.Value()
45
46 if not mtk.LicenseManager.Activate(aKey):
47 print("Failed to activate Manufacturing Toolkit license.")
48 return 1
49
50 aModel = mtk.ModelData_Model()
51
52 if not mtk.ModelData_ModelReader().Read(mtk.UTF16String(theSource), aModel):
53 print("Failed to read the file " + theSource)
54 return 1
55
56
57 aVisitor = ShapeExplorer()
58 aModel.Accept(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 file to be read")
67 sys.exit(1)
68
69 aSource = os.path.abspath(sys.argv[1])
70
71 sys.exit(main(aSource))
72