8
8
from OCP .XCAFPrs import XCAFPrs_AISObject
9
9
from OCP .TopoDS import TopoDS_Shape
10
10
from OCP .AIS import AIS_InteractiveObject , AIS_Shape
11
- from OCP .Quantity import \
12
- Quantity_TOC_RGB as TOC_RGB , Quantity_Color , Quantity_NOC_GOLD as GOLD
11
+ from OCP .Quantity import (
12
+ Quantity_TOC_RGB as TOC_RGB ,
13
+ Quantity_Color ,
14
+ Quantity_NOC_GOLD as GOLD ,
15
+ )
13
16
from OCP .Graphic3d import Graphic3d_NOM_JADE , Graphic3d_MaterialAspect
14
17
15
18
from PyQt5 .QtGui import QColor
@@ -25,48 +28,66 @@ def is_cq_obj(obj):
25
28
return isinstance (obj , (Workplane , Shape , Assembly , Sketch ))
26
29
27
30
28
- def find_cq_objects (results : dict ):
31
+ def find_cq_objects (results : dict ):
29
32
30
- return {k :SimpleNamespace (shape = v ,options = {}) for k ,v in results .items () if is_cq_obj (v )}
33
+ return {
34
+ k : SimpleNamespace (shape = v , options = {})
35
+ for k , v in results .items ()
36
+ if is_cq_obj (v )
37
+ }
31
38
32
39
33
- def to_compound (obj : Union [cq .Workplane , List [cq .Workplane ], cq .Shape , List [cq .Shape ], cq .Sketch ]):
40
+ def to_compound (
41
+ obj : Union [cq .Workplane , List [cq .Workplane ], cq .Shape , List [cq .Shape ], cq .Sketch ],
42
+ ):
34
43
35
44
vals = []
36
45
37
- if isinstance (obj ,cq .Workplane ):
46
+ if isinstance (obj , cq .Workplane ):
38
47
vals .extend (obj .vals ())
39
- elif isinstance (obj ,cq .Shape ):
48
+ elif isinstance (obj , cq .Shape ):
40
49
vals .append (obj )
41
- elif isinstance (obj ,list ) and isinstance (obj [0 ],cq .Workplane ):
42
- for o in obj : vals .extend (o .vals ())
43
- elif isinstance (obj ,list ) and isinstance (obj [0 ],cq .Shape ):
50
+ elif isinstance (obj , list ) and isinstance (obj [0 ], cq .Workplane ):
51
+ for o in obj :
52
+ vals .extend (o .vals ())
53
+ elif isinstance (obj , list ) and isinstance (obj [0 ], cq .Shape ):
44
54
vals .extend (obj )
45
55
elif isinstance (obj , TopoDS_Shape ):
46
56
vals .append (cq .Shape .cast (obj ))
47
- elif isinstance (obj ,list ) and isinstance (obj [0 ],TopoDS_Shape ):
57
+ elif isinstance (obj , list ) and isinstance (obj [0 ], TopoDS_Shape ):
48
58
vals .extend (cq .Shape .cast (o ) for o in obj )
49
59
elif isinstance (obj , cq .Sketch ):
50
60
if obj ._faces :
51
61
vals .append (obj ._faces )
52
62
else :
53
63
vals .extend (obj ._edges )
54
64
else :
55
- raise ValueError (f' Invalid type { type (obj )} ' )
65
+ raise ValueError (f" Invalid type { type (obj )} " )
56
66
57
67
return cq .Compound .makeCompound (vals )
58
68
59
69
60
- def to_workplane (obj : cq .Shape ):
70
+ def to_workplane (obj : cq .Shape ):
61
71
62
- rv = cq .Workplane ('XY' )
63
- rv .objects = [obj ,]
72
+ rv = cq .Workplane ("XY" )
73
+ rv .objects = [
74
+ obj ,
75
+ ]
64
76
65
77
return rv
66
78
67
79
68
- def make_AIS (obj : Union [cq .Workplane , List [cq .Workplane ], cq .Shape , List [cq .Shape ], cq .Assembly , AIS_InteractiveObject ],
69
- options = {}):
80
+ def make_AIS (
81
+ obj : Union [
82
+ cq .Workplane ,
83
+ List [cq .Workplane ],
84
+ cq .Shape ,
85
+ List [cq .Shape ],
86
+ cq .Assembly ,
87
+ AIS_InteractiveObject ,
88
+ ],
89
+ options = {},
90
+ ):
70
91
71
92
shape = None
72
93
@@ -82,28 +103,29 @@ def make_AIS(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Sha
82
103
set_material (ais , DEFAULT_MATERIAL )
83
104
set_color (ais , DEFAULT_FACE_COLOR )
84
105
85
- if ' alpha' in options :
86
- set_transparency (ais , options [' alpha' ])
87
- if ' color' in options :
88
- set_color (ais , to_occ_color (options [' color' ]))
89
- if ' rgba' in options :
90
- r ,g , b , a = options [' rgba' ]
91
- set_color (ais , to_occ_color ((r ,g , b )))
106
+ if " alpha" in options :
107
+ set_transparency (ais , options [" alpha" ])
108
+ if " color" in options :
109
+ set_color (ais , to_occ_color (options [" color" ]))
110
+ if " rgba" in options :
111
+ r , g , b , a = options [" rgba" ]
112
+ set_color (ais , to_occ_color ((r , g , b )))
92
113
set_transparency (ais , a )
93
114
94
- return ais ,shape
115
+ return ais , shape
95
116
96
117
97
- def export (obj : Union [cq .Workplane , List [cq .Workplane ]], type : str ,
98
- file , precision = 1e-1 ):
118
+ def export (
119
+ obj : Union [cq .Workplane , List [cq .Workplane ]], type : str , file , precision = 1e-1
120
+ ):
99
121
100
122
comp = to_compound (obj )
101
123
102
- if type == ' stl' :
124
+ if type == " stl" :
103
125
comp .exportStl (file , tolerance = precision )
104
- elif type == ' step' :
126
+ elif type == " step" :
105
127
comp .exportStep (file )
106
- elif type == ' brep' :
128
+ elif type == " brep" :
107
129
comp .exportBrep (file )
108
130
109
131
@@ -116,17 +138,14 @@ def to_occ_color(color) -> Quantity_Color:
116
138
elif isinstance (color [0 ], float ):
117
139
color = QColor .fromRgbF (* color )
118
140
else :
119
- raise ValueError (' Unknown color format' )
141
+ raise ValueError (" Unknown color format" )
120
142
else :
121
143
color = QColor (color )
122
144
123
- return Quantity_Color (color .redF (),
124
- color .greenF (),
125
- color .blueF (),
126
- TOC_RGB )
145
+ return Quantity_Color (color .redF (), color .greenF (), color .blueF (), TOC_RGB )
127
146
128
147
129
- def get_occ_color (obj : Union [AIS_InteractiveObject , Quantity_Color ]) -> QColor :
148
+ def get_occ_color (obj : Union [AIS_InteractiveObject , Quantity_Color ]) -> QColor :
130
149
131
150
if isinstance (obj , AIS_InteractiveObject ):
132
151
color = Quantity_Color ()
@@ -137,7 +156,7 @@ def get_occ_color(obj : Union[AIS_InteractiveObject, Quantity_Color]) -> QColor:
137
156
return QColor .fromRgbF (color .Red (), color .Green (), color .Blue ())
138
157
139
158
140
- def set_color (ais : AIS_Shape , color : Quantity_Color ) -> AIS_Shape :
159
+ def set_color (ais : AIS_Shape , color : Quantity_Color ) -> AIS_Shape :
141
160
142
161
drawer = ais .Attributes ()
143
162
drawer .SetupOwnShadingAspect ()
@@ -146,7 +165,7 @@ def set_color(ais : AIS_Shape, color : Quantity_Color) -> AIS_Shape:
146
165
return ais
147
166
148
167
149
- def set_material (ais : AIS_Shape , material : Graphic3d_MaterialAspect ) -> AIS_Shape :
168
+ def set_material (ais : AIS_Shape , material : Graphic3d_MaterialAspect ) -> AIS_Shape :
150
169
151
170
drawer = ais .Attributes ()
152
171
drawer .SetupOwnShadingAspect ()
@@ -155,7 +174,7 @@ def set_material(ais : AIS_Shape, material: Graphic3d_MaterialAspect) -> AIS_Sha
155
174
return ais
156
175
157
176
158
- def set_transparency (ais : AIS_Shape , alpha : float ) -> AIS_Shape :
177
+ def set_transparency (ais : AIS_Shape , alpha : float ) -> AIS_Shape :
159
178
160
179
drawer = ais .Attributes ()
161
180
drawer .SetupOwnShadingAspect ()
@@ -184,13 +203,13 @@ def reload_cq():
184
203
reload (cq .occ_impl .exporters .dxf )
185
204
reload (cq .occ_impl .exporters .amf )
186
205
reload (cq .occ_impl .exporters .json )
187
- #reload(cq.occ_impl.exporters.assembly)
206
+ # reload(cq.occ_impl.exporters.assembly)
188
207
reload (cq .occ_impl .exporters )
189
208
reload (cq .assembly )
190
209
reload (cq )
191
210
192
211
193
- def is_obj_empty (obj : Union [cq .Workplane ,cq .Shape ]) -> bool :
212
+ def is_obj_empty (obj : Union [cq .Workplane , cq .Shape ]) -> bool :
194
213
195
214
rv = False
196
215
0 commit comments