From d97ee8eed4f9a1e4ab8f5ca38a99a5202db3630f Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 13 Dec 2023 16:40:50 +0500 Subject: [PATCH] Support editing IfcSurfaceStyleLighting in UI --- .../blenderbim/bim/module/style/__init__.py | 1 + .../blenderbim/bim/module/style/operator.py | 44 ++++++++++++------- .../blenderbim/bim/module/style/prop.py | 24 ++++++++++ .../blenderbim/bim/module/style/ui.py | 11 +++-- src/blenderbim/blenderbim/tool/style.py | 2 + 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/style/__init__.py b/src/blenderbim/blenderbim/bim/module/style/__init__.py index 6e02e61de1..7871feabac 100644 --- a/src/blenderbim/blenderbim/bim/module/style/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/style/__init__.py @@ -43,6 +43,7 @@ classes = ( operator.UpdateCurrentStyle, operator.UpdateStyleColours, operator.UpdateStyleTextures, + prop.ColourRgb, prop.Style, prop.Texture, prop.BIMStylesProperties, diff --git a/src/blenderbim/blenderbim/bim/module/style/operator.py b/src/blenderbim/blenderbim/bim/module/style/operator.py index ed684424dc..7e5117860b 100644 --- a/src/blenderbim/blenderbim/bim/module/style/operator.py +++ b/src/blenderbim/blenderbim/bim/module/style/operator.py @@ -506,9 +506,23 @@ class EnableEditingSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator): surface_style = tool.Style.get_style_elements(style).get(self.ifc_class, None) attributes = tool.Style.get_style_ui_props_attributes(self.ifc_class) + + # lighting style require special handling since Attribute doesn't support colors + callback = None + if self.ifc_class == "IfcSurfaceStyleLighting": + + def callback(attribute_name, _, data): + color = attributes.add() + color.name = attribute_name + color_value = data[attribute_name] + if color_value is None: + return + color.color_name = color_value.Name or "" + color.color_value = (color_value.Red, color_value.Green, color_value.Blue) + if attributes is not None: attributes.clear() - blenderbim.bim.helper.import_attributes2(surface_style or self.ifc_class, attributes) + blenderbim.bim.helper.import_attributes2(surface_style or self.ifc_class, attributes, callback) class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator): @@ -576,13 +590,12 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator): tool.Loader.create_surface_style_with_textures(material, shading_style, texture_style) else: attributes = tool.Style.get_style_ui_props_attributes(self.surface_style.is_a()) - if attributes is not None: - ifcopenshell.api.run( - "style.edit_surface_style", - tool.Ifc.get(), - style=self.surface_style, - attributes=blenderbim.bim.helper.export_attributes(attributes), - ) + ifcopenshell.api.run( + "style.edit_surface_style", + tool.Ifc.get(), + style=self.surface_style, + attributes=blenderbim.bim.helper.export_attributes(attributes), + ) def add_new_style(self): material = tool.Ifc.get_object(self.style) @@ -627,14 +640,13 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator): tool.Loader.create_surface_style_with_textures(material, shading_style, texture_style) else: attributes = tool.Style.get_style_ui_props_attributes(self.props.is_editing_class) - if attributes is not None: - surface_style = ifcopenshell.api.run( - "style.add_surface_style", - tool.Ifc.get(), - style=self.style, - ifc_class=self.props.is_editing_class, - attributes=blenderbim.bim.helper.export_attributes(attributes), - ) + surface_style = ifcopenshell.api.run( + "style.add_surface_style", + tool.Ifc.get(), + style=self.style, + ifc_class=self.props.is_editing_class, + attributes=blenderbim.bim.helper.export_attributes(attributes), + ) def get_shading_attributes(self): return { diff --git a/src/blenderbim/blenderbim/bim/module/style/prop.py b/src/blenderbim/blenderbim/bim/module/style/prop.py index ffef612554..da450a5aee 100644 --- a/src/blenderbim/blenderbim/bim/module/style/prop.py +++ b/src/blenderbim/blenderbim/bim/module/style/prop.py @@ -112,6 +112,29 @@ class Texture(PropertyGroup): path: StringProperty(name="Texture Path", update=update_shader_graph) +class ColourRgb(PropertyGroup): + name: StringProperty() + color_value: FloatVectorProperty(size=3, subtype="COLOR", default=(1, 1, 1)) + # not exposed in the UI, here just to preserve the data + color_name: StringProperty("Color Name") + + # to fit blender.bim.helper.export_attributes + def get_value(self): + return { + "Name": self.color_name or None, + "Red": self.color_value[0], + "Green": self.color_value[1], + "Blue": self.color_value[2], + } + + # to fit blender.bim.helper.draw_attribute + is_uri = False + is_optional = False + + def get_value_name(self): + return "color_value" + + class BIMStylesProperties(PropertyGroup): is_adding: BoolProperty(name="Is Adding") is_editing: BoolProperty(name="Is Editing") @@ -120,6 +143,7 @@ class BIMStylesProperties(PropertyGroup): attributes: CollectionProperty(name="Attributes", type=Attribute) external_style_attributes: CollectionProperty(name="External Style Attributes", type=Attribute) refraction_style_attributes: CollectionProperty(name="Refraction Style Attributes", type=Attribute) + lighting_style_colours: CollectionProperty(name="Lighting Style Colours", type=ColourRgb) style_type: EnumProperty(items=get_style_types, default=2, name="Style Type") style_name: StringProperty(name="Style Name") surface_style_class: EnumProperty( diff --git a/src/blenderbim/blenderbim/bim/module/style/ui.py b/src/blenderbim/blenderbim/bim/module/style/ui.py index 2ba47aac7e..6b7d57efc9 100644 --- a/src/blenderbim/blenderbim/bim/module/style/ui.py +++ b/src/blenderbim/blenderbim/bim/module/style/ui.py @@ -136,9 +136,8 @@ class BIM_PT_styles(Panel): self.draw_surface_style_with_textures() elif self.props.is_editing_class == "IfcSurfaceStyleRefraction": self.draw_refraction_surface_style() - else: - # TODO: UI Lighting - self.layout.label(text=f"{self.props.is_editing_class} UI is not yet supported.") + else: # IfcSurfaceStyleLighting + self.draw_lighting_surface_style() def draw_surface_style_shading(self): row = self.layout.row() @@ -246,6 +245,12 @@ class BIM_PT_styles(Panel): row.operator("bim.edit_surface_style", text="Save Refraction Style", icon="CHECKMARK") row.operator("bim.disable_editing_style", text="", icon="CANCEL") + def draw_lighting_surface_style(self): + blenderbim.bim.helper.draw_attributes(self.props.lighting_style_colours, self.layout) + row = self.layout.row(align=True) + row.operator("bim.edit_surface_style", text="Save Lighting Style", icon="CHECKMARK") + row.operator("bim.disable_editing_style", text="", icon="CANCEL") + class BIM_PT_style(MaterialButtonsPanel, Panel): bl_label = "Style" diff --git a/src/blenderbim/blenderbim/tool/style.py b/src/blenderbim/blenderbim/tool/style.py index b812591291..3299dafebe 100644 --- a/src/blenderbim/blenderbim/tool/style.py +++ b/src/blenderbim/blenderbim/tool/style.py @@ -460,6 +460,8 @@ class Style(blenderbim.core.tool.Style): return props.external_style_attributes elif style_type == "IfcSurfaceStyleRefraction": return props.refraction_style_attributes + elif style_type == "IfcSurfaceStyleLighting": + return props.lighting_style_colours @classmethod def import_presentation_styles(cls, style_type):