mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
aggregate.assign_object - support batching #4474
This commit is contained in:
@@ -25,19 +25,23 @@ import ifcopenshell.util.placement
|
||||
|
||||
|
||||
class TestAssignObject(test.bootstrap.IFC4):
|
||||
def test_assigning_a_container(self):
|
||||
def test_assigning_an_aggregate(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
rel = ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
assert ifcopenshell.util.element.get_aggregate(subelement) == element
|
||||
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
rel = ifcopenshell.api.run(
|
||||
"aggregate.assign_object", self.file, products=[subelement1, subelement2], relating_object=element
|
||||
)
|
||||
assert ifcopenshell.util.element.get_aggregate(subelement1) == element
|
||||
assert ifcopenshell.util.element.get_aggregate(subelement2) == element
|
||||
assert rel.is_a("IfcRelAggregates")
|
||||
|
||||
def test_doing_nothing_if_the_aggregate_is_already_assigned(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
total_elements = len([e for e in self.file])
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
assert len([e for e in self.file]) == total_elements
|
||||
|
||||
def test_that_old_aggregate_relationships_are_updated_if_they_still_have_elements(self):
|
||||
@@ -45,20 +49,20 @@ class TestAssignObject(test.bootstrap.IFC4):
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement1, relating_object=element1)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement2, relating_object=element1)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement1], relating_object=element1)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement2], relating_object=element1)
|
||||
rel = subelement1.Decomposes[0]
|
||||
assert len(rel.RelatedObjects) == 2
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement1, relating_object=element2)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement1], relating_object=element2)
|
||||
assert len(rel.RelatedObjects) == 1
|
||||
|
||||
def test_that_old_aggregate_relationships_are_purged_if_no_more_elements_are_contained(self):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement1, relating_object=element1)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement1], relating_object=element1)
|
||||
rel_id = subelement1.Decomposes[0].id()
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement1, relating_object=element2)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement1], relating_object=element2)
|
||||
with pytest.raises(RuntimeError):
|
||||
self.file.by_id(rel_id)
|
||||
|
||||
@@ -68,7 +72,7 @@ class TestAssignObject(test.bootstrap.IFC4):
|
||||
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element1)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element1)
|
||||
matrix1 = numpy.array(
|
||||
(
|
||||
(1.0, 0.0, 0.0, 1.0),
|
||||
@@ -94,7 +98,7 @@ class TestAssignObject(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run(
|
||||
"geometry.edit_object_placement", self.file, product=subelement, matrix=matrix1.copy(), is_si=False
|
||||
)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element2)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element2)
|
||||
assert subelement.ObjectPlacement.PlacementRelTo.PlacesObject[0] == element2
|
||||
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), matrix1)
|
||||
|
||||
@@ -105,7 +109,7 @@ class TestAssignObject(test.bootstrap.IFC4):
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
placement = self.file.createIfcGridPlacement()
|
||||
subelement.ObjectPlacement = placement
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
assert subelement.ObjectPlacement == placement
|
||||
|
||||
def test_removing_containment_if_it_exists(self):
|
||||
@@ -115,5 +119,5 @@ class TestAssignObject(test.bootstrap.IFC4):
|
||||
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=[subelement], relating_structure=container)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
assert not ifcopenshell.util.element.get_container(subelement, should_get_direct=True)
|
||||
|
||||
@@ -26,7 +26,7 @@ class TestUnassignObject(test.bootstrap.IFC4):
|
||||
def test_unassigning_an_object(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement)
|
||||
assert ifcopenshell.util.element.get_aggregate(subelement) is None
|
||||
|
||||
@@ -34,14 +34,14 @@ class TestUnassignObject(test.bootstrap.IFC4):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement1, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement2, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement1], relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement2], relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement1)
|
||||
assert len(self.file.by_type("IfcRelAggregates")) == 1
|
||||
|
||||
def test_the_rel_is_purged_if_there_are_no_more_decomposed_elements(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement)
|
||||
assert len(self.file.by_type("IfcRelAggregates")) == 0
|
||||
|
||||
@@ -253,7 +253,7 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
||||
(0.0, 0.0, 0.0, 1.0),
|
||||
)
|
||||
)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
ifcopenshell.api.run(
|
||||
"geometry.edit_object_placement", self.file, product=element, matrix=matrix.copy(), is_si=False
|
||||
)
|
||||
@@ -629,7 +629,7 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
||||
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
storey = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=storey, relating_object=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[storey], relating_object=building)
|
||||
wall = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[wall], relating_structure=storey)
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class TestCopyClass(test.bootstrap.IFC4):
|
||||
def test_copying_a_container_only_and_not_its_decomposition(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuildingStorey")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
|
||||
assert element.IsDecomposedBy
|
||||
assert not new.IsDecomposedBy
|
||||
@@ -97,7 +97,7 @@ class TestCopyClass(test.bootstrap.IFC4):
|
||||
def test_copying_an_aggregate_only_and_not_its_decomposition(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
|
||||
assert element.IsDecomposedBy
|
||||
assert not new.IsDecomposedBy
|
||||
@@ -105,7 +105,7 @@ class TestCopyClass(test.bootstrap.IFC4):
|
||||
def test_copying_an_aggregate_decomposition_and_maintaining_the_aggregate_relationship(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
new = ifcopenshell.api.run("root.copy_class", self.file, product=subelement)
|
||||
assert new.Decomposes[0].RelatingObject == element
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
def test_removing_all_aggregate_relationships_of_a_whole(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=element)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
@@ -223,7 +223,7 @@ class TestRemoveProduct(test.bootstrap.IFC4):
|
||||
def test_removing_all_aggregate_relationships_of_a_part(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
total_entities = len(list(self.file))
|
||||
ifcopenshell.api.run("root.remove_product", self.file, product=subelement)
|
||||
assert len(list(self.file)) == total_entities - 2
|
||||
|
||||
@@ -118,6 +118,6 @@ class TestAssignContainer(test.bootstrap.IFC4):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
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("aggregate.assign_object", self.file, products=[subelement], relating_object=aggregate)
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[subelement], relating_structure=element)
|
||||
assert not ifcopenshell.util.element.get_aggregate(subelement)
|
||||
|
||||
@@ -83,3 +83,11 @@ class TestTemporarySupportForDeprecatedAPIArguments(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("layer.unassign_layer", self.file, item=items[2], layer=layer)
|
||||
assert len(layer.AssignedItems) == 2
|
||||
assert set(layer.AssignedItems) == set(items[:2])
|
||||
|
||||
@deprecation_check
|
||||
def test_assigning_an_aggregate(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
rel = ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
assert ifcopenshell.util.element.get_aggregate(subelement) == element
|
||||
assert rel.is_a("IfcRelAggregates")
|
||||
|
||||
@@ -706,7 +706,7 @@ class TestGetContainerIFC4(test.bootstrap.IFC4):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
assert subject.get_container(subelement) == building
|
||||
|
||||
def test_getting_nothing_if_we_enforce_only_getting_direct_spatial_containers(self):
|
||||
@@ -714,7 +714,7 @@ class TestGetContainerIFC4(test.bootstrap.IFC4):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcElementAssembly")
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
assert subject.get_container(subelement, should_get_direct=True) is None
|
||||
|
||||
|
||||
@@ -736,7 +736,7 @@ class TestGetDecompositionIFC4(test.bootstrap.IFC4):
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBeam")
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
results = subject.get_decomposition(building)
|
||||
assert element in results
|
||||
assert subelement in results
|
||||
@@ -756,7 +756,7 @@ class TestGetAggregateIFC4(test.bootstrap.IFC4):
|
||||
def test_getting_the_containing_aggregate_of_a_subelement(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcCovering")
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
assert subject.get_aggregate(subelement) == element
|
||||
|
||||
|
||||
|
||||
@@ -236,9 +236,9 @@ class TestFilterElements(test.bootstrap.IFC4):
|
||||
project = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject", name="Project")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=space)
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element2], relating_structure=storey)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=space, relating_object=storey)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=storey, relating_object=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=building, relating_object=project)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[space], relating_object=storey)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[storey], relating_object=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[building], relating_object=project)
|
||||
assert subject.filter_elements(self.file, "IfcWall, location=NULL") == set()
|
||||
assert subject.filter_elements(self.file, "IfcWall, location=Space") == {element}
|
||||
assert subject.filter_elements(self.file, "IfcWall, location=G") == {element, element2}
|
||||
@@ -469,7 +469,7 @@ class TestSelector(test.bootstrap.IFC4):
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcMember")
|
||||
building = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, products=[element], relating_structure=building)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[subelement], relating_object=element)
|
||||
assert set(subject.Selector.parse(self.file, "@ .IfcBuilding")) == {element, subelement}
|
||||
|
||||
def test_selecting_elements_from_a_prefiltered_list(self):
|
||||
|
||||
Reference in New Issue
Block a user