do not use doCommand without using format string, add overloaded method of runCommand

This commit is contained in:
wmayer 2016-09-15 18:53:37 +02:00
parent 1efd9a4b4f
commit f44df3cdf0
17 changed files with 60 additions and 47 deletions

View File

@ -464,7 +464,7 @@ void Command::doCommand(DoCmd_Type eType, const char* sCmd, ...)
}
/// Run a App level Action
void Command::runCommand(DoCmd_Type eType,const char* sCmd)
void Command::runCommand(DoCmd_Type eType, const char* sCmd)
{
if (eType == Gui)
Gui::Application::Instance->macroManager()->addLine(MacroManager::Gui,sCmd);
@ -473,6 +473,16 @@ void Command::runCommand(DoCmd_Type eType,const char* sCmd)
Base::Interpreter().runString(sCmd);
}
/// Run a App level Action
void Command::runCommand(DoCmd_Type eType, const QByteArray& sCmd)
{
if (eType == Gui)
Gui::Application::Instance->macroManager()->addLine(MacroManager::Gui,sCmd.constData());
else
Gui::Application::Instance->macroManager()->addLine(MacroManager::App,sCmd.constData());
Base::Interpreter().runString(sCmd.constData());
}
void Command::addModule(DoCmd_Type eType,const char* sModuleName)
{
if(alreadyLoadedModule.find(sModuleName) == alreadyLoadedModule.end()) {
@ -931,7 +941,7 @@ void PythonCommand::activated(int iMsg)
}
}
else {
doCommand(Doc,Activation.c_str());
runCommand(Doc,Activation.c_str());
}
}

View File

@ -243,6 +243,7 @@ public:
/// Run a App level Action
static void doCommand(DoCmd_Type eType,const char* sCmd,...);
static void runCommand(DoCmd_Type eType,const char* sCmd);
static void runCommand(DoCmd_Type eType,const QByteArray& sCmd);
/// import an external (or own) module only once
static void addModule(DoCmd_Type eType,const char* sModuleName);
/// assures the switch to a certain workbench, if already in the workbench, does nothing.
@ -254,7 +255,9 @@ public:
static std::string getPythonTuple(const std::string& name, const std::vector<std::string>& subnames);
/// translate a string to a python string literal (needed e.g. in file names for windows...)
const std::string strToPython(const char* Str);
const std::string strToPython(const std::string &Str){return strToPython(Str.c_str());};
const std::string strToPython(const std::string &Str){
return strToPython(Str.c_str());
}
//@}
/** @name Helper methods to generate help pages */

View File

@ -404,7 +404,7 @@ void StdCmdNew::activated(int iMsg)
QString cmd;
cmd = QString::fromLatin1("App.newDocument(\"%1\")")
.arg(qApp->translate("StdCmdNew","Unnamed"));
doCommand(Command::Doc,(const char*)cmd.toUtf8());
runCommand(Command::Doc,cmd.toUtf8());
}
//===========================================================================

View File

@ -189,7 +189,7 @@ const QString TaskFemConstraint::makeRefText(const App::DocumentObject* obj, con
void TaskDlgFemConstraint::open()
{
ConstraintView->setVisible(true);
Gui::Command::doCommand(Gui::Command::Doc,ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast<Fem::Constraint*>(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts
Gui::Command::runCommand(Gui::Command::Doc,ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast<Fem::Constraint*>(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts
}
bool TaskDlgFemConstraint::accept()

View File

@ -453,7 +453,7 @@ void TaskDlgFemConstraintContact::open()
QString msg = QObject::tr("Constraint Contact");
Gui::Command::openCommand((const char*)msg.toUtf8());
ConstraintView->setVisible(true);
Gui::Command::doCommand(Gui::Command::Doc,ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast<Fem::Constraint*>(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts
Gui::Command::runCommand(Gui::Command::Doc,ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast<Fem::Constraint*>(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts
}
}

View File

@ -328,7 +328,7 @@ bool Tessellation::accept()
.arg(label);
}
}
Gui::Command::doCommand(Gui::Command::Doc, (const char*)cmd.toUtf8());
Gui::Command::runCommand(Gui::Command::Doc, cmd.toUtf8());
// if Standard mesher is used and face colors should be applied
if (method == 0) { // Standard

View File

@ -1016,7 +1016,7 @@ void CmdPartMakeSolid::activated(int iMsg)
{
std::vector<App::DocumentObject*> objs = Gui::Selection().getObjectsOfType
(Part::Feature::getClassTypeId());
doCommand(Doc, "import Part");
runCommand(Doc, "import Part");
for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) {
const TopoDS_Shape& shape = static_cast<Part::Feature*>(*it)->Shape.getValue();
if (!shape.IsNull()) {
@ -1057,7 +1057,7 @@ void CmdPartMakeSolid::activated(int iMsg)
try {
if (!str.isEmpty())
doCommand(Doc, (const char*)str.toLatin1());
runCommand(Doc, str.toLatin1());
}
catch (const Base::Exception& e) {
Base::Console().Error("Cannot convert %s because %s.\n",
@ -1094,7 +1094,7 @@ void CmdPartReverseShape::activated(int iMsg)
{
std::vector<App::DocumentObject*> objs = Gui::Selection().getObjectsOfType
(Part::Feature::getClassTypeId());
doCommand(Doc, "import Part");
runCommand(Doc, "import Part");
for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) {
const TopoDS_Shape& shape = static_cast<Part::Feature*>(*it)->Shape.getValue();
if (!shape.IsNull()) {
@ -1111,7 +1111,7 @@ void CmdPartReverseShape::activated(int iMsg)
try {
if (!str.isEmpty())
doCommand(Doc, (const char*)str.toLatin1());
runCommand(Doc, str.toLatin1());
}
catch (const Base::Exception& e) {
Base::Console().Error("Cannot convert %s because %s.\n",
@ -1217,7 +1217,7 @@ void CmdPartMakeFace::activated(int iMsg)
str << ")";
doCommand(Doc,str.str().c_str());
runCommand(Doc,str.str().c_str());
commitCommand();
updateActive();
}

View File

@ -27,7 +27,7 @@
# include <QApplication>
# include <QDir>
# include <QFileInfo>
# include <QLineEdit>
# include <QLineEdit>
#endif
#include <Gui/Application.h>
@ -57,13 +57,13 @@ void CmdPartCylinder::activated(int iMsg)
cmd = qApp->translate("CmdPartCylinder","Cylinder");
openCommand((const char*)cmd.toUtf8());
doCommand(Doc,"App.ActiveDocument.addObject(\"Part::Cylinder\",\"Cylinder\")");
runCommand(Doc,"App.ActiveDocument.addObject(\"Part::Cylinder\",\"Cylinder\")");
cmd = QString::fromLatin1("App.ActiveDocument.ActiveObject.Label = \"%1\"")
.arg(qApp->translate("CmdPartCylinder","Cylinder"));
doCommand(Doc,(const char*)cmd.toUtf8());
runCommand(Doc,cmd.toUtf8());
commitCommand();
updateActive();
doCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
}
bool CmdPartCylinder::isActive(void)
@ -97,13 +97,13 @@ void CmdPartBox::activated(int iMsg)
cmd = qApp->translate("CmdPartBox","Cube");
openCommand((const char*)cmd.toUtf8());
doCommand(Doc,"App.ActiveDocument.addObject(\"Part::Box\",\"Box\")");
runCommand(Doc,"App.ActiveDocument.addObject(\"Part::Box\",\"Box\")");
cmd = QString::fromLatin1("App.ActiveDocument.ActiveObject.Label = \"%1\"")
.arg(qApp->translate("CmdPartBox","Cube"));
doCommand(Doc,(const char*)cmd.toUtf8());
runCommand(Doc,cmd.toUtf8());
commitCommand();
updateActive();
doCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
}
bool CmdPartBox::isActive(void)
@ -137,13 +137,13 @@ void CmdPartSphere::activated(int iMsg)
cmd = qApp->translate("CmdPartSphere","Sphere");
openCommand((const char*)cmd.toUtf8());
doCommand(Doc,"App.ActiveDocument.addObject(\"Part::Sphere\",\"Sphere\")");
runCommand(Doc,"App.ActiveDocument.addObject(\"Part::Sphere\",\"Sphere\")");
cmd = QString::fromLatin1("App.ActiveDocument.ActiveObject.Label = \"%1\"")
.arg(qApp->translate("CmdPartSphere","Sphere"));
doCommand(Doc,(const char*)cmd.toUtf8());
runCommand(Doc,cmd.toUtf8());
commitCommand();
updateActive();
doCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
}
bool CmdPartSphere::isActive(void)
@ -177,13 +177,13 @@ void CmdPartCone::activated(int iMsg)
cmd = qApp->translate("CmdPartCone","Cone");
openCommand((const char*)cmd.toUtf8());
doCommand(Doc,"App.ActiveDocument.addObject(\"Part::Cone\",\"Cone\")");
runCommand(Doc,"App.ActiveDocument.addObject(\"Part::Cone\",\"Cone\")");
cmd = QString::fromLatin1("App.ActiveDocument.ActiveObject.Label = \"%1\"")
.arg(qApp->translate("CmdPartCone","Cone"));
doCommand(Doc,(const char*)cmd.toUtf8());
runCommand(Doc,cmd.toUtf8());
commitCommand();
updateActive();
doCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
}
bool CmdPartCone::isActive(void)
@ -217,13 +217,13 @@ void CmdPartTorus::activated(int iMsg)
cmd = qApp->translate("CmdPartTorus","Torus");
openCommand((const char*)cmd.toUtf8());
doCommand(Doc,"App.ActiveDocument.addObject(\"Part::Torus\",\"Torus\")");
runCommand(Doc,"App.ActiveDocument.addObject(\"Part::Torus\",\"Torus\")");
cmd = QString::fromLatin1("App.ActiveDocument.ActiveObject.Label = \"%1\"")
.arg(qApp->translate("CmdPartTorus","Torus"));
doCommand(Doc,(const char*)cmd.toUtf8());
runCommand(Doc,cmd.toUtf8());
commitCommand();
updateActive();
doCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
runCommand(Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
}
bool CmdPartTorus::isActive(void)

View File

@ -100,10 +100,10 @@ void Picker::createPrimitive(QWidget* widget, const QString& descr, Gui::Documen
// Execute the Python block
doc->openCommand(descr.toUtf8());
Gui::Command::doCommand(Gui::Command::Doc, (const char*)cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Doc, cmd.toLatin1());
doc->commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
Gui::Command::doCommand(Gui::Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
Gui::Command::runCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
Gui::Command::runCommand(Gui::Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
}
catch (const Base::Exception& e) {
QMessageBox::warning(widget, descr, QString::fromLatin1(e.what()));
@ -666,10 +666,10 @@ void DlgPrimitives::createPrimitive(const QString& placement)
// Execute the Python block
QString prim = tr("Create %1").arg(ui.comboBox1->currentText());
Gui::Application::Instance->activeDocument()->openCommand(prim.toUtf8());
Gui::Command::doCommand(Gui::Command::Doc, (const char*)cmd.toUtf8());
Gui::Command::runCommand(Gui::Command::Doc, cmd.toUtf8());
Gui::Application::Instance->activeDocument()->commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
Gui::Command::doCommand(Gui::Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
Gui::Command::runCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
Gui::Command::runCommand(Gui::Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
}
catch (const Base::PyException& e) {
QMessageBox::warning(this, tr("Create %1")

View File

@ -327,7 +327,7 @@ bool TaskDlgBooleanParameters::accept()
for (std::vector<std::string>::const_iterator it = bodies.begin(); it != bodies.end(); ++it)
str << "App.ActiveDocument." << *it << ",";
str << "]";
Gui::Command::doCommand(Gui::Command::Doc,str.str().c_str());
Gui::Command::runCommand(Gui::Command::Doc,str.str().c_str());
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Boolean: Accept: Input error"), QString::fromLatin1(e.what()));

View File

@ -219,7 +219,7 @@ bool TaskDlgDressUpParameters::accept()
for (std::vector<std::string>::const_iterator it = refs.begin(); it != refs.end(); ++it)
str << "\"" << *it << "\",";
str << "])";
Gui::Command::doCommand(Gui::Command::Doc,str.str().c_str());
Gui::Command::runCommand(Gui::Command::Doc,str.str().c_str());
return TaskDlgFeatureParameters::accept();
}

View File

@ -588,9 +588,9 @@ void TaskBoxPrimitives::setPrimitive(QString name)
// Execute the Python block
QString prim = tr("Create primitive");
Gui::Application::Instance->activeDocument()->openCommand(prim.toUtf8());
Gui::Command::doCommand(Gui::Command::Doc, (const char*)cmd.toUtf8());
Gui::Command::runCommand(Gui::Command::Doc, cmd.toUtf8());
Gui::Application::Instance->activeDocument()->commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
Gui::Command::runCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
}
catch (const Base::PyException& e) {
QMessageBox::warning(this, tr("Create primitive"), QString::fromLatin1(e.what()));

View File

@ -150,7 +150,7 @@ void CmdRaytracingWriteCamera::activated(int iMsg)
<< "(" << upvec.getValue()[0] <<"," << upvec.getValue()[1] <<"," << upvec.getValue()[2] <<") )" ;
doCommand(Doc,"import Raytracing");
doCommand(Gui,out.str().c_str());
doCommand(Gui,"%s", out.str().c_str());
// Bring ref-count of root-node back to zero to cause the
// destruction of the camera.
@ -201,7 +201,7 @@ void CmdRaytracingWritePart::activated(int iMsg)
<< Name << "\",App.ActiveDocument." << obj.front()->getNameInDocument() << ".Shape)";
doCommand(Doc,"import Raytracing");
doCommand(Doc,out.str().c_str());
doCommand(Doc,"%s",out.str().c_str());
}
bool CmdRaytracingWritePart::isActive(void)

View File

@ -171,7 +171,7 @@ void CmdApproxPlane::activated(int iMsg)
<< "Base.Rotation(" << q0 << "," << q1 << "," << q2 << "," << q3 << "))" << std::endl;
openCommand("Fit plane");
doCommand(Gui::Command::Doc, str.str().c_str());
runCommand(Gui::Command::Doc, str.str().c_str());
commitCommand();
updateActive();
}
@ -251,7 +251,7 @@ void CmdViewTriangulation::activated(int iMsg)
.arg(document)
.arg(object)
;
doCommand(Doc, command.toLatin1());
runCommand(Doc, command.toLatin1());
}
commitCommand();

View File

@ -165,7 +165,7 @@ bool FitBSplineSurfaceWidget::accept()
Gui::WaitCursor wc;
Gui::Command::addModule(Gui::Command::App, "ReverseEngineering");
Gui::Command::openCommand("Fit B-Spline");
Gui::Command::doCommand(Gui::Command::Doc, command.toLatin1());
Gui::Command::runCommand(Gui::Command::Doc, command.toLatin1());
Gui::Command::commitCommand();
Gui::Command::updateActive();
}

View File

@ -99,7 +99,7 @@ bool PoissonWidget::accept()
Gui::WaitCursor wc;
Gui::Command::addModule(Gui::Command::App, "ReverseEngineering");
Gui::Command::openCommand("Poisson reconstruction");
Gui::Command::doCommand(Gui::Command::Doc, command.toLatin1());
Gui::Command::runCommand(Gui::Command::Doc, command.toLatin1());
Gui::Command::commitCommand();
Gui::Command::updateActive();
}

View File

@ -4255,7 +4255,7 @@ bool ViewProviderSketch::setEdit(int ModNum)
);
cmdstr.replace(QString::fromLatin1("{sketch_name}"),QString::fromLatin1(this->getSketchObject()->getNameInDocument()));
QByteArray cmdstr_bytearray = cmdstr.toLatin1();
Gui::Command::doCommand(Gui::Command::Gui, cmdstr_bytearray.data());
Gui::Command::runCommand(Gui::Command::Gui, cmdstr_bytearray);
} catch (Base::PyException &e){
Base::Console().Error("ViewProviderSketch::setEdit: visibility automation failed with an error: \n");
e.ReportException();
@ -4620,7 +4620,7 @@ void ViewProviderSketch::unsetEdit(int ModNum)
);
cmdstr.replace(QString::fromLatin1("{sketch_name}"),QString::fromLatin1(this->getSketchObject()->getNameInDocument()));
QByteArray cmdstr_bytearray = cmdstr.toLatin1();
Gui::Command::doCommand(Gui::Command::Gui, cmdstr_bytearray.data());
Gui::Command::runCommand(Gui::Command::Gui, cmdstr_bytearray);
} catch (Base::PyException &e){
Base::Console().Error("ViewProviderSketch::unsetEdit: visibility automation failed with an error: \n");
e.ReportException();
@ -4667,7 +4667,7 @@ void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int Mo
);
cmdstr.replace(QString::fromLatin1("{sketch_name}"),QString::fromLatin1(this->getSketchObject()->getNameInDocument()));
QByteArray cmdstr_bytearray = cmdstr.toLatin1();
Gui::Command::doCommand(Gui::Command::Gui, cmdstr_bytearray.data());
Gui::Command::runCommand(Gui::Command::Gui, cmdstr_bytearray);
} catch (Base::PyException &e){
Base::Console().Error("ViewProviderSketch::setEdit: visibility automation failed with an error: \n");
e.ReportException();