From 7d1f1f214375f57873eb9bce8a502756279298c1 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Tue, 30 Jan 2024 15:14:32 +0100 Subject: [PATCH] Assembly: Esc pref --- src/Mod/Assembly/Gui/PreCompiled.h | 7 +++ .../Gui/Resources/preferences/Assembly.ui | 60 ++++++++++++++++++- src/Mod/Assembly/Gui/ViewProviderAssembly.cpp | 16 +++++ src/Mod/Assembly/Gui/ViewProviderAssembly.h | 2 + src/Mod/Assembly/Preferences.py | 14 ++++- src/Mod/Assembly/UtilsAssembly.py | 8 +++ 6 files changed, 103 insertions(+), 4 deletions(-) diff --git a/src/Mod/Assembly/Gui/PreCompiled.h b/src/Mod/Assembly/Gui/PreCompiled.h index 02bfff4f01..79ef18d8f4 100644 --- a/src/Mod/Assembly/Gui/PreCompiled.h +++ b/src/Mod/Assembly/Gui/PreCompiled.h @@ -42,6 +42,13 @@ #include #endif +#include + +// all of Inventor +#ifndef __InventorAll__ +#include +#endif + #endif //_PreComp_ #endif // POINTSGUI_PRECOMPILED_H diff --git a/src/Mod/Assembly/Gui/Resources/preferences/Assembly.ui b/src/Mod/Assembly/Gui/Resources/preferences/Assembly.ui index 83a06b97c5..642cbe1da0 100644 --- a/src/Mod/Assembly/Gui/Resources/preferences/Assembly.ui +++ b/src/Mod/Assembly/Gui/Resources/preferences/Assembly.ui @@ -13,8 +13,57 @@ General - - + + + + + Allow to leave edit mode when pressing Esc button + + + Esc leave edit mode + + + true + + + LeaveEditWithEscape + + + Mod/Assembly + + + + + + + Ground first part: + + + + + + + When you insert the first part in the assembly, you can choose to ground the part automatically. + + + 0 + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + Qt::Vertical @@ -29,6 +78,13 @@ + + + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
+
diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp index ab7a4a1c46..b2ee2e1c2b 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #endif #include @@ -235,6 +236,21 @@ App::DocumentObject* ViewProviderAssembly::getActivePart() const return activeView->getActiveObject(PARTKEY); } +bool ViewProviderAssembly::keyPressed(bool pressed, int key) +{ + if (key == SoKeyboardEvent::ESCAPE) { + if (isInEditMode()) { + + ParameterGrp::handle hPgr = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Assembly"); + + return !hPgr->GetBool("LeaveEditWithEscape", true); + } + } + + return false; // handle all other key events +} + bool ViewProviderAssembly::mouseMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer) { // Initialize or end the dragging of parts diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.h b/src/Mod/Assembly/Gui/ViewProviderAssembly.h index dc2dc8a4ff..5cc7bd684f 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.h +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.h @@ -84,6 +84,8 @@ public: App::DocumentObject* getActivePart() const; + /// is called when the Provider is in edit and a key event ocours. Only ESC ends edit. + bool keyPressed(bool pressed, int key) override; /// is called when the provider is in edit and the mouse is moved bool mouseMove(const SbVec2s& pos, Gui::View3DInventorViewer* viewer) override; /// is called when the Provider is in edit and the mouse is clicked diff --git a/src/Mod/Assembly/Preferences.py b/src/Mod/Assembly/Preferences.py index 71c60323ef..8db2be359b 100644 --- a/src/Mod/Assembly/Preferences.py +++ b/src/Mod/Assembly/Preferences.py @@ -24,6 +24,8 @@ import FreeCAD import FreeCADGui +from UtilsAssembly import tr + def preferences(): return FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Assembly") @@ -34,7 +36,15 @@ class PreferencesPage: self.form = FreeCADGui.PySideUic.loadUi(":preferences/Assembly.ui") def saveSettings(self): - pass + pref = preferences() + pref.SetBool("LeaveEditWithEscape", self.form.checkBoxEnableEscape.isChecked()) + pref.SetInt("GroundFirstPart", self.form.groundFirstPart.currentIndex()) def loadSettings(self): - pass + pref = preferences() + self.form.checkBoxEnableEscape.setChecked(pref.GetBool("LeaveEditWithEscape", True)) + self.form.groundFirstPart.clear() + self.form.groundFirstPart.addItem(tr("Assembly", "Ask")) + self.form.groundFirstPart.addItem(tr("Assembly", "Always")) + self.form.groundFirstPart.addItem(tr("Assembly", "Never")) + self.form.groundFirstPart.setCurrentIndex(pref.GetInt("GroundFirstPart", 0)) diff --git a/src/Mod/Assembly/UtilsAssembly.py b/src/Mod/Assembly/UtilsAssembly.py index 8e623dc737..dfb2e3cb7b 100644 --- a/src/Mod/Assembly/UtilsAssembly.py +++ b/src/Mod/Assembly/UtilsAssembly.py @@ -27,6 +27,10 @@ import Part if App.GuiUp: import FreeCADGui as Gui +import PySide.QtCore as QtCore +import PySide.QtGui as QtGui + + # translate = App.Qt.translate __title__ = "Assembly utilitary functions" @@ -34,6 +38,10 @@ __author__ = "Ondsel" __url__ = "https://www.freecad.org" +def tr(context, text, comment=None): + return QtCore.QCoreApplication.translate(context, text, comment) + + def activeAssembly(): doc = Gui.ActiveDocument