Fix issue #1637 Blender ID collision for bim.assign_resource and bim.unassign_resource

This commit is contained in:
bosonprojets
2021-08-14 15:04:13 +01:00
parent 0cc6ca11b1
commit ca20d94d66
3 changed files with 67 additions and 95 deletions
@@ -76,9 +76,7 @@ classes = (
operator.AddTaskColumn,
operator.RemoveTaskColumn,
operator.SetTaskSortColumn,
operator.EnableAssigningResources,
operator.AssignResource,
operator.UnassignResource,
operator.EnableAssigningProcessToResource,
prop.WorkPlan,
prop.BIMWorkPlanProperties,
prop.Task,
@@ -818,22 +818,44 @@ class AssignProcess(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
task: bpy.props.IntProperty()
related_object: bpy.props.StringProperty()
parent_resource: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
related_objects = (
[bpy.data.objects.get(self.related_object)] if self.related_object else context.selected_objects
)
for related_object in related_objects:
self.file = IfcStore.get_file()
self.file = IfcStore.get_file()
if self.parent_resource:
resource = ifcopenshell.api.run(
"resource.add_resource",
self.file,
**{
"parent_resource": self.file.by_id(self.parent_resource),
"ifc_class": self.file.by_id(self.parent_resource).is_a(),
"name": self.file.by_id(self.parent_resource).Name + ": " + self.file.by_id(self.task).Name,
},
)
ifcopenshell.api.run(
"sequence.assign_process",
self.file,
related_object=self.file.by_id(related_object.BIMObjectProperties.ifc_definition_id),
relating_process=self.file.by_id(self.task),
**{
"related_object": resource,
"relating_process": self.file.by_id(self.task),
},
)
ResourceData.load(self.file)
bpy.ops.bim.load_resources()
else:
related_objects = (
[bpy.data.objects.get(self.related_object)] if self.related_object else context.selected_objects
)
for related_object in related_objects:
ifcopenshell.api.run(
"sequence.assign_process",
self.file,
related_object=self.file.by_id(related_object.BIMObjectProperties.ifc_definition_id),
relating_process=self.file.by_id(self.task),
)
Data.load(self.file)
return {"FINISHED"}
@@ -844,22 +866,38 @@ class UnassignProcess(bpy.types.Operator):
bl_options = {"REGISTER", "UNDO"}
task: bpy.props.IntProperty()
related_object: bpy.props.StringProperty()
resource: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
related_objects = (
[bpy.data.objects.get(self.related_object)] if self.related_object else context.selected_objects
)
for related_object in related_objects:
self.file = IfcStore.get_file()
self.file = IfcStore.get_file()
if self.resource:
ifcopenshell.api.run(
"sequence.unassign_process",
self.file,
related_object=self.file.by_id(related_object.BIMObjectProperties.ifc_definition_id),
related_object=self.file.by_id(self.resource),
relating_process=self.file.by_id(self.task),
)
ifcopenshell.api.run(
"resource.remove_resource",
self.file,
resource=self.file.by_id(self.resource),
)
ResourceData.load(self.file)
bpy.ops.bim.load_resources()
else:
related_objects = (
[bpy.data.objects.get(self.related_object)] if self.related_object else context.selected_objects
)
for related_object in related_objects:
ifcopenshell.api.run(
"sequence.unassign_process",
self.file,
related_object=self.file.by_id(related_object.BIMObjectProperties.ifc_definition_id),
relating_process=self.file.by_id(self.task),
)
Data.load(self.file)
return {"FINISHED"}
@@ -1980,8 +2018,8 @@ class SetTaskSortColumn(bpy.types.Operator):
return {"FINISHED"}
class EnableAssigningResources(bpy.types.Operator):
bl_idname = "bim.enable_assigning_resources"
class EnableAssigningProcessToResource(bpy.types.Operator):
bl_idname = "bim.enable_assigning_process_to_resources"
bl_label = "Enable Assigning Resources To Tasks"
bl_options = {"REGISTER", "UNDO"}
task: bpy.props.IntProperty()
@@ -1991,66 +2029,3 @@ class EnableAssigningResources(bpy.types.Operator):
self.props.active_task_id = self.task
self.props.editing_task_type = "RESOURCES"
return {"FINISHED"}
class AssignResource(bpy.types.Operator):
bl_idname = "bim.assign_resource"
bl_label = "Assign Resource"
bl_options = {"REGISTER", "UNDO"}
task: bpy.props.IntProperty()
parent_resource: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = IfcStore.get_file()
resource = ifcopenshell.api.run(
"resource.add_resource",
self.file,
**{
"parent_resource": self.file.by_id(self.parent_resource),
"ifc_class": self.file.by_id(self.parent_resource).is_a(),
"name": self.file.by_id(self.parent_resource).Name + ": " + self.file.by_id(self.task).Name,
},
)
ifcopenshell.api.run(
"sequence.assign_process",
self.file,
**{
"related_object": resource,
"relating_process": self.file.by_id(self.task),
},
)
Data.load(self.file)
ResourceData.load(self.file)
bpy.ops.bim.load_resources()
return {"FINISHED"}
class UnassignResource(bpy.types.Operator):
bl_idname = "bim.unassign_resource"
bl_label = "Unassign Resource"
bl_options = {"REGISTER", "UNDO"}
task: bpy.props.IntProperty()
resource: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"sequence.unassign_process",
self.file,
related_object=self.file.by_id(self.resource),
relating_process=self.file.by_id(self.task),
)
ifcopenshell.api.run(
"resource.remove_resource",
self.file,
resource=self.file.by_id(self.resource),
)
Data.load(self.file)
ResourceData.load(self.file)
bpy.ops.bim.load_resources()
return {"FINISHED"}
@@ -293,20 +293,19 @@ class BIM_PT_work_schedules(Panel):
def draw_editable_task_resource_ui(self):
row = self.layout.row(align=True)
row.prop(self.props, "resources", text="")
op = row.operator("bim.assign_resource", text="", icon="ADD")
op.parent_resource = int(self.props.resources)
op.task = self.props.active_task_id
task = Data.tasks[self.props.active_task_id]
ResourceData.load(IfcStore.get_file())
for related_obect_id in task["OperatesOn"]:
resource = ResourceData.resources[related_obect_id]
row = self.layout.row(align=True)
row.label(text=resource["Name"], icon="COMMUNITY")
op = row.operator("bim.unassign_resource", text="", icon="X")
op = row.operator("bim.assign_process", text="", icon="ADD")
if self.props.resources:
op.parent_resource = int(self.props.resources)
op.task = self.props.active_task_id
op.resource = related_obect_id
task = Data.tasks[self.props.active_task_id]
ResourceData.load(IfcStore.get_file())
for related_obect_id in task["OperatesOn"]:
resource = ResourceData.resources[related_obect_id]
row = self.layout.row(align=True)
row.label(text=resource["Name"], icon="COMMUNITY")
op = row.operator("bim.unassign_process", text="", icon="X")
op.task = self.props.active_task_id
op.resource = related_obect_id
class BIM_UL_task_columns(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
@@ -436,7 +435,7 @@ class BIM_UL_tasks(UIList):
row.operator(
"bim.enable_editing_task_calendar", text="", icon="VIEW_ORTHO"
).task = item.ifc_definition_id
row.operator("bim.enable_assigning_resources", text="", icon="COMMUNITY").task = item.ifc_definition_id
row.operator("bim.enable_assigning_process_to_resources", text="", icon="COMMUNITY").task = item.ifc_definition_id
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