From af1a40c913792a6d502ed2d3ad5febc34f540b2c Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 30 Aug 2022 20:08:50 +1000 Subject: [PATCH] Fix bug where if an object placement was reused elsewhere a circular reference was created --- .../api/geometry/edit_object_placement.py | 3 +- .../geometry/test_edit_object_placement.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py index f604d5a3da..64d16873f0 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/edit_object_placement.py @@ -44,7 +44,7 @@ class Usecase: placement_rel_to = self.get_placement_rel_to() relative_placement = self.get_relative_placement(placement_rel_to) - new_placement = self.file.createIfcLocalPlacement(placement_rel_to, relative_placement) + new_placement = self.file.createIfcLocalPlacement(RelativePlacement=relative_placement) old_placement = self.settings["product"].ObjectPlacement @@ -59,6 +59,7 @@ class Usecase: if inverse.is_a("IfcLocalPlacement"): ifcopenshell.util.element.replace_attribute(inverse, old_placement, new_placement) + new_placement.PlacementRelTo = placement_rel_to self.settings["product"].ObjectPlacement = new_placement ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": self.settings["product"]}) diff --git a/src/ifcopenshell-python/test/api/geometry/test_edit_object_placement.py b/src/ifcopenshell-python/test/api/geometry/test_edit_object_placement.py index e213ed21a2..bd0d24b728 100644 --- a/src/ifcopenshell-python/test/api/geometry/test_edit_object_placement.py +++ b/src/ifcopenshell-python/test/api/geometry/test_edit_object_placement.py @@ -134,6 +134,40 @@ class TestEditObjectPlacement(test.bootstrap.IFC4): assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), matrix2) assert element.ObjectPlacement != element2.ObjectPlacement + def test_changing_an_object_placement_shared_by_its_parent(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) + matrix1 = numpy.array( + ( + (1.0, 0.0, 0.0, 1.0), + (0.0, 1.0, 0.0, 2.0), + (0.0, 0.0, 1.0, 3.0), + (0.0, 0.0, 0.0, 1.0), + ) + ) + matrix2 = numpy.array( + ( + (1.0, 0.0, 0.0, 4.0), + (0.0, 1.0, 0.0, 5.0), + (0.0, 0.0, 1.0, 6.0), + (0.0, 0.0, 0.0, 1.0), + ) + ) + ifcopenshell.api.run( + "geometry.edit_object_placement", self.file, product=element, matrix=matrix1.copy(), is_si=False + ) + subelement.ObjectPlacement = element.ObjectPlacement + ifcopenshell.api.run( + "geometry.edit_object_placement", self.file, product=subelement, matrix=matrix2.copy(), is_si=False + ) + assert subelement.ObjectPlacement.PlacementRelTo != subelement.ObjectPlacement + assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), matrix2) + assert element.ObjectPlacement != subelement.ObjectPlacement + + def test_changing_placements_relative_to_a_spatial_container(self): ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject") ifcopenshell.api.run("unit.assign_unit", self.file)