mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Prioritise editing rendering surface styles over shading surface styles
This commit is contained in:
@@ -1,43 +1,10 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, **settings):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"name": "Name",
|
||||
"surface_colour": [], # RGB
|
||||
"diffuse_colour": [], # RGB
|
||||
"transparency": 0,
|
||||
"external_definition": {"location": None, "identification": None, "name": "Name"},
|
||||
}
|
||||
self.settings = {"name": None}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
styles = [self.create_surface_style_rendering()]
|
||||
if self.settings["external_definition"]:
|
||||
styles.append(self.create_externally_defined_surface_style())
|
||||
# Name is filled out because Revit treats this incorrectly as the material name
|
||||
return self.file.createIfcSurfaceStyle(self.settings["name"], "BOTH", styles)
|
||||
|
||||
def create_surface_style_rendering(self):
|
||||
return self.file.create_entity(
|
||||
"IfcSurfaceStyleRendering",
|
||||
**{
|
||||
"SurfaceColour": self.create_colour_rgb(self.settings["surface_colour"]),
|
||||
"Transparency": self.settings["transparency"],
|
||||
"ReflectanceMethod": "NOTDEFINED",
|
||||
"DiffuseColour": self.create_colour_rgb(self.settings["diffuse_colour"]),
|
||||
}
|
||||
)
|
||||
|
||||
def create_externally_defined_surface_style(self):
|
||||
self.file.create_entity(
|
||||
"IfcExternallyDefinedSurfaceStyle",
|
||||
**{
|
||||
"Location": self.settings["location"],
|
||||
"Identification": self.settings["identification"],
|
||||
"Name": self.settings["name"],
|
||||
}
|
||||
)
|
||||
|
||||
def create_colour_rgb(self, colour):
|
||||
return self.file.createIfcColourRgb(None, colour[0], colour[1], colour[2])
|
||||
return self.file.createIfcSurfaceStyle(self.settings["name"], "BOTH")
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, **settings):
|
||||
self.file = file
|
||||
self.settings = {"style": None, "ifc_class": "IfcSurfaceStyleRendering", "attributes": {}}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
for key, value in self.settings["attributes"].items():
|
||||
if key == "SurfaceColour" and value:
|
||||
self.settings["attributes"][key] = self.create_colour_rgb(value)
|
||||
if key == "DiffuseColour" and isinstance(value, dict):
|
||||
self.settings["attributes"][key] = self.create_colour_rgb(value)
|
||||
|
||||
style_item = self.file.create_entity(self.settings["ifc_class"], **self.settings["attributes"])
|
||||
styles = list(self.settings["style"].Styles or [])
|
||||
|
||||
duplicate_items = [s for s in styles if s.is_a(self.settings["ifc_class"])]
|
||||
for duplicate_item in duplicate_items:
|
||||
self.file.remove(duplicate_item)
|
||||
|
||||
styles.append(style_item)
|
||||
self.settings["style"].Styles = styles
|
||||
return style_item
|
||||
|
||||
def create_colour_rgb(self, value):
|
||||
return self.file.createIfcColourRgb(value["Name"], value["Red"], value["Green"], value["Blue"])
|
||||
@@ -15,9 +15,9 @@ class Usecase:
|
||||
setattr(self.settings["style"], key, value)
|
||||
|
||||
def edit_surface_colour(self, value):
|
||||
self.settings["style"].SurfaceColour[1] = value[0]
|
||||
self.settings["style"].SurfaceColour[2] = value[1]
|
||||
self.settings["style"].SurfaceColour[3] = value[2]
|
||||
self.settings["style"].SurfaceColour[1] = value["Red"]
|
||||
self.settings["style"].SurfaceColour[2] = value["Green"]
|
||||
self.settings["style"].SurfaceColour[3] = value["Blue"]
|
||||
|
||||
def is_colour_or_factor(self, name):
|
||||
return name in [
|
||||
@@ -29,15 +29,15 @@ class Usecase:
|
||||
]
|
||||
|
||||
def edit_colour_or_factor(self, name, value):
|
||||
if isinstance(value, (list, tuple)):
|
||||
if isinstance(value, dict):
|
||||
attribute = getattr(self.settings["style"], name)
|
||||
if not attribute or not attribute.is_a("IfcColourRgb"):
|
||||
colour = self.file.createIfcColourRgb(None, 0, 0, 0)
|
||||
setattr(self.settings["style"], name, colour)
|
||||
attribute = getattr(self.settings["style"], name)
|
||||
attribute[1] = value[0]
|
||||
attribute[2] = value[1]
|
||||
attribute[3] = value[2]
|
||||
attribute[1] = value["Red"]
|
||||
attribute[2] = value["Green"]
|
||||
attribute[3] = value["Blue"]
|
||||
else:
|
||||
existing_value = getattr(self.settings["style"], name)
|
||||
if existing_value and existing_value.id():
|
||||
|
||||
Reference in New Issue
Block a user