spatial.assign_container - support batching #4474

This commit is contained in:
Andrej730
2024-04-05 14:57:11 +05:00
parent ee6c7a9fad
commit 52995d1cdd
32 changed files with 157 additions and 119 deletions
@@ -28,18 +28,20 @@ class TestAssignContainer(test.bootstrap.IFC4):
def test_assigning_a_container(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
rel = ifcopenshell.api.run(
"spatial.assign_container", self.file, product=subelement, relating_structure=element
"spatial.assign_container", self.file, products=[subelement, subelement2], relating_structure=element
)
assert ifcopenshell.util.element.get_container(subelement) == element
assert ifcopenshell.util.element.get_container(subelement2) == element
assert rel.is_a("IfcRelContainedInSpatialStructure")
def test_doing_nothing_if_the_container_is_already_assigned(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
total_elements = len([e for e in self.file])
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
assert len([e for e in self.file]) == total_elements
def test_that_old_containment_relationships_are_updated_if_they_still_contain_elements(self):
@@ -47,20 +49,20 @@ class TestAssignContainer(test.bootstrap.IFC4):
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement1, relating_structure=element1)
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement2, relating_structure=element1)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement1], relating_structure=element1)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement2], relating_structure=element1)
rel = subelement1.ContainedInStructure[0]
assert len(rel.RelatedElements) == 2
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement1, relating_structure=element2)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement1], relating_structure=element2)
assert len(rel.RelatedElements) == 1
def test_that_old_containment_relationships_are_purged_if_no_more_elements_are_contained(self):
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement1, relating_structure=element1)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement1], relating_structure=element1)
rel_id = subelement1.ContainedInStructure[0].id()
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement1, relating_structure=element2)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement1], relating_structure=element2)
with pytest.raises(RuntimeError):
self.file.by_id(rel_id)
@@ -70,7 +72,7 @@ class TestAssignContainer(test.bootstrap.IFC4):
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element1)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element1)
matrix1 = numpy.array(
(
(1.0, 0.0, 0.0, 1.0),
@@ -96,7 +98,7 @@ class TestAssignContainer(test.bootstrap.IFC4):
ifcopenshell.api.run(
"geometry.edit_object_placement", self.file, product=subelement, matrix=matrix1.copy(), is_si=False
)
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element2)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element2)
assert subelement.ObjectPlacement.PlacementRelTo.PlacesObject[0] == element2
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), matrix1)
@@ -107,7 +109,7 @@ class TestAssignContainer(test.bootstrap.IFC4):
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
placement = self.file.createIfcGridPlacement()
subelement.ObjectPlacement = placement
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
assert subelement.ObjectPlacement == placement
def test_removing_aggregation_if_it_exists(self):
@@ -117,5 +119,5 @@ class TestAssignContainer(test.bootstrap.IFC4):
aggregate = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=aggregate)
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
assert not ifcopenshell.util.element.get_aggregate(subelement)
@@ -28,7 +28,7 @@ class TestRemoveContainer(test.bootstrap.IFC4):
def test_removing_a_container(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
ifcopenshell.api.run("spatial.remove_container", self.file, product=subelement)
assert ifcopenshell.util.element.get_container(subelement) is None
@@ -41,14 +41,14 @@ class TestRemoveContainer(test.bootstrap.IFC4):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement1, relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement2, relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement1], relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement2], relating_structure=element)
ifcopenshell.api.run("spatial.remove_container", self.file, product=subelement1)
assert self.file.by_type("IfcRelContainedInSpatialStructure")[0].RelatedElements == (subelement2,)
def test_deleting_the_rel_when_a_container_is_removed_with_no_elements(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
ifcopenshell.api.run("spatial.remove_container", self.file, product=subelement)
assert len(self.file.by_type("IfcRelContainedInSpatialStructure")) == 0
@@ -28,7 +28,7 @@ class TestAssignContainer(test.bootstrap.IFC4):
def test_unassigning_a_container(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
ifcopenshell.api.run("spatial.unassign_container", self.file, product=subelement)
assert not self.file.by_type("IfcRelContainedInSpatialStructure")
@@ -36,8 +36,8 @@ class TestAssignContainer(test.bootstrap.IFC4):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement2, relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement2], relating_structure=element)
ifcopenshell.api.run("spatial.unassign_container", self.file, product=subelement)
rel = self.file.by_type("IfcRelContainedInSpatialStructure")[0]
assert list(rel.RelatedElements) == [subelement2]