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
38import cadexchanger.CadExMesh as mesh
39
40sys.path.append(os.path.abspath(os.path.dirname(Path(__file__).resolve()) + r"/../../"))
41import cadex_license as license
42
43import math
44
45
46class FirstFaceGetter(cadex.ModelData_Model_VoidElementVisitor):
47 def __init__(self):
48 cadex.ModelData_Model_VoidElementVisitor.__init__(self)
49 self.myFace = None
50
51 def VisitPart(self, thePart: cadex.ModelData_Part):
52 if self.myFace is None:
53 aBRep = thePart.BRepRepresentation()
54 self.ExploreBRep(aBRep)
55
56 def ExploreBRep(self, theBRep: cadex.ModelData_BRepRepresentation):
57 aBodyList = theBRep.Get()
58 aFirstBody = aBodyList.First()
59 for aShape in cadex.ModelData_Shape_Iterator(aFirstBody, cadex.ModelData_ST_Face):
61 break
62
63 def FirstFace(self):
64 return self.myFace
65
66def PrintFaceToPolyAssociation(theFace: cadex.ModelData_Face,
68 aMeshPatch = theAssociations.Get(theFace)
69 anITS = cadex.ModelData_IndexedTriangleSet.Cast(aMeshPatch.PVS())
70 aTriangleIndices = aMeshPatch.Indices()
71
72 print(f"Face triangulation contains {len(aTriangleIndices)} triangles.")
73
74 aNumberOfTrianglesToPrint = min(4, len(aTriangleIndices))
75
76 for i in range(aNumberOfTrianglesToPrint):
77 aTriangleIndex = aTriangleIndices.Element(i)
78 print(f"Triangle index {aTriangleIndex} with vertices: ")
79 for aVertexNumber in range(3):
80 aVertexIndex = anITS.CoordinateIndex(aTriangleIndex, aVertexNumber);
81 aPoint = anITS.Coordinate(aVertexIndex);
82 print(f" Vertex index {aVertexIndex} with coords",
83 f"(X: {aPoint.X()}, Y: {aPoint.Y()}, Z: {aPoint.Z()})")
84
85def main(theSource: str):
86 aKey = license.Value()
87
88 if not cadex.LicenseManager.Activate(aKey):
89 print("Failed to activate CAD Exchanger license.")
90 return 1
91
93
95 print("Failed to read the file " + theSource)
96 return 1
97
98
100 aParam.SetAngularDeflection(math.pi * 10 / 180)
101 aParam.SetChordalDeflection(0.003)
102 aParam.SetSaveBRepToPolyAssociations(True)
103
105 aMesher.Compute(aModel, True)
106
107
108 aVisitor = FirstFaceGetter();
109 aModel.AcceptElementVisitor(aVisitor);
110
111 aFace = aVisitor.FirstFace();
112 aBRepToPolyAssociations = aMesher.BRepToPolyAssociations();
113 PrintFaceToPolyAssociation(aFace, aBRepToPolyAssociations)
114
115
117 print("Unable to save the model")
118 return 1
119
120 print("Completed")
121 return 0
122
123if __name__ == "__main__":
124 if len(sys.argv) != 2:
125 print("Usage: " + os.path.abspath(Path(__file__).resolve()) + " <input_file>, where:")
126 print(" <input_file> is a name of the XML file to be read")
127 sys.exit(1)
128
129 aSource = os.path.abspath(sys.argv[1])
130
131 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
Contains connecting information between B-Rep and Poly representation.
Definition: ModelData_BRepToPolyAssociations.hxx:42
static const ModelData_Face & Cast(const ModelData_Shape &theShape)
Cast operator.
Definition: ModelData_Face.cxx:282
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33
Writes any format that CAD Exchanger can export.
Definition: ModelData_ModelWriter.hxx:33