mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
spatial.dereference_structure - support batching #4474
This commit is contained in:
@@ -108,6 +108,9 @@ ARGUMENTS_DEPRECATION = {
|
||||
"spatial.reference_structure": partial(
|
||||
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:
|
||||
def __init__(self, file, product=None, relating_structure=None):
|
||||
"""Dereferences the a product and space
|
||||
def __init__(
|
||||
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.
|
||||
:type product: ifcopenshell.entity_instance.entity_instance
|
||||
:param products: The list of physical IfcElements that exists in the space.
|
||||
:type products: list[ifcopenshell.entity_instance.entity_instance]
|
||||
:param relating_structure: The IfcSpatialStructureElement element, such
|
||||
as IfcBuilding, IfcBuildingStorey, or IfcSpace that the element
|
||||
exists in.
|
||||
@@ -63,19 +68,20 @@ class Usecase:
|
||||
ifcopenshell.api.run("spatial.reference_structure", model, products=[column], relating_structure=storey3)
|
||||
|
||||
# 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.settings = {"product": product, "relating_structure": relating_structure}
|
||||
self.settings = {"products": products, "relating_structure": relating_structure}
|
||||
|
||||
def execute(self):
|
||||
for rel in self.settings["product"].ReferencedInStructures:
|
||||
if rel.RelatingStructure != self.settings["relating_structure"]:
|
||||
def execute(self) -> None:
|
||||
products = set(self.settings["products"])
|
||||
for rel in self.settings["relating_structure"].ReferencesElements:
|
||||
related_elements = set(rel.RelatedElements)
|
||||
if not related_elements.intersection(products):
|
||||
continue
|
||||
related_elements = list(rel.RelatedElements)
|
||||
related_elements.remove(self.settings["product"])
|
||||
related_elements = related_elements - products
|
||||
if related_elements:
|
||||
rel.RelatedElements = related_elements
|
||||
rel.RelatedElements = list(related_elements)
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
||||
else:
|
||||
history = rel.OwnerHistory
|
||||
|
||||
Reference in New Issue
Block a user