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
42class SubshapeAppearancesCollector(cadex.ModelData_BRepRepresentation_SubshapeVisitor):
43 def __init__(self, theBRep: cadex.ModelData_BRepRepresentation, theAppSet: set):
44 super().__init__()
45 self.myBRep = theBRep
46 self.myAppSet = theAppSet
47
48 def VisitShape(self, theShape: cadex.ModelData_Shape):
49 self.ExploreShapeAppearances(theShape)
50
51 def ExploreShapeAppearances(self, theShape: cadex.ModelData_Shape):
52 anApp = self.myBRep.Appearance(theShape)
53 if anApp:
54 self.myAppSet.add(anApp)
55
56
57class RepVisitor(cadex.ModelData_Part_RepresentationVisitor):
58 def __init__(self, theAppSet: set):
59 super().__init__()
60 self.myAppSet = theAppSet
61
62 def VisitBRep(self, theBRep: cadex.ModelData_BRepRepresentation):
63 aCollector = SubshapeAppearancesCollector(theBRep, self.myAppSet)
64 theBRep.Accept(aCollector)
65
66 def VisitPoly(self, thePolyRep: cadex.ModelData_PolyRepresentation):
67 self.ExplorePVSAppearances(thePolyRep)
68
69 def ExplorePVSAppearances(self, thePolyRep: cadex.ModelData_PolyRepresentation):
70 aList = thePolyRep.Get()
71 for aPVS in aList:
72 anApp = aPVS.Appearance()
73 if anApp:
74 self.myAppSet.add(anApp)
75
76class SGEAppearancesCollector(cadex.ModelData_Model_CombinedElementVisitor):
77 def __init__(self, theAppSet):
78 super().__init__()
79 self.myAppSet = theAppSet
80
81 def VisitPart(self, thePart: cadex.ModelData_Part):
82 self.ExploreSGEAppearance(thePart)
83 aVisitor = RepVisitor(self.myAppSet)
84 thePart.Accept(aVisitor)
85
86 def VisitEnterSGE(self, theElement) -> bool:
87 self.ExploreSGEAppearance(theElement)
88 return True
89
90
91 def ExploreSGEAppearance(self, theSGE: cadex.ModelData_SceneGraphElement):
92 anApp = theSGE.Appearance()
93 if anApp:
94 self.myAppSet.add(anApp)
95
96
97class AppearancesCollector:
98 def __init__(self, theModel: cadex.ModelData_Model):
99 self.myModel = theModel
100 aCollector = SGEAppearancesCollector(set())
101 self.myModel.AcceptElementVisitor(aCollector)
102 self.myAppSet = aCollector.myAppSet
103
104
105 def PrintAppearancesCount(self):
106 print("Total model unique Appearances count:", len(self.myAppSet))
107
108
109def main(theSource: str):
110 aKey = license.Value()
111
112 if not cadex.LicenseManager.Activate(aKey):
113 print("Failed to activate CAD Exchanger license.")
114 return 1
115
117
119 print("Failed to read the file", theSource)
120 return 1
121
122
123 aCollector = AppearancesCollector(aModel)
124
125
126 aCollector.PrintAppearancesCount()
127
128 print("Completed")
129 return 0
130
131if __name__ == "__main__":
132 if len(sys.argv) != 2:
133 print("Usage: " + os.path.abspath(Path(__file__).resolve()) + " <input_file>, where:")
134 print(" <input_file> is a name of the XML file to be read")
135 sys.exit(1)
136
137 aSource = os.path.abspath(sys.argv[1])
138 sys.exit(main(aSource))
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