From d73a5c46eac1b9db5bd5e80a3b6d78eb9738cedc Mon Sep 17 00:00:00 2001 From: bosonprojets Date: Sat, 1 May 2021 21:45:27 +0000 Subject: [PATCH] Add support for editing sequence relationship attributes in blenderBIM --- .../bim/module/sequence/__init__.py | 3 + .../bim/module/sequence/operator.py | 66 +++++++++++++++++++ .../blenderbim/bim/module/sequence/prop.py | 2 + .../blenderbim/bim/module/sequence/ui.py | 27 ++++++++ 4 files changed, 98 insertions(+) diff --git a/src/blenderbim/blenderbim/bim/module/sequence/__init__.py b/src/blenderbim/blenderbim/bim/module/sequence/__init__.py index 96b96c9f9b..d1e8ffaf88 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/__init__.py @@ -16,6 +16,9 @@ classes = ( operator.EnableEditingWorkSchedule, operator.EnableEditingTasks, operator.DisableEditingWorkSchedule, + operator.DisableEditingSequenceAttributes, + operator.EditSequenceAttributes, + operator.EnableEditingSequenceAttributes, operator.AddWorkCalendar, operator.EditWorkCalendar, operator.EditWorkTime, diff --git a/src/blenderbim/blenderbim/bim/module/sequence/operator.py b/src/blenderbim/blenderbim/bim/module/sequence/operator.py index d40519edeb..353277af33 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/operator.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/operator.py @@ -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"} diff --git a/src/blenderbim/blenderbim/bim/module/sequence/prop.py b/src/blenderbim/blenderbim/bim/module/sequence/prop.py index 2f83dedb8d..bcfe67a8e1 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/prop.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/prop.py @@ -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): diff --git a/src/blenderbim/blenderbim/bim/module/sequence/ui.py b/src/blenderbim/blenderbim/bim/module/sequence/ui.py index 36875cdfe6..482a924b7b 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/ui.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/ui.py @@ -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"]: