mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Implement unassigning products to tasks
This commit is contained in:
@@ -40,6 +40,7 @@ classes = (
|
||||
operator.DisableEditingTaskTime,
|
||||
operator.EditTaskTime,
|
||||
operator.AssignProduct,
|
||||
operator.UnassignProduct,
|
||||
prop.WorkPlan,
|
||||
prop.BIMWorkPlanProperties,
|
||||
prop.Task,
|
||||
|
||||
@@ -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"}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user