Systems UI - support adding child systems #7062

This commit is contained in:
Andrej730
2025-09-15 09:51:51 +05:00
parent c661bb62ca
commit 5de96c9f95
3 changed files with 30 additions and 5 deletions
@@ -24,6 +24,7 @@ import bonsai.tool as tool
import bonsai.core.system as core
import bonsai.bim.helper
from bonsai.bim.module.system.data import PortData, SystemData
from typing import TYPE_CHECKING
class LoadSystems(bpy.types.Operator):
@@ -51,9 +52,22 @@ class AddSystem(bpy.types.Operator, tool.Ifc.Operator):
bl_label = "Add System"
bl_options = {"REGISTER", "UNDO"}
parent_system_id: bpy.props.IntProperty() # pyright: ignore[reportRedeclaration]
if TYPE_CHECKING:
parent_system_id: int
@classmethod
def description(cls, context, properties) -> str:
if properties.parent_system_id:
return "Add new subsystem to the active system."
return "Add new IfcSystem."
def _execute(self, context):
props = tool.System.get_system_props()
core.add_system(tool.Ifc, tool.System, ifc_class=props.system_class)
ifc_file = tool.Ifc.get()
parent_system = None if self.parent_system_id == 0 else ifc_file.by_id(self.parent_system_id)
core.add_system(tool.Ifc, tool.System, ifc_class=props.system_class, parent_system=parent_system)
class EditSystem(bpy.types.Operator, tool.Ifc.Operator):
+5 -1
View File
@@ -66,6 +66,7 @@ class BIM_PT_systems(Panel):
if not ObjectSystemData.is_loaded:
ObjectSystemData.load()
assert self.layout
self.props = tool.System.get_system_props()
active_system_item = self.props.active_system_ui_item
row = self.layout.row(align=True)
@@ -91,12 +92,15 @@ class BIM_PT_systems(Panel):
row = self.layout.row(align=True)
row.label(text="{} Systems Found in Project".format(SystemData.data["total_systems"]), icon="OUTLINER")
if self.props.is_editing:
row.operator("bim.add_system", text="", icon="ADD")
row.operator("bim.disable_system_editing_ui", text="", icon="CANCEL")
row = self.layout.row(align=True)
prop_with_search(row, self.props, "system_class", text="")
row.operator("bim.add_system", text="", icon="ADD")
if active_system_item:
op = row.operator("bim.add_system", text="", icon="ADD")
op.parent_system_id = active_system_item.ifc_definition_id
system_id = active_system_item.ifc_definition_id
op = row.operator("bim.select_system_products", text="", icon="RESTRICT_SELECT_OFF")
op.system = system_id
+10 -3
View File
@@ -17,7 +17,7 @@
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING, Optional, Union
if TYPE_CHECKING:
import bpy
@@ -36,8 +36,15 @@ def disable_system_editing_ui(system: type[tool.System]) -> None:
system.disable_system_editing_ui()
def add_system(ifc: type[tool.Ifc], system: type[tool.System], ifc_class: str) -> None:
ifc.run("system.add_system", ifc_class=ifc_class)
def add_system(
ifc: type[tool.Ifc],
system: type[tool.System],
ifc_class: str,
parent_system: Union[ifcopenshell.entity_instance, None],
) -> None:
new_system = ifc.run("system.add_system", ifc_class=ifc_class)
if parent_system:
ifc.run("group.assign_group", products=[new_system], group=parent_system)
system.import_systems()