put settings at the end. black

This commit is contained in:
falken10vdl
2025-12-19 09:07:26 +01:00
parent 53115e0654
commit 2264fbeb44
6 changed files with 92 additions and 72 deletions
-2
View File
@@ -240,8 +240,6 @@ def on_register(scene):
is_registering = False is_registering = False
# Classes that need to be registered after modules (due to cross-module dependencies) # Classes that need to be registered after modules (due to cross-module dependencies)
late_classes = ( late_classes = (
ui.DefaultParameters, # Register before BIM_ADDON_preferences ui.DefaultParameters, # Register before BIM_ADDON_preferences
+11 -6
View File
@@ -539,7 +539,9 @@ def draw_filter(
if preferences.chain_filter_with_set_operations: if preferences.chain_filter_with_set_operations:
show_mode_toggle = j > 0 show_mode_toggle = j > 0
else: else:
show_mode_toggle = preferences.default_filter_with_set_operations_for_globalid_and_class and j > 0 # PR 7315 mode show_mode_toggle = (
preferences.default_filter_with_set_operations_for_globalid_and_class and j > 0
) # PR 7315 mode
if show_mode_toggle: if show_mode_toggle:
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"} mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
op = row.operator( op = row.operator(
@@ -758,7 +760,9 @@ def draw_filter(
if preferences.chain_filter_with_set_operations: if preferences.chain_filter_with_set_operations:
show_mode_toggle = j > 0 show_mode_toggle = j > 0
else: else:
show_mode_toggle = preferences.default_filter_with_set_operations_for_globalid_and_class and j > 0 # PR 7315 mode show_mode_toggle = (
preferences.default_filter_with_set_operations_for_globalid_and_class and j > 0
) # PR 7315 mode
if show_mode_toggle: if show_mode_toggle:
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"} mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
op = row.operator( op = row.operator(
@@ -785,19 +789,22 @@ def draw_filter(
op.index = j op.index = j
op.module = module op.module = module
# ============================================================================ # ============================================================================
# UI Panel Visibility Helpers # UI Panel Visibility Helpers
# ============================================================================ # ============================================================================
def get_tab_names(): def get_tab_names():
from bonsai.bim.prop import get_tab from bonsai.bim.prop import get_tab
enum_items = get_tab(None, None) enum_items = get_tab(None, None)
# Exclude None separators and the BLENDER tab (not part of BIM tab system) # Exclude None separators and the BLENDER tab (not part of BIM tab system)
return [item[0] for item in enum_items if item is not None and item[0] != "BLENDER"] return [item[0] for item in enum_items if item is not None and item[0] != "BLENDER"]
def get_panel_tab_name(panel_class): def get_panel_tab_name(panel_class):
if hasattr(panel_class, 'bim_tab_name'): if hasattr(panel_class, "bim_tab_name"):
return panel_class.bim_tab_name return panel_class.bim_tab_name
return "PROJECT" # Default fallback return "PROJECT" # Default fallback
@@ -870,12 +877,10 @@ def get_panel_config(panel_id, create_if_missing=False):
return None return None
def get_all_tab_panels(force_refresh=False): def get_all_tab_panels(force_refresh=False):
panels = {tab_name: [] for tab_name in get_tab_names() if tab_name != "BOOKMARK"} panels = {tab_name: [] for tab_name in get_tab_names() if tab_name != "BOOKMARK"}
panels["BOOKMARK"] = [] panels["BOOKMARK"] = []
bim_props = tool.Blender.get_bim_props() bim_props = tool.Blender.get_bim_props()
for prop in bim_props.panel_properties: for prop in bim_props.panel_properties:
panel_class = getattr(bpy.types, prop.name, None) panel_class = getattr(bpy.types, prop.name, None)
@@ -919,7 +924,7 @@ def initialize_panel_properties():
for attr_name in dir(bpy.types): for attr_name in dir(bpy.types):
if attr_name.startswith("BIM_PT_tab_"): if attr_name.startswith("BIM_PT_tab_"):
panel_class = getattr(bpy.types, attr_name) panel_class = getattr(bpy.types, attr_name)
if not hasattr(panel_class, 'bl_idname'): if not hasattr(panel_class, "bl_idname"):
continue continue
panel_id = panel_class.bl_idname panel_id = panel_class.bl_idname
@@ -1056,9 +1056,11 @@ class LoadProject(bpy.types.Operator, IFCFileSelector, ImportHelper):
return tooltip return tooltip
def execute(self, context): def execute(self, context):
if (tool.Blender.get_addon_preferences().save_metadata_blend_file if (
tool.Blender.get_addon_preferences().save_metadata_blend_file
and self.should_start_fresh_session and self.should_start_fresh_session
and not self.is_advanced): and not self.is_advanced
):
filepath = self.get_filepath() filepath = self.get_filepath()
metadata_path = Path(str(filepath) + ".metadata.blend") metadata_path = Path(str(filepath) + ".metadata.blend")
if metadata_path.exists() and metadata_path.is_file(): if metadata_path.exists() and metadata_path.is_file():
@@ -1762,7 +1764,10 @@ class ExportIFC(bpy.types.Operator, ExportHelper):
try: try:
bpy.ops.bim.save_blend_metadata_file() bpy.ops.bim.save_blend_metadata_file()
blendmetadata_path = output_file + ".metadata.blend" blendmetadata_path = output_file + ".metadata.blend"
self.report({"INFO"}, f'IFC Project "{os.path.basename(output_file)}" And Metadata File Saved to: {os.path.basename(blendmetadata_path)}') self.report(
{"INFO"},
f'IFC Project "{os.path.basename(output_file)}" And Metadata File Saved to: {os.path.basename(blendmetadata_path)}',
)
except Exception as e: except Exception as e:
self.report({"ERROR"}, f"Failed to save blend metadata file: {e}") self.report({"ERROR"}, f"Failed to save blend metadata file: {e}")
else: else:
+22 -15
View File
@@ -33,7 +33,15 @@ import bonsai.bim
import bonsai.tool as tool import bonsai.tool as tool
import bonsai.bim.handler import bonsai.bim.handler
from enum import Enum from enum import Enum
from bonsai.bim.helper import get_all_tab_panels, get_tab_visibility, set_tab_visibility, get_tab_names, get_panel_config, initialize_panel_properties, initialize_tab_visibilities from bonsai.bim.helper import (
get_all_tab_panels,
get_tab_visibility,
set_tab_visibility,
get_tab_names,
get_panel_config,
initialize_panel_properties,
initialize_tab_visibilities,
)
from bpy_extras.io_utils import ImportHelper from bpy_extras.io_utils import ImportHelper
from bonsai.bim import import_ifc from bonsai.bim import import_ifc
from bonsai.bim.prop import StrProperty from bonsai.bim.prop import StrProperty
@@ -236,6 +244,7 @@ class SelectIfcFile(bpy.types.Operator, IFCFileSelector, ImportHelper):
return res return res
return ImportHelper.invoke(self, context, event) return ImportHelper.invoke(self, context, event)
class SaveBlendMetadataFile(bpy.types.Operator): class SaveBlendMetadataFile(bpy.types.Operator):
bl_idname = "bim.save_blend_metadata_file" bl_idname = "bim.save_blend_metadata_file"
bl_label = "Save Blend Metadata File" bl_label = "Save Blend Metadata File"
@@ -254,7 +263,7 @@ class SaveBlendMetadataFile(bpy.types.Operator):
blendmetadata_path = ifc_file + ".metadata.blend" blendmetadata_path = ifc_file + ".metadata.blend"
# Save a temporary copy of the current blend file # Save a temporary copy of the current blend file
temp_path = bpy.path.abspath('//__temp_blendmetadata.blend') temp_path = bpy.path.abspath("//__temp_blendmetadata.blend")
bpy.ops.wm.save_as_mainfile(filepath=temp_path, copy=True) bpy.ops.wm.save_as_mainfile(filepath=temp_path, copy=True)
cleanup_script = f""" cleanup_script = f"""
@@ -323,18 +332,17 @@ bpy.ops.wm.save_as_mainfile(filepath=r'{blendmetadata_path}')
""" """
import tempfile import tempfile
with tempfile.NamedTemporaryFile('w', suffix='.py', delete=False) as script_file:
with tempfile.NamedTemporaryFile("w", suffix=".py", delete=False) as script_file:
script_file.write(cleanup_script) script_file.write(cleanup_script)
script_path = script_file.name script_path = script_file.name
blender_exe = bpy.app.binary_path blender_exe = bpy.app.binary_path
import subprocess import subprocess
result = subprocess.run([
blender_exe, result = subprocess.run(
temp_path, [blender_exe, temp_path, "--background", "--python", script_path], capture_output=True, text=True
'--background', )
'--python', script_path
], capture_output=True, text=True)
# Print the output from the background process (includes debug info) # Print the output from the background process (includes debug info)
if result.stdout: if result.stdout:
@@ -352,6 +360,7 @@ bpy.ops.wm.save_as_mainfile(filepath=r'{blendmetadata_path}')
return {"FINISHED"} return {"FINISHED"}
class LoadBlendMetadataAndIFC(bpy.types.Operator): class LoadBlendMetadataAndIFC(bpy.types.Operator):
bl_idname = "bim.load_blend_metadata_and_ifc" bl_idname = "bim.load_blend_metadata_and_ifc"
bl_label = "Load Blend Metadata and IFC" bl_label = "Load Blend Metadata and IFC"
@@ -379,6 +388,7 @@ class LoadBlendMetadataAndIFC(bpy.types.Operator):
self.report({"INFO"}, f"Loaded metadata and IFC: {metadata_path}, {ifc_file}") self.report({"INFO"}, f"Loaded metadata and IFC: {metadata_path}, {ifc_file}")
return {"FINISHED"} return {"FINISHED"}
# TODO: Unused operator. # TODO: Unused operator.
# Is there a need for this or 'DIR_PATH' propety subtype does almost the same, # Is there a need for this or 'DIR_PATH' propety subtype does almost the same,
# but also has alt+click? # but also has alt+click?
@@ -1781,7 +1791,9 @@ class BIM_OT_toggle_panel_visibility(bpy.types.Operator):
def execute(self, context): def execute(self, context):
panel_name = self.action.replace("TOGGLE_VISIBILITY_", "") panel_name = self.action.replace("TOGGLE_VISIBILITY_", "")
active_tab = getattr(context.scene, "active_tab_name", None) or getattr(tool.Blender.get_bim_props(), "tab", None) active_tab = getattr(context.scene, "active_tab_name", None) or getattr(
tool.Blender.get_bim_props(), "tab", None
)
is_bookmark_tab = active_tab == "BOOKMARK" is_bookmark_tab = active_tab == "BOOKMARK"
panel_config = get_panel_config(panel_name, create_if_missing=True) panel_config = get_panel_config(panel_name, create_if_missing=True)
@@ -1894,8 +1906,6 @@ class BIM_OT_manage_tab_panels(bpy.types.Operator):
panel_config.is_visible_in_tab = item["visible"] panel_config.is_visible_in_tab = item["visible"]
panel_config.is_bookmarked = item["bookmarked"] panel_config.is_bookmarked = item["bookmarked"]
self.report({"INFO"}, f"Panels for {self.tab_name} managed successfully.") self.report({"INFO"}, f"Panels for {self.tab_name} managed successfully.")
return {"FINISHED"} return {"FINISHED"}
@@ -1955,9 +1965,6 @@ class BIM_OT_toggle_tab_visibility(bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
class BIM_OT_reset_ui_layout(bpy.types.Operator): class BIM_OT_reset_ui_layout(bpy.types.Operator):
"""Reset UI Layout to Default""" """Reset UI Layout to Default"""
+16 -11
View File
@@ -702,16 +702,6 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
description="Show mass and time units section in the new project wizard panel", description="Show mass and time units section in the new project wizard panel",
default=False, default=False,
) )
save_metadata_blend_file: BoolProperty(
name="Save non ifc data to .metadata.blend File",
description="Save session data (window layout, settings) to a .metadata.blend file alongside the IFC file. This file is automatically loaded when opening the project.",
default=False,
)
user_ui_customization: BoolProperty(
name="User UI Customization",
description="Enable user interface customization features (hide/show tabs and panels, bookmark panels) and save the session settings as part of the .metadata.blend file",
default=False,
)
chain_filter_with_set_operations: BoolProperty( chain_filter_with_set_operations: BoolProperty(
name="NEW filter mode: Enable chained filters with set operations", name="NEW filter mode: Enable chained filters with set operations",
@@ -724,6 +714,17 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
default=False, default=False,
) )
save_metadata_blend_file: BoolProperty(
name="Save non ifc data to .metadata.blend File",
description="Save session data (window layout, settings) to a .metadata.blend file alongside the IFC file. This file is automatically loaded when opening the project.",
default=False,
)
user_ui_customization: BoolProperty(
name="User UI Customization",
description="Enable user interface customization features (hide/show tabs and panels, bookmark panels) and save the session settings as part of the .metadata.blend file",
default=False,
)
if TYPE_CHECKING: if TYPE_CHECKING:
svg2pdf_command: str svg2pdf_command: str
svg2dxf_command: str svg2dxf_command: str
@@ -1007,7 +1008,11 @@ class BIM_PT_tabs(Panel):
self.draw_tab_entry(row_left, "PACKAGE", "FM", True, aprops.tab == "FM") self.draw_tab_entry(row_left, "PACKAGE", "FM", True, aprops.tab == "FM")
if get_tab_visibility("QUALITY"): if get_tab_visibility("QUALITY"):
self.draw_tab_entry(row_left, "COMMUNITY", "QUALITY", True, aprops.tab == "QUALITY") self.draw_tab_entry(row_left, "COMMUNITY", "QUALITY", True, aprops.tab == "QUALITY")
if addon_prefs.save_metadata_blend_file and addon_prefs.user_ui_customization and get_tab_visibility("BOOKMARK"): if (
addon_prefs.save_metadata_blend_file
and addon_prefs.user_ui_customization
and get_tab_visibility("BOOKMARK")
):
self.draw_tab_entry(row_left, "SOLO_ON", "BOOKMARK", True, aprops.tab == "BOOKMARK") self.draw_tab_entry(row_left, "SOLO_ON", "BOOKMARK", True, aprops.tab == "BOOKMARK")
row_left.operator("bim.switch_tab", text="", emboss=False, icon="UV_SYNC_SELECT") row_left.operator("bim.switch_tab", text="", emboss=False, icon="UV_SYNC_SELECT")