mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
Fix possibility of adding new invalid surface styles
1) Add default values for new IfcSurfaceStyleLighting so they won't appear invalid. 2) Temporarily disable starting surface style with a texture style since it requires additional texture UI to be exposed or some default texture to be assigned to keep it valid.
This commit is contained in:
@@ -643,32 +643,48 @@ class AddPresentationStyle(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = tool.Style.get_style_props()
|
props = tool.Style.get_style_props()
|
||||||
|
ifc_file = tool.Ifc.get()
|
||||||
if props.style_type == "IfcSurfaceStyle":
|
if props.style_type == "IfcSurfaceStyle":
|
||||||
style = ifcopenshell.api.run("style.add_style", tool.Ifc.get(), name=props.style_name)
|
|
||||||
|
def get_colour_dict(name: Union[str, None], r: float, g: float, b: float) -> dict[str, Any]:
|
||||||
|
return {
|
||||||
|
"Name": name,
|
||||||
|
"Red": r,
|
||||||
|
"Green": g,
|
||||||
|
"Blue": b,
|
||||||
|
}
|
||||||
|
|
||||||
# setup surface style element
|
# setup surface style element
|
||||||
surface_style = None
|
surface_style = None
|
||||||
if props.surface_style_class in ("IfcSurfaceStyleShading", "IfcSurfaceStyleRendering"):
|
if props.surface_style_class in ("IfcSurfaceStyleShading", "IfcSurfaceStyleRendering"):
|
||||||
attributes = {
|
attributes = {
|
||||||
"SurfaceColour": {
|
"SurfaceColour": get_colour_dict(None, *props.surface_colour),
|
||||||
"Name": None,
|
|
||||||
"Red": props.surface_colour[0],
|
|
||||||
"Green": props.surface_colour[1],
|
|
||||||
"Blue": props.surface_colour[2],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if props.surface_style_class == "IfcSurfaceStyleRendering":
|
if props.surface_style_class == "IfcSurfaceStyleRendering":
|
||||||
attributes["ReflectanceMethod"] = "NOTDEFINED"
|
attributes["ReflectanceMethod"] = "NOTDEFINED"
|
||||||
|
elif props.surface_style_class == "IfcSurfaceStyleLighting":
|
||||||
|
# Requires all those colors to be valid style.
|
||||||
|
attributes = {
|
||||||
|
"DiffuseTransmissionColour": get_colour_dict(None, 0.0, 0.0, 0.0),
|
||||||
|
"DiffuseReflectionColour": get_colour_dict(None, 0.0, 0.0, 0.0),
|
||||||
|
"TransmissionColour": get_colour_dict(None, 0.0, 0.0, 0.0),
|
||||||
|
"ReflectanceColour": get_colour_dict(None, 0.0, 0.0, 0.0),
|
||||||
|
}
|
||||||
|
elif props.surface_style_class == "IfcSurfaceStyleWithTextures":
|
||||||
|
# TODO: Requires textures to be valid.
|
||||||
|
self.report(
|
||||||
|
{"ERROR"},
|
||||||
|
"Adding IfcSurfaceStyleWithTextures directly is not supported yet."
|
||||||
|
"You can create Rendering style and then add Texture style to it.",
|
||||||
|
)
|
||||||
|
return {"CANCELLED"}
|
||||||
else:
|
else:
|
||||||
# NOTE: for all other styles we produce just empty styles.
|
# The rest of styles are valid even without any attributes assigned.
|
||||||
# In the future we might need to expose to adding presentation style UI
|
|
||||||
# LightingStyle colors and TextureStyle textures UI
|
|
||||||
# as they are required for those surface styles to keep IFC valid
|
|
||||||
attributes = {}
|
attributes = {}
|
||||||
|
|
||||||
surface_style = ifcopenshell.api.run(
|
style = ifcopenshell.api.style.add_style(ifc_file, name=props.style_name)
|
||||||
"style.add_surface_style",
|
surface_style = ifcopenshell.api.style.add_surface_style(
|
||||||
tool.Ifc.get(),
|
ifc_file,
|
||||||
style=style,
|
style=style,
|
||||||
ifc_class=props.surface_style_class,
|
ifc_class=props.surface_style_class,
|
||||||
attributes=attributes,
|
attributes=attributes,
|
||||||
|
|||||||
@@ -22,11 +22,12 @@ from typing import Any, Optional, Literal
|
|||||||
|
|
||||||
|
|
||||||
SURFACE_STYLE_TYPES = Literal[
|
SURFACE_STYLE_TYPES = Literal[
|
||||||
"IfcExternallyDefinedSurfaceStyle",
|
"IfcSurfaceStyleShading",
|
||||||
|
"IfcSurfaceStyleRendering",
|
||||||
|
"IfcSurfaceStyleWithTextures",
|
||||||
"IfcSurfaceStyleLighting",
|
"IfcSurfaceStyleLighting",
|
||||||
"IfcSurfaceStyleRefraction",
|
"IfcSurfaceStyleRefraction",
|
||||||
"IfcSurfaceStyleShading",
|
"IfcExternallyDefinedSurfaceStyle",
|
||||||
"IfcSurfaceStyleWithTextures",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user