mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
root.copy_class to support copying ports in ifc2x3
This commit is contained in:
@@ -86,24 +86,40 @@ class Usecase:
|
|||||||
inverse.RelatedObjects = [to_element]
|
inverse.RelatedObjects = [to_element]
|
||||||
pset = ifcopenshell.util.element.copy_deep(self.file, inverse.RelatingPropertyDefinition)
|
pset = ifcopenshell.util.element.copy_deep(self.file, inverse.RelatingPropertyDefinition)
|
||||||
inverse.RelatingPropertyDefinition = pset
|
inverse.RelatingPropertyDefinition = pset
|
||||||
elif inverse.is_a("IfcRelNests") and inverse.RelatingObject == from_element:
|
elif (
|
||||||
ports = [e for e in inverse.RelatedObjects if e.is_a("IfcDistributionPort")]
|
inverse.is_a("IfcRelNests")
|
||||||
if ports:
|
and inverse.RelatingObject == from_element
|
||||||
new_ports = [ifcopenshell.api.run("root.copy_class", self.file, product=p) for p in ports]
|
or inverse.is_a("IfcRelConnectsPortToElement")
|
||||||
inverse = ifcopenshell.util.element.copy(self.file, inverse)
|
and inverse.RelatedElement == from_element
|
||||||
|
):
|
||||||
|
# IfcRelConnectsPortToElement was used in IFC2X3
|
||||||
|
if inverse.is_a("IfcRelNests"):
|
||||||
|
ports = [e for e in inverse.RelatedObjects if e.is_a("IfcDistributionPort")]
|
||||||
|
else: # IfcRelConnectsPortToElement
|
||||||
|
ports = [inverse.RelatingPort]
|
||||||
|
if not ports:
|
||||||
|
continue
|
||||||
|
new_ports = [ifcopenshell.api.run("root.copy_class", self.file, product=p) for p in ports]
|
||||||
|
inverse = ifcopenshell.util.element.copy(self.file, inverse)
|
||||||
|
|
||||||
|
if inverse.is_a("IfcRelNests"):
|
||||||
inverse.RelatingObject = to_element
|
inverse.RelatingObject = to_element
|
||||||
inverse.RelatedObjects = new_ports
|
inverse.RelatedObjects = new_ports
|
||||||
for port in new_ports:
|
else:
|
||||||
ifcopenshell.api.run("system.unassign_port", self.file, element=from_element, port=port)
|
inverse.RelatedElement = to_element
|
||||||
matrix = ifcopenshell.util.placement.get_local_placement(port.ObjectPlacement)
|
inverse.RelatingPort = new_ports[0]
|
||||||
ifcopenshell.api.run(
|
|
||||||
"geometry.edit_object_placement",
|
for port in new_ports:
|
||||||
self.file,
|
ifcopenshell.api.run("system.unassign_port", self.file, element=from_element, port=port)
|
||||||
product=port,
|
matrix = ifcopenshell.util.placement.get_local_placement(port.ObjectPlacement)
|
||||||
matrix=matrix,
|
ifcopenshell.api.run(
|
||||||
is_si=False,
|
"geometry.edit_object_placement",
|
||||||
should_transform_children=False,
|
self.file,
|
||||||
)
|
product=port,
|
||||||
|
matrix=matrix,
|
||||||
|
is_si=False,
|
||||||
|
should_transform_children=False,
|
||||||
|
)
|
||||||
elif inverse.is_a("IfcRelAggregates") and inverse.RelatingObject == from_element:
|
elif inverse.is_a("IfcRelAggregates") and inverse.RelatingObject == from_element:
|
||||||
continue
|
continue
|
||||||
elif inverse.is_a("IfcRelContainedInSpatialStructure") and inverse.RelatingStructure == from_element:
|
elif inverse.is_a("IfcRelContainedInSpatialStructure") and inverse.RelatingStructure == from_element:
|
||||||
|
|||||||
@@ -232,3 +232,15 @@ class TestCopyClass(test.bootstrap.IFC4):
|
|||||||
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
|
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
|
||||||
assert len(self.file.by_type("IfcRelAssignsToGroup")) == 1
|
assert len(self.file.by_type("IfcRelAssignsToGroup")) == 1
|
||||||
assert new.HasAssignments[0].RelatingGroup == group
|
assert new.HasAssignments[0].RelatingGroup == group
|
||||||
|
|
||||||
|
|
||||||
|
class TestCopyClassIFC2X3(test.bootstrap.IFC2X3):
|
||||||
|
def test_copying_distribution_ports_bug(self):
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowTerminal")
|
||||||
|
port = ifcopenshell.api.run("system.add_port", self.file)
|
||||||
|
ifcopenshell.api.run("system.assign_port", self.file, element=element, port=port)
|
||||||
|
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
|
||||||
|
new_ports = ifcopenshell.util.system.get_ports(new)
|
||||||
|
assert port not in new_ports
|
||||||
|
assert new_ports[0].is_a("IfcDistributionPort")
|
||||||
|
assert ifcopenshell.util.system.get_ports(element) == [port]
|
||||||
|
|||||||
Reference in New Issue
Block a user