Simplify work calendar UI

This commit is contained in:
Dion Moult
2021-04-29 09:55:50 +10:00
parent 4ab23d231d
commit b726ba7816
4 changed files with 24 additions and 66 deletions
@@ -17,8 +17,6 @@ classes = (
operator.EnableEditingTasks, operator.EnableEditingTasks,
operator.DisableEditingWorkSchedule, operator.DisableEditingWorkSchedule,
operator.DisableTaskEditingUI, operator.DisableTaskEditingUI,
operator.LoadWorkCalendars,
operator.DisableWorkCalendarEditingUI,
operator.AddWorkCalendar, operator.AddWorkCalendar,
operator.EditWorkCalendar, operator.EditWorkCalendar,
operator.RemoveWorkCalendar, operator.RemoveWorkCalendar,
@@ -54,7 +52,6 @@ classes = (
ui.BIM_PT_work_plans, ui.BIM_PT_work_plans,
ui.BIM_PT_work_schedules, ui.BIM_PT_work_schedules,
ui.BIM_PT_work_calendars, ui.BIM_PT_work_calendars,
ui.BIM_UL_work_calendars,
ui.BIM_UL_tasks, ui.BIM_UL_tasks,
) )
@@ -747,32 +747,6 @@ class GenerateGanttChart(bpy.types.Operator):
self.create_new_task_json(task_id) self.create_new_task_json(task_id)
class LoadWorkCalendars(bpy.types.Operator):
bl_idname = "bim.load_work_calendars"
bl_label = "Load Work Calendars"
def execute(self, context):
props = context.scene.BIMWorkCalendarProperties
while len(props.work_calendars) > 0:
props.work_calendars.remove(0)
for ifc_definition_id, work_calendar in Data.work_calendars.items():
new = props.work_calendars.add()
new.ifc_definition_id = ifc_definition_id
new.name = work_calendar["Name"] or "Unnamed"
props.is_editing = True
bpy.ops.bim.disable_editing_work_calendar()
return {"FINISHED"}
class DisableWorkCalendarEditingUI(bpy.types.Operator):
bl_idname = "bim.disable_work_calendar_editing_ui"
bl_label = "Disable WorkCalendar Editing UI"
def execute(self, context):
context.scene.BIMWorkCalendarProperties.is_editing = False
return {"FINISHED"}
class AddWorkCalendar(bpy.types.Operator): class AddWorkCalendar(bpy.types.Operator):
bl_idname = "bim.add_work_calendar" bl_idname = "bim.add_work_calendar"
bl_label = "Add Work Calendar" bl_label = "Add Work Calendar"
@@ -780,7 +754,6 @@ class AddWorkCalendar(bpy.types.Operator):
def execute(self, context): def execute(self, context):
ifcopenshell.api.run("sequence.add_work_calendar", IfcStore.get_file()) ifcopenshell.api.run("sequence.add_work_calendar", IfcStore.get_file())
Data.load(IfcStore.get_file()) Data.load(IfcStore.get_file())
bpy.ops.bim.load_work_calendars()
return {"FINISHED"} return {"FINISHED"}
@@ -806,7 +779,7 @@ class EditWorkCalendar(bpy.types.Operator):
**{"work_calendar": self.file.by_id(props.active_work_calendar_id), "attributes": attributes}, **{"work_calendar": self.file.by_id(props.active_work_calendar_id), "attributes": attributes},
) )
Data.load(IfcStore.get_file()) Data.load(IfcStore.get_file())
bpy.ops.bim.load_work_calendars() bpy.ops.bim.disable_editing_work_calendar()
return {"FINISHED"} return {"FINISHED"}
@@ -821,7 +794,6 @@ class RemoveWorkCalendar(bpy.types.Operator):
"sequence.remove_work_calendar", self.file, **{"work_calendar": self.file.by_id(self.work_calendar)} "sequence.remove_work_calendar", self.file, **{"work_calendar": self.file.by_id(self.work_calendar)}
) )
Data.load(self.file) Data.load(self.file)
bpy.ops.bim.load_work_calendars()
return {"FINISHED"} return {"FINISHED"}
@@ -266,28 +266,30 @@ class BIM_PT_work_calendars(Panel):
if not Data.is_loaded: if not Data.is_loaded:
Data.load(IfcStore.get_file()) Data.load(IfcStore.get_file())
self.props = context.scene.BIMWorkCalendarProperties self.props = context.scene.BIMWorkCalendarProperties
row = self.layout.row()
row.operator("bim.add_work_calendar", icon="ADD")
for work_calendar_id, work_calendar in Data.work_calendars.items():
self.draw_work_calendar_ui(work_calendar_id, work_calendar)
def draw_work_calendar_ui(self, work_calendar_id, work_calendar):
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.label(text="{} Work Calendar Found".format(len(Data.work_calendars)), icon="TEXT") row.label(text=work_calendar["Name"] or "Unnamed", icon="VIEW_ORTHO")
if self.props.is_editing: if self.props.active_work_calendar_id == work_calendar_id:
row.operator("bim.add_work_calendar", text="", icon="ADD") row.operator("bim.edit_work_calendar", text="", icon="CHECKMARK")
row.operator("bim.disable_work_calendar_editing_ui", text="", icon="CHECKMARK") row.operator("bim.disable_editing_work_calendar", text="", icon="CANCEL")
elif self.props.active_work_calendar_id:
row.operator("bim.remove_work_calendar", text="", icon="X").work_calendar = work_calendar_id
else: else:
row.operator("bim.load_work_calendars", text="", icon="GREASEPENCIL") op = row.operator("bim.enable_editing_work_calendar", text="", icon="GREASEPENCIL")
op.work_calendar = work_calendar_id
row.operator("bim.remove_work_calendar", text="", icon="X").work_calendar = work_calendar_id
if self.props.is_editing: if self.props.active_work_calendar_id == work_calendar_id:
self.layout.template_list( self.draw_editable_ui()
"BIM_UL_work_calendars",
"",
self.props,
"work_calendars",
self.props,
"active_work_calendar_index",
)
if self.props.active_work_calendar_id: def draw_editable_ui(self):
self.draw_editable_ui(context)
def draw_editable_ui(self, context):
for attribute in self.props.work_calendar_attributes: for attribute in self.props.work_calendar_attributes:
row = self.layout.row(align=True) row = self.layout.row(align=True)
if attribute.data_type == "string": if attribute.data_type == "string":
@@ -296,19 +298,3 @@ class BIM_PT_work_calendars(Panel):
row.prop(attribute, "enum_value", text=attribute.name) row.prop(attribute, "enum_value", text=attribute.name)
if attribute.is_optional: if attribute.is_optional:
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="") row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
class BIM_UL_work_calendars(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
if item:
row = layout.row(align=True)
row.label(text=item.name)
if context.scene.BIMWorkCalendarProperties.active_work_calendar_id == item.ifc_definition_id:
row.operator("bim.edit_work_calendar", text="", icon="CHECKMARK")
row.operator("bim.disable_editing_work_calendar", text="", icon="X")
elif context.scene.BIMWorkCalendarProperties.active_work_calendar_id:
row.operator("bim.remove_work_calendar", text="", icon="X").work_calendar = item.ifc_definition_id
else:
op = row.operator("bim.enable_editing_work_calendar", text="", icon="GREASEPENCIL")
op.work_calendar = item.ifc_definition_id
row.operator("bim.remove_work_calendar", text="", icon="X").work_calendar = item.ifc_definition_id
@@ -1,3 +1,6 @@
import ifcopenshell
class Usecase: class Usecase:
def __init__(self, file, **settings): def __init__(self, file, **settings):
self.file = file self.file = file