Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 9b855be

Browse files
committed
Implement unassigning products to tasks
1 parent 3143f8c commit 9b855be

6 files changed

Lines changed: 69 additions & 6 deletions

File tree

src/blenderbim/blenderbim/bim/module/sequence/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
operator.DisableEditingTaskTime,
4141
operator.EditTaskTime,
4242
operator.AssignProduct,
43+
operator.UnassignProduct,
4344
prop.WorkPlan,
4445
prop.BIMWorkPlanProperties,
4546
prop.Task,

src/blenderbim/blenderbim/bim/module/sequence/operator.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,3 +761,25 @@ def execute(self, context):
761761
)
762762
Data.load(self.file)
763763
return {"FINISHED"}
764+
765+
766+
class UnassignProduct(bpy.types.Operator):
767+
bl_idname = "bim.unassign_product"
768+
bl_label = "Unassign Product"
769+
task: bpy.props.IntProperty()
770+
related_product: bpy.props.StringProperty()
771+
772+
def execute(self, context):
773+
related_products = (
774+
[bpy.data.objects.get(self.related_product)] if self.related_product else bpy.context.selected_objects
775+
)
776+
for related_product in related_products:
777+
self.file = IfcStore.get_file()
778+
ifcopenshell.api.run(
779+
"sequence.unassign_product",
780+
self.file,
781+
relating_product=self.file.by_id(related_product.BIMObjectProperties.ifc_definition_id),
782+
related_object=self.file.by_id(self.task),
783+
)
784+
Data.load(self.file)
785+
return {"FINISHED"}

src/blenderbim/blenderbim/bim/module/sequence/ui.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ def draw_item(self, context, layout, data, item, icon, active_data, active_propn
261261
row.prop(item, "finish", emboss=False, text="")
262262
row.prop(item, "duration", emboss=False, text="")
263263

264+
if context.active_object:
265+
oprops = context.active_object.BIMObjectProperties
266+
row = layout.row(align=True)
267+
if oprops.ifc_definition_id in Data.tasks[item.ifc_definition_id]["RelatingProducts"]:
268+
op = row.operator("bim.unassign_product", text="", icon="KEYFRAME_HLT", emboss=False)
269+
op.task = item.ifc_definition_id
270+
else:
271+
op = row.operator("bim.assign_product", text="", icon="KEYFRAME", emboss=False)
272+
op.task = item.ifc_definition_id
273+
264274
if props.active_task_id == item.ifc_definition_id:
265275
if props.active_task_time_id:
266276
row.operator("bim.edit_task_time", text="", icon="CHECKMARK")
@@ -293,5 +303,3 @@ def draw_item(self, context, layout, data, item, icon, active_data, active_propn
293303
row.operator("bim.enable_editing_task", text="", icon="GREASEPENCIL").task = item.ifc_definition_id
294304
row.operator("bim.add_task", text="", icon="ADD").task = item.ifc_definition_id
295305
row.operator("bim.remove_task", text="", icon="X").task = item.ifc_definition_id
296-
row = layout.row(align=True)
297-
row.operator("bim.assign_product", text="ADD", icon="OUTLINER_COLLECTION").task = item.ifc_definition_id

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ifcopenshell.api
22
import ifcopenshell
33

4+
45
class Usecase:
56
def __init__(self, file, **settings):
67
self.file = file
@@ -16,9 +17,9 @@ def execute(self):
1617
"root.create_entity",
1718
self.file,
1819
ifc_class="IfcTask",
19-
name= None,
20-
predefined_type= "NOTDEFINED",
21-
identification= "none",
20+
name=None,
21+
predefined_type="NOTDEFINED",
22+
identification="none",
2223
)
2324
task.IsMilestone = False
2425
if self.settings["work_schedule"]:
@@ -33,6 +34,6 @@ def execute(self):
3334
)
3435
elif self.settings["parent_task"]:
3536
ifcopenshell.api.run(
36-
"nest.assign_object", self.file, object=task, relating_object=self.settings["parent_task"]
37+
"nest.assign_object", self.file, related_object=task, relating_object=self.settings["parent_task"]
3738
)
3839
return task

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,18 @@ def load_tasks(cls):
7979
data = task.get_info()
8080
del data["OwnerHistory"]
8181
data["RelatedObjects"] = []
82+
data["RelatingProducts"] = []
8283
data["IsPredecessorTo"] = []
8384
data["IsSuccessorFrom"] = []
8485
if task.TaskTime:
8586
data["TaskTime"] = data["TaskTime"].id()
8687
for rel in task.IsNestedBy:
8788
[data["RelatedObjects"].append(o.id()) for o in rel.RelatedObjects if o.is_a("IfcTask")]
89+
[
90+
data["RelatingProducts"].append(r.RelatingProduct.id())
91+
for r in task.HasAssignments
92+
if r.is_a("IfcRelAssignsToProduct")
93+
]
8894
[data["IsPredecessorTo"].append(rel.RelatedProcess.id()) for rel in task.IsPredecessorTo or []]
8995
[data["IsSuccessorFrom"].append(rel.RelatingProcess.id()) for rel in task.IsSuccessorFrom or []]
9096
cls.tasks[task.id()] = data
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import ifcopenshell
2+
import ifcopenshell.api
3+
4+
5+
class Usecase:
6+
def __init__(self, file, **settings):
7+
self.file = file
8+
self.settings = {
9+
"relating_product": None,
10+
"related_object": None,
11+
}
12+
for key, value in settings.items():
13+
self.settings[key] = value
14+
15+
def execute(self):
16+
for rel in self.settings["related_object"].HasAssignments or []:
17+
if not rel.is_a("IfcRelAssignsToProduct") or rel.RelatingProduct != self.settings["relating_product"]:
18+
continue
19+
if len(rel.RelatedObjects) == 1:
20+
return self.file.remove(rel)
21+
related_objects = list(rel.RelatedObjects)
22+
related_objects.remove(self.settings["related_object"])
23+
rel.RelatedObjects = related_objects
24+
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
25+
return rel

0 commit comments

Comments
 (0)