From fbadcc017bbd1ffdfea6253f849c3e857baa0eff Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 25 Oct 2021 15:36:55 +1100 Subject: [PATCH] Get psets utility can now filter only psets or qtos --- .../ifcopenshell/util/element.py | 10 ++++++- .../test/util/test_element.py | 26 +++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 654ef21fa0..9af1ce647d 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -1,16 +1,24 @@ import ifcopenshell -def get_psets(element): +def get_psets(element, psets_only=False, qtos_only=False): psets = {} if element.is_a("IfcTypeObject"): if element.HasPropertySets: for definition in element.HasPropertySets: + if psets_only and not definition.is_a("IfcPropertySet"): + continue + if qtos_only and not definition.is_a("IfcElementQuantity"): + continue psets[definition.Name] = get_property_definition(definition) elif hasattr(element, "IsDefinedBy"): for relationship in element.IsDefinedBy: if relationship.is_a("IfcRelDefinesByProperties"): definition = relationship.RelatingPropertyDefinition + if psets_only and not definition.is_a("IfcPropertySet"): + continue + if qtos_only and not definition.is_a("IfcElementQuantity"): + continue psets[definition.Name] = get_property_definition(definition) return psets diff --git a/src/ifcopenshell-python/test/util/test_element.py b/src/ifcopenshell-python/test/util/test_element.py index e305e3b3ef..8bd4dedcb3 100644 --- a/src/ifcopenshell-python/test/util/test_element.py +++ b/src/ifcopenshell-python/test/util/test_element.py @@ -10,36 +10,52 @@ class TestGetPsetsIFC4(test.bootstrap.IFC4): assert subject.get_psets(element) == {} pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name") ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"}) - assert subject.get_psets(element) == {"name": {"a": "b", "id": 2}} + assert subject.get_psets(element) == {"name": {"a": "b", "id": pset.id()}} def test_getting_the_psets_of_a_product_type_as_a_dictionary(self): type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType") assert subject.get_psets(type_element) == {} pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name") ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"}) - assert subject.get_psets(type_element) == {"name": {"x": "y", "id": 2}} + assert subject.get_psets(type_element) == {"name": {"x": "y", "id": pset.id()}} def test_getting_psets_from_an_element_which_cannot_have_psets(self): assert subject.get_psets(self.file.create_entity("IfcPerson")) == {} + def test_only_getting_psets_and_not_qtos(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="pset") + ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"}) + qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="qto") + ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"x": 42}) + assert subject.get_psets(element, psets_only=True) == {"pset": {"a": "b", "id": pset.id()}} + + def test_only_getting_qtos_and_not_psets(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="pset") + ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"}) + qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="qto") + ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"x": 42}) + assert subject.get_psets(element, qtos_only=True) == {"qto": {"x": 42, "id": qto.id()}} + class TestGetPropertyDefinitionIFC4(test.bootstrap.IFC4): def test_getting_the_properties_of_a_pset(self): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name") ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": "b"}) - assert subject.get_property_definition(pset) == {"a": "b", "id": 2} + assert subject.get_property_definition(pset) == {"a": "b", "id": pset.id()} def test_getting_the_properties_of_a_qto(self): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") qto = ifcopenshell.api.run("pset.add_qto", self.file, product=element, name="name") ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"x": 42}) - assert subject.get_property_definition(qto) == {"x": 42, "id": 2} + assert subject.get_property_definition(qto) == {"x": 42, "id": qto.id()} def test_getting_the_properties_of_a_predefined_pset(self): pset = self.file.create_entity("IfcDoorLiningProperties", ifcopenshell.guid.new()) pset.LiningDepth = 42 - assert subject.get_property_definition(pset) == {"LiningDepth": 42, "id": 1} + assert subject.get_property_definition(pset) == {"LiningDepth": 42, "id": pset.id()} class TestGetQuantitiesIFC4(test.bootstrap.IFC4):