remove Application::runPythonCode

This commit is contained in:
wmayer 2016-09-15 23:14:31 +02:00
parent 0ef07032fd
commit afa37847b5
19 changed files with 118 additions and 140 deletions

View File

@ -622,16 +622,15 @@ void Application::exportTo(const char* FileName, const char* DocName, const char
std::string code = str.str(); std::string code = str.str();
// the original file name is required // the original file name is required
if (runPythonCode(code.c_str(), false)) { Gui::Command::runCommand(Gui::Command::App, code.c_str());
// search for a module that is able to open the exported file because otherwise // search for a module that is able to open the exported file because otherwise
// it doesn't need to be added to the recent files list (#0002047) // it doesn't need to be added to the recent files list (#0002047)
std::map<std::string, std::string> importMap = App::GetApplication().getImportFilters(te.c_str()); std::map<std::string, std::string> importMap = App::GetApplication().getImportFilters(te.c_str());
if (!importMap.empty()) if (!importMap.empty())
getMainWindow()->appendRecentFile(QString::fromUtf8(File.filePath().c_str())); getMainWindow()->appendRecentFile(QString::fromUtf8(File.filePath().c_str()));
}
// allow exporters to pass _objs__ to submodules before deleting it // allow exporters to pass _objs__ to submodules before deleting it
runPythonCode("del __objs__", false); Gui::Command::runCommand(Gui::Command::App, "del __objs__");
} }
catch (const Base::PyException& e){ catch (const Base::PyException& e){
// Usually thrown if the file is invalid somehow // Usually thrown if the file is invalid somehow
@ -1363,49 +1362,6 @@ CommandManager &Application::commandManager(void)
return d->commandManager; return d->commandManager;
} }
bool Application::runPythonCode(const char* cmd, bool gui, bool pyexc)
{
if (gui)
d->macroMngr->addLine(MacroManager::Gui,cmd);
else
d->macroMngr->addLine(MacroManager::App,cmd);
try {
Base::Interpreter().runString(cmd);
return true;
}
catch (Base::PyException &e) {
if (pyexc) {
e.ReportException();
Base::Console().Error("Stack Trace: %s\n",e.getStackTrace().c_str());
}
else {
throw; // re-throw to handle in calling instance
}
}
catch (Base::AbortException&) {
}
catch (Base::Exception &e) {
e.ReportException();
}
catch (std::exception &e) {
std::string str;
str += "C++ exception thrown (";
str += e.what();
str += ")";
Base::Console().Error(str.c_str());
}
catch (const char* e) {
Base::Console().Error("%s\n", e);
}
#ifndef FC_DEBUG
catch (...) {
Base::Console().Error("Unknown C++ exception in command thrown\n");
}
#endif
return false;
}
//************************************************************************** //**************************************************************************
// Init, Destruct and ingleton // Init, Destruct and ingleton

View File

@ -178,8 +178,6 @@ public:
Gui::MacroManager *macroManager(void); Gui::MacroManager *macroManager(void);
/// Reference to the command manager /// Reference to the command manager
Gui::CommandManager &commandManager(void); Gui::CommandManager &commandManager(void);
/// Run a Python command
bool runPythonCode(const char* cmd, bool gui=false, bool pyexc=true);
/// helper which create the commands /// helper which create the commands
void createStandardOperations(); void createStandardOperations();
//@} //@}

View File

@ -25,6 +25,7 @@
#ifndef _PreComp_ #ifndef _PreComp_
# include <sstream> # include <sstream>
# include <QApplication> # include <QApplication>
# include <QByteArray>
# include <QDir> # include <QDir>
# include <QKeySequence> # include <QKeySequence>
# include <QMessageBox> # include <QMessageBox>

View File

@ -33,6 +33,8 @@
#include <Base/Type.h> #include <Base/Type.h>
class QWidget; class QWidget;
class QByteArray;
typedef struct _object PyObject; typedef struct _object PyObject;
namespace App namespace App

View File

@ -31,6 +31,7 @@
#include "DlgProjectUtility.h" #include "DlgProjectUtility.h"
#include "Application.h" #include "Application.h"
#include "Command.h"
#include "ui_DlgProjectUtility.h" #include "ui_DlgProjectUtility.h"
@ -140,7 +141,7 @@ void DlgProjectUtility::on_extractButton_clicked()
str << doctools << "\n"; str << doctools << "\n";
str << "extractDocument(\"" << (const char*)source.toUtf8() str << "extractDocument(\"" << (const char*)source.toUtf8()
<< "\", \"" << (const char*)dest.toUtf8() << "\")"; << "\", \"" << (const char*)dest.toUtf8() << "\")";
Application::Instance->runPythonCode(str.str().c_str()); Gui::Command::runCommand(Gui::Command::App, str.str().c_str());
} }
void DlgProjectUtility::on_createButton_clicked() void DlgProjectUtility::on_createButton_clicked()
@ -162,7 +163,7 @@ void DlgProjectUtility::on_createButton_clicked()
str << doctools << "\n"; str << doctools << "\n";
str << "createDocument(\"" << (const char*)source.toUtf8() str << "createDocument(\"" << (const char*)source.toUtf8()
<< "\", \"" << (const char*)dest.toUtf8() << "\")"; << "\", \"" << (const char*)dest.toUtf8() << "\")";
Application::Instance->runPythonCode(str.str().c_str()); Gui::Command::runCommand(Gui::Command::App, str.str().c_str());
if (ui->checkLoadProject->isChecked()) if (ui->checkLoadProject->isChecked())
Application::Instance->open((const char*)dest.toUtf8(),"FreeCAD"); Application::Instance->open((const char*)dest.toUtf8(),"FreeCAD");

View File

@ -57,6 +57,7 @@
#include <App/Document.h> #include <App/Document.h>
#include <Gui/Application.h> #include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/Document.h> #include <Gui/Document.h>
#include <QDomDocument> #include <QDomDocument>
@ -212,7 +213,7 @@ QString DocumentRecovery::createProjectFile(const QString& documentXml)
str << doctools << "\n"; str << doctools << "\n";
str << "createDocument(\"" << (const char*)source.toUtf8() str << "createDocument(\"" << (const char*)source.toUtf8()
<< "\", \"" << (const char*)dest.toUtf8() << "\")"; << "\", \"" << (const char*)dest.toUtf8() << "\")";
Application::Instance->runPythonCode(str.str().c_str()); Gui::Command::runCommand(Gui::Command::App, str.str().c_str());
return dest; return dest;
} }

View File

@ -30,6 +30,7 @@
#include "ui_Placement.h" #include "ui_Placement.h"
#include <Gui/DockWindowManager.h> #include <Gui/DockWindowManager.h>
#include <Gui/Application.h> #include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/Document.h> #include <Gui/Document.h>
#include <Gui/Selection.h> #include <Gui/Selection.h>
#include <Gui/ViewProvider.h> #include <Gui/ViewProvider.h>
@ -230,7 +231,7 @@ void Placement::applyPlacement(const QString& data, bool incremental)
.arg(data); .arg(data);
} }
Application::Instance->runPythonCode((const char*)cmd.toLatin1()); Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1());
} }
} }

View File

@ -46,6 +46,7 @@
#include <App/DocumentObjectGroup.h> #include <App/DocumentObjectGroup.h>
#include "Tree.h" #include "Tree.h"
#include "Command.h"
#include "Document.h" #include "Document.h"
#include "BitmapFactory.h" #include "BitmapFactory.h"
#include "ViewProviderDocumentObject.h" #include "ViewProviderDocumentObject.h"
@ -226,7 +227,7 @@ void TreeWidget::onCreateGroup()
.arg(QString::fromLatin1(doc->getName())).arg(name); .arg(QString::fromLatin1(doc->getName())).arg(name);
Gui::Document* gui = Gui::Application::Instance->getDocument(doc); Gui::Document* gui = Gui::Application::Instance->getDocument(doc);
gui->openCommand("Create group"); gui->openCommand("Create group");
Gui::Application::Instance->runPythonCode(cmd.toUtf8()); Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8());
gui->commitCommand(); gui->commitCommand();
} }
else if (this->contextItem->type() == ObjectType) { else if (this->contextItem->type() == ObjectType) {
@ -241,7 +242,7 @@ void TreeWidget::onCreateGroup()
.arg(name); .arg(name);
Gui::Document* gui = Gui::Application::Instance->getDocument(doc); Gui::Document* gui = Gui::Application::Instance->getDocument(doc);
gui->openCommand("Create group"); gui->openCommand("Create group");
Gui::Application::Instance->runPythonCode(cmd.toUtf8()); Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8());
gui->commitCommand(); gui->commitCommand();
} }
} }

View File

@ -208,7 +208,7 @@ void ViewProviderDocumentObjectGroup::drop(const std::vector<const App::Document
.arg(QString::fromLatin1(doc->getName())) .arg(QString::fromLatin1(doc->getName()))
.arg(QString::fromLatin1(par->getNameInDocument())) .arg(QString::fromLatin1(par->getNameInDocument()))
.arg(QString::fromLatin1(obj->getNameInDocument())); .arg(QString::fromLatin1(obj->getNameInDocument()));
Gui::Application::Instance->runPythonCode(cmd.toUtf8()); Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8());
} }
// build Python command for execution // build Python command for execution
@ -219,7 +219,7 @@ void ViewProviderDocumentObjectGroup::drop(const std::vector<const App::Document
.arg(QString::fromLatin1(grp->getNameInDocument())) .arg(QString::fromLatin1(grp->getNameInDocument()))
.arg(QString::fromLatin1(obj->getNameInDocument())); .arg(QString::fromLatin1(obj->getNameInDocument()));
Gui::Application::Instance->runPythonCode(cmd.toUtf8()); Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8());
} }
gui->commitCommand(); gui->commitCommand();

View File

@ -36,6 +36,7 @@
#include <Base/Tools.h> #include <Base/Tools.h>
#include <Base/Console.h> #include <Base/Console.h>
#include <Base/Interpreter.h>
#include <App/Application.h> #include <App/Application.h>
#include <App/Document.h> #include <App/Document.h>
#include <App/DocumentObject.h> #include <App/DocumentObject.h>
@ -44,6 +45,7 @@
#include <App/PropertyUnits.h> #include <App/PropertyUnits.h>
#include <Gui/Application.h> #include <Gui/Application.h>
#include <Gui/Control.h> #include <Gui/Control.h>
#include <Gui/Command.h>
#include <Gui/Document.h> #include <Gui/Document.h>
#include <Gui/Selection.h> #include <Gui/Selection.h>
#include <Gui/ViewProviderDocumentObject.h> #include <Gui/ViewProviderDocumentObject.h>
@ -53,7 +55,7 @@
#include <Gui/QuantitySpinBox.h> #include <Gui/QuantitySpinBox.h>
#include "PropertyItem.h" #include "PropertyItem.h"
#include <SpinBox.h> #include <Gui/SpinBox.h>
using namespace Gui::PropertyEditor; using namespace Gui::PropertyEditor;
@ -353,7 +355,19 @@ void PropertyItem::setPropertyValue(const QString& value)
App::PropertyContainer* parent = (*it)->getContainer(); App::PropertyContainer* parent = (*it)->getContainer();
if (parent && !parent->isReadOnly(*it) && !(*it)->testStatus(App::Property::ReadOnly)) { if (parent && !parent->isReadOnly(*it) && !(*it)->testStatus(App::Property::ReadOnly)) {
QString cmd = QString::fromLatin1("%1 = %2").arg(pythonIdentifier(*it)).arg(value); QString cmd = QString::fromLatin1("%1 = %2").arg(pythonIdentifier(*it)).arg(value);
Gui::Application::Instance->runPythonCode((const char*)cmd.toUtf8()); try {
Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8());
}
catch (Base::PyException &e) {
e.ReportException();
Base::Console().Error("Stack Trace: %s\n",e.getStackTrace().c_str());
}
catch (Base::Exception &e) {
e.ReportException();
}
catch (...) {
Base::Console().Error("Unknown C++ exception in PropertyItem::setPropertyValue thrown\n");
}
} }
} }
} }

View File

@ -51,6 +51,7 @@
#include <Gui/BitmapFactory.h> #include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h> #include <Gui/ViewProvider.h>
#include <Gui/Application.h> #include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/Document.h> #include <Gui/Document.h>
#include <Gui/View3DInventor.h> #include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h> #include <Gui/View3DInventorViewer.h>
@ -232,29 +233,28 @@ void CrossSections::apply()
section->purgeTouched(); section->purgeTouched();
} }
#else #else
Gui::Application* app = Gui::Application::Instance;
Base::SequencerLauncher seq("Cross-sections...", obj.size() * (d.size() +1)); Base::SequencerLauncher seq("Cross-sections...", obj.size() * (d.size() +1));
app->runPythonCode("import Part\n"); Gui::Command::runCommand(Gui::Command::App, "import Part\n");
app->runPythonCode("from FreeCAD import Base\n"); Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base\n");
for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) { for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) {
App::Document* doc = (*it)->getDocument(); App::Document* doc = (*it)->getDocument();
std::string s = (*it)->getNameInDocument(); std::string s = (*it)->getNameInDocument();
s += "_cs"; s += "_cs";
app->runPythonCode(QString::fromLatin1( Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1(
"wires=list()\n" "wires=list()\n"
"shape=FreeCAD.getDocument(\"%1\").%2.Shape\n") "shape=FreeCAD.getDocument(\"%1\").%2.Shape\n")
.arg(QLatin1String(doc->getName())) .arg(QLatin1String(doc->getName()))
.arg(QLatin1String((*it)->getNameInDocument())).toLatin1()); .arg(QLatin1String((*it)->getNameInDocument())).toLatin1());
for (std::vector<double>::iterator jt = d.begin(); jt != d.end(); ++jt) { for (std::vector<double>::iterator jt = d.begin(); jt != d.end(); ++jt) {
app->runPythonCode(QString::fromLatin1( Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1(
"for i in shape.slice(Base.Vector(%1,%2,%3),%4):\n" "for i in shape.slice(Base.Vector(%1,%2,%3),%4):\n"
" wires.append(i)\n" " wires.append(i)\n"
).arg(a).arg(b).arg(c).arg(*jt).toLatin1()); ).arg(a).arg(b).arg(c).arg(*jt).toLatin1());
seq.next(); seq.next();
} }
app->runPythonCode(QString::fromLatin1( Gui::Command::runCommand(Gui::Command::App, QString::fromLatin1(
"comp=Part.Compound(wires)\n" "comp=Part.Compound(wires)\n"
"slice=FreeCAD.getDocument(\"%1\").addObject(\"Part::Feature\",\"%2\")\n" "slice=FreeCAD.getDocument(\"%1\").addObject(\"Part::Feature\",\"%2\")\n"
"slice.Shape=comp\n" "slice.Shape=comp\n"

View File

@ -936,7 +936,7 @@ bool DlgFilletEdges::accept()
"del __fillets__\n" "del __fillets__\n"
"FreeCADGui.ActiveDocument.%2.Visibility = False\n") "FreeCADGui.ActiveDocument.%2.Visibility = False\n")
.arg(name).arg(shape); .arg(name).arg(shape);
Gui::Application::Instance->runPythonCode((const char*)code.toLatin1()); Gui::Command::runCommand(Gui::Command::App, code.toLatin1());
activeDoc->commitTransaction(); activeDoc->commitTransaction();
activeDoc->recompute(); activeDoc->recompute();
if (d->fillet) { if (d->fillet) {

View File

@ -405,7 +405,7 @@ void DlgRevolution::accept()
.arg(strAxisLink) //%12 .arg(strAxisLink) //%12
.arg(symmetric) //13 .arg(symmetric) //13
; ;
Gui::Application::Instance->runPythonCode((const char*)code.toLatin1()); Gui::Command::runCommand(Gui::Command::App, code.toLatin1());
QByteArray to = name.toLatin1(); QByteArray to = name.toLatin1();
QByteArray from = shape.toLatin1(); QByteArray from = shape.toLatin1();
Gui::Command::copyVisual(to, "ShapeColor", from); Gui::Command::copyVisual(to, "ShapeColor", from);

View File

@ -171,7 +171,7 @@ bool Mirroring::accept()
.arg(this->document).arg(shape).arg(label) .arg(this->document).arg(shape).arg(label)
.arg(normx).arg(normy).arg(normz) .arg(normx).arg(normy).arg(normz)
.arg(basex).arg(basey).arg(basez); .arg(basex).arg(basey).arg(basez);
Gui::Application::Instance->runPythonCode((const char*)code.toLatin1()); Gui::Command::runCommand(Gui::Command::App, code.toLatin1());
QByteArray from = shape.toLatin1(); QByteArray from = shape.toLatin1();
Gui::Command::copyVisual("ActiveObject", "ShapeColor", from); Gui::Command::copyVisual("ActiveObject", "ShapeColor", from);
Gui::Command::copyVisual("ActiveObject", "LineColor", from); Gui::Command::copyVisual("ActiveObject", "LineColor", from);

View File

@ -34,6 +34,7 @@
#include <Gui/Application.h> #include <Gui/Application.h>
#include <Gui/BitmapFactory.h> #include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Document.h> #include <Gui/Document.h>
#include <Gui/Selection.h> #include <Gui/Selection.h>
#include <Gui/ViewProvider.h> #include <Gui/ViewProvider.h>
@ -66,8 +67,8 @@ public:
LoftWidget::LoftWidget(QWidget* parent) LoftWidget::LoftWidget(QWidget* parent)
: d(new Private()) : d(new Private())
{ {
Gui::Application::Instance->runPythonCode("from FreeCAD import Base"); Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base");
Gui::Application::Instance->runPythonCode("import Part"); Gui::Command::runCommand(Gui::Command::App, "import Part");
d->ui.setupUi(this); d->ui.setupUi(this);
d->ui.selector->setAvailableLabel(tr("Vertex/Edge/Wire/Face")); d->ui.selector->setAvailableLabel(tr("Vertex/Edge/Wire/Face"));
@ -175,7 +176,7 @@ bool LoftWidget::accept()
Gui::Document* doc = Gui::Application::Instance->getDocument(d->document.c_str()); Gui::Document* doc = Gui::Application::Instance->getDocument(d->document.c_str());
if (!doc) throw Base::Exception("Document doesn't exist anymore"); if (!doc) throw Base::Exception("Document doesn't exist anymore");
doc->openCommand("Loft"); doc->openCommand("Loft");
Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1());
doc->getDocument()->recompute(); doc->getDocument()->recompute();
App::DocumentObject* obj = doc->getDocument()->getActiveObject(); App::DocumentObject* obj = doc->getDocument()->getActiveObject();
if (obj && !obj->isValid()) { if (obj && !obj->isValid()) {

View File

@ -68,8 +68,8 @@ public:
OffsetWidget::OffsetWidget(Part::Offset* offset, QWidget* parent) OffsetWidget::OffsetWidget(Part::Offset* offset, QWidget* parent)
: d(new Private()) : d(new Private())
{ {
Gui::Application::Instance->runPythonCode("from FreeCAD import Base"); Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base");
Gui::Application::Instance->runPythonCode("import Part"); Gui::Command::runCommand(Gui::Command::App, "import Part");
d->offset = offset; d->offset = offset;
d->ui.setupUi(this); d->ui.setupUi(this);

View File

@ -37,6 +37,7 @@
#include <Gui/Application.h> #include <Gui/Application.h>
#include <Gui/BitmapFactory.h> #include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Document.h> #include <Gui/Document.h>
#include <Gui/Selection.h> #include <Gui/Selection.h>
#include <Gui/SelectionFilter.h> #include <Gui/SelectionFilter.h>
@ -94,6 +95,8 @@ public:
ShapeSelection* gate; ShapeSelection* gate;
Private() Private()
{ {
Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base");
Gui::Command::runCommand(Gui::Command::App, "import Part");
} }
~Private() ~Private()
{ {
@ -105,9 +108,6 @@ public:
ShapeBuilderWidget::ShapeBuilderWidget(QWidget* parent) ShapeBuilderWidget::ShapeBuilderWidget(QWidget* parent)
: d(new Private()) : d(new Private())
{ {
Gui::Application::Instance->runPythonCode("from FreeCAD import Base");
Gui::Application::Instance->runPythonCode("import Part");
d->ui.setupUi(this); d->ui.setupUi(this);
d->ui.label->setText(QString()); d->ui.label->setText(QString());
d->bg.addButton(d->ui.radioButtonEdgeFromVertex, 0); d->bg.addButton(d->ui.radioButtonEdgeFromVertex, 0);
@ -201,7 +201,7 @@ void ShapeBuilderWidget::createEdgeFromVertex()
try { try {
Gui::Application::Instance->activeDocument()->openCommand("Edge"); Gui::Application::Instance->activeDocument()->openCommand("Edge");
Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1());
Gui::Application::Instance->activeDocument()->commitCommand(); Gui::Application::Instance->activeDocument()->commitCommand();
} }
catch (const Base::Exception&) { catch (const Base::Exception&) {
@ -253,7 +253,7 @@ void ShapeBuilderWidget::createFaceFromVertex()
try { try {
Gui::Application::Instance->activeDocument()->openCommand("Face"); Gui::Application::Instance->activeDocument()->openCommand("Face");
Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1());
Gui::Application::Instance->activeDocument()->commitCommand(); Gui::Application::Instance->activeDocument()->commitCommand();
} }
catch (const Base::Exception&) { catch (const Base::Exception&) {
@ -305,7 +305,7 @@ void ShapeBuilderWidget::createFaceFromEdge()
try { try {
Gui::Application::Instance->activeDocument()->openCommand("Face"); Gui::Application::Instance->activeDocument()->openCommand("Face");
Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1());
Gui::Application::Instance->activeDocument()->commitCommand(); Gui::Application::Instance->activeDocument()->commitCommand();
} }
catch (const Base::Exception&) { catch (const Base::Exception&) {
@ -368,7 +368,7 @@ void ShapeBuilderWidget::createShellFromFace()
try { try {
Gui::Application::Instance->activeDocument()->openCommand("Shell"); Gui::Application::Instance->activeDocument()->openCommand("Shell");
Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1());
Gui::Application::Instance->activeDocument()->commitCommand(); Gui::Application::Instance->activeDocument()->commitCommand();
} }
catch (const Base::Exception&) { catch (const Base::Exception&) {
@ -420,7 +420,7 @@ void ShapeBuilderWidget::createSolidFromShell()
try { try {
Gui::Application::Instance->activeDocument()->openCommand("Solid"); Gui::Application::Instance->activeDocument()->openCommand("Solid");
Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1());
Gui::Application::Instance->activeDocument()->commitCommand(); Gui::Application::Instance->activeDocument()->commitCommand();
} }
catch (const Base::Exception&) { catch (const Base::Exception&) {

View File

@ -43,6 +43,7 @@
#include <Gui/Application.h> #include <Gui/Application.h>
#include <Gui/BitmapFactory.h> #include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Document.h> #include <Gui/Document.h>
#include <Gui/Selection.h> #include <Gui/Selection.h>
#include <Gui/SelectionFilter.h> #include <Gui/SelectionFilter.h>
@ -127,8 +128,8 @@ public:
SweepWidget::SweepWidget(QWidget* parent) SweepWidget::SweepWidget(QWidget* parent)
: d(new Private()) : d(new Private())
{ {
Gui::Application::Instance->runPythonCode("from FreeCAD import Base"); Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base");
Gui::Application::Instance->runPythonCode("import Part"); Gui::Command::runCommand(Gui::Command::App, "import Part");
d->ui.setupUi(this); d->ui.setupUi(this);
d->ui.selector->setAvailableLabel(tr("Vertex/Edge/Wire/Face")); d->ui.selector->setAvailableLabel(tr("Vertex/Edge/Wire/Face"));
@ -321,7 +322,7 @@ bool SweepWidget::accept()
Gui::Document* doc = Gui::Application::Instance->getDocument(d->document.c_str()); Gui::Document* doc = Gui::Application::Instance->getDocument(d->document.c_str());
if (!doc) throw Base::Exception("Document doesn't exist anymore"); if (!doc) throw Base::Exception("Document doesn't exist anymore");
doc->openCommand("Sweep"); doc->openCommand("Sweep");
Gui::Application::Instance->runPythonCode((const char*)cmd.toLatin1(), false, false); Gui::Command::runCommand(Gui::Command::App, cmd.toLatin1());
doc->getDocument()->recompute(); doc->getDocument()->recompute();
App::DocumentObject* obj = doc->getDocument()->getActiveObject(); App::DocumentObject* obj = doc->getDocument()->getActiveObject();
if (obj && !obj->isValid()) { if (obj && !obj->isValid()) {

View File

@ -45,6 +45,7 @@
#include <App/Application.h> #include <App/Application.h>
#include <App/Document.h> #include <App/Document.h>
#include <App/DocumentObject.h> #include <App/DocumentObject.h>
#include <Gui/Command.h>
#include <Mod/Part/App/PartFeatures.h> #include <Mod/Part/App/PartFeatures.h>
@ -90,8 +91,8 @@ public:
ThicknessWidget::ThicknessWidget(Part::Thickness* thickness, QWidget* parent) ThicknessWidget::ThicknessWidget(Part::Thickness* thickness, QWidget* parent)
: d(new Private()) : d(new Private())
{ {
Gui::Application::Instance->runPythonCode("from FreeCAD import Base"); Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base");
Gui::Application::Instance->runPythonCode("import Part"); Gui::Command::runCommand(Gui::Command::App, "import Part");
d->thickness = thickness; d->thickness = thickness;
d->ui.setupUi(this); d->ui.setupUi(this);