context.data - skip passing unnecessary attributes

This commit is contained in:
Andrej730
2024-09-27 11:40:31 +05:00
parent 3b64350a3f
commit 8ff94d3f61
2 changed files with 8 additions and 10 deletions
+4 -6
View File
@@ -18,6 +18,8 @@
import bpy
import bonsai.tool as tool
import ifcopenshell
from typing import Any
def refresh():
@@ -34,7 +36,7 @@ class ContextData:
cls.is_loaded = True
@classmethod
def get_contexts(cls):
def get_contexts(cls) -> list[dict[str, Any]]:
results = []
for context in tool.Ifc.get().by_type("IfcGeometricRepresentationContext", include_subtypes=False):
results.append(
@@ -42,14 +44,12 @@ class ContextData:
"id": context.id(),
"context_type": context.ContextType,
"subcontexts": cls.get_subcontexts(context),
"is_editing": bpy.context.scene.BIMContextProperties.active_context_id == context.id(),
"props": bpy.context.scene.BIMContextProperties.context_attributes,
}
)
return results
@classmethod
def get_subcontexts(cls, context):
def get_subcontexts(cls, context: ifcopenshell.entity_instance) -> list[dict[str, Any]]:
results = []
for subcontext in context.HasSubContexts:
results.append(
@@ -58,8 +58,6 @@ class ContextData:
"context_type": subcontext.ContextType,
"context_identifier": subcontext.ContextIdentifier,
"target_view": subcontext.TargetView,
"is_editing": bpy.context.scene.BIMContextProperties.active_context_id == subcontext.id(),
"props": bpy.context.scene.BIMContextProperties.context_attributes,
}
)
return results
+4 -4
View File
@@ -52,11 +52,11 @@ class BIM_PT_context(bpy.types.Panel):
for ifc_context in ContextData.data["contexts"]:
box = self.layout.box()
if ifc_context["is_editing"]:
if props.active_context_id == ifc_context["id"]:
row = box.row(align=True)
row.operator("bim.edit_context", icon="CHECKMARK")
row.operator("bim.disable_editing_context", icon="CANCEL", text="")
bonsai.bim.helper.draw_attributes(ifc_context["props"], box)
bonsai.bim.helper.draw_attributes(props.context_attributes, box)
else:
row = box.row(align=True)
row.label(text=ifc_context["context_type"])
@@ -73,11 +73,11 @@ class BIM_PT_context(bpy.types.Panel):
op.parent = ifc_context["id"]
for subcontext in ifc_context["subcontexts"]:
if subcontext["is_editing"]:
if props.active_context_id == subcontext["id"]:
row = box.row(align=True)
row.operator("bim.edit_context", icon="CHECKMARK")
row.operator("bim.disable_editing_context", icon="CANCEL", text="")
bonsai.bim.helper.draw_attributes(subcontext["props"], box)
bonsai.bim.helper.draw_attributes(props.context_attributes, box)
else:
row = box.row(align=True)
row.label(text=subcontext["context_type"])