Start cleaning up type manager to serve its new purpose as a fancy dropdown

This commit is contained in:
Dion Moult
2024-09-29 22:39:21 +10:00
parent 1bcc7199f6
commit 8a0e87b8f8
7 changed files with 57 additions and 59 deletions
@@ -60,8 +60,6 @@ classes = (
product.AddOccurrence,
product.AlignProduct,
product.ChangeTypePage,
product.DisableAddType,
product.EnableAddType,
product.LoadTypeThumbnails,
product.MirrorElements,
product.SetActiveType,
@@ -139,6 +137,8 @@ classes = (
ui.BIM_PT_railing,
ui.BIM_PT_roof,
ui.BIM_MT_type_manager_menu,
ui.BIM_MT_type_menu,
ui.LaunchTypeMenu,
ui.LaunchTypeManager,
ui.BIM_MT_elements,
grid.BIM_OT_add_object,
@@ -46,24 +46,6 @@ import json
from typing import Any, Union, Optional
class EnableAddType(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.enable_add_type"
bl_label = "Enable Add Type"
bl_options = {"REGISTER", "UNDO"}
def _execute(self, context):
bpy.context.scene.BIMModelProperties.is_adding_type = True
class DisableAddType(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.disable_add_type"
bl_label = "Disable Add Type"
bl_options = {"REGISTER", "UNDO"}
def _execute(self, context):
bpy.context.scene.BIMModelProperties.is_adding_type = False
class AddEmptyType(bpy.types.Operator, AddObjectHelper):
bl_idname = "bim.add_empty_type"
bl_label = "Add Empty Type"
+1 -1
View File
@@ -112,9 +112,9 @@ class BIMModelProperties(PropertyGroup):
relating_type_id: bpy.props.EnumProperty(
items=get_relating_type_id, name="Relating Type", update=update_relating_type_id
)
menu_relating_type_id: bpy.props.IntProperty()
icon_id: bpy.props.IntProperty()
updating: bpy.props.BoolProperty(default=False)
is_adding_type: bpy.props.BoolProperty(default=False)
occurrence_name_style: bpy.props.EnumProperty(
items=[("CLASS", "By Class", ""), ("TYPE", "By Type", ""), ("CUSTOM", "Custom", "")],
name="Occurrence Name Style",
+39 -38
View File
@@ -49,6 +49,37 @@ class BIM_MT_type_manager_menu(bpy.types.Menu):
layout.operator("bim.purge_unused_objects", text="Purge Unused Types", icon="TRASH").object_type = "TYPE"
class BIM_MT_type_menu(bpy.types.Menu):
bl_label = "Type Menu"
bl_idname = "BIM_MT_type_menu"
relating_type_id: bpy.props.IntProperty(name="Relating Type Id")
def draw(self, context):
props = context.scene.BIMModelProperties
layout = self.layout
op = layout.operator("bim.launch_rename_type", icon="GREASEPENCIL", text="Rename Type")
op.element = props.menu_relating_type_id
op = layout.operator("bim.select_type", icon="OBJECT_DATA")
op.relating_type = props.menu_relating_type_id
op = layout.operator("bim.duplicate_type", icon="DUPLICATE")
op.element = props.menu_relating_type_id
layout.separator()
op = layout.operator("bim.remove_type", icon="X")
op.element = props.menu_relating_type_id
class LaunchTypeMenu(bpy.types.Operator):
bl_idname = "bim.launch_type_menu"
bl_label = "Launch Type Menu"
relating_type_id: bpy.props.IntProperty(name="Relating Type Id")
def execute(self, context):
props = context.scene.BIMModelProperties
props.menu_relating_type_id = self.relating_type_id
bpy.ops.wm.call_menu(name="BIM_MT_type_menu")
return {"FINISHED"}
class LaunchTypeManager(bpy.types.Operator):
bl_idname = "bim.launch_type_manager"
bl_label = "Launch Type Manager"
@@ -56,6 +87,7 @@ class LaunchTypeManager(bpy.types.Operator):
bl_description = "Display all available Construction Types to add new instances"
def execute(self, context):
bpy.ops.bim.hotkey("INVOKE_DEFAULT", hotkey="S_A")
return {"FINISHED"}
def invoke(self, context, event):
@@ -78,8 +110,8 @@ class LaunchTypeManager(bpy.types.Operator):
props = context.scene.BIMModelProperties
row = self.layout.row(align=True)
prop_with_search(row, props, "type_class", text="", should_click_ok_to_validate=True)
prop_with_search(row, props, "ifc_class", text="", should_click_ok_to_validate=True)
row.operator("bim.launch_add_element", icon="ADD", text="")
row.menu("BIM_MT_type_manager_menu", text="", icon="PREFERENCES")
columns = self.layout.column_flow(columns=3)
@@ -102,34 +134,19 @@ class LaunchTypeManager(bpy.types.Operator):
op = row.operator("bim.change_type_page", icon="TRIA_RIGHT", text="")
op.page = AuthoringData.data["next_page"]
if props.is_adding_type:
row = self.layout.row()
box = row.box()
row = box.row()
row.prop(props, "type_predefined_type")
row = box.row()
row.prop(props, "type_template")
row = box.row()
row.prop(props, "type_name")
row = box.row(align=True)
row.operator("bim.add_type", icon="CHECKMARK", text="Save New Type")
row.operator("bim.disable_add_type", icon="CANCEL", text="")
else:
row = self.layout.row()
# row.operator("bim.enable_add_type", icon="ADD", text="Create New Type")
row.operator("bim.launch_add_element", icon="ADD", text="Create New Type")
flow = self.layout.grid_flow(row_major=True, columns=3, even_columns=True, even_rows=True, align=True)
for relating_type in AuthoringData.data["paginated_relating_types"]:
outer_col = flow.column()
box = outer_col.box()
row = box.row()
row.alignment = "CENTER"
op = row.operator("bim.set_active_type", text=relating_type["name"], icon="FILE_3D", emboss=False)
row = box.row(align=True)
op = row.operator("bim.set_active_type", text=relating_type["name"], icon="FILE_3D")
op.relating_type = relating_type["id"]
op = row.operator("bim.launch_type_menu", icon="DOWNARROW_HLT", text="")
op.relating_type_id = relating_type["id"]
row = box.row()
row.alignment = "CENTER"
op = row.operator("bim.set_active_type", text=relating_type["description"], emboss=False)
@@ -150,22 +167,6 @@ class LaunchTypeManager(bpy.types.Operator):
op = box.operator("bim.load_type_thumbnails", text="Load Thumbnails", icon="FILE_REFRESH")
op.ifc_class = props.type_class
row = box.row(align=True)
text = f"Add {relating_type['predefined_type']}" if relating_type["predefined_type"] else "Add"
op = row.operator("bim.add_constr_type_instance", icon="ADD", text=text)
op.from_invoke = True
op.relating_type_id = relating_type["id"]
op = row.operator("bim.rename_type", icon="GREASEPENCIL", text="")
op.element = relating_type["id"]
op = row.operator("bim.select_type", icon="OBJECT_DATA", text="")
op.relating_type = relating_type["id"]
op = row.operator("bim.duplicate_type", icon="DUPLICATE", text="")
op.element = relating_type["id"]
op = row.operator("bim.remove_type", icon="X", text="")
op.element = relating_type["id"]
class BIM_PT_authoring(Panel):
bl_label = "Architectural"
@@ -559,5 +559,6 @@ class LaunchAddElement(bpy.types.Operator, tool.Ifc.Operator):
bl_description = "Add an IFC physical product, construction type, and more"
def execute(self, context):
# This stub operator is needed because operators from menu skip the invoke call
bpy.ops.bim.add_element("INVOKE_DEFAULT")
return {"FINISHED"}
@@ -26,6 +26,7 @@ classes = (
operator.DisableEditingType,
operator.DuplicateType,
operator.EnableEditingType,
operator.LaunchRenameType,
operator.RemoveType,
operator.RenameType,
operator.SelectSimilarType,
@@ -515,6 +515,19 @@ class RenameType(bpy.types.Operator, tool.Ifc.Operator):
self.layout.prop(self, "name")
class LaunchRenameType(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.launch_rename_type"
bl_label = "Launch Rename Type"
bl_options = {"REGISTER", "UNDO"}
element: bpy.props.IntProperty()
name: bpy.props.StringProperty(name="Name")
def execute(self, context):
# This stub operator is needed because operators from menu skip the invoke call
bpy.ops.bim.rename_type("INVOKE_DEFAULT", element=self.element, name=self.name)
return {"FINISHED"}
class AutoRenameOccurrences(bpy.types.Operator):
bl_idname = "bim.auto_rename_occurrences"
bl_label = "Auto Rename Occurrences"