Code review for assign product with myoualid

This commit is contained in:
Dion Moult
2021-04-21 11:11:08 +10:00
parent 8dd781aea2
commit 3143f8c9a5
6 changed files with 52 additions and 79 deletions
@@ -628,7 +628,6 @@ class EnableEditingTask(bpy.types.Operator):
if data[attribute.name()]:
new.enum_value = data[attribute.name()]
props.active_task_id = self.task
props.should_show_times = True
return {"FINISHED"}
@@ -662,9 +661,7 @@ class EditTask(bpy.types.Operator):
attributes[attribute.name] = attribute.enum_value
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"sequence.edit_task",
self.file,
**{"task": self.file.by_id(props.active_task_id), "attributes": attributes}
"sequence.edit_task", self.file, **{"task": self.file.by_id(props.active_task_id), "attributes": attributes}
)
Data.load(IfcStore.get_file())
bpy.ops.bim.disable_editing_task()
@@ -748,17 +745,19 @@ class AssignProduct(bpy.types.Operator):
bl_idname = "bim.assign_product"
bl_label = "Assign Product"
task: bpy.props.IntProperty()
related_product: bpy.props.StringProperty()
def execute(self, context):
obj = bpy.context.active_object.BIMObjectProperties.ifc_definition_id
props = context.scene.BIMWorkScheduleProperties
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"sequence.assign_product",
self.file,
relating_product = self.file.by_id(obj),
related_process = self.file.by_id(self.task),
related_products = (
[bpy.data.objects.get(self.related_product)] if self.related_product else bpy.context.selected_objects
)
props.has_assignment = True
for related_product in related_products:
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"sequence.assign_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"}
@@ -107,7 +107,6 @@ class Task(PropertyGroup):
identification: StringProperty(name="Identification", update=updateTaskIdentification)
ifc_definition_id: IntProperty(name="IFC Definition ID")
has_children: BoolProperty(name="Has Children")
has_assignment: BoolProperty(name="Has Assignement")
is_expanded: BoolProperty(name="Is Expanded")
level_index: IntProperty(name="Level Index")
duration: StringProperty(name="Duration")
@@ -137,7 +136,7 @@ class BIMWorkScheduleProperties(PropertyGroup):
active_task_index: IntProperty(name="Active Task Index")
active_task_id: IntProperty(name="Active Task Id")
task_attributes: CollectionProperty(name="Task Attributes", type=Attribute)
should_show_times: BoolProperty(name="Should Show Times", default=False)
should_show_times: BoolProperty(name="Should Show Times", default=True)
active_task_time_id: IntProperty(name="Active Task Id")
task_time_attributes: CollectionProperty(name="Task Time Attributes", type=Attribute)
contracted_tasks: StringProperty(name="Contracted Task Items", default="[]")
@@ -293,8 +293,5 @@ 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
if context.selected_objects:
obj = context.selected_objects[0]
pass
row = layout.row(align=True)
row.operator("bim.assign_product", text="ADD", icon="OUTLINER_COLLECTION").task = item.ifc_definition_id