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

Method filter

src/ifctester/ifctester/facet.py:277–303  ·  view source on GitHub ↗
(
        self, ifc_file: ifcopenshell.file, elements: Optional[list[ifcopenshell.entity_instance]]
    )

Source from the content-addressed store, hash-verified

275 super().__init__(name, value, cardinality, instructions)
276
277 def filter(
278 self, ifc_file: ifcopenshell.file, elements: Optional[list[ifcopenshell.entity_instance]]
279 ) -> list[ifcopenshell.entity_instance]:
280 if isinstance(elements, list):
281 return super().filter(ifc_file, elements)
282
283 results = []
284 schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(ifc_file.schema_identifier)
285 entities = {entity.name(): entity for entity in schema.entities()}
286
287 def ignore_subtypes(entity):
288 for subentity in entity.subtypes():
289 # entity might be already removed as .entities() order is not hierarchical
290 if entities.pop(subentity.name(), None):
291 ignore_subtypes(subentity)
292
293 while entities:
294 entity_name, entity = entities.popitem()
295 for attribute in entity.attributes():
296 if attribute.name() == self.name:
297 results.extend(ifc_file.by_type(entity_name, include_subtypes=True))
298 # e.g. if IfcRoot already has .Name, it's safe not to check all it's subtypes attributes
299 ignore_subtypes(entity)
300
301 # TODO: perhaps we should consider value in the filter
302
303 return results
304
305 def __call__(self, inst: ifcopenshell.entity_instance, logger: Optional[Logger] = None) -> AttributeResult:
306 if isinstance(self.name, str):

Callers

nothing calls this directly

Calls 6

schema_by_nameMethod · 0.80
attributesMethod · 0.80
filterMethod · 0.45
nameMethod · 0.45
extendMethod · 0.45
by_typeMethod · 0.45

Tested by

no test coverage detected