mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
spatial.dereference_structure - support batching #4474
This commit is contained in:
@@ -42,7 +42,7 @@ def dereference_structure(
|
|||||||
element: Optional[ifcopenshell.entity_instance] = None,
|
element: Optional[ifcopenshell.entity_instance] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
if spatial.can_reference(structure, element):
|
if spatial.can_reference(structure, element):
|
||||||
return ifc.run("spatial.dereference_structure", product=element, relating_structure=structure)
|
return ifc.run("spatial.dereference_structure", products=[element], relating_structure=structure)
|
||||||
|
|
||||||
|
|
||||||
def assign_container(
|
def assign_container(
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class TestReferenceStructure:
|
|||||||
class TestDereferenceStructure:
|
class TestDereferenceStructure:
|
||||||
def test_run(self, ifc, spatial):
|
def test_run(self, ifc, spatial):
|
||||||
spatial.can_reference("structure", "element").should_be_called().will_return(True)
|
spatial.can_reference("structure", "element").should_be_called().will_return(True)
|
||||||
ifc.run("spatial.dereference_structure", product="element", relating_structure="structure").should_be_called()
|
ifc.run("spatial.dereference_structure", products=["element"], relating_structure="structure").should_be_called()
|
||||||
subject.dereference_structure(ifc, spatial, structure="structure", element="element")
|
subject.dereference_structure(ifc, spatial, structure="structure", element="element")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,9 @@ ARGUMENTS_DEPRECATION = {
|
|||||||
"spatial.reference_structure": partial(
|
"spatial.reference_structure": partial(
|
||||||
batching_argument_deprecation, prev_argument="product", new_argument="products"
|
batching_argument_deprecation, prev_argument="product", new_argument="products"
|
||||||
),
|
),
|
||||||
|
"spatial.dereference_structure": partial(
|
||||||
|
batching_argument_deprecation, prev_argument="product", new_argument="products"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,11 +22,16 @@ import ifcopenshell.util.element
|
|||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
def __init__(self, file, product=None, relating_structure=None):
|
def __init__(
|
||||||
"""Dereferences the a product and space
|
self,
|
||||||
|
file: ifcopenshell.file,
|
||||||
|
products: list[ifcopenshell.entity_instance],
|
||||||
|
relating_structure: ifcopenshell.entity_instance,
|
||||||
|
):
|
||||||
|
"""Dereferences a list of products and space
|
||||||
|
|
||||||
:param product: The physical IfcElement that exists in the space.
|
:param products: The list of physical IfcElements that exists in the space.
|
||||||
:type product: ifcopenshell.entity_instance.entity_instance
|
:type products: list[ifcopenshell.entity_instance.entity_instance]
|
||||||
:param relating_structure: The IfcSpatialStructureElement element, such
|
:param relating_structure: The IfcSpatialStructureElement element, such
|
||||||
as IfcBuilding, IfcBuildingStorey, or IfcSpace that the element
|
as IfcBuilding, IfcBuildingStorey, or IfcSpace that the element
|
||||||
exists in.
|
exists in.
|
||||||
@@ -63,19 +68,20 @@ class Usecase:
|
|||||||
ifcopenshell.api.run("spatial.reference_structure", model, products=[column], relating_structure=storey3)
|
ifcopenshell.api.run("spatial.reference_structure", model, products=[column], relating_structure=storey3)
|
||||||
|
|
||||||
# Actually, it only goes up to storey 2.
|
# Actually, it only goes up to storey 2.
|
||||||
ifcopenshell.api.run("spatial.dereference_structure", model, product=column, relating_structure=storey3)
|
ifcopenshell.api.run("spatial.dereference_structure", model, products=[column], relating_structure=storey3)
|
||||||
"""
|
"""
|
||||||
self.file = file
|
self.file = file
|
||||||
self.settings = {"product": product, "relating_structure": relating_structure}
|
self.settings = {"products": products, "relating_structure": relating_structure}
|
||||||
|
|
||||||
def execute(self):
|
def execute(self) -> None:
|
||||||
for rel in self.settings["product"].ReferencedInStructures:
|
products = set(self.settings["products"])
|
||||||
if rel.RelatingStructure != self.settings["relating_structure"]:
|
for rel in self.settings["relating_structure"].ReferencesElements:
|
||||||
|
related_elements = set(rel.RelatedElements)
|
||||||
|
if not related_elements.intersection(products):
|
||||||
continue
|
continue
|
||||||
related_elements = list(rel.RelatedElements)
|
related_elements = related_elements - products
|
||||||
related_elements.remove(self.settings["product"])
|
|
||||||
if related_elements:
|
if related_elements:
|
||||||
rel.RelatedElements = related_elements
|
rel.RelatedElements = list(related_elements)
|
||||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
||||||
else:
|
else:
|
||||||
history = rel.OwnerHistory
|
history = rel.OwnerHistory
|
||||||
|
|||||||
@@ -26,28 +26,42 @@ class TestDereferenceStructure(test.bootstrap.IFC4):
|
|||||||
def test_removing_a_container(self):
|
def test_removing_a_container(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
ifcopenshell.api.run("spatial.reference_structure", self.file, products=[subelement], relating_structure=element)
|
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
ifcopenshell.api.run("spatial.dereference_structure", self.file, product=subelement, relating_structure=element)
|
ifcopenshell.api.run(
|
||||||
|
"spatial.reference_structure", self.file, products=[subelement, subelement2], relating_structure=element
|
||||||
|
)
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"spatial.dereference_structure", self.file, products=[subelement, subelement2], relating_structure=element
|
||||||
|
)
|
||||||
assert ifcopenshell.util.element.get_referenced_structures(subelement) == []
|
assert ifcopenshell.util.element.get_referenced_structures(subelement) == []
|
||||||
|
assert len(self.file.by_type("IfcRelReferencedInSpatialStructure")) == 0
|
||||||
|
|
||||||
def test_doing_nothing_if_no_container(self):
|
def test_doing_nothing_if_no_container(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
ifcopenshell.api.run("spatial.dereference_structure", self.file, product=subelement, relating_structure=element)
|
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"spatial.dereference_structure", self.file, products=[subelement, subelement2], relating_structure=element
|
||||||
|
)
|
||||||
assert ifcopenshell.util.element.get_referenced_structures(subelement) == []
|
assert ifcopenshell.util.element.get_referenced_structures(subelement) == []
|
||||||
|
assert ifcopenshell.util.element.get_referenced_structures(subelement2) == []
|
||||||
|
|
||||||
def test_updating_the_rel_when_a_reference_is_removed_with_multipled_elements(self):
|
def test_updating_the_rel_when_a_reference_is_removed_with_multipled_elements(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
subelement1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
subelement2 = 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.reference_structure", self.file, products=[subelement1], relating_structure=element)
|
subelement3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
ifcopenshell.api.run("spatial.reference_structure", self.file, products=[subelement2], relating_structure=element)
|
ifcopenshell.api.run(
|
||||||
ifcopenshell.api.run("spatial.dereference_structure", self.file, product=subelement1, relating_structure=element)
|
"spatial.reference_structure", self.file, products=[subelement1], relating_structure=element
|
||||||
assert self.file.by_type("IfcRelReferencedInSpatialStructure")[0].RelatedElements == (subelement2,)
|
)
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"spatial.reference_structure", self.file, products=[subelement2, subelement3], relating_structure=element
|
||||||
|
)
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"spatial.dereference_structure", self.file, products=[subelement1, subelement2], relating_structure=element
|
||||||
|
)
|
||||||
|
assert element.ReferencesElements[0].RelatedElements == (subelement3,)
|
||||||
|
|
||||||
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")
|
class TestDereferenceStructureIFC2X3(test.bootstrap.IFC2X3, TestDereferenceStructure):
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
pass
|
||||||
ifcopenshell.api.run("spatial.reference_structure", self.file, products=[subelement], relating_structure=element)
|
|
||||||
ifcopenshell.api.run("spatial.dereference_structure", self.file, product=subelement, relating_structure=element)
|
|
||||||
assert len(self.file.by_type("IfcRelReferencedInSpatialStructure")) == 0
|
|
||||||
|
|||||||
@@ -280,3 +280,11 @@ class TestTemporarySupportForDeprecatedAPIArguments(test.bootstrap.IFC4):
|
|||||||
)
|
)
|
||||||
assert ifcopenshell.util.element.get_referenced_structures(subelement) == [element]
|
assert ifcopenshell.util.element.get_referenced_structures(subelement) == [element]
|
||||||
assert rel.is_a("IfcRelReferencedInSpatialStructure")
|
assert rel.is_a("IfcRelReferencedInSpatialStructure")
|
||||||
|
|
||||||
|
@deprecation_check
|
||||||
|
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.reference_structure", self.file, products=[subelement], relating_structure=element)
|
||||||
|
ifcopenshell.api.run("spatial.dereference_structure", self.file, product=subelement, relating_structure=element)
|
||||||
|
assert ifcopenshell.util.element.get_referenced_structures(subelement) == []
|
||||||
|
|||||||
Reference in New Issue
Block a user