18
18
from .cq import Workplane
19
19
from .occ_impl .shapes import Shape , Compound
20
20
from .occ_impl .geom import Location
21
- from .occ_impl .assembly import Color
21
+ from .occ_impl .assembly import Color , Material , AssemblyElement
22
22
from .occ_impl .solver import (
23
23
ConstraintKind ,
24
24
ConstraintSolver ,
@@ -85,6 +85,7 @@ class Assembly(object):
85
85
loc : Location
86
86
name : str
87
87
color : Optional [Color ]
88
+ material : Optional [Material ]
88
89
metadata : Dict [str , Any ]
89
90
90
91
obj : AssemblyObjects
@@ -107,6 +108,7 @@ def __init__(
107
108
loc : Optional [Location ] = None ,
108
109
name : Optional [str ] = None ,
109
110
color : Optional [Color ] = None ,
111
+ material : Optional [Material ] = None ,
110
112
metadata : Optional [Dict [str , Any ]] = None ,
111
113
):
112
114
"""
@@ -116,6 +118,7 @@ def __init__(
116
118
:param loc: location of the root object (default: None, interpreted as identity transformation)
117
119
:param name: unique name of the root object (default: None, resulting in an UUID being generated)
118
120
:param color: color of the added object (default: None)
121
+ :param material: material of the added object (default: None)
119
122
:param metadata: a store for user-defined metadata (default: None)
120
123
:return: An Assembly object.
121
124
@@ -135,6 +138,7 @@ def __init__(
135
138
self .loc = loc if loc else Location ()
136
139
self .name = name if name else str (uuid ())
137
140
self .color = color if color else None
141
+ self .material = material if material else None
138
142
self .metadata = metadata if metadata else {}
139
143
self .parent = None
140
144
@@ -153,7 +157,9 @@ def _copy(self) -> "Assembly":
153
157
Make a deep copy of an assembly
154
158
"""
155
159
156
- rv = self .__class__ (self .obj , self .loc , self .name , self .color , self .metadata )
160
+ rv = self .__class__ (
161
+ self .obj , self .loc , self .name , self .color , self .material , self .metadata
162
+ )
157
163
158
164
for ch in self .children :
159
165
ch_copy = ch ._copy ()
@@ -172,6 +178,7 @@ def add(
172
178
loc : Optional [Location ] = None ,
173
179
name : Optional [str ] = None ,
174
180
color : Optional [Color ] = None ,
181
+ material : Optional [Material ] = None ,
175
182
) -> "Assembly" :
176
183
"""
177
184
Add a subassembly to the current assembly.
@@ -183,6 +190,8 @@ def add(
183
190
the subassembly being used)
184
191
:param color: color of the added object (default: None, resulting in the color stored in the
185
192
subassembly being used)
193
+ :param material: material of the added object (default: None, resulting in the material stored in the
194
+ subassembly being used)
186
195
"""
187
196
...
188
197
@@ -193,6 +202,7 @@ def add(
193
202
loc : Optional [Location ] = None ,
194
203
name : Optional [str ] = None ,
195
204
color : Optional [Color ] = None ,
205
+ material : Optional [Material ] = None ,
196
206
metadata : Optional [Dict [str , Any ]] = None ,
197
207
) -> "Assembly" :
198
208
"""
@@ -204,6 +214,7 @@ def add(
204
214
:param name: unique name of the root object (default: None, resulting in an UUID being
205
215
generated)
206
216
:param color: color of the added object (default: None)
217
+ :param material: material of the added object (default: None)
207
218
:param metadata: a store for user-defined metadata (default: None)
208
219
"""
209
220
...
@@ -225,6 +236,9 @@ def add(self, arg, **kwargs):
225
236
subassy .loc = kwargs ["loc" ] if kwargs .get ("loc" ) else arg .loc
226
237
subassy .name = kwargs ["name" ] if kwargs .get ("name" ) else arg .name
227
238
subassy .color = kwargs ["color" ] if kwargs .get ("color" ) else arg .color
239
+ subassy .material = (
240
+ kwargs ["material" ] if kwargs .get ("material" ) else arg .material
241
+ )
228
242
subassy .metadata = (
229
243
kwargs ["metadata" ] if kwargs .get ("metadata" ) else arg .metadata
230
244
)
@@ -658,22 +672,31 @@ def __iter__(
658
672
loc : Optional [Location ] = None ,
659
673
name : Optional [str ] = None ,
660
674
color : Optional [Color ] = None ,
661
- ) -> Iterator [Tuple [Shape , str , Location , Optional [Color ]]]:
675
+ material : Optional [Material ] = None ,
676
+ ) -> Iterator [AssemblyElement ]:
662
677
"""
663
- Assembly iterator yielding shapes, names, locations and colors .
678
+ Assembly iterator yielding shapes, names, locations, colors and materials .
664
679
"""
665
680
666
681
name = f"{ name } /{ self .name } " if name else self .name
667
682
loc = loc * self .loc if loc else self .loc
668
683
color = self .color if self .color else color
684
+ material = self .material if self .material else material
669
685
670
686
if self .obj :
671
- yield self .obj if isinstance (self .obj , Shape ) else Compound .makeCompound (
672
- s for s in self .obj .vals () if isinstance (s , Shape )
673
- ), name , loc , color
687
+ shape = (
688
+ self .obj
689
+ if isinstance (self .obj , Shape )
690
+ else Compound .makeCompound (
691
+ s for s in self .obj .vals () if isinstance (s , Shape )
692
+ )
693
+ )
694
+ yield AssemblyElement (
695
+ shape = shape , name = name , location = loc , color = color , material = material
696
+ )
674
697
675
698
for ch in self .children :
676
- yield from ch .__iter__ (loc , name , color )
699
+ yield from ch .__iter__ (loc , name , color , material )
677
700
678
701
def toCompound (self ) -> Compound :
679
702
"""
0 commit comments