Support editing IfcSurfaceStyleLighting in UI

This commit is contained in:
Andrej730
2023-12-13 16:40:50 +05:00
parent f8af28f12a
commit d97ee8eed4
5 changed files with 63 additions and 19 deletions
@@ -43,6 +43,7 @@ classes = (
operator.UpdateCurrentStyle,
operator.UpdateStyleColours,
operator.UpdateStyleTextures,
prop.ColourRgb,
prop.Style,
prop.Texture,
prop.BIMStylesProperties,
@@ -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 {
@@ -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(
@@ -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"
+2
View File
@@ -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):