Add support for editing sequence relationship attributes in blenderBIM

This commit is contained in:
bosonprojets
2021-05-01 21:45:27 +00:00
parent 037261afb9
commit d73a5c46ea
4 changed files with 98 additions and 0 deletions
@@ -16,6 +16,9 @@ classes = (
operator.EnableEditingWorkSchedule,
operator.EnableEditingTasks,
operator.DisableEditingWorkSchedule,
operator.DisableEditingSequenceAttributes,
operator.EditSequenceAttributes,
operator.EnableEditingSequenceAttributes,
operator.AddWorkCalendar,
operator.EditWorkCalendar,
operator.EditWorkTime,
@@ -1184,3 +1184,69 @@ class DisableEditingTaskTime(bpy.types.Operator):
context.scene.BIMWorkScheduleProperties.active_task_time_id = 0
bpy.ops.bim.disable_editing_task()
return {"FINISHED"}
class EnableEditingSequenceAttributes(bpy.types.Operator):
bl_idname = "bim.enable_editing_sequence_attributes"
bl_label = "Enable Editing Sequence Attributes"
sequence: bpy.props.IntProperty()
def execute(self, context):
self.props = context.scene.BIMWorkScheduleProperties
self.props.active_sequence_id = self.sequence
while len(self.props.sequence_attributes) > 0:
self.props.sequence_attributes.remove(0)
self.enable_editing_sequence_attributes()
return {'FINISHED'}
def enable_editing_sequence_attributes(self):
data = Data.sequences[self.sequence]
for attribute in IfcStore.get_schema().declaration_by_name("IfcRelSequence").all_attributes():
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
if data_type == "entity":
continue
new = self.props.sequence_attributes.add()
new.name = attribute.name()
new.is_null = data[attribute.name()] is None
new.is_optional = attribute.optional()
new.data_type = data_type
if 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))
if data[attribute.name()]:
new.enum_value = data[attribute.name()]
class EditSequenceAttributes(bpy.types.Operator):
bl_idname = "bim.edit_sequence_attributes"
bl_label = "Edit Work Schedule"
def execute(self, context):
props = context.scene.BIMWorkScheduleProperties
attributes = {}
for attribute in props.sequence_attributes:
if attribute.is_null:
attributes[attribute.name] = None
else:
if attribute.data_type == "string":
attributes[attribute.name] = attribute.string_value
elif attribute.data_type == "enum":
attributes[attribute.name] = attribute.enum_value
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"sequence.edit_sequence",
self.file,
**{"rel_sequence": self.file.by_id(props.active_sequence_id), "attributes": attributes},
)
Data.load(self.file)
bpy.ops.bim.disable_editing_sequence_attributes()
return {"FINISHED"}
class DisableEditingSequenceAttributes(bpy.types.Operator):
bl_idname = "bim.disable_editing_sequence_attributes"
bl_label = "Disable Editing Sequence Attributes"
def execute(self, context):
context.scene.BIMWorkScheduleProperties.active_sequence_id = 0
return {"FINISHED"}
@@ -161,6 +161,8 @@ class BIMWorkScheduleProperties(PropertyGroup):
task_time_attributes: CollectionProperty(name="Task Time Attributes", type=Attribute)
contracted_tasks: StringProperty(name="Contracted Task Items", default="[]")
is_task_update_enabled: BoolProperty(name="Is Task Update Enabled", default=True)
active_sequence_id: IntProperty(name="Active Sequence Id")
sequence_attributes: CollectionProperty(name="Sequence Attributes", type=Attribute)
class BIMTaskTreeProperties(PropertyGroup):
@@ -173,6 +173,33 @@ class BIM_PT_work_schedules(Panel):
row.label(text=task["Name"] or "Unnamed")
row.label(text=sequence["SequenceType"] or "N/A")
if self.props.active_sequence_id == sequence["id"]:
row = self.layout.row()
row.operator("bim.edit_sequence_attributes", text="", icon="CHECKMARK")
row.operator("bim.disable_editing_sequence_attributes", text="", icon="X")
self.draw_editable_sequence_attributes_ui()
else:
row = self.layout.row()
row.operator("bim.enable_editing_sequence_attributes", text="", icon="GREASEPENCIL").sequence = sequence["id"]
def draw_editable_sequence_attributes_ui(self):
for attribute in self.props.sequence_attributes:
row = self.layout.row(align=True)
if attribute.data_type == "string":
row.prop(attribute, "string_value", text=attribute.name)
elif attribute.data_type == "boolean":
row.prop(attribute, "bool_value", text=attribute.name)
elif attribute.data_type == "integer":
row.prop(attribute, "int_value", text=attribute.name)
elif attribute.data_type == "float":
row.prop(attribute, "float_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="")
def draw_editable_task_calendar_ui(self):
task = Data.tasks[self.props.active_task_id]
if task["HasAssignmentsWorkCalendar"]: