From 9122f006c7056d802f5a0230427dcfba51b15fe0 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 20 May 2024 23:21:13 +1000 Subject: [PATCH] Deprecate material attributes panel in favour of new material manager. --- .../bim/module/attribute/__init__.py | 3 -- .../blenderbim/bim/module/attribute/data.py | 26 ------------- .../bim/module/attribute/operator.py | 20 ++-------- .../blenderbim/bim/module/attribute/ui.py | 39 ++----------------- src/blenderbim/blenderbim/core/material.py | 1 + src/blenderbim/blenderbim/core/tool.py | 5 ++- src/blenderbim/blenderbim/tool/material.py | 13 +++++++ 7 files changed, 25 insertions(+), 82 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/attribute/__init__.py b/src/blenderbim/blenderbim/bim/module/attribute/__init__.py index 33dc7a9304..cfe35505b5 100644 --- a/src/blenderbim/blenderbim/bim/module/attribute/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/attribute/__init__.py @@ -27,15 +27,12 @@ classes = ( operator.CopyAttributeToSelection, prop.BIMAttributeProperties, ui.BIM_PT_object_attributes, - ui.BIM_PT_material_attributes, ) def register(): bpy.types.Object.BIMAttributeProperties = bpy.props.PointerProperty(type=prop.BIMAttributeProperties) - bpy.types.Material.BIMAttributeProperties = bpy.props.PointerProperty(type=prop.BIMAttributeProperties) def unregister(): del bpy.types.Object.BIMAttributeProperties - del bpy.types.Material.BIMAttributeProperties diff --git a/src/blenderbim/blenderbim/bim/module/attribute/data.py b/src/blenderbim/blenderbim/bim/module/attribute/data.py index c3f3dc814d..955a4f8927 100644 --- a/src/blenderbim/blenderbim/bim/module/attribute/data.py +++ b/src/blenderbim/blenderbim/bim/module/attribute/data.py @@ -23,7 +23,6 @@ import blenderbim.tool as tool def refresh(): AttributesData.is_loaded = False - MaterialAttributesData.is_loaded = False class AttributesData: @@ -51,28 +50,3 @@ class AttributesData: key = "STEP ID" results.append({"name": key, "value": str(value)}) return results - - -class MaterialAttributesData: - data = {} - is_loaded = False - - @classmethod - def load(cls): - cls.data = {"ifc_definition_id": cls.ifc_definition_id(), "attributes": cls.attributes()} - cls.is_loaded = True - - @classmethod - def ifc_definition_id(cls): - return bpy.context.active_object.active_material.BIMObjectProperties.ifc_definition_id - - @classmethod - def attributes(cls): - results = [] - element = tool.Ifc.get_entity(bpy.context.active_object.active_material) - data = element.get_info() - for key, value in data.items(): - if value is None or isinstance(value, ifcopenshell.entity_instance) or key in ["id", "type"]: - continue - results.append({"name": key, "value": str(value)}) - return results diff --git a/src/blenderbim/blenderbim/bim/module/attribute/operator.py b/src/blenderbim/blenderbim/bim/module/attribute/operator.py index 21a81526ce..613cd72f80 100644 --- a/src/blenderbim/blenderbim/bim/module/attribute/operator.py +++ b/src/blenderbim/blenderbim/bim/module/attribute/operator.py @@ -40,14 +40,10 @@ class EnableEditingAttributes(bpy.types.Operator): bl_label = "Enable Editing Attributes" bl_options = {"REGISTER", "UNDO"} obj: bpy.props.StringProperty() - obj_type: bpy.props.StringProperty() def execute(self, context): self.file = IfcStore.get_file() - if self.obj_type == "Object": - obj = bpy.data.objects.get(self.obj) - elif self.obj_type == "Material": - obj = bpy.data.materials.get(self.obj) + obj = bpy.data.objects.get(self.obj) props = obj.BIMAttributeProperties props.attributes.clear() @@ -85,13 +81,9 @@ class DisableEditingAttributes(bpy.types.Operator): bl_label = "Disable Editing Attributes" bl_options = {"REGISTER", "UNDO"} obj: bpy.props.StringProperty() - obj_type: bpy.props.StringProperty() def execute(self, context): - if self.obj_type == "Object": - obj = bpy.data.objects.get(self.obj) - elif self.obj_type == "Material": - obj = bpy.data.materials.get(self.obj) + obj = bpy.data.objects.get(self.obj) props = obj.BIMAttributeProperties props.is_editing_attributes = False return {"FINISHED"} @@ -102,14 +94,10 @@ class EditAttributes(bpy.types.Operator, Operator): bl_label = "Edit Attributes" bl_options = {"REGISTER", "UNDO"} obj: bpy.props.StringProperty() - obj_type: bpy.props.StringProperty() def _execute(self, context): self.file = IfcStore.get_file() - if self.obj_type == "Object": - obj = bpy.data.objects.get(self.obj) - elif self.obj_type == "Material": - obj = bpy.data.materials.get(self.obj) + obj = bpy.data.objects.get(self.obj) props = obj.BIMAttributeProperties product = tool.Ifc.get_entity(obj) @@ -126,7 +114,7 @@ class EditAttributes(bpy.types.Operator, Operator): attributes = blenderbim.bim.helper.export_attributes(props.attributes, callback=callback) ifcopenshell.api.run("attribute.edit_attributes", self.file, product=product, attributes=attributes) - bpy.ops.bim.disable_editing_attributes(obj=obj.name, obj_type=self.obj_type) + bpy.ops.bim.disable_editing_attributes(obj=obj.name) return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/attribute/ui.py b/src/blenderbim/blenderbim/bim/module/attribute/ui.py index 7ffd360c19..e1948dcc2b 100644 --- a/src/blenderbim/blenderbim/bim/module/attribute/ui.py +++ b/src/blenderbim/blenderbim/bim/module/attribute/ui.py @@ -19,28 +19,25 @@ import blenderbim.bim.helper from bpy.types import Panel from blenderbim.bim.ifc import IfcStore -from blenderbim.bim.module.attribute.data import AttributesData, MaterialAttributesData +from blenderbim.bim.module.attribute.data import AttributesData -def draw_ui(context, layout, obj_type, attributes): - obj = context.active_object if obj_type == "Object" else context.active_object.active_material +def draw_ui(context, layout, attributes): + obj = context.active_object oprops = obj.BIMObjectProperties props = obj.BIMAttributeProperties if props.is_editing_attributes: row = layout.row(align=True) op = row.operator("bim.edit_attributes", icon="CHECKMARK", text="Save Attributes") - op.obj_type = obj_type op.obj = obj.name op = row.operator("bim.disable_editing_attributes", icon="CANCEL", text="") - op.obj_type = obj_type op.obj = obj.name blenderbim.bim.helper.draw_attributes(props.attributes, layout, copy_operator="bim.copy_attribute_to_selection") else: row = layout.row() op = row.operator("bim.enable_editing_attributes", icon="GREASEPENCIL", text="Edit") - op.obj_type = obj_type op.obj = obj.name for attribute in attributes: @@ -72,32 +69,4 @@ class BIM_PT_object_attributes(Panel): def draw(self, context): if not AttributesData.is_loaded: AttributesData.load() - draw_ui(context, self.layout, "Object", AttributesData.data["attributes"]) - - -class BIM_PT_material_attributes(Panel): - bl_label = "Material Attributes" - bl_idname = "BIM_PT_material_attributes" - bl_space_type = "PROPERTIES" - bl_region_type = "WINDOW" - bl_context = "material" - - @classmethod - def poll(cls, context): - if not IfcStore.get_file(): - return False - try: - return bool(context.active_object.active_material.BIMObjectProperties.ifc_definition_id) - except: - return False - - def draw(self, context): - if not MaterialAttributesData.is_loaded: - MaterialAttributesData.load() - elif ( - context.active_object.active_material.BIMObjectProperties.ifc_definition_id - != MaterialAttributesData.data["ifc_definition_id"] - ): - MaterialAttributesData.load() - - draw_ui(context, self.layout, "Material", MaterialAttributesData.data["attributes"]) + draw_ui(context, self.layout, AttributesData.data["attributes"]) diff --git a/src/blenderbim/blenderbim/core/material.py b/src/blenderbim/blenderbim/core/material.py index da265b2a7c..87a3ae9e0a 100644 --- a/src/blenderbim/blenderbim/core/material.py +++ b/src/blenderbim/blenderbim/core/material.py @@ -85,6 +85,7 @@ def enable_editing_material(material_tool, material): def edit_material(ifc, material_tool, material): attributes = material_tool.get_material_attributes() ifc.run("material.edit_material", material=material, attributes=attributes) + material_tool.sync_blender_material_name(material) material_tool.disable_editing_material() material_type = material_tool.get_active_material_type() material_tool.import_material_definitions(material_type) diff --git a/src/blenderbim/blenderbim/core/tool.py b/src/blenderbim/blenderbim/core/tool.py index 186ca93001..ec5a7550c3 100644 --- a/src/blenderbim/blenderbim/core/tool.py +++ b/src/blenderbim/blenderbim/core/tool.py @@ -487,12 +487,12 @@ class Material: def disable_editing_materials(cls): pass def enable_editing_material(cls, material): pass def enable_editing_materials(cls): pass - def get_active_material_type(cls): pass def get_active_material(cls): pass + def get_active_material_type(cls): pass def get_active_object_material(cls, obj): pass def get_elements_by_material(cls, material): pass - def get_material_attributes(cls): pass def get_material(cls, element, should_inherit): pass + def get_material_attributes(cls): pass def get_name(cls, obj): pass def get_type(cls, element): pass def has_material_profile(cls, element): pass @@ -503,6 +503,7 @@ class Material: def is_material_used_in_sets(cls, material): pass def load_material_attributes(cls, material): pass def replace_material_with_material_profile(cls, element): pass + def sync_blender_material_name(cls, material): pass @interface diff --git a/src/blenderbim/blenderbim/tool/material.py b/src/blenderbim/blenderbim/tool/material.py index e49b6a3d61..03a7cf940d 100644 --- a/src/blenderbim/blenderbim/tool/material.py +++ b/src/blenderbim/blenderbim/tool/material.py @@ -242,3 +242,16 @@ class Material(blenderbim.core.tool.Material): meshes_to_objects[mesh] = obj for obj in meshes_to_objects.values(): tool.Geometry.reload_representation(obj) + + @classmethod + def sync_blender_material_name(cls, material): + name = material.Name or "Unnamed" + obj = tool.Ifc.get_object(material) + if obj: + obj.name = name + style = tool.Style.get_style(obj) + if style: + style.Name = name + obj = tool.Ifc.get_object(style) + if obj: + obj.name = name