From 32f0911479c676fefbf48d73f51696a64b34f817 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sun, 9 Oct 2022 22:22:12 +1100 Subject: [PATCH] Elements with filled openings don't have their openings copied, as it depends on the fill --- .../ifcopenshell/api/root/copy_class.py | 22 ++++++++++--------- .../test/api/root/test_copy_class.py | 9 ++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py index 99a89231d0..708855b938 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py @@ -72,16 +72,18 @@ class Usecase: continue elif inverse.is_a("IfcRelVoidsElement") and inverse.RelatingBuildingElement == from_element: opening = inverse.RelatedOpeningElement - new_opening = ifcopenshell.api.run("root.copy_class", self.file, product=opening) - new_opening.VoidsElements[0].RelatingBuildingElement = to_element - if new_opening.ObjectPlacement and new_opening.ObjectPlacement.is_a("IfcLocalPlacement"): - if to_element.ObjectPlacement: - new_opening.ObjectPlacement.PlacementRelTo = to_element.ObjectPlacement - # For now, we do copy opening representations - if opening.Representation: - new_opening.Representation = ifcopenshell.util.element.copy_deep( - self.file, opening.Representation, exclude=["IfcGeometricRepresentationContext"] - ) + # We don't copy filled openings, since there is no guarantee the filling is also copied + if not opening.HasFillings: + new_opening = ifcopenshell.api.run("root.copy_class", self.file, product=opening) + new_opening.VoidsElements[0].RelatingBuildingElement = to_element + if new_opening.ObjectPlacement and new_opening.ObjectPlacement.is_a("IfcLocalPlacement"): + if to_element.ObjectPlacement: + new_opening.ObjectPlacement.PlacementRelTo = to_element.ObjectPlacement + # For now, we do copy opening representations + if opening.Representation: + new_opening.Representation = ifcopenshell.util.element.copy_deep( + self.file, opening.Representation, exclude=["IfcGeometricRepresentationContext"] + ) elif inverse.is_a("IfcRelFillsElement"): continue elif inverse.is_a("IfcRelConnectsPathElements"): diff --git a/src/ifcopenshell-python/test/api/root/test_copy_class.py b/src/ifcopenshell-python/test/api/root/test_copy_class.py index 0be520f1e4..e46e7f6ae7 100644 --- a/src/ifcopenshell-python/test/api/root/test_copy_class.py +++ b/src/ifcopenshell-python/test/api/root/test_copy_class.py @@ -115,6 +115,15 @@ class TestCopyClass(test.bootstrap.IFC4): assert new.HasOpenings[0].RelatedOpeningElement != opening assert new.HasOpenings[0].RelatedOpeningElement.is_a("IfcOpeningElement") + def test_copying_an_element_with_a_filled_opening_should_not_copy_the_opening_nor_fill(self): + wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement") + window = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWindow") + ifcopenshell.api.run("void.add_opening", self.file, opening=opening, element=wall) + ifcopenshell.api.run("void.add_filling", self.file, opening=opening, element=window) + new = ifcopenshell.api.run("root.copy_class", self.file, product=wall) + assert not new.HasOpenings + def test_copying_an_opening_voiding_an_element(self): wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") opening = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcOpeningElement")