mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Systems UI - cache active system data
This commit is contained in:
@@ -23,7 +23,7 @@ import ifcopenshell.util.system
|
||||
import ifcopenshell.util.unit
|
||||
from ifcopenshell.util.doc import get_entity_doc
|
||||
import bonsai.tool as tool
|
||||
from typing import Any
|
||||
from typing import Any, Union
|
||||
|
||||
|
||||
def refresh():
|
||||
@@ -44,6 +44,7 @@ class SystemData:
|
||||
cls.data = {
|
||||
"system_class": cls.system_class(),
|
||||
"total_systems": cls.total_systems(),
|
||||
"active_system": cls.active_system(),
|
||||
}
|
||||
cls.is_loaded = True
|
||||
|
||||
@@ -64,6 +65,13 @@ class SystemData:
|
||||
def total_systems(cls):
|
||||
return len(tool.System.get_systems())
|
||||
|
||||
@classmethod
|
||||
def active_system(cls) -> Union[dict[str, Any], None]:
|
||||
active_system = tool.System.get_active_system()
|
||||
if not active_system:
|
||||
return None
|
||||
return {"id": active_system.id(), "Name": active_system.Name, "ifc_class": active_system.is_a()}
|
||||
|
||||
|
||||
class ObjectSystemData:
|
||||
data = {}
|
||||
|
||||
@@ -22,7 +22,7 @@ import ifcopenshell.util.system
|
||||
import bonsai.tool as tool
|
||||
import bonsai.core.system as core
|
||||
import bonsai.bim.helper
|
||||
from bonsai.bim.module.system.data import PortData
|
||||
from bonsai.bim.module.system.data import PortData, SystemData
|
||||
|
||||
|
||||
class LoadSystems(bpy.types.Operator):
|
||||
@@ -157,12 +157,13 @@ class UnassignSystem(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
class SelectSystemProducts(bpy.types.Operator):
|
||||
bl_idname = "bim.select_system_products"
|
||||
bl_label = "Select System Products"
|
||||
bl_label = "Select System Products And Set Active System"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
system: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
core.select_system_products(tool.System, system=tool.Ifc.get().by_id(self.system))
|
||||
SystemData.data["active_system"] = SystemData.active_system()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
|
||||
@@ -72,9 +72,11 @@ class BIM_PT_systems(Panel):
|
||||
row.prop(self.props, "should_draw_decorations")
|
||||
|
||||
row = self.layout.row()
|
||||
if active_system := tool.System.get_active_system():
|
||||
if active_system := SystemData.data["active_system"]:
|
||||
row.label(text=f"Active system:")
|
||||
tool.System.draw_system_ui(self.layout, active_system.id(), active_system.Name, active_system.is_a())
|
||||
tool.System.draw_system_ui(
|
||||
self.layout, active_system["id"], active_system["Name"], active_system["ifc_class"]
|
||||
)
|
||||
else:
|
||||
row.label(text="No active system is selected")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user