ifcpatch - add ifc2x3 tests and test for MergeDuplicateTypes

This commit is contained in:
Andrej730
2024-04-12 10:57:35 +05:00
parent 67a6e4d258
commit 9e310318d4
6 changed files with 181 additions and 79 deletions
+25 -23
View File
@@ -22,31 +22,30 @@ import ifcpatch
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
import test.bootstrap
class TestExtractElements:
class TestExtractElements(test.bootstrap.IFC4):
def test_basic(self):
ifc_file = ifcopenshell.file()
project = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcProject")
wall = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcWall")
output = ifcpatch.execute({"file": ifc_file, "recipe": "ExtractElements", "arguments": ["IfcWall"]})
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
output = ifcpatch.execute({"file": self.file, "recipe": "ExtractElements", "arguments": ["IfcWall"]})
assert output.by_type("IfcProject")[0].GlobalId == project.GlobalId
assert output.by_type("IfcWall")[0].GlobalId == wall.GlobalId
def test_keep_spatial_structure(self):
ifc_file = ifcopenshell.file()
project = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcProject")
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
site = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcSite")
building = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuilding")
storey = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuildingStorey")
wall = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcWall")
ifcopenshell.api.run("aggregate.assign_object", ifc_file, products=[building], relating_object=site)
ifcopenshell.api.run("aggregate.assign_object", ifc_file, products=[storey], relating_object=building)
ifcopenshell.api.run("spatial.assign_container", ifc_file, products=[wall], relating_structure=storey)
site = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
storey = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey")
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[building], relating_object=site)
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[storey], relating_object=building)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[wall], relating_structure=storey)
output = ifcpatch.execute({"file": ifc_file, "recipe": "ExtractElements", "arguments": ["IfcWall"]})
output = ifcpatch.execute({"file": self.file, "recipe": "ExtractElements", "arguments": ["IfcWall"]})
wall_new = output.by_type("IfcWall")[0]
assert (storey_new := ifcopenshell.util.element.get_container(wall_new)).GlobalId == storey.GlobalId
@@ -54,16 +53,15 @@ class TestExtractElements:
assert (site_new := ifcopenshell.util.element.get_aggregate(building_new)).GlobalId == site.GlobalId
def test_keep_aggregate_in_spatial_structure(self):
ifc_file = ifcopenshell.file()
project = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcProject")
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
element = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcElementAssembly")
container = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcBuildingStorey")
subelement = ifcopenshell.api.run("root.create_entity", ifc_file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", ifc_file, products=[element], relating_structure=container)
ifcopenshell.api.run("aggregate.assign_object", ifc_file, products=[subelement], relating_object=element)
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
container = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=container)
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
output = ifcpatch.execute({"file": ifc_file, "recipe": "ExtractElements", "arguments": ["IfcWall"]})
output = ifcpatch.execute({"file": self.file, "recipe": "ExtractElements", "arguments": ["IfcWall"]})
wall_new = output.by_type("IfcWall")[0]
assembly = output.by_type("IfcElementAssembly")[0]
@@ -76,3 +74,7 @@ class TestExtractElements:
output = ifcpatch.execute({"file": ifc, "recipe": "ExtractElements", "arguments": ["IfcWall"]})
assert output.by_type("IfcWall")
assert not output.by_type("IfcSlab")
class TestExtractElementsIFC2X3(test.bootstrap.IFC2X3, TestExtractElements):
pass