From e909f254329e18b7b62853eb3d28f0daa6a6d969 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 21 Mar 2022 10:22:25 +1100 Subject: [PATCH] Removing a property set now also removes properties --- .../ifcopenshell/api/pset/remove_pset.py | 7 ++- .../test/api/pset/test_remove_pset.py | 59 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/ifcopenshell-python/test/api/pset/test_remove_pset.py diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset/remove_pset.py b/src/ifcopenshell-python/ifcopenshell/api/pset/remove_pset.py index 505593d81a..e2d663cf8f 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset/remove_pset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset/remove_pset.py @@ -37,7 +37,12 @@ class Usecase: inverse.RelatedObjects = related_objects should_remove_pset = False if should_remove_pset: + if self.settings["pset"].is_a("IfcPropertySet"): + properties = self.settings["pset"].HasProperties or [] + elif self.settings["pset"].is_a("IfcQuantitySet"): + properties = self.settings["pset"].Quantities or [] + for prop in properties: + self.file.remove(prop) self.file.remove(self.settings["pset"]) for element in to_purge: self.file.remove(element) - # TODO: implement deep purging diff --git a/src/ifcopenshell-python/test/api/pset/test_remove_pset.py b/src/ifcopenshell-python/test/api/pset/test_remove_pset.py new file mode 100644 index 0000000000..4f5291a3ef --- /dev/null +++ b/src/ifcopenshell-python/test/api/pset/test_remove_pset.py @@ -0,0 +1,59 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2022 Dion Moult +# +# This file is part of IfcOpenShell. +# +# IfcOpenShell is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# IfcOpenShell is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with IfcOpenShell. If not, see . + +import test.bootstrap +import ifcopenshell.api + + +class TestRemovePset(test.bootstrap.IFC4): + def test_removing_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="Foo_Bar") + assert len(self.file.by_type("IfcRelDefinesByProperties")) == 1 + ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset) + assert len(self.file.by_type("IfcRelDefinesByProperties")) == 0 + assert len(self.file.by_type("IfcPropertySet")) == 0 + + def test_only_unassigning_if_pset_is_used_by_other_elements(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar") + rel = self.file.by_type("IfcRelDefinesByProperties")[0] + rel.RelatedObjects = [element, element2] + assert len(self.file.by_type("IfcRelDefinesByProperties")) == 1 + ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset) + assert ifcopenshell.util.element.get_psets(element) == {} + assert "Foo_Bar" in ifcopenshell.util.element.get_psets(element2) + + def test_removing_a_pset_with_properties(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="Foo_Bar") + ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"}) + ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset) + assert len(self.file.by_type("IfcRelDefinesByProperties")) == 0 + assert len(self.file.by_type("IfcPropertySet")) == 0 + assert len(self.file.by_type("IfcPropertySingleValue")) == 0 + + def test_removing_a_qto_with_quantities(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="Foo_Bar") + ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"Foo": 42}) + ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=qto) + assert len(self.file.by_type("IfcRelDefinesByProperties")) == 0 + assert len(self.file.by_type("IfcQuantitySet")) == 0 + assert len(self.file.by_type("IfcPhysicalSimpleQuantity")) == 0