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.
This commit is contained in:
tetektoza
2025-06-17 01:00:35 +02:00
committed by Yorik van Havre
parent 0817510181
commit e8ae780ae5
3 changed files with 75 additions and 2 deletions

View File

@@ -37,6 +37,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkDoNotAskAgain">
<property name="text">
<string>Do not ask again and use this setting</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">

View File

@@ -306,6 +306,50 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>New type</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_14">
<property name="toolTip">
<string>When enabled, converting objects to IFC types will always keep the original object</string>
</property>
<property name="text">
<string>Always keep original object when converting to type</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ConvertTypeKeepOriginal</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/NativeIFC</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_15">
<property name="toolTip">
<string>When enabled, a dialog will be shown each time when converting objects to IFC types</string>
</property>
<property name="text">
<string>Show dialog when converting to type</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ConvertTypeAskAgain</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/NativeIFC</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View File

@@ -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)