model.workspace - cache is_representation_item

To avoid accessing IFC on every draw call
This commit is contained in:
Andrej730
2024-10-21 12:32:42 +05:00
parent 1d90665c3a
commit ce6c56cab4
2 changed files with 12 additions and 2 deletions
@@ -555,6 +555,7 @@ class ItemData:
cls.data = {}
cls.data["representation_identifier"] = cls.representation_identifier()
cls.data["representation_type"] = cls.representation_type()
cls.data["is_representation_item_active"] = cls.is_representation_item_active()
@classmethod
def representation_identifier(cls):
@@ -567,3 +568,10 @@ class ItemData:
props = bpy.context.scene.BIMGeometryProperties
rep = tool.Geometry.get_active_representation(props.representation_obj)
return rep.RepresentationType
@classmethod
def is_representation_item_active(cls) -> bool:
object = bpy.context.active_object
if not object:
return False
return tool.Geometry.is_representation_item(object)
@@ -258,7 +258,7 @@ def format_ifc_camel_case(string):
class EditItemUI:
@classmethod
def draw(cls, context, layout):
def draw(cls, context: bpy.types.Context, layout: bpy.types.UILayout):
if not ItemData.is_loaded:
ItemData.load()
@@ -270,8 +270,10 @@ class EditItemUI:
row = cls.layout.row()
row.label(text="Type: " + ItemData.data["representation_type"], icon="OUTLINER_OB_MESH")
cls.layout.menu("BIM_MT_add_representation_item", icon="ADD")
if not (obj := context.active_object) or not tool.Geometry.is_representation_item(obj):
if not ItemData.data["is_representation_item_active"]:
return
obj = context.active_object
assert obj
for item_attribute in obj.data.BIMMeshProperties.item_attributes:
row = cls.layout.row()
row.prop(item_attribute, item_attribute.get_value_name(display_only=True), text=item_attribute.name)