From 3e0adb8dfd59d39b05541ff7f28191cfb3ac6954 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 19 Jun 2023 10:57:11 +0500 Subject: [PATCH] Added button to update current style #3293 Example - https://i.imgur.com/f4Yi3MR.png Now changing style type should be a bit more intuitive - previously there were no button and it wasn't possible to change style type for all selected objects / changing style type for the entire scene were hidden in N-panel Miscellaneous section. Now it also able to change style type for all blender materials, even the ones that don't have any objects using them (wasn't possible before 7c0c934b4) --- .../blenderbim/bim/module/misc/ui.py | 2 - .../blenderbim/bim/module/style/__init__.py | 1 + .../blenderbim/bim/module/style/operator.py | 47 +++++++++++++++++++ .../blenderbim/bim/module/style/prop.py | 11 ++--- .../blenderbim/bim/module/style/ui.py | 1 + 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/misc/ui.py b/src/blenderbim/blenderbim/bim/module/misc/ui.py index 910f4a003d..9fe4e178cc 100644 --- a/src/blenderbim/blenderbim/bim/module/misc/ui.py +++ b/src/blenderbim/blenderbim/bim/module/misc/ui.py @@ -30,8 +30,6 @@ class BIM_PT_misc_utilities(bpy.types.Panel): def draw(self, context): layout = self.layout props = context.scene.BIMMiscProperties - row = layout.row() - row.prop(context.scene.BIMStylesProperties, "active_style_type", icon="SHADING_RENDERED", text="") row = layout.split(factor=0.2, align=True) row.prop(props, "override_colour", text="") row.operator("bim.set_override_colour") diff --git a/src/blenderbim/blenderbim/bim/module/style/__init__.py b/src/blenderbim/blenderbim/bim/module/style/__init__.py index c831f47d57..0d9c3901be 100644 --- a/src/blenderbim/blenderbim/bim/module/style/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/style/__init__.py @@ -24,6 +24,7 @@ classes = ( operator.EnableEditingStyle, operator.DisableEditingStyle, operator.EditStyle, + operator.UpdateCurrentStyle, operator.EnableEditingExternalStyle, operator.DisableEditingExternalStyle, operator.EditExternalStyle, diff --git a/src/blenderbim/blenderbim/bim/module/style/operator.py b/src/blenderbim/blenderbim/bim/module/style/operator.py index 9dd0401c7c..dad1c65319 100644 --- a/src/blenderbim/blenderbim/bim/module/style/operator.py +++ b/src/blenderbim/blenderbim/bim/module/style/operator.py @@ -107,6 +107,53 @@ class EditStyle(bpy.types.Operator, tool.Ifc.Operator): core.edit_style(tool.Ifc, tool.Style, obj=context.active_object.active_material) +class UpdateCurrentStyle(bpy.types.Operator): + bl_idname = "bim.update_current_style" + bl_label = "Update Current Style" + bl_description = ( + "Update style for all selected objects according to current style type\n(Shading/External).\n\n" + + "SHIFT+CLICK to update ALL styles in the .ifc file to current style type" + ) + bl_options = {"REGISTER", "UNDO"} + update_all: bpy.props.BoolProperty(name="Update All", default=False) + + @classmethod + def poll(cls, context): + poll = ( + context.active_object is not None + and context.active_object.active_material is not None + and context.active_object.active_material.BIMMaterialProperties.ifc_style_id != 0 + ) + if not poll: + cls.poll_message_set( + "Object is not selected or material is not assigned or material doesn't have IFC Style" + ) + return poll + + def invoke(self, context, event): + # updating all styles on shift+click + if event.type == "LEFTMOUSE" and event.shift: + self.update_all = True + else: + # can't rely on default value since the line above + # will set the value to `True` for all future operator calls + self.update_all = False + return self.execute(context) + + def execute(self, context): + current_style_type = context.active_object.active_material.BIMStyleProperties.active_style_type + if self.update_all: + context.scene.BIMStylesProperties.active_style_type = current_style_type + return {"FINISHED"} + + materials = [] + for obj in context.selected_objects: + mat = obj.active_material + if mat and mat.BIMMaterialProperties.ifc_style_id != 0: + mat.BIMStyleProperties.active_style_type = current_style_type + return {"FINISHED"} + + class BrowseExternalStyle(bpy.types.Operator): bl_idname = "bim.browse_external_style" bl_label = "Browse External Style" diff --git a/src/blenderbim/blenderbim/bim/module/style/prop.py b/src/blenderbim/blenderbim/bim/module/style/prop.py index 266a2d56d8..1b2a9035be 100644 --- a/src/blenderbim/blenderbim/bim/module/style/prop.py +++ b/src/blenderbim/blenderbim/bim/module/style/prop.py @@ -53,14 +53,9 @@ STYLE_TYPES = [ def update_shading_styles(self, context): - materials_to_objects = dict() - - for obj in bpy.data.objects: - blender_material = obj.active_material - if blender_material and blender_material.BIMMaterialProperties.ifc_style_id != 0: - materials_to_objects[blender_material] = obj - - for mat, obj in materials_to_objects.items(): + for mat in bpy.data.materials: + if mat.BIMMaterialProperties.ifc_style_id == 0: + continue tool.Style.change_current_style_type(mat, self.active_style_type) diff --git a/src/blenderbim/blenderbim/bim/module/style/ui.py b/src/blenderbim/blenderbim/bim/module/style/ui.py index 0d2fcdeba7..33a75aa778 100644 --- a/src/blenderbim/blenderbim/bim/module/style/ui.py +++ b/src/blenderbim/blenderbim/bim/module/style/ui.py @@ -90,6 +90,7 @@ class BIM_PT_style(MaterialButtonsPanel, Panel): return row.prop(style_props, "active_style_type", icon="SHADING_RENDERED", text="") + row.operator("bim.update_current_style", icon="FILE_REFRESH", text="") row = self.layout.row(align=True) row.operator("bim.update_style_colours", icon="GREASEPENCIL") row.operator("bim.update_style_textures", icon="TEXTURE", text="")