From e3979cadc74a718adf38f33fa1b4457afa0dee4a Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 13 Apr 2023 14:08:02 +1000 Subject: [PATCH] Fix #2974. Type property sets are now properly copied. --- .../ifcopenshell/api/root/copy_class.py | 8 ++++++++ .../test/api/root/test_copy_class.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py index 0e2a88c317..a2618078e1 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py @@ -76,6 +76,7 @@ class Usecase: def copy_direct_attributes(self, to_element): self.remove_representations(to_element) self.copy_object_placements(to_element) + self.copy_psets(to_element) def copy_indirect_attributes(self, from_element, to_element): for inverse in self.file.get_inverse(from_element): @@ -160,3 +161,10 @@ class Usecase: element.ObjectPlacement.RelativePlacement = ifcopenshell.util.element.copy_deep( self.file, element.ObjectPlacement.RelativePlacement ) + + def copy_psets(self, element): + if not element.is_a("IfcTypeObject") or not element.HasPropertySets: + return + element.HasPropertySets = [ + ifcopenshell.util.element.copy_deep(self.file, pset) for pset in element.HasPropertySets + ] diff --git a/src/ifcopenshell-python/test/api/root/test_copy_class.py b/src/ifcopenshell-python/test/api/root/test_copy_class.py index 3c7e7a0c45..9512fe1014 100644 --- a/src/ifcopenshell-python/test/api/root/test_copy_class.py +++ b/src/ifcopenshell-python/test/api/root/test_copy_class.py @@ -57,6 +57,20 @@ class TestCopyClass(test.bootstrap.IFC4): assert pset.HasProperties[0].Name == new_pset.HasProperties[0].Name assert pset.HasProperties[0].NominalValue.wrappedValue == new_pset.HasProperties[0].NominalValue.wrappedValue + def test_copying_type_psets_so_changing_properties_of_the_new_type_does_not_affect_the_old(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType") + pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foobar") + ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"foo": "bar"}) + new = ifcopenshell.api.run("root.copy_class", self.file, product=element) + pset = element.HasPropertySets[0] + new_pset = new.HasPropertySets[0] + assert element.HasPropertySets[0] != new.HasPropertySets[0] + assert pset != new_pset + assert pset.Name == new_pset.Name + assert pset.HasProperties[0] != new_pset.HasProperties[0] + assert pset.HasProperties[0].Name == new_pset.HasProperties[0].Name + assert pset.HasProperties[0].NominalValue.wrappedValue == new_pset.HasProperties[0].NominalValue.wrappedValue + def test_copying_a_container_only_and_not_its_contents(self): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding") subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")