Skip to content

Commit a9c0c1f

Browse files
committed
control.unassign_control to support batching
1 parent abfb563 commit a9c0c1f

8 files changed

Lines changed: 32 additions & 28 deletions

File tree

src/bonsai/bonsai/core/cost.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,7 @@ def unassign_cost_item_type(
154154
"""
155155
if not product_types:
156156
product_types = list(spatial.get_selected_product_types())
157-
[
158-
ifc.run("control.unassign_control", relating_control=cost_item, related_object=product_type)
159-
for product_type in product_types
160-
]
157+
ifc.run("control.unassign_control", relating_control=cost_item, related_objects=product_types)
161158
cost.load_cost_item_types(cost_item)
162159
return product_types
163160

@@ -213,7 +210,7 @@ def assign_cost_value(
213210
if existing_cost_rate is None:
214211
ifc.run("control.assign_control", relating_control=cost_rate, related_objects=[cost_item])
215212
else:
216-
ifc.run("control.unassign_control", relating_control=existing_cost_rate, related_object=cost_item)
213+
ifc.run("control.unassign_control", relating_control=existing_cost_rate, related_objects=[cost_item])
217214
ifc.run("control.assign_control", relating_control=cost_rate, related_objects=[cost_item])
218215

219216

src/bonsai/bonsai/core/sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def remove_task_calendar(
433433
task: ifcopenshell.entity_instance,
434434
work_calendar: ifcopenshell.entity_instance,
435435
) -> None:
436-
ifc.run("control.unassign_control", relating_control=work_calendar, related_object=task)
436+
ifc.run("control.unassign_control", relating_control=work_calendar, related_objects=[task])
437437
ifc.run("sequence.cascade_schedule", task=task)
438438
sequence.load_task_properties()
439439

src/ifc5d/ifc5d/csv2ifc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def create_cost_item(self, cost_item: CostItem, parent: Optional[ifcopenshell.en
358358
)
359359
else:
360360
ifcopenshell.api.control.unassign_control(
361-
self.file, relating_control=existing_cost_rate, related_object=cost_item["ifc"]
361+
self.file, relating_control=existing_cost_rate, related_objects=[cost_item["ifc"]]
362362
)
363363
ifcopenshell.api.control.assign_control(
364364
self.file, relating_control=rate_cost_item, related_objects=[cost_item["ifc"]]

src/ifcopenshell-python/ifcopenshell/api/control/unassign_control.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,19 @@
1919
import ifcopenshell
2020
import ifcopenshell.api.owner
2121
import ifcopenshell.util.element
22-
from typing import Union
2322

2423

2524
def unassign_control(
2625
file: ifcopenshell.file,
2726
relating_control: ifcopenshell.entity_instance,
28-
related_object: ifcopenshell.entity_instance,
29-
) -> Union[ifcopenshell.entity_instance, None]:
27+
related_objects: list[ifcopenshell.entity_instance],
28+
) -> None:
3029
"""Unassigns a planning control or constraint to an object
3130
3231
:param relating_control: The IfcControl entity that is creating the
3332
control or constraint
34-
:param related_object: The IfcObjectDefinition that is being controlled
35-
:return: If the control still is related to other objects, the
36-
IfcRelAssignsToControl is returned, otherwise None.
33+
:param related_objects: The list IfcObjectDefinitions that is being controlled
34+
:return: None
3735
3836
Example:
3937
@@ -49,19 +47,19 @@ def unassign_control(
4947
5048
# And now let's change our mind
5149
ifcopenshell.api.control.unassign_control(model,
52-
relating_control=cost_item, related_object=wall)
50+
relating_control=cost_item, related_objects=[wall])
5351
"""
54-
for rel in related_object.HasAssignments or []:
55-
if not rel.is_a("IfcRelAssignsToControl") or rel.RelatingControl != relating_control:
56-
continue
57-
if len(rel.RelatedObjects) == 1:
52+
related_objects_set = set(related_objects)
53+
control_assignments = set(relating_control.Controls)
54+
rels = set(rel for obj in related_objects_set for rel in obj.HasAssignments if rel in control_assignments)
55+
56+
for rel in rels:
57+
related_objects_new = set(rel.RelatedObjects) - related_objects_set
58+
if related_objects_new:
59+
rel.RelatedObjects = list(related_objects_new)
60+
ifcopenshell.api.owner.update_owner_history(file, element=rel)
61+
else:
5862
history = rel.OwnerHistory
5963
file.remove(rel)
6064
if history:
6165
ifcopenshell.util.element.remove_deep2(file, history)
62-
return
63-
related_objects = list(rel.RelatedObjects)
64-
related_objects.remove(related_object)
65-
rel.RelatedObjects = related_objects
66-
ifcopenshell.api.owner.update_owner_history(file, element=rel)
67-
return rel

src/ifcopenshell-python/ifcopenshell/api/cost/unassign_cost_item_quantity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def execute(self, cost_item: ifcopenshell.entity_instance, products: list[ifcope
8686
for product in products:
8787
ifcopenshell.api.control.unassign_control(
8888
self.file,
89-
related_object=product,
89+
related_objects=[product],
9090
relating_control=cost_item,
9191
)
9292
self.update_cost_item_count(cost_item)

src/ifcopenshell-python/ifcopenshell/api/sequence/remove_work_calendar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def remove_work_calendar(file: ifcopenshell.file, work_calendar: ifcopenshell.en
5454
ifcopenshell.api.control.unassign_control(
5555
file,
5656
relating_control=work_calendar,
57-
related_object=related_object,
57+
related_objects=[related_object],
5858
)
5959

6060
# Currently in API work times are created already attached

src/ifcopenshell-python/test/api/control/test_unassign_control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ def test_run(self):
2929
# assign and unassign
3030
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_objects=[wall])
3131
assert relation
32-
ifcopenshell.api.control.unassign_control(self.file, relating_control=control, related_object=wall)
32+
ifcopenshell.api.control.unassign_control(self.file, relating_control=control, related_objects=[wall])
3333
assert len(self.file.by_type("IfcRelAssignsToControl")) == 0
3434

3535
# 1 control 2 related objects
3636
wall1 = self.file.createIfcWall()
3737
relation = ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_objects=[wall])
3838
assert relation
3939
ifcopenshell.api.control.assign_control(self.file, relating_control=control, related_objects=[wall1])
40-
ifcopenshell.api.control.unassign_control(self.file, relating_control=control, related_object=wall1)
40+
ifcopenshell.api.control.unassign_control(self.file, relating_control=control, related_objects=[wall1])
4141
assert len(self.file.by_type("IfcRelAssignsToControl")) == 1
4242
assert relation.RelatedObjects == (wall,)
4343

src/ifcopenshell-python/test/api/test_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,12 @@ def test_assigning_control(self):
4343
control = ifcopenshell.api.cost.add_cost_schedule(model)
4444
ifcopenshell.api.control.assign_control(model, relating_control=control, related_objects=[element])
4545
assert list(ifcopenshell.util.element.get_controls(element)) == [control]
46+
47+
@deprecation_check
48+
def test_unassigning_control(self):
49+
TestTemporarySupportForDeprecatedAPIArguments.test_assigning_control(self)
50+
model = self.file
51+
element = model.by_type("IfcWall")[0]
52+
control = model.by_type("IfcCostSchedule")[0]
53+
ifcopenshell.api.control.unassign_control(model, relating_control=control, related_objects=[element])
54+
assert list(ifcopenshell.util.element.get_controls(element)) == []

0 commit comments

Comments
 (0)