diff --git a/src/blenderbim/blenderbim/bim/module/sequence/__init__.py b/src/blenderbim/blenderbim/bim/module/sequence/__init__.py index 6e3658388f..b205cce8bb 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/__init__.py @@ -40,6 +40,7 @@ classes = ( operator.DisableEditingTaskTime, operator.EditTaskTime, operator.AssignProduct, + operator.UnassignProduct, prop.WorkPlan, prop.BIMWorkPlanProperties, prop.Task, diff --git a/src/blenderbim/blenderbim/bim/module/sequence/operator.py b/src/blenderbim/blenderbim/bim/module/sequence/operator.py index c07d659323..3984198796 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/operator.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/operator.py @@ -761,3 +761,25 @@ class AssignProduct(bpy.types.Operator): ) Data.load(self.file) return {"FINISHED"} + + +class UnassignProduct(bpy.types.Operator): + bl_idname = "bim.unassign_product" + bl_label = "Unassign Product" + task: bpy.props.IntProperty() + related_product: bpy.props.StringProperty() + + def execute(self, context): + related_products = ( + [bpy.data.objects.get(self.related_product)] if self.related_product else bpy.context.selected_objects + ) + for related_product in related_products: + self.file = IfcStore.get_file() + ifcopenshell.api.run( + "sequence.unassign_product", + self.file, + relating_product=self.file.by_id(related_product.BIMObjectProperties.ifc_definition_id), + related_object=self.file.by_id(self.task), + ) + Data.load(self.file) + return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/sequence/ui.py b/src/blenderbim/blenderbim/bim/module/sequence/ui.py index 0831afbf90..492fbda7a9 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/ui.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/ui.py @@ -261,6 +261,16 @@ class BIM_UL_tasks(UIList): row.prop(item, "finish", emboss=False, text="") row.prop(item, "duration", emboss=False, text="") + if context.active_object: + oprops = context.active_object.BIMObjectProperties + row = layout.row(align=True) + if oprops.ifc_definition_id in Data.tasks[item.ifc_definition_id]["RelatingProducts"]: + op = row.operator("bim.unassign_product", text="", icon="KEYFRAME_HLT", emboss=False) + op.task = item.ifc_definition_id + else: + op = row.operator("bim.assign_product", text="", icon="KEYFRAME", emboss=False) + op.task = item.ifc_definition_id + if props.active_task_id == item.ifc_definition_id: if props.active_task_time_id: row.operator("bim.edit_task_time", text="", icon="CHECKMARK") @@ -293,5 +303,3 @@ class BIM_UL_tasks(UIList): row.operator("bim.enable_editing_task", text="", icon="GREASEPENCIL").task = item.ifc_definition_id row.operator("bim.add_task", text="", icon="ADD").task = item.ifc_definition_id row.operator("bim.remove_task", text="", icon="X").task = item.ifc_definition_id - row = layout.row(align=True) - row.operator("bim.assign_product", text="ADD", icon="OUTLINER_COLLECTION").task = item.ifc_definition_id diff --git a/src/ifcopenshell-python/ifcopenshell/api/sequence/add_task.py b/src/ifcopenshell-python/ifcopenshell/api/sequence/add_task.py index 1102606064..98ce8bc33a 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/sequence/add_task.py +++ b/src/ifcopenshell-python/ifcopenshell/api/sequence/add_task.py @@ -1,6 +1,7 @@ import ifcopenshell.api import ifcopenshell + class Usecase: def __init__(self, file, **settings): self.file = file @@ -16,9 +17,9 @@ class Usecase: "root.create_entity", self.file, ifc_class="IfcTask", - name= None, - predefined_type= "NOTDEFINED", - identification= "none", + name=None, + predefined_type="NOTDEFINED", + identification="none", ) task.IsMilestone = False if self.settings["work_schedule"]: @@ -33,6 +34,6 @@ class Usecase: ) elif self.settings["parent_task"]: ifcopenshell.api.run( - "nest.assign_object", self.file, object=task, relating_object=self.settings["parent_task"] + "nest.assign_object", self.file, related_object=task, relating_object=self.settings["parent_task"] ) return task diff --git a/src/ifcopenshell-python/ifcopenshell/api/sequence/data.py b/src/ifcopenshell-python/ifcopenshell/api/sequence/data.py index b2289fc178..c193551f23 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/sequence/data.py +++ b/src/ifcopenshell-python/ifcopenshell/api/sequence/data.py @@ -79,12 +79,18 @@ class Data: data = task.get_info() del data["OwnerHistory"] data["RelatedObjects"] = [] + data["RelatingProducts"] = [] data["IsPredecessorTo"] = [] data["IsSuccessorFrom"] = [] if task.TaskTime: data["TaskTime"] = data["TaskTime"].id() for rel in task.IsNestedBy: [data["RelatedObjects"].append(o.id()) for o in rel.RelatedObjects if o.is_a("IfcTask")] + [ + data["RelatingProducts"].append(r.RelatingProduct.id()) + for r in task.HasAssignments + if r.is_a("IfcRelAssignsToProduct") + ] [data["IsPredecessorTo"].append(rel.RelatedProcess.id()) for rel in task.IsPredecessorTo or []] [data["IsSuccessorFrom"].append(rel.RelatingProcess.id()) for rel in task.IsSuccessorFrom or []] cls.tasks[task.id()] = data diff --git a/src/ifcopenshell-python/ifcopenshell/api/sequence/unassign_product.py b/src/ifcopenshell-python/ifcopenshell/api/sequence/unassign_product.py new file mode 100644 index 0000000000..5d28bc43d0 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/sequence/unassign_product.py @@ -0,0 +1,25 @@ +import ifcopenshell +import ifcopenshell.api + + +class Usecase: + def __init__(self, file, **settings): + self.file = file + self.settings = { + "relating_product": None, + "related_object": None, + } + for key, value in settings.items(): + self.settings[key] = value + + def execute(self): + for rel in self.settings["related_object"].HasAssignments or []: + if not rel.is_a("IfcRelAssignsToProduct") or rel.RelatingProduct != self.settings["relating_product"]: + continue + if len(rel.RelatedObjects) == 1: + return self.file.remove(rel) + related_objects = list(rel.RelatedObjects) + related_objects.remove(self.settings["related_object"]) + rel.RelatedObjects = related_objects + ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel}) + return rel