CAM: apply precommit
This commit is contained in:
@@ -22,8 +22,8 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <QDir>
|
||||
# include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
@@ -39,37 +39,44 @@
|
||||
#include "ui_DlgProcessorChooser.h"
|
||||
|
||||
|
||||
namespace PathGui {
|
||||
class Module : public Py::ExtensionModule<Module>
|
||||
namespace PathGui
|
||||
{
|
||||
class Module: public Py::ExtensionModule<Module>
|
||||
{
|
||||
public:
|
||||
Module() : Py::ExtensionModule<Module>("PathGui")
|
||||
Module()
|
||||
: Py::ExtensionModule<Module>("PathGui")
|
||||
{
|
||||
add_varargs_method("open",&Module::open,
|
||||
"open(filename): Opens a GCode file as a new document"
|
||||
);
|
||||
add_varargs_method("insert",&Module::insert,
|
||||
"insert(filename,docname): Imports a given GCode file into the given document"
|
||||
);
|
||||
add_varargs_method("export",&Module::exporter,
|
||||
"export(objectslist,filename): Exports a given list of Path objects to a GCode file"
|
||||
);
|
||||
initialize("This module is the PathGui module."); // register with Python
|
||||
add_varargs_method("open",
|
||||
&Module::open,
|
||||
"open(filename): Opens a GCode file as a new document");
|
||||
add_varargs_method(
|
||||
"insert",
|
||||
&Module::insert,
|
||||
"insert(filename,docname): Imports a given GCode file into the given document");
|
||||
add_varargs_method(
|
||||
"export",
|
||||
&Module::exporter,
|
||||
"export(objectslist,filename): Exports a given list of Path objects to a GCode file");
|
||||
initialize("This module is the PathGui module."); // register with Python
|
||||
}
|
||||
|
||||
~Module() override {}
|
||||
~Module() override
|
||||
{}
|
||||
|
||||
private:
|
||||
Py::Object open(const Py::Tuple& args)
|
||||
{
|
||||
char* Name;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "et","utf-8",&Name))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &Name)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
Base::FileInfo fi(EncodedName);
|
||||
if (!fi.exists())
|
||||
if (!fi.exists()) {
|
||||
throw Py::RuntimeError("File not found");
|
||||
}
|
||||
|
||||
Gui::WaitCursor wc;
|
||||
wc.restoreCursor();
|
||||
@@ -78,8 +85,10 @@ private:
|
||||
std::string path = App::Application::getHomePath();
|
||||
path += "Mod/CAM/Path/Post/scripts/";
|
||||
QDir dir1(QString::fromUtf8(path.c_str()), QString::fromLatin1("*_pre.py"));
|
||||
std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
||||
->GetASCII("MacroPath",App::Application::getUserMacroDir().c_str());
|
||||
std::string cMacroPath =
|
||||
App::GetApplication()
|
||||
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
||||
->GetASCII("MacroPath", App::Application::getUserMacroDir().c_str());
|
||||
QDir dir2(QString::fromUtf8(cMacroPath.c_str()), QString::fromLatin1("*_pre.py"));
|
||||
QFileInfoList list = dir1.entryInfoList();
|
||||
list << dir2.entryInfoList();
|
||||
@@ -98,22 +107,24 @@ private:
|
||||
std::ostringstream pre;
|
||||
std::ostringstream cmd;
|
||||
if (processor.empty()) {
|
||||
App::Document *pcDoc = App::GetApplication().newDocument();
|
||||
Gui::Command::runCommand(Gui::Command::Gui,"import Path");
|
||||
App::Document* pcDoc = App::GetApplication().newDocument();
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "import Path");
|
||||
cmd << "Path.read(\"" << EncodedName << "\",\"" << pcDoc->getName() << "\")";
|
||||
Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
|
||||
} else {
|
||||
Gui::Command::runCommand(Gui::Command::Gui, cmd.str().c_str());
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
QFileInfo fileInfo = list.at(i);
|
||||
if (fileInfo.baseName().toStdString() == processor) {
|
||||
if (fileInfo.absoluteFilePath().contains(QString::fromLatin1("scripts"))) {
|
||||
pre << "from Path.Post.scripts import " << processor;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
pre << "import " << processor;
|
||||
}
|
||||
Gui::Command::runCommand(Gui::Command::Gui,pre.str().c_str());
|
||||
Gui::Command::runCommand(Gui::Command::Gui, pre.str().c_str());
|
||||
cmd << processor << ".open(\"" << EncodedName << "\")";
|
||||
Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
|
||||
Gui::Command::runCommand(Gui::Command::Gui, cmd.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,15 +139,17 @@ private:
|
||||
Py::Object insert(const Py::Tuple& args)
|
||||
{
|
||||
char* Name;
|
||||
char* DocName=nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&DocName))
|
||||
char* DocName = nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "et|s", "utf-8", &Name, &DocName)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
Base::FileInfo fi(EncodedName);
|
||||
if (!fi.exists())
|
||||
if (!fi.exists()) {
|
||||
throw Py::RuntimeError("File not found");
|
||||
}
|
||||
|
||||
Gui::WaitCursor wc;
|
||||
wc.restoreCursor();
|
||||
@@ -145,8 +158,10 @@ private:
|
||||
std::string path = App::Application::getHomePath();
|
||||
path += "Mod/CAM/Path/Post/scripts/";
|
||||
QDir dir1(QString::fromUtf8(path.c_str()), QString::fromLatin1("*_pre.py"));
|
||||
std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
||||
->GetASCII("MacroPath",App::Application::getUserMacroDir().c_str());
|
||||
std::string cMacroPath =
|
||||
App::GetApplication()
|
||||
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
||||
->GetASCII("MacroPath", App::Application::getUserMacroDir().c_str());
|
||||
QDir dir2(QString::fromUtf8(cMacroPath.c_str()), QString::fromLatin1("*_pre.py"));
|
||||
QFileInfoList list = dir1.entryInfoList();
|
||||
list << dir2.entryInfoList();
|
||||
@@ -162,11 +177,13 @@ private:
|
||||
}
|
||||
processor = Dlg.getProcessor();
|
||||
|
||||
App::Document *pcDoc = nullptr;
|
||||
if (DocName)
|
||||
App::Document* pcDoc = nullptr;
|
||||
if (DocName) {
|
||||
pcDoc = App::GetApplication().getDocument(DocName);
|
||||
else
|
||||
}
|
||||
else {
|
||||
pcDoc = App::GetApplication().getActiveDocument();
|
||||
}
|
||||
|
||||
if (!pcDoc) {
|
||||
pcDoc = App::GetApplication().newDocument(DocName);
|
||||
@@ -175,21 +192,24 @@ private:
|
||||
std::ostringstream pre;
|
||||
std::ostringstream cmd;
|
||||
if (processor.empty()) {
|
||||
Gui::Command::runCommand(Gui::Command::Gui,"import Path");
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "import Path");
|
||||
cmd << "Path.read(\"" << EncodedName << "\",\"" << pcDoc->getName() << "\")";
|
||||
Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
|
||||
} else {
|
||||
Gui::Command::runCommand(Gui::Command::Gui, cmd.str().c_str());
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
QFileInfo fileInfo = list.at(i);
|
||||
if (fileInfo.baseName().toStdString() == processor) {
|
||||
if (fileInfo.absoluteFilePath().contains(QString::fromLatin1("scripts"))) {
|
||||
pre << "from Path.Post.scripts import " << processor;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
pre << "import " << processor;
|
||||
}
|
||||
Gui::Command::runCommand(Gui::Command::Gui,pre.str().c_str());
|
||||
cmd << processor << ".insert(\"" << EncodedName << "\",\"" << pcDoc->getName() << "\")";
|
||||
Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
|
||||
Gui::Command::runCommand(Gui::Command::Gui, pre.str().c_str());
|
||||
cmd << processor << ".insert(\"" << EncodedName << "\",\""
|
||||
<< pcDoc->getName() << "\")";
|
||||
Gui::Command::runCommand(Gui::Command::Gui, cmd.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,8 +225,9 @@ private:
|
||||
{
|
||||
PyObject* object;
|
||||
char* Name;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "Oet",&object,"utf-8",&Name))
|
||||
if (!PyArg_ParseTuple(args.ptr(), "Oet", &object, "utf-8", &Name)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
@@ -215,14 +236,17 @@ private:
|
||||
|
||||
try {
|
||||
Py::Sequence objlist(object);
|
||||
if (objlist.size() == 0)
|
||||
if (objlist.size() == 0) {
|
||||
throw Py::RuntimeError("No object to export");
|
||||
}
|
||||
|
||||
std::string path = App::Application::getHomePath();
|
||||
path += "Mod/CAM/Path/Post/scripts/";
|
||||
QDir dir1(QString::fromUtf8(path.c_str()), QString::fromLatin1("*_post.py"));
|
||||
std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
||||
->GetASCII("MacroPath",App::Application::getUserMacroDir().c_str());
|
||||
std::string cMacroPath =
|
||||
App::GetApplication()
|
||||
.GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
|
||||
->GetASCII("MacroPath", App::Application::getUserMacroDir().c_str());
|
||||
QDir dir2(QString::fromUtf8(cMacroPath.c_str()), QString::fromLatin1("*_post.py"));
|
||||
QFileInfoList list = dir1.entryInfoList();
|
||||
list << dir2.entryInfoList();
|
||||
@@ -242,30 +266,38 @@ private:
|
||||
std::ostringstream cmd;
|
||||
if (processor.empty()) {
|
||||
if (objlist.size() > 1) {
|
||||
throw Py::RuntimeError("Cannot export more than one object without using a post script");
|
||||
throw Py::RuntimeError(
|
||||
"Cannot export more than one object without using a post script");
|
||||
}
|
||||
PyObject* item = objlist[0].ptr();
|
||||
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
||||
App::DocumentObject* obj =
|
||||
static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
||||
App::Document* doc = obj->getDocument();
|
||||
Gui::Command::runCommand(Gui::Command::Gui,"import Path");
|
||||
cmd << "Path.write(FreeCAD.getDocument(\"" << doc->getName() << "\").getObject(\"" << obj->getNameInDocument() << "\"),\"" << EncodedName << "\")";
|
||||
Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
|
||||
} else {
|
||||
Gui::Command::runCommand(Gui::Command::Gui, "import Path");
|
||||
cmd << "Path.write(FreeCAD.getDocument(\"" << doc->getName()
|
||||
<< "\").getObject(\"" << obj->getNameInDocument() << "\"),\"" << EncodedName
|
||||
<< "\")";
|
||||
Gui::Command::runCommand(Gui::Command::Gui, cmd.str().c_str());
|
||||
}
|
||||
else {
|
||||
return Py::None();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
QFileInfo fileInfo = list.at(i);
|
||||
if (fileInfo.baseName().toStdString() == processor) {
|
||||
if (fileInfo.absoluteFilePath().contains(QString::fromLatin1("scripts"))) {
|
||||
pre << "from Path.Post.scripts import " << processor;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
pre << "import " << processor;
|
||||
}
|
||||
Gui::Command::runCommand(Gui::Command::Gui,pre.str().c_str());
|
||||
cmd << processor << ".export(__objs__,\"" << EncodedName << "\",\"" << arguments << "\")";
|
||||
Gui::Command::runCommand(Gui::Command::Gui,cmd.str().c_str());
|
||||
Gui::Command::runCommand(Gui::Command::Gui, pre.str().c_str());
|
||||
cmd << processor << ".export(__objs__,\"" << EncodedName << "\",\""
|
||||
<< arguments << "\")";
|
||||
Gui::Command::runCommand(Gui::Command::Gui, cmd.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,4 +315,4 @@ PyObject* initModule()
|
||||
return Base::Interpreter().addModule(new Module);
|
||||
}
|
||||
|
||||
} // namespace PathGui
|
||||
} // namespace PathGui
|
||||
|
||||
Reference in New Issue
Block a user