mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +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
|
import ifcopenshell.util.unit
|
||||||
from ifcopenshell.util.doc import get_entity_doc
|
from ifcopenshell.util.doc import get_entity_doc
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
from typing import Any
|
from typing import Any, Union
|
||||||
|
|
||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
@@ -44,6 +44,7 @@ class SystemData:
|
|||||||
cls.data = {
|
cls.data = {
|
||||||
"system_class": cls.system_class(),
|
"system_class": cls.system_class(),
|
||||||
"total_systems": cls.total_systems(),
|
"total_systems": cls.total_systems(),
|
||||||
|
"active_system": cls.active_system(),
|
||||||
}
|
}
|
||||||
cls.is_loaded = True
|
cls.is_loaded = True
|
||||||
|
|
||||||
@@ -64,6 +65,13 @@ class SystemData:
|
|||||||
def total_systems(cls):
|
def total_systems(cls):
|
||||||
return len(tool.System.get_systems())
|
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:
|
class ObjectSystemData:
|
||||||
data = {}
|
data = {}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import ifcopenshell.util.system
|
|||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
import bonsai.core.system as core
|
import bonsai.core.system as core
|
||||||
import bonsai.bim.helper
|
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):
|
class LoadSystems(bpy.types.Operator):
|
||||||
@@ -157,12 +157,13 @@ class UnassignSystem(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
class SelectSystemProducts(bpy.types.Operator):
|
class SelectSystemProducts(bpy.types.Operator):
|
||||||
bl_idname = "bim.select_system_products"
|
bl_idname = "bim.select_system_products"
|
||||||
bl_label = "Select System Products"
|
bl_label = "Select System Products And Set Active System"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
system: bpy.props.IntProperty()
|
system: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
core.select_system_products(tool.System, system=tool.Ifc.get().by_id(self.system))
|
core.select_system_products(tool.System, system=tool.Ifc.get().by_id(self.system))
|
||||||
|
SystemData.data["active_system"] = SystemData.active_system()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -72,9 +72,11 @@ class BIM_PT_systems(Panel):
|
|||||||
row.prop(self.props, "should_draw_decorations")
|
row.prop(self.props, "should_draw_decorations")
|
||||||
|
|
||||||
row = self.layout.row()
|
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:")
|
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:
|
else:
|
||||||
row.label(text="No active system is selected")
|
row.label(text="No active system is selected")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user