mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 18:16:20 +00:00
Indicate in UI if type material was overridden by occurrence material
Example - https://i.imgur.com/T1hidJg.png +small optimization in material_name
This commit is contained in:
@@ -167,6 +167,9 @@ class ObjectMaterialData:
|
|||||||
cls.data["type_material"] = cls.type_material()
|
cls.data["type_material"] = cls.type_material()
|
||||||
cls.data["material_type"] = cls.material_type()
|
cls.data["material_type"] = cls.material_type()
|
||||||
cls.data["active_material_constituents"] = cls.active_material_constituents()
|
cls.data["active_material_constituents"] = cls.active_material_constituents()
|
||||||
|
# after material_name and type_material
|
||||||
|
cls.data["is_type_material_overridden"] = cls.is_type_material_overridden()
|
||||||
|
|
||||||
cls.is_loaded = True
|
cls.is_loaded = True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -295,8 +298,7 @@ class ObjectMaterialData:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def material_name(cls):
|
def material_name(cls):
|
||||||
element = tool.Ifc.get_entity(bpy.context.active_object)
|
material = cls.material
|
||||||
material = ifcopenshell.util.element.get_material(element)
|
|
||||||
if material:
|
if material:
|
||||||
return getattr(material, "Name", None) or "Unnamed"
|
return getattr(material, "Name", None) or "Unnamed"
|
||||||
|
|
||||||
@@ -340,3 +342,18 @@ class ObjectMaterialData:
|
|||||||
if not cls.material or not material.is_a("IfcMaterialConstituentSet"):
|
if not cls.material or not material.is_a("IfcMaterialConstituentSet"):
|
||||||
return []
|
return []
|
||||||
return [m.Name for m in material.MaterialConstituents if m.Name]
|
return [m.Name for m in material.MaterialConstituents if m.Name]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def is_type_material_overridden(cls) -> bool:
|
||||||
|
if not cls.data["type_material"]:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# try to avoid accessing ifc
|
||||||
|
if cls.data["material_name"] != cls.data["type_material"]:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# in theory material can be overridden by the same material
|
||||||
|
# so we check occurrence material explicitly
|
||||||
|
element = tool.Ifc.get_entity(bpy.context.active_object)
|
||||||
|
occurrence_material = ifcopenshell.util.element.get_material(element, should_inherit=False)
|
||||||
|
return bool(occurrence_material)
|
||||||
|
|||||||
@@ -177,7 +177,13 @@ class BIM_PT_object_material(Panel):
|
|||||||
|
|
||||||
if ObjectMaterialData.data["type_material"]:
|
if ObjectMaterialData.data["type_material"]:
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.label(text="Inherited Material: " + ObjectMaterialData.data["type_material"], icon="CON_CHILDOF")
|
if ObjectMaterialData.data["is_type_material_overridden"]:
|
||||||
|
row.label(
|
||||||
|
text=f"Inherited Material Is Occurrence Overridden",
|
||||||
|
icon="CON_CHILDOF",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
row.label(text="Inherited Material: " + ObjectMaterialData.data["type_material"], icon="CON_CHILDOF")
|
||||||
|
|
||||||
if ObjectMaterialData.data["material_class"]:
|
if ObjectMaterialData.data["material_class"]:
|
||||||
return self.draw_material_ui()
|
return self.draw_material_ui()
|
||||||
|
|||||||
Reference in New Issue
Block a user