From 2b5a95f3d08cb3773d664f453f3851c78b2befc7 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Thu, 19 Jun 2025 21:33:14 +0200 Subject: [PATCH] PartDesign: Return to previous feature after edit --- src/Mod/PartDesign/Gui/ViewProvider.cpp | 28 ++++++++-------- src/Mod/PartDesign/Gui/ViewProvider.h | 4 +-- src/Mod/PartDesign/Gui/ViewProviderBody.cpp | 36 ++++++++++++++++++--- src/Mod/PartDesign/Gui/ViewProviderBody.h | 4 +++ 4 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/Mod/PartDesign/Gui/ViewProvider.cpp b/src/Mod/PartDesign/Gui/ViewProvider.cpp index 7b8d88fb3b..a5ad685d3f 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.cpp +++ b/src/Mod/PartDesign/Gui/ViewProvider.cpp @@ -108,14 +108,18 @@ bool ViewProvider::setEdit(int ModNum) msgBox.setInformativeText(QObject::tr("Close this dialog?")); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::Yes); - int ret = msgBox.exec(); - if (ret == QMessageBox::Yes) { + + if (msgBox.exec() == QMessageBox::Yes) { Gui::Control().reject(); } else { return false; } } + previouslyShownViewProvider = dynamic_cast( + Gui::Application::Instance->getViewProvider(getBodyViewProvider()->getShownFeature()) + ); + // clear the selection (convenience) Gui::Selection().clearSelection(); @@ -146,27 +150,21 @@ TaskDlgFeatureParameters *ViewProvider::getEditDialog() { void ViewProvider::unsetEdit(int ModNum) { // return to the WB we were in before editing the PartDesign feature - if (!oldWb.empty()) + if (!oldWb.empty()) { Gui::Command::assureWorkbench(oldWb.c_str()); + } + + // ensure that after edit we still show the same feature + if (previouslyShownViewProvider) { + previouslyShownViewProvider->show(); + } if (ModNum == ViewProvider::Default) { // when pressing ESC make sure to close the dialog -#if 0 - PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); -#endif Gui::Control().closeDialog(); -#if 0 - if ((activeBody != NULL) && (oldTip != NULL)) { - Gui::Selection().clearSelection(); - Gui::Selection().addSelection(oldTip->getDocument()->getName(), oldTip->getNameInDocument()); - Gui::Command::doCommand(Gui::Command::Gui,"FreeCADGui.runCommand('PartDesign_MoveTip')"); - } -#endif - oldTip = nullptr; } else { PartGui::ViewProviderPart::unsetEdit(ModNum); - oldTip = nullptr; } } diff --git a/src/Mod/PartDesign/Gui/ViewProvider.h b/src/Mod/PartDesign/Gui/ViewProvider.h index 6e303a0e6e..773d4aef78 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.h +++ b/src/Mod/PartDesign/Gui/ViewProvider.h @@ -91,8 +91,8 @@ protected: virtual TaskDlgFeatureParameters *getEditDialog(); std::string oldWb; - App::DocumentObject* oldTip{nullptr}; - bool isSetTipIcon{false}; + ViewProvider* previouslyShownViewProvider { nullptr }; + bool isSetTipIcon { false }; }; using ViewProviderPython = Gui::ViewProviderFeaturePythonT; diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index cbd9359127..639e926aa7 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -330,15 +330,43 @@ void ViewProviderBody::setVisualBodyMode(bool bodymode) { } } -std::vector< std::string > ViewProviderBody::getDisplayModes() const { +std::vector ViewProviderBody::getDisplayModes() const +{ - //we get all display modes and remove the "Group" mode, as this is what we use for "Through" - //body display mode - std::vector< std::string > modes = ViewProviderPart::getDisplayModes(); + // we get all display modes and remove the "Group" mode, as this is what we use for "Through" + // body display mode + std::vector modes = ViewProviderPart::getDisplayModes(); modes.erase(modes.begin()); return modes; } +PartDesign::Feature* ViewProviderBody::getShownFeature() const +{ + auto body = static_cast(getObject()); + auto features = body->Group.getValues(); + + for (auto feature : features) { + if (!feature->isDerivedFrom()) { + continue; + } + + if (feature->Visibility.getValue()) { + return static_cast(feature); + } + } + + return nullptr; +} + +Gui::ViewProvider* ViewProviderBody::getShownViewProvider() const +{ + if (const auto* feature = getShownFeature()) { + return Gui::Application::Instance->getViewProvider(feature); + } + + return nullptr; +} + bool ViewProviderBody::canDropObjects() const { // if the BaseFeature property is marked as hidden or read-only then diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.h b/src/Mod/PartDesign/Gui/ViewProviderBody.h index 3e4d331a08..da174dc98c 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.h +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -78,6 +79,9 @@ public: */ SbBox3f getBoundBox (); + PartDesign::Feature* getShownFeature() const; + ViewProvider* getShownViewProvider() const; + /** Check whether objects can be added to the view provider by drag and drop */ bool canDropObjects() const override; /** Check whether the object can be dropped to the view provider by drag and drop */