Fix bug where copying a container also copied its contents

This commit is contained in:
Dion Moult
2021-10-14 15:52:38 +11:00
parent 04209c78b9
commit d384b3d7df
2 changed files with 25 additions and 0 deletions
@@ -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:
@@ -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")