mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
Fix invalid ifc saving texture style without any textures / option to remove surface style
Now it won't allow saving texture style without textures and there is a button to remove part of surface style.
This commit is contained in:
@@ -39,6 +39,7 @@ classes = (
|
||||
operator.EnableEditingSurfaceStyle,
|
||||
operator.LoadStyles,
|
||||
operator.RemoveStyle,
|
||||
operator.RemoveSurfaceStyle,
|
||||
operator.SaveUVToStyle,
|
||||
operator.SelectByStyle,
|
||||
operator.SelectStyleInStylesUI,
|
||||
|
||||
@@ -695,6 +695,7 @@ class EnableEditingSurfaceStyle(bpy.types.Operator):
|
||||
|
||||
props.is_editing_style = self.style
|
||||
props.is_editing_class = self.ifc_class
|
||||
props.is_editing_existing_style = self.ifc_class in style_elements
|
||||
tool.Style.set_surface_style_props()
|
||||
|
||||
surface_style = style_elements.get(self.ifc_class, None)
|
||||
@@ -788,7 +789,11 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator):
|
||||
elif self.props.is_editing_class == "IfcSurfaceStyleWithTextures":
|
||||
# TODO: fix same issues as with creating new IfcSurfaceStyleWithTextures
|
||||
material = tool.Ifc.get_object(self.style)
|
||||
textures = tool.Ifc.run("style.add_surface_textures", textures=self.get_texture_attributes(), uv_maps=[])
|
||||
textures = self.get_texture_attributes()
|
||||
if not textures:
|
||||
self.report({"ERROR"}, "Cannot save texture style without any textures.")
|
||||
return {"CANCELLED"}
|
||||
textures = tool.Ifc.run("style.add_surface_textures", textures=textures, uv_maps=[])
|
||||
texture_style = tool.Ifc.run(
|
||||
"style.add_surface_style",
|
||||
style=self.style,
|
||||
@@ -1151,3 +1156,19 @@ class SelectStyleInStylesUI(bpy.types.Operator):
|
||||
f"Style '{style.Name or 'Unnamed'}' is selected in Styles UI.",
|
||||
)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class RemoveSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.remove_surface_style"
|
||||
bl_label = "Remove Surface Style"
|
||||
bl_description = "Remove the currently edited surface style from the active style"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def _execute(self, context):
|
||||
ifc_file = tool.Ifc.get()
|
||||
props = context.scene.BIMStylesProperties
|
||||
style = ifc_file.by_id(props.is_editing_style)
|
||||
surface_style = tool.Style.get_style_elements(style)[props.is_editing_class]
|
||||
ifcopenshell.api.style.remove_surface_style(ifc_file, surface_style)
|
||||
core.disable_editing_style(tool.Style)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -155,10 +155,14 @@ class ColourRgb(PropertyGroup):
|
||||
|
||||
|
||||
class BIMStylesProperties(PropertyGroup):
|
||||
is_adding: BoolProperty(name="Is Adding")
|
||||
is_editing: BoolProperty(name="Is Editing")
|
||||
is_editing_style: IntProperty(name="Is Editing Style")
|
||||
is_editing_class: StringProperty(name="Is Editing Class")
|
||||
is_adding: BoolProperty(name="Is Adding", description="Is adding new IfcPresentationStyle")
|
||||
is_editing: BoolProperty(name="Is Editing", description="Is editing IfcPresentationStyle")
|
||||
is_editing_style: IntProperty(name="Is Editing Style", description="Is editing new presentation item surface style")
|
||||
is_editing_class: StringProperty(
|
||||
name="Is Editing Class",
|
||||
description="Presentation item surface style class currently edited",
|
||||
)
|
||||
is_editing_existing_style: BoolProperty(name="Is Editing Existing", description="Is editing existing surface style")
|
||||
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)
|
||||
|
||||
@@ -130,30 +130,32 @@ class BIM_PT_styles(Panel):
|
||||
if self.props.is_editing_style:
|
||||
if self.props.is_editing_class == "IfcSurfaceStyle":
|
||||
bonsai.bim.helper.draw_attributes(self.props.attributes, self.layout)
|
||||
row = self.layout.row(align=True)
|
||||
row.operator("bim.edit_style", text="Save Attributes", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_style", text="", icon="CANCEL")
|
||||
edit_label = "Save Attributes"
|
||||
elif self.props.is_editing_class == "IfcSurfaceStyleShading":
|
||||
self.draw_surface_style_shading()
|
||||
edit_label = "Save Shading Style"
|
||||
elif self.props.is_editing_class == "IfcSurfaceStyleRendering":
|
||||
self.draw_surface_style_rendering()
|
||||
edit_label = "Save Rendering Style"
|
||||
elif self.props.is_editing_class == "IfcExternallyDefinedSurfaceStyle":
|
||||
self.draw_externally_defined_surface_style()
|
||||
edit_label = "Save External Style"
|
||||
elif self.props.is_editing_class == "IfcSurfaceStyleWithTextures":
|
||||
self.draw_surface_style_with_textures()
|
||||
edit_label = "Save Texture Style"
|
||||
elif self.props.is_editing_class == "IfcSurfaceStyleRefraction":
|
||||
self.draw_refraction_surface_style()
|
||||
edit_label = "Save Refaction Style"
|
||||
else: # IfcSurfaceStyleLighting
|
||||
self.draw_lighting_surface_style()
|
||||
edit_label = "Save Lighting Style"
|
||||
self.draw_edit_ui(edit_label)
|
||||
|
||||
def draw_surface_style_shading(self):
|
||||
row = self.layout.row()
|
||||
row.prop(self.props, "surface_colour")
|
||||
row = self.layout.row()
|
||||
row.prop(self.props, "transparency")
|
||||
row = self.layout.row(align=True)
|
||||
row.operator("bim.edit_surface_style", text="Save Shading Style", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_style", text="", icon="CANCEL")
|
||||
|
||||
def draw_surface_style_rendering(self):
|
||||
row = self.layout.row()
|
||||
@@ -213,10 +215,6 @@ class BIM_PT_styles(Panel):
|
||||
icon="RADIOBUT_OFF" if self.props.is_specular_highlight_null else "RADIOBUT_ON",
|
||||
)
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
row.operator("bim.edit_surface_style", text="Save Rendering Style", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_style", text="", icon="CANCEL")
|
||||
|
||||
def draw_surface_style_with_textures(self):
|
||||
textures = self.props.textures
|
||||
row = self.layout.row(align=True)
|
||||
@@ -235,30 +233,25 @@ class BIM_PT_styles(Panel):
|
||||
op_clear = row.operator("bim.remove_texture_map", text="", icon="X")
|
||||
op_path.texture_map_index = op_clear.texture_map_index = i
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
row.operator("bim.edit_surface_style", text="Save Texture Style", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_style", text="", icon="CANCEL")
|
||||
|
||||
def draw_externally_defined_surface_style(self):
|
||||
row = self.layout.row()
|
||||
op = row.operator("bim.browse_external_style", icon="APPEND_BLEND", text="Append From Blend File")
|
||||
style = self.props.styles[self.props.active_style_index]
|
||||
op.active_surface_style_id = style.ifc_definition_id
|
||||
bonsai.bim.helper.draw_attributes(self.props.external_style_attributes, self.layout)
|
||||
row = self.layout.row(align=True)
|
||||
row.operator("bim.edit_surface_style", text="Save External Style", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_style", text="", icon="CANCEL")
|
||||
|
||||
def draw_refraction_surface_style(self):
|
||||
bonsai.bim.helper.draw_attributes(self.props.refraction_style_attributes, self.layout)
|
||||
row = self.layout.row(align=True)
|
||||
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):
|
||||
bonsai.bim.helper.draw_attributes(self.props.lighting_style_colours, self.layout)
|
||||
|
||||
def draw_edit_ui(self, edit_label: str):
|
||||
row = self.layout.row(align=True)
|
||||
row.operator("bim.edit_surface_style", text="Save Lighting Style", icon="CHECKMARK")
|
||||
row.operator("bim.edit_surface_style", text=edit_label, icon="CHECKMARK")
|
||||
if self.props.is_editing_existing_style:
|
||||
row.operator("bim.remove_surface_style", text="", icon="X")
|
||||
row.operator("bim.disable_editing_style", text="", icon="CANCEL")
|
||||
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ class Style(bonsai.core.tool.Style):
|
||||
def disable_editing(cls) -> None:
|
||||
props = bpy.context.scene.BIMStylesProperties
|
||||
props.is_editing_style = 0
|
||||
props.is_editing_class = ""
|
||||
props.attributes.clear()
|
||||
props.external_style_attributes.clear()
|
||||
props.refraction_style_attributes.clear()
|
||||
|
||||
Reference in New Issue
Block a user