From d384b3d7df24bd554a57d05f92655667ec264fd1 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 14 Oct 2021 15:52:38 +1100 Subject: [PATCH] Fix bug where copying a container also copied its contents --- .../ifcopenshell/api/root/copy_class.py | 2 ++ .../test/api/root/test_copy_class.py | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py index 94cb1eef14..045285f45e 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py @@ -27,6 +27,8 @@ class Usecase: inverse.RelatingPropertyDefinition = pset elif inverse.is_a("IfcRelAggregates") and inverse.RelatingObject == from_element: continue + elif inverse.is_a("IfcRelContainedInSpatialStructure") and inverse.RelatingStructure == from_element: + continue elif inverse.is_a("IfcRelFillsElement"): continue else: 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 19a02821b0..e731ec783b 100644 --- a/src/ifcopenshell-python/test/api/root/test_copy_class.py +++ b/src/ifcopenshell-python/test/api/root/test_copy_class.py @@ -24,6 +24,29 @@ 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_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") + ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element) + new = ifcopenshell.api.run("root.copy_class", self.file, product=element) + assert element.ContainsElements + assert not new.ContainsElements + + def test_copying_contents_of_a_container(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") + ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element) + new = ifcopenshell.api.run("root.copy_class", self.file, product=subelement) + assert new.ContainedInStructure[0].RelatingStructure == element + + def test_copying_a_container_only_and_not_its_decomposition(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding") + subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey") + ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element) + new = ifcopenshell.api.run("root.copy_class", self.file, product=element) + assert element.IsDecomposedBy + assert not new.IsDecomposedBy + def test_copying_an_aggregate_only_and_not_its_decomposition(self): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly") subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")