mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Systems UI - support adding child systems #7062
This commit is contained in:
@@ -24,6 +24,7 @@ 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, SystemData
|
from bonsai.bim.module.system.data import PortData, SystemData
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
|
||||||
class LoadSystems(bpy.types.Operator):
|
class LoadSystems(bpy.types.Operator):
|
||||||
@@ -51,9 +52,22 @@ class AddSystem(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_label = "Add System"
|
bl_label = "Add System"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
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):
|
def _execute(self, context):
|
||||||
props = tool.System.get_system_props()
|
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):
|
class EditSystem(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ class BIM_PT_systems(Panel):
|
|||||||
if not ObjectSystemData.is_loaded:
|
if not ObjectSystemData.is_loaded:
|
||||||
ObjectSystemData.load()
|
ObjectSystemData.load()
|
||||||
|
|
||||||
|
assert self.layout
|
||||||
self.props = tool.System.get_system_props()
|
self.props = tool.System.get_system_props()
|
||||||
active_system_item = self.props.active_system_ui_item
|
active_system_item = self.props.active_system_ui_item
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
@@ -91,12 +92,15 @@ class BIM_PT_systems(Panel):
|
|||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.label(text="{} Systems Found in Project".format(SystemData.data["total_systems"]), icon="OUTLINER")
|
row.label(text="{} Systems Found in Project".format(SystemData.data["total_systems"]), icon="OUTLINER")
|
||||||
if self.props.is_editing:
|
if self.props.is_editing:
|
||||||
|
row.operator("bim.add_system", text="", icon="ADD")
|
||||||
row.operator("bim.disable_system_editing_ui", text="", icon="CANCEL")
|
row.operator("bim.disable_system_editing_ui", text="", icon="CANCEL")
|
||||||
|
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
prop_with_search(row, self.props, "system_class", text="")
|
prop_with_search(row, self.props, "system_class", text="")
|
||||||
row.operator("bim.add_system", text="", icon="ADD")
|
|
||||||
if active_system_item:
|
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
|
system_id = active_system_item.ifc_definition_id
|
||||||
op = row.operator("bim.select_system_products", text="", icon="RESTRICT_SELECT_OFF")
|
op = row.operator("bim.select_system_products", text="", icon="RESTRICT_SELECT_OFF")
|
||||||
op.system = system_id
|
op.system = system_id
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional, Union
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import bpy
|
import bpy
|
||||||
@@ -36,8 +36,15 @@ def disable_system_editing_ui(system: type[tool.System]) -> None:
|
|||||||
system.disable_system_editing_ui()
|
system.disable_system_editing_ui()
|
||||||
|
|
||||||
|
|
||||||
def add_system(ifc: type[tool.Ifc], system: type[tool.System], ifc_class: str) -> None:
|
def add_system(
|
||||||
ifc.run("system.add_system", ifc_class=ifc_class)
|
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()
|
system.import_systems()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user