mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
aggregate.unassign_object - support batching #4474
This commit is contained in:
@@ -492,7 +492,7 @@ class UnassignStructuralLoadCase(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
self.file,
|
self.file,
|
||||||
**{
|
**{
|
||||||
"relating_object": self.file.by_id(self.work_plan),
|
"relating_object": self.file.by_id(self.work_plan),
|
||||||
"product": self.file.by_id(self.load_case),
|
"products": [self.file.by_id(self.load_case)],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ def unassign_object(ifc, aggregate, collector, relating_obj=None, related_obj=No
|
|||||||
if related_element:
|
if related_element:
|
||||||
relating_obj = ifc.get_object(relating_element)
|
relating_obj = ifc.get_object(relating_element)
|
||||||
if relating_obj:
|
if relating_obj:
|
||||||
ifc.run("aggregate.unassign_object", product=related_element)
|
ifc.run("aggregate.unassign_object", products=[related_element])
|
||||||
if container:
|
if container:
|
||||||
ifc.run("spatial.assign_container", products=[related_element], relating_structure=container)
|
ifc.run("spatial.assign_container", products=[related_element], relating_structure=container)
|
||||||
collector.assign(relating_obj)
|
collector.assign(relating_obj)
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ def assign_work_schedule(ifc, work_plan=None, work_schedule=None):
|
|||||||
|
|
||||||
|
|
||||||
def unassign_work_schedule(ifc, work_schedule=None):
|
def unassign_work_schedule(ifc, work_schedule=None):
|
||||||
ifc.run("aggregate.unassign_object", product=work_schedule)
|
ifc.run("aggregate.unassign_object", products=[work_schedule])
|
||||||
|
|
||||||
|
|
||||||
def enable_editing_work_schedule(sequence, work_schedule=None):
|
def enable_editing_work_schedule(sequence, work_schedule=None):
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class TestUnassignObject:
|
|||||||
ifc.get_entity("related_obj").should_be_called().will_return("element")
|
ifc.get_entity("related_obj").should_be_called().will_return("element")
|
||||||
aggregate.get_container("element").should_be_called().will_return("container")
|
aggregate.get_container("element").should_be_called().will_return("container")
|
||||||
ifc.run("spatial.assign_container", products=["element"], relating_structure="container").should_be_called()
|
ifc.run("spatial.assign_container", products=["element"], relating_structure="container").should_be_called()
|
||||||
ifc.run("aggregate.unassign_object", product="element").should_be_called().will_return("rel")
|
ifc.run("aggregate.unassign_object", products=["element"]).should_be_called()
|
||||||
collector.assign("relating_obj").should_be_called()
|
collector.assign("relating_obj").should_be_called()
|
||||||
collector.assign("related_obj").should_be_called()
|
collector.assign("related_obj").should_be_called()
|
||||||
subject.unassign_object(ifc, aggregate, collector, relating_obj="relating_obj", related_obj="related_obj")
|
subject.unassign_object(ifc, aggregate, collector, relating_obj="relating_obj", related_obj="related_obj")
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ ARGUMENTS_DEPRECATION = {
|
|||||||
),
|
),
|
||||||
"group.unassign_group": partial(batching_argument_deprecation, prev_argument="product", new_argument="products"),
|
"group.unassign_group": partial(batching_argument_deprecation, prev_argument="product", new_argument="products"),
|
||||||
"aggregate.assign_object": partial(batching_argument_deprecation, prev_argument="product", new_argument="products"),
|
"aggregate.assign_object": partial(batching_argument_deprecation, prev_argument="product", new_argument="products"),
|
||||||
|
"aggregate.unassign_object": partial(batching_argument_deprecation, prev_argument="product", new_argument="products"),
|
||||||
"layer.assign_layer": partial(batching_argument_deprecation, prev_argument="item", new_argument="items"),
|
"layer.assign_layer": partial(batching_argument_deprecation, prev_argument="item", new_argument="items"),
|
||||||
"layer.unassign_layer": partial(batching_argument_deprecation, prev_argument="item", new_argument="items"),
|
"layer.unassign_layer": partial(batching_argument_deprecation, prev_argument="item", new_argument="items"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ import ifcopenshell.util.element
|
|||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
def __init__(self, file, product=None):
|
def __init__(self, file: ifcopenshell.file, products: list[ifcopenshell.entity_instance]):
|
||||||
"""Unassigns a product from its aggregate
|
"""Unassigns products from their aggregate
|
||||||
|
|
||||||
A product (i.e. a smaller part of a whole) may be aggregated into zero
|
A product (i.e. a smaller part of a whole) may be aggregated into zero
|
||||||
or one larger space or element. This function will remove that
|
or one larger space or element. This function will remove that
|
||||||
@@ -37,12 +37,11 @@ class Usecase:
|
|||||||
If the product is not part of an aggregation relationship, nothing will
|
If the product is not part of an aggregation relationship, nothing will
|
||||||
happen.
|
happen.
|
||||||
|
|
||||||
:param product: The part of the aggregate, typically an IfcElement or
|
:param products: The list of parts of the aggregate, typically of IfcElements or
|
||||||
IfcSpatialStructureElement subclass
|
IfcSpatialStructureElement subclass
|
||||||
:type product: ifcopenshell.entity_instance.entity_instance
|
:type product: list[ifcopenshell.entity_instance.entity_instance]
|
||||||
:return: The IfcRelAggregate relationship instance, only returned if the
|
:return: None
|
||||||
whole still contains any other parts.
|
:rtype: None
|
||||||
:rtype: ifcopenshell.entity_instance.entity_instance, None
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -53,26 +52,29 @@ class Usecase:
|
|||||||
subelement2 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding")
|
subelement2 = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, products=[subelement1], relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[subelement1], relating_object=element)
|
||||||
ifcopenshell.api.run("aggregate.assign_object", model, products=[subelement2], relating_object=element)
|
ifcopenshell.api.run("aggregate.assign_object", model, products=[subelement2], relating_object=element)
|
||||||
# The relationship is returned as element still has subelement2
|
# nothing is returned
|
||||||
rel = ifcopenshell.api.run("aggregate.unassign_object", model, product=subelement1)
|
ifcopenshell.api.run("aggregate.unassign_object", model, products=[subelement1])
|
||||||
# Nothing is returned, as element is now empty
|
# nothing is returned, relationship is removed
|
||||||
ifcopenshell.api.run("aggregate.unassign_object", model, product=subelement2)
|
ifcopenshell.api.run("aggregate.unassign_object", model, products=[subelement2])
|
||||||
"""
|
"""
|
||||||
self.file = file
|
self.file = file
|
||||||
self.settings = { "product": product }
|
self.settings = {"products": products}
|
||||||
|
|
||||||
def execute(self):
|
def execute(self) -> None:
|
||||||
for rel in self.settings["product"].Decomposes or []:
|
products = set(self.settings["products"])
|
||||||
if not rel.is_a("IfcRelAggregates"):
|
rels = set(
|
||||||
continue
|
rel
|
||||||
if len(rel.RelatedObjects) == 1:
|
for product in products
|
||||||
|
if (rel := next((rel for rel in product.Decomposes if rel.is_a("IfcRelAggregates")), None))
|
||||||
|
)
|
||||||
|
|
||||||
|
for rel in rels:
|
||||||
|
related_objects = set(rel.RelatedObjects) - products
|
||||||
|
if related_objects:
|
||||||
|
rel.RelatedObjects = list(related_objects)
|
||||||
|
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
||||||
|
else:
|
||||||
history = rel.OwnerHistory
|
history = rel.OwnerHistory
|
||||||
self.file.remove(rel)
|
self.file.remove(rel)
|
||||||
if history:
|
if history:
|
||||||
ifcopenshell.util.element.remove_deep2(self.file, history)
|
ifcopenshell.util.element.remove_deep2(self.file, history)
|
||||||
return
|
|
||||||
related_objects = list(rel.RelatedObjects)
|
|
||||||
related_objects.remove(self.settings["product"])
|
|
||||||
rel.RelatedObjects = related_objects
|
|
||||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
|
||||||
return rel
|
|
||||||
|
|||||||
@@ -141,10 +141,7 @@ class Usecase:
|
|||||||
return structure_rel
|
return structure_rel
|
||||||
|
|
||||||
# can be either only aggregated or only contained at the same time
|
# can be either only aggregated or only contained at the same time
|
||||||
for product in products_without_containers:
|
ifcopenshell.api.run("aggregate.unassign_object", self.file, products=products_without_containers)
|
||||||
aggregate = ifcopenshell.util.element.get_aggregate(product)
|
|
||||||
if aggregate:
|
|
||||||
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=product)
|
|
||||||
|
|
||||||
# unassign elements from previous containers
|
# unassign elements from previous containers
|
||||||
for rel in previous_containers_rels:
|
for rel in previous_containers_rels:
|
||||||
|
|||||||
@@ -25,10 +25,14 @@ import ifcopenshell.util.element
|
|||||||
class TestUnassignObject(test.bootstrap.IFC4):
|
class TestUnassignObject(test.bootstrap.IFC4):
|
||||||
def test_unassigning_an_object(self):
|
def test_unassigning_an_object(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
subelement = 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, products=[subelement], relating_object=element)
|
subelement2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement)
|
ifcopenshell.api.run(
|
||||||
assert ifcopenshell.util.element.get_aggregate(subelement) is None
|
"aggregate.assign_object", self.file, products=[subelement1, subelement2], relating_object=element
|
||||||
|
)
|
||||||
|
ifcopenshell.api.run("aggregate.unassign_object", self.file, products=[subelement1, subelement2])
|
||||||
|
assert ifcopenshell.util.element.get_aggregate(subelement1) is None
|
||||||
|
assert ifcopenshell.util.element.get_aggregate(subelement2) is None
|
||||||
|
|
||||||
def test_the_rel_is_kept_if_there_are_more_decomposed_elements(self):
|
def test_the_rel_is_kept_if_there_are_more_decomposed_elements(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
@@ -36,12 +40,12 @@ class TestUnassignObject(test.bootstrap.IFC4):
|
|||||||
subelement1 = 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, products=[subelement1], 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.assign_object", self.file, products=[subelement2], relating_object=element)
|
||||||
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement1)
|
ifcopenshell.api.run("aggregate.unassign_object", self.file, products=[subelement1])
|
||||||
assert len(self.file.by_type("IfcRelAggregates")) == 1
|
assert len(self.file.by_type("IfcRelAggregates")) == 1
|
||||||
|
|
||||||
def test_the_rel_is_purged_if_there_are_no_more_decomposed_elements(self):
|
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")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSite")
|
||||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||||
ifcopenshell.api.run("aggregate.assign_object", self.file, products=[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)
|
ifcopenshell.api.run("aggregate.unassign_object", self.file, products=[subelement])
|
||||||
assert len(self.file.by_type("IfcRelAggregates")) == 0
|
assert len(self.file.by_type("IfcRelAggregates")) == 0
|
||||||
|
|||||||
@@ -91,3 +91,12 @@ class TestTemporarySupportForDeprecatedAPIArguments(test.bootstrap.IFC4):
|
|||||||
rel = ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
rel = ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||||
assert ifcopenshell.util.element.get_aggregate(subelement) == element
|
assert ifcopenshell.util.element.get_aggregate(subelement) == element
|
||||||
assert rel.is_a("IfcRelAggregates")
|
assert rel.is_a("IfcRelAggregates")
|
||||||
|
|
||||||
|
@deprecation_check
|
||||||
|
def test_unassigning_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")
|
||||||
|
ifcopenshell.api.run("aggregate.assign_object", self.file, product=subelement, relating_object=element)
|
||||||
|
ifcopenshell.api.run("aggregate.unassign_object", self.file, product=subelement)
|
||||||
|
assert ifcopenshell.util.element.get_aggregate(subelement) is None
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.h
|
|||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.unassign_object",
|
"aggregate.unassign_object",
|
||||||
self.file,
|
self.file,
|
||||||
product=removed_element,
|
products=[removed_element],
|
||||||
relating_object=result,
|
relating_object=result,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user