From dc7de6b195034e8f813e7c88d2e3be2ccd7b2341 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 15 Sep 2020 13:21:32 +0200 Subject: [PATCH] PD: do not use active document in task dialogs because this is error-prone --- .../PartDesign/Gui/TaskFeatureParameters.cpp | 6 +++--- src/Mod/PartDesign/Gui/TaskPipeParameters.cpp | 21 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp index 6e18f38a15..86ff21c778 100644 --- a/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp @@ -27,7 +27,7 @@ #endif #include -#include +#include #include #include #include @@ -110,7 +110,7 @@ bool TaskDlgFeatureParameters::accept() { FCMD_OBJ_HIDE(previous); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); + Gui::cmdAppDocument(feature, "recompute()"); if (!feature->isValid()) { throw Base::RuntimeError(vp->getObject()->getStatusString()); @@ -125,7 +125,7 @@ bool TaskDlgFeatureParameters::accept() { param->detachSelection(); } - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::cmdGuiDocument(feature, "resetEdit()"); Gui::Command::commitCommand(); } catch (const Base::Exception& e) { // Generally the only thing that should fail is feature->isValid() others should be fine diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp index 0a6da45849..61ed52167c 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include #include #include @@ -112,9 +112,11 @@ TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView, bool /*newObj std::vector strings = pipe->Spine.getSubValues(); for (std::vector::const_iterator it = strings.begin(); it != strings.end(); ++it) ui->listWidgetReferences->addItem(QString::fromStdString(*it)); - if(strings.size()>0){ - static_cast(vp)->makeTemporaryVisible(true); + + if (!strings.empty()) { + PipeView->makeTemporaryVisible(true); } + ui->comboBoxTransition->setCurrentIndex(pipe->Transition.getValue()); updateUI(); @@ -134,14 +136,15 @@ TaskPipeParameters::~TaskPipeParameters() svp->setVisible(spineShow); spineShow = false; } + //setting visibility to true is needed when preselecting profile and path prior to invoking sweep - std::string pipeName = pipe->getNameInDocument(); - Gui::Command::doCommand(Gui::Command::Gui,"App.ActiveDocument.%s.ViewObject.Visibility=True",pipeName.c_str()); + Gui::cmdGuiObject(pipe, "Visibility = True"); static_cast(vp)->highlightReferences(false, false); } } - catch (const Base::RuntimeError&) { + catch (const Base::Exception& e) { // getDocument() may raise an exception + e.ReportException(); } delete ui; @@ -401,7 +404,7 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newO this->groupLayout()->addWidget(proxy); PartDesign::Pipe* pipe = static_cast(PipeView->getObject()); - Gui::Document* doc = Gui::Application::Instance->activeDocument(); + Gui::Document* doc = Gui::Application::Instance->getDocument(pipe->getDocument()); //make sure the user sees an important things: the base feature to select edges and the //spine/auxiliary spine he already selected @@ -881,10 +884,10 @@ bool TaskDlgPipeParameters::accept() } try { - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); + Gui::cmdAppDocument(pcPipe, "recompute()"); if (!vp->getObject()->isValid()) throw Base::RuntimeError(vp->getObject()->getStatusString()); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::cmdGuiDocument(pcPipe, "resetEdit()"); Gui::Command::commitCommand(); //we need to add the copied features to the body after the command action, as otherwise FreeCAD crashes unexplainably