From e8ae780ae51d84c55105dbaded977d987cd279ff Mon Sep 17 00:00:00 2001 From: tetektoza Date: Tue, 17 Jun 2025 01:00:35 +0200 Subject: [PATCH] BIM: Allow user to skip dialog during type conversion As the title says - this adds a new option to the dialog to `never ask again` as well user can customize both settings through preferences. --- src/Mod/BIM/Resources/ui/dialogConvertType.ui | 7 +++ .../BIM/Resources/ui/preferencesNativeIFC.ui | 44 +++++++++++++++++++ src/Mod/BIM/nativeifc/ifc_types.py | 26 ++++++++++- 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/Mod/BIM/Resources/ui/dialogConvertType.ui b/src/Mod/BIM/Resources/ui/dialogConvertType.ui index 4466ceacff..d846f5f083 100644 --- a/src/Mod/BIM/Resources/ui/dialogConvertType.ui +++ b/src/Mod/BIM/Resources/ui/dialogConvertType.ui @@ -37,6 +37,13 @@ + + + + Do not ask again and use this setting + + + diff --git a/src/Mod/BIM/Resources/ui/preferencesNativeIFC.ui b/src/Mod/BIM/Resources/ui/preferencesNativeIFC.ui index 45c21b4e4c..136249f741 100644 --- a/src/Mod/BIM/Resources/ui/preferencesNativeIFC.ui +++ b/src/Mod/BIM/Resources/ui/preferencesNativeIFC.ui @@ -306,6 +306,50 @@ + + + + New type + + + + + + When enabled, converting objects to IFC types will always keep the original object + + + Always keep original object when converting to type + + + ConvertTypeKeepOriginal + + + Mod/NativeIFC + + + + + + + When enabled, a dialog will be shown each time when converting objects to IFC types + + + Show dialog when converting to type + + + true + + + ConvertTypeAskAgain + + + Mod/NativeIFC + + + + + + diff --git a/src/Mod/BIM/nativeifc/ifc_types.py b/src/Mod/BIM/nativeifc/ifc_types.py index 8d78796ee8..7967c471a9 100644 --- a/src/Mod/BIM/nativeifc/ifc_types.py +++ b/src/Mod/BIM/nativeifc/ifc_types.py @@ -30,6 +30,9 @@ from . import ifc_tools translate = FreeCAD.Qt.translate +# Parameters object for NativeIFC preferences +PARAMS = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/NativeIFC") + def show_type(obj): """Adds the types of that object as FreeCAD objects""" @@ -73,17 +76,36 @@ def convert_to_type(obj, keep_object=False): return if not getattr(obj, "Shape", None): return - if FreeCAD.GuiUp: + + # Check preferences + always_keep = PARAMS.GetBool("ConvertTypeKeepOriginal", False) + ask_again = PARAMS.GetBool("ConvertTypeAskAgain", True) + + if FreeCAD.GuiUp and ask_again: import FreeCADGui dlg = FreeCADGui.PySideUic.loadUi(":/ui/dialogConvertType.ui") - + original_text = dlg.label.text() dlg.label.setText(original_text.replace("%1", obj.Class+"Type")) + # Set the initial state of the checkbox from the "always keep" preference + dlg.checkKeepObject.setChecked(always_keep) + result = dlg.exec_() if not result: return + keep_object = dlg.checkKeepObject.isChecked() + do_not_ask_again = dlg.checkDoNotAskAgain.isChecked() + + # If "Do not ask again" is checked, disable future dialogs and save the current choice + if do_not_ask_again: + PARAMS.SetBool("ConvertTypeAskAgain", False) + PARAMS.SetBool("ConvertTypeKeepOriginal", keep_object) + else: + # Use the saved preference when GUI is not available or user chose "do not ask again" + keep_object = always_keep + element = ifc_tools.get_ifc_element(obj) ifcfile = ifc_tools.get_ifcfile(obj) project = ifc_tools.get_project(obj)