disable editing rep item style if it comes from material constituent through shape aspect

This commit is contained in:
Andrej730
2024-02-15 16:35:00 +05:00
parent 5c60c2e35b
commit eebe7d596d
2 changed files with 44 additions and 0 deletions
@@ -1649,11 +1649,43 @@ class RemoveRepresentationItem(bpy.types.Operator, Operator):
bpy.ops.bim.enable_editing_representation_items()
def poll_editing_representaiton_item_style(cls, context):
if not (obj := getattr(context, "active_object", None)):
return False
props = obj.BIMGeometryProperties
if not props.is_editing:
return False
if not 0 <= props.active_item_index < len(props.items):
return False
item = props.items[props.active_item_index]
shape_aspect = item.shape_aspect
if shape_aspect == "":
return True
from blenderbim.bim.module.material.data import ObjectMaterialData
if not ObjectMaterialData.is_loaded:
ObjectMaterialData.load()
constituents = ObjectMaterialData.data["active_material_constituents"]
if any(c for c in constituents if c == shape_aspect):
cls.poll_message_set(
"Style comes from item's shape aspect related to the material constituent "
"with the same name and cannot be edited on representation item directly - "
"you can change it from the material constituent"
)
return False
return True
class EnableEditingRepresentationItemStyle(bpy.types.Operator, Operator):
bl_idname = "bim.enable_editing_representation_item_style"
bl_label = "Enable Editing Representation Item Style"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
return poll_editing_representaiton_item_style(cls, context)
def _execute(self, context):
props = context.active_object.BIMGeometryProperties
props.is_editing_item_style = True
@@ -1704,6 +1736,10 @@ class UnassignRepresentationItemStyle(bpy.types.Operator, Operator):
bl_label = "Unassign Representation Item Style"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
return poll_editing_representaiton_item_style(cls, context)
def _execute(self, context):
obj = context.active_object
props = obj.BIMGeometryProperties
@@ -152,6 +152,7 @@ class ObjectMaterialData:
cls.data["materials"] = cls.materials()
cls.data["type_material"] = cls.type_material()
cls.data["material_type"] = cls.material_type()
cls.data["active_material_constituents"] = cls.active_material_constituents()
cls.is_loaded = True
@classmethod
@@ -318,3 +319,10 @@ class ObjectMaterialData:
if version == "IFC2X3":
material_types = ["IfcMaterial", "IfcMaterialLayerSet", "IfcMaterialList"]
return [(m, m, ifcopenshell.util.doc.get_entity_doc(version, m).get("description", "")) for m in material_types]
@classmethod
def active_material_constituents(cls):
material = cls.material
if not material.is_a("IfcMaterialConstituentSet"):
return []
return [m.Name for m in material.MaterialConstituents if m.Name]