mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Port locations now sync relative to their parent even when not actively displayed in the viewport
This commit is contained in:
@@ -103,6 +103,10 @@ class Usecase:
|
||||
for referenced_placement in placement.ReferencedByPlacements:
|
||||
matrix = ifcopenshell.util.placement.get_local_placement(referenced_placement)
|
||||
for obj in referenced_placement.PlacesObject:
|
||||
# Although a port is technically a nested child, it is generally
|
||||
# more intuitive that the ports always move with the parent.
|
||||
if obj.is_a("IfcDistributionPort"):
|
||||
continue
|
||||
results.append({"product": obj, "matrix": matrix, "is_si": False, "should_transform_children": False})
|
||||
results.extend(self.get_children_settings(referenced_placement))
|
||||
return results
|
||||
|
||||
@@ -49,13 +49,20 @@ class Usecase:
|
||||
ports = [e for e in inverse.RelatedObjects if e.is_a("IfcDistributionPort")]
|
||||
if ports:
|
||||
new_ports = [ifcopenshell.api.run("root.copy_class", self.file, product=p) for p in ports]
|
||||
[
|
||||
ifcopenshell.api.run("system.unassign_port", self.file, element=from_element, port=p)
|
||||
for p in new_ports
|
||||
]
|
||||
inverse = ifcopenshell.util.element.copy(self.file, inverse)
|
||||
inverse.RelatingObject = to_element
|
||||
inverse.RelatedObjects = new_ports
|
||||
for port in new_ports:
|
||||
ifcopenshell.api.run("system.unassign_port", self.file, element=from_element, port=port)
|
||||
matrix = ifcopenshell.util.placement.get_local_placement(port.ObjectPlacement)
|
||||
ifcopenshell.api.run(
|
||||
"geometry.edit_object_placement",
|
||||
self.file,
|
||||
product=port,
|
||||
matrix=matrix,
|
||||
is_si=False,
|
||||
should_transform_children=False,
|
||||
)
|
||||
elif inverse.is_a("IfcRelAggregates") and inverse.RelatingObject == from_element:
|
||||
continue
|
||||
elif inverse.is_a("IfcRelContainedInSpatialStructure") and inverse.RelatingStructure == from_element:
|
||||
|
||||
@@ -460,8 +460,55 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
||||
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), submatrix)
|
||||
assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement
|
||||
|
||||
def test_changing_placements_always_affecting_child_ports_as_a_special_case(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="IfcChiller")
|
||||
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),
|
||||
)
|
||||
)
|
||||
shifted_submatrix = numpy.array(
|
||||
(
|
||||
(1.0, 0.0, 0.0, 1.0),
|
||||
(0.0, 1.0, 0.0, 3.0),
|
||||
(0.0, 0.0, 1.0, 5.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
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"geometry.edit_object_placement",
|
||||
self.file,
|
||||
product=element,
|
||||
matrix=submatrix.copy(),
|
||||
is_si=False,
|
||||
should_transform_children=False,
|
||||
)
|
||||
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), submatrix)
|
||||
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), shifted_submatrix)
|
||||
assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement
|
||||
|
||||
class TestEditObjectPlacement(test.bootstrap.IFC2X3):
|
||||
|
||||
class TestEditObjectPlacementIFC2X3(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)
|
||||
|
||||
@@ -38,7 +38,7 @@ class TestAssignReference(test.bootstrap.IFC4):
|
||||
assert reference.LibraryRefForObjects[0].RelatedObjects == (product,)
|
||||
|
||||
|
||||
class TestAssignReference(test.bootstrap.IFC2X3):
|
||||
class TestAssignReferenceIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_assigning_a_reference(self):
|
||||
reference = self.file.createIfcLibraryReference()
|
||||
product = self.file.createIfcWall()
|
||||
|
||||
@@ -151,6 +151,8 @@ class TestCopyClass(test.bootstrap.IFC4):
|
||||
assert not new.Types
|
||||
|
||||
def test_copying_distribution_ports(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="IfcChiller")
|
||||
port = ifcopenshell.api.run("system.add_port", self.file)
|
||||
ifcopenshell.api.run("system.assign_port", self.file, element=element, port=port)
|
||||
|
||||
@@ -363,7 +363,7 @@ class TestGetlayers(test.bootstrap.IFC4):
|
||||
assert subject.get_layers(self.file, element) == [layer]
|
||||
|
||||
|
||||
class TestGetlayers(test.bootstrap.IFC2X3):
|
||||
class TestGetlayersIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_getting_the_layer_of_a_product_item(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
layer = ifcopenshell.api.run("layer.add_layer", self.file)
|
||||
|
||||
Reference in New Issue
Block a user