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
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
41
42
43class PartPolyVisitor(cadex.ModelData_Model_VoidElementVisitor):
44 def VisitPart(self, thePart: cadex.ModelData_Part):
45 aPolyRep = thePart.PolyRepresentation(cadex.ModelData_RM_Poly)
46 if aPolyRep:
47 self.ExplorePoly(aPolyRep)
48
49
50 def ExplorePoly(self, thePoly: cadex.ModelData_PolyRepresentation):
51
52
53 aList = thePoly.Get()
54
55
56 for i, aPVS in enumerate(aList):
57 print(f"PolyShape {i}:")
58 self.PrintPVSInfo(aPVS)
59
60
61 def PrintPVSInfo(self, thePVS: cadex.ModelData_PolyVertexSet):
63 print("IndexedTriangleSet type.")
64 ITS = cadex.ModelData_IndexedTriangleSet.Cast(thePVS)
65 self.DumpTriangleSet(ITS)
67 print("PolyLineSet type.")
68 PLS = cadex.ModelData_PolyLineSet.Cast(thePVS)
69 self.DumpPolyLineSet(PLS)
71 print("PolyPointSet type.")
72 PPS = cadex.ModelData_PolyPointSet.Cast(thePVS)
73 self.DumpPolyPointSet(PPS)
74 else:
75 print("Undefined type")
76
77 def DumpPolyPointSet(self, thePS: cadex.ModelData_PolyPointSet):
78 n = thePS.NumberOfVertices()
79
80 print(f"PolyPoint set contains {n} vertices")
81 for i in range(n):
82 print(f"Point {i}:")
83 print(" Node coordinates:")
84 aP = thePS.Coordinate(i)
85 print(f" ({aP.X()}, {aP.Y()}, {aP.Z()})")
86
87
88 def DumpPolyLineSet(self, thePLS: cadex.ModelData_PolyLineSet):
89 n = thePLS.NumberOfPolyLines()
90
91 print(f"PolyLine set contains {n} PolyLines")
92 for i in range(n):
93 print(f"PolyLine {i}:")
94 print(" Node coordinates:")
95 for j in range(thePLS.NumberOfVertices(i)):
96 aV = thePLS.Coordinate(i, j)
97 print(f" ({aV.X()}, {aV.Y()}, {aV.Z()})")
98
99
100
101 def DumpTriangleSet(self, theTS: cadex.ModelData_IndexedTriangleSet):
102 n = theTS.NumberOfFaces()
103
104 print(f"Triangle set contains {n} number of faces")
105 for i in range(n):
106 print(f"Triangle {i}:")
107 for j in range(3):
108 print(f" Node {j}:")
109
110
111 aV = theTS.Coordinate(i, j);
112 print(f" Coordinates: ({aV.X()}, {aV.Y()}, {aV.Z()})")
113
114
115 if theTS.HasUVCoordinates():
116 aUV = theTS.UVCoordinate(i, j)
117 print(f" UV Coordinates: ({aUV.X()}, {aUV.Y()})")
118
119
120 if theTS.HasNormals():
121 aN = theTS.VertexNormal(i, j)
122 print(f" Normal vector: ({aN.X()}, {aN.Y()}, {aN.Z()})")
123
124
125 if theTS.HasColors():
126 aColor = theTS.VertexColor(i, j)
127
128
129def main(theSource: str):
130 aKey = license.Value()
131
132 if not cadex.LicenseManager.Activate(aKey):
133 print("Failed to activate CAD Exchanger license.")
134 return 1
135
137
139 print("Failed to read the file " + theSource)
140 return 1
141
142
144 aMesherParams.SetGranularity(cadex.ModelAlgo_BRepMesherParameters.Fine)
145
147 aMesher.Compute(aModel)
148
149
150 aVisitor = PartPolyVisitor()
151 aModel.AcceptElementVisitor(aVisitor)
152
153 print("Completed")
154 return 0
155
156if __name__ == "__main__":
157 if len(sys.argv) != 2:
158 print("Usage: " + os.path.abspath(Path(__file__).resolve()) + " <input_file>, where:")
159 print(" <input_file> is a name of the XML file to be read")
160 sys.exit(1)
161
162 aSource = os.path.abspath(sys.argv[1])
163 sys.exit(main(aSource))
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
Computes a polygonal representation from a B-Rep one.
Definition: ModelAlgo_BRepMesher.hxx:48
Defines parameters used by the B-Rep mesher.
Definition: ModelAlgo_BRepMesherParameters.hxx:33
static IdType GetTypeId()
Definition: ModelData_IndexedTriangleSet.cxx:134
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33
static IdType GetTypeId()
Definition: ModelData_PolyLineSet.cxx:57
static IdType GetTypeId()
Definition: ModelData_PolyPointSet.cxx:56