Skip to content

Commit

Permalink
PD: do not use active document in task dialogs because this is error-…
Browse files Browse the repository at this point in the history
…prone
  • Loading branch information
wwmayer committed Sep 15, 2020
1 parent 74e4a3e commit 1c730a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#endif

#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/CommandT.h>
#include <Gui/MainWindow.h>
#include <Gui/BitmapFactory.h>
#include <Mod/PartDesign/App/Feature.h>
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand Down
21 changes: 12 additions & 9 deletions src/Mod/PartDesign/Gui/TaskPipeParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Gui/CommandT.h>
#include <Gui/MainWindow.h>
#include <Mod/PartDesign/App/FeaturePipe.h>
#include <Mod/Sketcher/App/SketchObject.h>
Expand Down Expand Up @@ -112,9 +112,11 @@ TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView, bool /*newObj
std::vector<std::string> strings = pipe->Spine.getSubValues();
for (std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); ++it)
ui->listWidgetReferences->addItem(QString::fromStdString(*it));
if(strings.size()>0){
static_cast<ViewProviderPipe*>(vp)->makeTemporaryVisible(true);

if (!strings.empty()) {
PipeView->makeTemporaryVisible(true);
}

ui->comboBoxTransition->setCurrentIndex(pipe->Transition.getValue());

updateUI();
Expand All @@ -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<ViewProviderPipe*>(vp)->highlightReferences(false, false);
}
}
catch (const Base::RuntimeError&) {
catch (const Base::Exception& e) {
// getDocument() may raise an exception
e.ReportException();
}

delete ui;
Expand Down Expand Up @@ -401,7 +404,7 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newO
this->groupLayout()->addWidget(proxy);

PartDesign::Pipe* pipe = static_cast<PartDesign::Pipe*>(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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1c730a7

Please sign in to comment.