mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
Check material override explicitly, not just by name
It was inconsistent when it was comparing usage with unnamed layer set and comparing usage with named layer set.
This commit is contained in:
@@ -177,6 +177,8 @@ class ObjectMaterialData:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def material_class(cls) -> Union[str, None]:
|
def material_class(cls) -> Union[str, None]:
|
||||||
element = tool.Ifc.get_entity(tool.Geometry.get_active_or_representation_obj())
|
element = tool.Ifc.get_entity(tool.Geometry.get_active_or_representation_obj())
|
||||||
|
assert element
|
||||||
|
cls.element = element
|
||||||
cls.material = ifcopenshell.util.element.get_material(element)
|
cls.material = ifcopenshell.util.element.get_material(element)
|
||||||
if cls.material:
|
if cls.material:
|
||||||
return cls.material.is_a()
|
return cls.material.is_a()
|
||||||
@@ -360,12 +362,15 @@ class ObjectMaterialData:
|
|||||||
key=lambda x: x[1],
|
key=lambda x: x[1],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type_material_: Union[ifcopenshell.entity_instance, None] = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def type_material(cls):
|
def type_material(cls):
|
||||||
element = tool.Ifc.get_entity(tool.Geometry.get_active_or_representation_obj())
|
element = tool.Ifc.get_entity(tool.Geometry.get_active_or_representation_obj())
|
||||||
element_type = ifcopenshell.util.element.get_type(element)
|
element_type = ifcopenshell.util.element.get_type(element)
|
||||||
if element_type and element_type != element:
|
if element_type and element_type != element:
|
||||||
material = ifcopenshell.util.element.get_material(element_type)
|
material = ifcopenshell.util.element.get_material(element_type)
|
||||||
|
cls.type_material_ = material
|
||||||
if not material:
|
if not material:
|
||||||
return
|
return
|
||||||
ifc_class = material.is_a()
|
ifc_class = material.is_a()
|
||||||
@@ -397,15 +402,18 @@ class ObjectMaterialData:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_type_material_overridden(cls) -> bool:
|
def is_type_material_overridden(cls) -> bool:
|
||||||
if not cls.data["type_material"]:
|
if not cls.material or not cls.type_material_:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# try to avoid accessing ifc
|
# Typically, we don't indicate Usages as material overrides
|
||||||
if cls.data["material_name"] != cls.data["type_material"]:
|
# as this is just Usages nature.
|
||||||
|
if "Usage" in cls.material.is_a():
|
||||||
|
return False
|
||||||
|
|
||||||
|
if cls.material != cls.type_material_:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# in theory material can be overridden by the same material
|
# in theory material can be overridden by the same material
|
||||||
# so we check occurrence material explicitly
|
# so we check occurrence material explicitly
|
||||||
element = tool.Ifc.get_entity(bpy.context.active_object)
|
occurrence_material = ifcopenshell.util.element.get_material(cls.element, should_inherit=False)
|
||||||
occurrence_material = ifcopenshell.util.element.get_material(element, should_inherit=False)
|
return bool(occurrence_material)
|
||||||
return bool(occurrence_material) and "Usage" not in occurrence_material.is_a()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user