Fix bug where copying elements shared a placement. This fix speeds up copying parent elements in the decomposition significantly, like when copying a storey.

This commit is contained in:
Dion Moult
2021-10-14 16:13:48 +11:00
parent dd3fc79fb9
commit 199be3363f
2 changed files with 27 additions and 5 deletions
@@ -1,3 +1,4 @@
import numpy
import test.bootstrap
import ifcopenshell.api
@@ -10,7 +11,20 @@ class TestCopyClass(test.bootstrap.IFC4):
assert new.GlobalId != element.GlobalId
assert new.is_a("IfcWall")
def test_copying_an_element_with_properties(self):
def test_copying_object_placements_so_children_of_the_original_element_dont_reference_the_new_element(self):
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
ifcopenshell.api.run("unit.assign_unit", self.file)
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)
matrix = numpy.identity(4)
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=element, matrix=matrix.copy())
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=subelement, matrix=matrix.copy())
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement
assert subelement.ObjectPlacement.PlacementRelTo != new.ObjectPlacement
def test_copying_psets_so_changing_properties_of_the_new_element_does_not_affect_the_old(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="Foobar")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"foo": "bar"})
@@ -32,7 +46,7 @@ class TestCopyClass(test.bootstrap.IFC4):
assert element.ContainsElements
assert not new.ContainsElements
def test_copying_contents_of_a_container(self):
def test_copying_contents_of_a_container_and_maintaining_the_containment_relationship(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)
@@ -55,7 +69,7 @@ class TestCopyClass(test.bootstrap.IFC4):
assert element.IsDecomposedBy
assert not new.IsDecomposedBy
def test_copying_an_aggregate_decomposition(self):
def test_copying_an_aggregate_decomposition_and_maintaining_the_aggregate_relationship(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")
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)