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
30from abc import abstractmethod
31
32import manufacturingtoolkit.CadExMTK as mtk
33
34class ShapeProcessor(mtk.ModelData_ModelElementVoidVisitor):
35 def __init__(self):
36 super().__init__()
37 self.myPartIndex = 0
38
39 def VisitPart(self, thePart: mtk.ModelData_Part):
40 aPartName = "noname" if thePart.Name().IsEmpty() else thePart.Name()
41
42 aBodyList = thePart.Bodies()
43 i = 0
44 for aBody in aBodyList:
45 aShapeIt = mtk.ModelData_ShapeIterator(aBody)
46 for aShape in aShapeIt:
47 if aShape.Type() == mtk.ShapeType_Solid:
48 print("Part #", self.myPartIndex, " [\"", aPartName, "\"] - solid #", i, " has:", sep="")
49 i += 1
50 self.ProcessSolid(mtk.ModelData_Solid.Cast(aShape))
51 elif aShape.Type() == mtk.ShapeType_Shell:
52 print("Part #", self.myPartIndex, " [\"", aPartName, "\"] - shell #", i, " has:", sep="")
53 i += 1
54 self.ProcessShell(mtk.ModelData_Shell.Cast (aShape))
55 self.myPartIndex += 1
56
57 @abstractmethod
58 def ProcessSolid(self, theSolid: mtk.ModelData_Solid):
59 pass
60
61 @abstractmethod
62 def ProcessShell(self, theShell: mtk.ModelData_Shell):
63 pass
64
65class SolidProcessor(mtk.ModelData_ModelElementVoidVisitor):
66 def __init__(self):
67 super().__init__()
68 self.myPartIndex = 0
69
70 def VisitPart(self, thePart: mtk.ModelData_Part):
71 aPartName = "noname" if thePart.Name().IsEmpty() else thePart.Name()
72
73 aBodyList = thePart.Bodies()
74 i = 0
75 for aBody in aBodyList:
76 aShapeIt = mtk.ModelData_ShapeIterator(aBody)
77 for aShape in aShapeIt:
78 if aShape.Type() == mtk.ShapeType_Solid:
79 print("Part #", self.myPartIndex, " [\"", aPartName, "\"] - solid #", i, " has:", sep="")
80 i += 1
81 self.ProcessSolid (mtk.ModelData_Solid.Cast (aShape))
82 self.myPartIndex += 1
83
84 @abstractmethod
85 def ProcessSolid(self, theSolid: mtk.ModelData_Solid):
86 pass
87
88class SolidAndMeshProcessor(mtk.ModelData_ModelElementVoidVisitor):
89 def __init__(self):
90 super().__init__()
91 self.myPartIndex = 0
92 self.myShapeIndex = 0
93
94 def VisitPart(self, thePart: mtk.ModelData_Part):
95 aPartName = "noname" if thePart.Name().IsEmpty() else thePart.Name()
96
97 myShapeIndex = 0
98 aBodyList = thePart.Bodies()
99 for aBody in aBodyList:
100 if mtk.ModelData_MeshBody.CompareType(aBody):
101 aMeshBody = mtk.ModelData_MeshBody.Cast(aBody)
102 self._ProcessMeshBody(aMeshBody, aPartName)
103 elif mtk.ModelData_SolidBody.CompareType(aBody):
104 aSolid = mtk.ModelData_SolidBody.Cast(aBody).Solid()
105 print("Part #", self.myPartIndex, " [\"", aPartName, "\"] - solid #", myShapeIndex, " has:", sep="")
106 self.ProcessSolid (aSolid, aPartName)
107 self.myShapeIndex += 1
108 self.myPartIndex += 1
109
110 @abstractmethod
111 def ProcessSolid(self, theSolid: mtk.ModelData_Solid, thePartName: mtk.UTF16String):
112 pass
113
114 @abstractmethod
115 def ProcessITS(self, theITS: mtk.ModelData_IndexedTriangleSet, thePartName: mtk.UTF16String):
116 pass
117
118 def _ProcessMeshBody(self, theMeshBody: mtk.ModelData_MeshBody, thePartName: mtk.UTF16String):
119 aMeshShapes = theMeshBody.Shapes()
120 for aMeshShape in aMeshShapes:
121 if(mtk.ModelData_IndexedTriangleSet.CompareType(aMeshShape)):
122 print("Part #", self.myPartIndex, " [\"", thePartName, "\"] - ITS #", self.myShapeIndex, " has:", sep="")
123 anITS = mtk.ModelData_IndexedTriangleSet.Cast(aMeshShape)
124 self.ProcessITS(anITS, thePartName)
125 self.myShapeIndex += 1
126