Support relative object placements for IFC2X3 ports.

This commit is contained in:
Dion Moult
2022-02-01 18:23:55 +11:00
parent 3e10f52965
commit a2c0045a40
2 changed files with 36 additions and 0 deletions
@@ -83,6 +83,9 @@ class Usecase:
elif getattr(self.settings["product"], "Nests", None):
relating_object = self.settings["product"].Nests[0].RelatingObject
return relating_object.ObjectPlacement if hasattr(relating_object, "ObjectPlacement") else None
elif getattr(self.settings["product"], "ContainedIn", None):
related_element = self.settings["product"].ContainedIn[0].RelatedElement
return related_element.ObjectPlacement if hasattr(related_element, "ObjectPlacement") else None
elif getattr(self.settings["product"], "VoidsElements", None):
relating_object = self.settings["product"].VoidsElements[0].RelatingBuildingElement
return relating_object.ObjectPlacement if hasattr(relating_object, "ObjectPlacement") else None
@@ -459,3 +459,36 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), matrix)
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), submatrix)
assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement
class TestEditObjectPlacement(test.bootstrap.IFC2X3):
def test_changing_placements_relative_to_a_distribution_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="IfcFlowSegment")
subelement = ifcopenshell.api.run("system.add_port", self.file, element=element)
matrix = numpy.array(
(
(1.0, 0.0, 0.0, 1.0),
(0.0, 1.0, 0.0, 1.0),
(0.0, 0.0, 1.0, 1.0),
(0.0, 0.0, 0.0, 1.0),
)
)
submatrix = 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),
)
)
ifcopenshell.api.run(
"geometry.edit_object_placement", self.file, product=element, matrix=matrix.copy(), is_si=False
)
ifcopenshell.api.run(
"geometry.edit_object_placement", self.file, product=subelement, matrix=submatrix.copy(), is_si=False
)
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), matrix)
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), submatrix)
assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement