mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-30 16:43:00 +00:00
New assign / unassign declaration usecase, minor code & formatting cleanup
This commit is contained in:
@@ -16,11 +16,12 @@ class LoadWorkPlans(bpy.types.Operator):
|
||||
for ifc_definition_id, work_plan in Data.work_plans.items():
|
||||
new = props.work_plans.add()
|
||||
new.ifc_definition_id = ifc_definition_id
|
||||
new.name = work_plan["Name"] or "Unnamed"
|
||||
new.name = work_plan["Name"] or "Unnamed"
|
||||
props.is_editing = True
|
||||
bpy.ops.bim.disable_editing_work_plan()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class DisableWorkPlanEditingUI(bpy.types.Operator):
|
||||
bl_idname = "bim.disable_work_plan_editing_ui"
|
||||
bl_label = "Disable WorkPlan Editing UI"
|
||||
@@ -58,25 +59,28 @@ class EditWorkPlan(bpy.types.Operator):
|
||||
attributes[attribute.name] = attribute.enum_value
|
||||
self.file = IfcStore.get_file()
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_work_plan", self.file, **{"work_plan": self.file.by_id(props.active_work_plan_id), "attributes": attributes}
|
||||
"sequence.edit_work_plan",
|
||||
self.file,
|
||||
**{"work_plan": self.file.by_id(props.active_work_plan_id), "attributes": attributes}
|
||||
)
|
||||
Data.load(IfcStore.get_file())
|
||||
bpy.ops.bim.load_work_plans()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class RemoveWorkPlan(bpy.types.Operator):
|
||||
bl_idname = "bim.remove_work_plan"
|
||||
bl_label = "Remove Work Plan"
|
||||
work_plan: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMWorkPlanProperties
|
||||
self.file = IfcStore.get_file()
|
||||
ifcopenshell.api.run("sequence.remove_work_plan", self.file, **{"work_plan": self.file.by_id(self.work_plan)})
|
||||
Data.load(IfcStore.get_file())
|
||||
bpy.ops.bim.load_work_plans()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class EnableEditingWorkPlan(bpy.types.Operator):
|
||||
bl_idname = "bim.enable_editing_work_plan"
|
||||
bl_label = "Enable Editing Work Plan"
|
||||
@@ -98,7 +102,9 @@ class EnableEditingWorkPlan(bpy.types.Operator):
|
||||
new.is_null = data[attribute.name()] is None
|
||||
new.is_optional = attribute.optional()
|
||||
new.data_type = data_type
|
||||
if data_type == "string":
|
||||
if attribute.name() in ["CreationDate", "StartTime", "FinishTime"]:
|
||||
new.string_value = "" if new.is_null else data[attribute.name()].isoformat()
|
||||
elif data_type == "string":
|
||||
new.string_value = "" if new.is_null else data[attribute.name()]
|
||||
elif data_type == "enum":
|
||||
new.enum_items = json.dumps(ifcopenshell.util.attribute.get_enum_items(attribute))
|
||||
@@ -107,6 +113,7 @@ class EnableEditingWorkPlan(bpy.types.Operator):
|
||||
props.active_work_plan_id = self.work_plan
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class DisableEditingWorkPlan(bpy.types.Operator):
|
||||
bl_idname = "bim.disable_editing_work_plan"
|
||||
bl_label = "Disable Editing Work Plan"
|
||||
@@ -115,6 +122,7 @@ class DisableEditingWorkPlan(bpy.types.Operator):
|
||||
context.scene.BIMWorkPlanProperties.active_work_plan_id = 0
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class LoadWorkSchedules(bpy.types.Operator):
|
||||
bl_idname = "bim.load_work_schedules"
|
||||
bl_label = "Load Work Schedules"
|
||||
@@ -125,12 +133,13 @@ class LoadWorkSchedules(bpy.types.Operator):
|
||||
props.work_schedules.remove(0)
|
||||
for ifc_definition_id, work_schedule in Data.work_schedules.items():
|
||||
new = props.work_schedules.add()
|
||||
new.ifc_definition_id = ifc_definition_id or "Unnamed"
|
||||
new.name = work_schedule["Name"]
|
||||
new.ifc_definition_id = ifc_definition_id
|
||||
new.name = work_schedule["Name"] or "Unnamed"
|
||||
props.is_editing = True
|
||||
bpy.ops.bim.disable_editing_work_schedule()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class DisableWorkScheduleEditingUI(bpy.types.Operator):
|
||||
bl_idname = "bim.disable_work_schedule_editing_ui"
|
||||
bl_label = "Disable WorkSchedule Editing UI"
|
||||
@@ -145,7 +154,7 @@ class AddWorkSchedule(bpy.types.Operator):
|
||||
bl_label = "Add Work Schedule"
|
||||
|
||||
def execute(self, context):
|
||||
result = ifcopenshell.api.run("sequence.add_work_schedule", IfcStore.get_file())
|
||||
ifcopenshell.api.run("sequence.add_work_schedule", IfcStore.get_file())
|
||||
Data.load(IfcStore.get_file())
|
||||
bpy.ops.bim.load_work_schedules()
|
||||
return {"FINISHED"}
|
||||
@@ -167,27 +176,31 @@ class EditWorkSchedule(bpy.types.Operator):
|
||||
elif attribute.data_type == "enum":
|
||||
attributes[attribute.name] = attribute.enum_value
|
||||
self.file = IfcStore.get_file()
|
||||
ifcopenshell.api.run("sequence.edit_work_schedule", self.file, **{
|
||||
"work_schedule": self.file.by_id(props.active_work_schedule_id),
|
||||
"attributes": attributes
|
||||
})
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_work_schedule",
|
||||
self.file,
|
||||
**{"work_schedule": self.file.by_id(props.active_work_schedule_id), "attributes": attributes}
|
||||
)
|
||||
Data.load(IfcStore.get_file())
|
||||
bpy.ops.bim.load_work_schedules()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class RemoveWorkSchedule(bpy.types.Operator):
|
||||
bl_idname = "bim.remove_work_schedule"
|
||||
bl_label = "Remove Work Schedule"
|
||||
work_schedule: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMWorkScheduleProperties
|
||||
self.file = IfcStore.get_file()
|
||||
ifcopenshell.api.run("sequence.remove_work_schedule", self.file, **{"work_schedule": self.file.by_id(self.work_schedule)})
|
||||
Data.load(IfcStore.get_file())
|
||||
ifcopenshell.api.run(
|
||||
"sequence.remove_work_schedule", self.file, **{"work_schedule": self.file.by_id(self.work_schedule)}
|
||||
)
|
||||
Data.load(self.file)
|
||||
bpy.ops.bim.load_work_schedules()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class EnableEditingWorkSchedule(bpy.types.Operator):
|
||||
bl_idname = "bim.enable_editing_work_schedule"
|
||||
bl_label = "Enable Editing Work Schedule"
|
||||
@@ -209,7 +222,9 @@ class EnableEditingWorkSchedule(bpy.types.Operator):
|
||||
new.is_null = data[attribute.name()] is None
|
||||
new.is_optional = attribute.optional()
|
||||
new.data_type = data_type
|
||||
if data_type == "string":
|
||||
if attribute.name() in ["CreationDate", "StartTime", "FinishTime"]:
|
||||
new.string_value = "" if new.is_null else data[attribute.name()].isoformat()
|
||||
elif data_type == "string":
|
||||
new.string_value = "" if new.is_null else data[attribute.name()]
|
||||
elif data_type == "enum":
|
||||
new.enum_items = json.dumps(ifcopenshell.util.attribute.get_enum_items(attribute))
|
||||
@@ -238,12 +253,13 @@ class LoadWorkCalendars(bpy.types.Operator):
|
||||
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 or "Unnamed"
|
||||
new.name = work_calendar["Name"]
|
||||
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"
|
||||
@@ -258,7 +274,7 @@ class AddWorkCalendar(bpy.types.Operator):
|
||||
bl_label = "Add Work Calendar"
|
||||
|
||||
def execute(self, context):
|
||||
result = 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())
|
||||
bpy.ops.bim.load_work_calendars()
|
||||
return {"FINISHED"}
|
||||
@@ -280,27 +296,31 @@ class EditWorkCalendar(bpy.types.Operator):
|
||||
elif attribute.data_type == "enum":
|
||||
attributes[attribute.name] = attribute.enum_value
|
||||
self.file = IfcStore.get_file()
|
||||
ifcopenshell.api.run("sequence.edit_work_calendar", self.file, **{
|
||||
"work_calendar": self.file.by_id(props.active_work_calendar_id),
|
||||
"attributes": attributes
|
||||
})
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_work_calendar",
|
||||
self.file,
|
||||
**{"work_calendar": self.file.by_id(props.active_work_calendar_id), "attributes": attributes}
|
||||
)
|
||||
Data.load(IfcStore.get_file())
|
||||
bpy.ops.bim.load_work_calendars()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class RemoveWorkCalendar(bpy.types.Operator):
|
||||
bl_idname = "bim.remove_work_calendar"
|
||||
bl_label = "Remove Work Plan"
|
||||
work_calendar: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMWorkCalendarProperties
|
||||
self.file = IfcStore.get_file()
|
||||
ifcopenshell.api.run("sequence.remove_work_calendar", self.file, **{"work_calendar": self.file.by_id(self.work_calendar)})
|
||||
Data.load(IfcStore.get_file())
|
||||
ifcopenshell.api.run(
|
||||
"sequence.remove_work_calendar", self.file, **{"work_calendar": self.file.by_id(self.work_calendar)}
|
||||
)
|
||||
Data.load(self.file)
|
||||
bpy.ops.bim.load_work_calendars()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class EnableEditingWorkCalendar(bpy.types.Operator):
|
||||
bl_idname = "bim.enable_editing_work_calendar"
|
||||
bl_label = "Enable Editing Work Plan"
|
||||
|
||||
@@ -61,4 +61,4 @@ class BIMWorkCalendarProperties(PropertyGroup):
|
||||
is_editing: BoolProperty(name="Is Editing", default=False)
|
||||
work_calendars: CollectionProperty(name="Work Calendar", type=WorkCalendar)
|
||||
active_work_calendar_index: IntProperty(name="Active Work Calendar Index")
|
||||
active_work_calendar_id: IntProperty(name="Active Work Calendar Id")
|
||||
active_work_calendar_id: IntProperty(name="Active Work Calendar Id")
|
||||
|
||||
@@ -43,7 +43,10 @@ class BIM_PT_work_plans(Panel):
|
||||
def draw_editable_ui(self, context):
|
||||
for attribute in self.props.work_plan_attributes:
|
||||
row = self.layout.row(align=True)
|
||||
row.prop(attribute, "string_value", text=attribute.name)
|
||||
if attribute.data_type == "string":
|
||||
row.prop(attribute, "string_value", text=attribute.name)
|
||||
elif attribute.data_type == "enum":
|
||||
row.prop(attribute, "enum_value", text=attribute.name)
|
||||
if attribute.is_optional:
|
||||
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
||||
|
||||
@@ -104,10 +107,14 @@ class BIM_PT_work_schedules(Panel):
|
||||
def draw_editable_ui(self, context):
|
||||
for attribute in self.props.work_schedule_attributes:
|
||||
row = self.layout.row(align=True)
|
||||
row.prop(attribute, "string_value", text=attribute.name)
|
||||
if attribute.data_type == "string":
|
||||
row.prop(attribute, "string_value", text=attribute.name)
|
||||
elif attribute.data_type == "enum":
|
||||
row.prop(attribute, "enum_value", text=attribute.name)
|
||||
if attribute.is_optional:
|
||||
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
||||
|
||||
|
||||
class BIM_UL_work_schedules(UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||
if item:
|
||||
@@ -123,6 +130,7 @@ class BIM_UL_work_schedules(UIList):
|
||||
op.work_schedule = item.ifc_definition_id
|
||||
row.operator("bim.remove_work_schedule", text="", icon="X").work_schedule = item.ifc_definition_id
|
||||
|
||||
|
||||
class BIM_PT_work_calendars(Panel):
|
||||
bl_label = "IFC Work Calendars"
|
||||
bl_idname = "BIM_PT_work_calendars"
|
||||
@@ -163,10 +171,14 @@ class BIM_PT_work_calendars(Panel):
|
||||
def draw_editable_ui(self, context):
|
||||
for attribute in self.props.work_calendar_attributes:
|
||||
row = self.layout.row(align=True)
|
||||
row.prop(attribute, "string_value", text=attribute.name)
|
||||
if attribute.data_type == "string":
|
||||
row.prop(attribute, "string_value", text=attribute.name)
|
||||
elif attribute.data_type == "enum":
|
||||
row.prop(attribute, "enum_value", text=attribute.name)
|
||||
if attribute.is_optional:
|
||||
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:
|
||||
@@ -230,4 +242,4 @@ class BIM_UL_tasks(UIList):
|
||||
row = layout.row(align=True)
|
||||
if item.identification:
|
||||
layout.label(text=item.identification)
|
||||
layout.label(text=item.name)
|
||||
layout.label(text=item.name)
|
||||
|
||||
Reference in New Issue
Block a user