PD: do not use active document in task dialogs because this is error-prone

This commit is contained in:
wmayer
2020-09-15 13:21:32 +02:00
parent 74e4a3e976
commit 1c730a7f00
2 changed files with 15 additions and 12 deletions

View File

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

View File

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