MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / IteratorForTypes

Class IteratorForTypes

src/ifc5d/ifc5d/qto.py:169–215  ·  view source on GitHub ↗

Currently ifcopenshell.geom.iterator support only IfcProducts, so this class is mimicking the iterator interface but works for IfcTypeProducts.

Source from the content-addressed store, hash-verified

167
168
169class IteratorForTypes:
170 """Currently ifcopenshell.geom.iterator support only IfcProducts, so this
171 class is mimicking the iterator interface but works for IfcTypeProducts."""
172
173 element: Union[ifcopenshell.entity_instance, None] = None
174 shape: Union[ifcopenshell.geom.ShapeType, None] = None
175
176 def __init__(
177 self,
178 ifc_file: ifcopenshell.file,
179 settings: ifcopenshell.geom.settings,
180 elements: Iterable[ifcopenshell.entity_instance],
181 ):
182 self.settings = settings
183 self.elements = list(elements)
184 self.element = None
185 self.file = ifc_file
186 model = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
187 assert model
188 self.context = model
189
190 def initialize(self) -> bool:
191 return bool(self.next())
192
193 def get_element_and_geometry(self) -> tuple[ifcopenshell.entity_instance, ifcopenshell.geom.ShapeType]:
194 # get() is not implemented so it won't be confused with iteartor.get().
195 # The difference is important since create_shape for product types
196 # doesn't ouput SpapeElementType, only ShapeTypes.
197 assert self.element and self.shape
198 return (self.element, self.shape)
199
200 def next(self) -> bool:
201 if not self.elements:
202 return False
203 while self.elements:
204 element = self.elements.pop()
205 if self.process_shape(element):
206 return True
207 return False
208
209 def process_shape(self, element: ifcopenshell.entity_instance):
210 representation = ifcopenshell.util.representation.get_representation(element, self.context)
211 if not representation:
212 return False
213 self.shape = ifcopenshell.geom.create_shape(self.settings, representation)
214 self.element = element
215 return True
216
217
218class QtoCalculator:

Callers 1

create_iteratorsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected