Fix UI bug where adding nested groups closed the UI

This commit is contained in:
Dion Moult
2022-09-04 11:17:40 +10:00
parent f11f648630
commit a7c56e742b
3 changed files with 19 additions and 37 deletions
@@ -20,19 +20,18 @@ import bpy
from . import ui, prop, operator from . import ui, prop, operator
classes = ( classes = (
operator.LoadGroups,
operator.ToggleGroup,
operator.DisableGroupEditingUI,
operator.AddGroup, operator.AddGroup,
operator.AddGroupToGroup,
operator.EditGroup,
operator.RemoveGroup,
operator.ToggleAssigningGroup,
operator.AssignGroup, operator.AssignGroup,
operator.UnassignGroup,
operator.EnableEditingGroup,
operator.DisableEditingGroup, operator.DisableEditingGroup,
operator.DisableGroupEditingUI,
operator.EditGroup,
operator.EnableEditingGroup,
operator.LoadGroups,
operator.RemoveGroup,
operator.SelectGroupProducts, operator.SelectGroupProducts,
operator.ToggleAssigningGroup,
operator.ToggleGroup,
operator.UnassignGroup,
operator.UpdateGroup, operator.UpdateGroup,
prop.ExpandedGroups, prop.ExpandedGroups,
prop.Group, prop.Group,
@@ -20,6 +20,7 @@ import bpy
import ifcopenshell.util.attribute import ifcopenshell.util.attribute
import ifcopenshell.api import ifcopenshell.api
import blenderbim.bim.helper import blenderbim.bim.helper
import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from ifcopenshell.api.group.data import Data from ifcopenshell.api.group.data import Data
from ifcopenshell.util.selector import Selector from ifcopenshell.util.selector import Selector
@@ -120,37 +121,19 @@ class AddGroup(bpy.types.Operator):
bl_idname = "bim.add_group" bl_idname = "bim.add_group"
bl_label = "Add New Group" bl_label = "Add New Group"
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
group: bpy.props.IntProperty()
def execute(self, context): def execute(self, context):
return IfcStore.execute_ifc_operator(self, context) return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context): def _execute(self, context):
result = ifcopenshell.api.run("group.add_group", IfcStore.get_file()) result = ifcopenshell.api.run("group.add_group", tool.Ifc.get())
Data.load(IfcStore.get_file()) if self.group:
ifcopenshell.api.run(
"group.assign_group", tool.Ifc.get(), products=[result], group=tool.Ifc.get().by_id(self.group)
)
Data.load(tool.Ifc.get())
bpy.ops.bim.load_groups(is_refresh=True) bpy.ops.bim.load_groups(is_refresh=True)
bpy.ops.bim.enable_editing_group(group=result.id())
return {"FINISHED"}
class AddGroupToGroup(bpy.types.Operator):
bl_idname = "bim.add_group_to_group"
bl_label = "Add Group to Group"
bl_options = {"REGISTER", "UNDO"}
group: bpy.props.IntProperty(name="Group ID")
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
self.file = IfcStore.get_file()
result = ifcopenshell.api.run("group.add_group", self.file)
ifcopenshell.api.run(
"group.assign_group", IfcStore.get_file(), products=[result], group=self.file.by_id(self.group)
)
Data.load(IfcStore.get_file())
bpy.ops.bim.load_groups(is_refresh=True)
bpy.ops.bim.disable_group_editing_ui()
return {"FINISHED"} return {"FINISHED"}
@@ -42,7 +42,7 @@ class BIM_PT_groups(Panel):
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.label(text=f"{len(Data.groups)} Groups Found", icon="OUTLINER") row.label(text=f"{len(Data.groups)} Groups Found", icon="OUTLINER")
if self.props.is_editing: if self.props.is_editing:
row.operator("bim.add_group", text="", icon="ADD") row.operator("bim.add_group", text="", icon="ADD").group = 0
row.operator("bim.disable_group_editing_ui", text="", icon="CANCEL") row.operator("bim.disable_group_editing_ui", text="", icon="CANCEL")
else: else:
row.operator("bim.load_groups", text="", icon="GREASEPENCIL") row.operator("bim.load_groups", text="", icon="GREASEPENCIL")
@@ -140,7 +140,7 @@ class BIM_UL_groups(UIList):
elif context.scene.BIMGroupProperties.active_group_id: elif context.scene.BIMGroupProperties.active_group_id:
op = row.operator("bim.select_group_products", text="", icon="RESTRICT_SELECT_OFF") op = row.operator("bim.select_group_products", text="", icon="RESTRICT_SELECT_OFF")
op.group = group_id op.group = group_id
op = row.operator("bim.add_group_to_group", text="", icon="ADD") op = row.operator("bim.add_group", text="", icon="ADD")
op.group = group_id op.group = group_id
op = row.operator("bim.remove_group", text="", icon="X") op = row.operator("bim.remove_group", text="", icon="X")
op.group = group_id op.group = group_id
@@ -153,7 +153,7 @@ class BIM_UL_groups(UIList):
op.group = group_id op.group = group_id
op = row.operator("bim.enable_editing_group", text="", icon="GREASEPENCIL") op = row.operator("bim.enable_editing_group", text="", icon="GREASEPENCIL")
op.group = group_id op.group = group_id
op = row.operator("bim.add_group_to_group", text="", icon="ADD") op = row.operator("bim.add_group", text="", icon="ADD")
op.group = group_id op.group = group_id
op = row.operator("bim.remove_group", text="", icon="X") op = row.operator("bim.remove_group", text="", icon="X")
op.group = group_id op.group = group_id