9
9
from OCP .TopoDS import TopoDS_Shape
10
10
from OCP .AIS import AIS_InteractiveObject , AIS_Shape
11
11
from OCP .Quantity import \
12
- Quantity_TOC_RGB as TOC_RGB , Quantity_Color
13
-
12
+ Quantity_TOC_RGB as TOC_RGB , Quantity_Color , Quantity_NOC_GOLD as GOLD
13
+ from OCP .Graphic3d import Graphic3d_NOM_JADE , Graphic3d_MaterialAspect
14
+
14
15
from PyQt5 .QtGui import QColor
15
16
17
+ DEFAULT_FACE_COLOR = Quantity_Color (GOLD )
18
+ DEFAULT_MATERIAL = Graphic3d_MaterialAspect (Graphic3d_NOM_JADE )
19
+
16
20
def find_cq_objects (results : dict ):
17
21
18
22
return {k :SimpleNamespace (shape = v ,options = {}) for k ,v in results .items () if isinstance (v ,cq .Workplane )}
@@ -30,7 +34,7 @@ def to_compound(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.
30
34
elif isinstance (obj ,list ) and isinstance (obj [0 ],cq .Shape ):
31
35
vals .extend (obj )
32
36
elif isinstance (obj , TopoDS_Shape ):
33
- vals .append (cq .Shape .cast (obj ))
37
+ vals .append (cq .Shape .cast (obj ))
34
38
elif isinstance (obj ,list ) and isinstance (obj [0 ],TopoDS_Shape ):
35
39
vals .extend (cq .Shape .cast (o ) for o in obj )
36
40
elif isinstance (obj , cq .Sketch ):
@@ -63,15 +67,18 @@ def make_AIS(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Sha
63
67
else :
64
68
shape = to_compound (obj )
65
69
ais = AIS_Shape (shape .wrapped )
66
-
70
+
71
+ set_material (ais , DEFAULT_MATERIAL )
72
+ set_color (ais , DEFAULT_FACE_COLOR )
73
+
67
74
if 'alpha' in options :
68
- ais . SetTransparency ( options ['alpha' ])
75
+ set_transparency ( ais , options ['alpha' ])
69
76
if 'color' in options :
70
- ais . SetColor ( to_occ_color (options ['color' ]))
77
+ set_color ( ais , to_occ_color (options ['color' ]))
71
78
if 'rgba' in options :
72
79
r ,g ,b ,a = options ['rgba' ]
73
- ais . SetColor ( to_occ_color ((r ,g ,b )))
74
- ais . SetTransparency ( a )
80
+ set_color ( ais , to_occ_color ((r ,g ,b )))
81
+ set_transparency ( ais , a )
75
82
76
83
return ais ,shape
77
84
@@ -88,7 +95,7 @@ def export(obj : Union[cq.Workplane, List[cq.Workplane]], type : str,
88
95
comp .exportBrep (file )
89
96
90
97
def to_occ_color (color ) -> Quantity_Color :
91
-
98
+
92
99
if not isinstance (color , QColor ):
93
100
if isinstance (color , tuple ):
94
101
if isinstance (color [0 ], int ):
@@ -118,12 +125,29 @@ def get_occ_color(obj : Union[AIS_InteractiveObject, Quantity_Color]) -> QColor:
118
125
def set_color (ais : AIS_Shape , color : Quantity_Color ) -> AIS_Shape :
119
126
120
127
drawer = ais .Attributes ()
128
+ drawer .SetupOwnShadingAspect ()
121
129
drawer .ShadingAspect ().SetColor (color )
122
130
123
131
return ais
124
132
133
+ def set_material (ais : AIS_Shape , material : Graphic3d_MaterialAspect ) -> AIS_Shape :
134
+
135
+ drawer = ais .Attributes ()
136
+ drawer .SetupOwnShadingAspect ()
137
+ drawer .ShadingAspect ().SetMaterial (material )
138
+
139
+ return ais
140
+
141
+ def set_transparency (ais : AIS_Shape , alpha : float ) -> AIS_Shape :
142
+
143
+ drawer = ais .Attributes ()
144
+ drawer .SetupOwnShadingAspect ()
145
+ drawer .ShadingAspect ().SetTransparency (alpha )
146
+
147
+ return ais
148
+
125
149
def reload_cq ():
126
-
150
+
127
151
# NB: order of reloads is important
128
152
reload (cq .types )
129
153
reload (cq .occ_impl .geom )
@@ -147,13 +171,13 @@ def reload_cq():
147
171
reload (cq .occ_impl .exporters )
148
172
reload (cq .assembly )
149
173
reload (cq )
150
-
151
-
174
+
175
+
152
176
def is_obj_empty (obj : Union [cq .Workplane ,cq .Shape ]) -> bool :
153
-
177
+
154
178
rv = False
155
-
179
+
156
180
if isinstance (obj , cq .Workplane ):
157
181
rv = True if isinstance (obj .val (), cq .Vector ) else False
158
-
182
+
159
183
return rv
0 commit comments