From 6b69276342de8894f1324e115bf329ce525f78cd Mon Sep 17 00:00:00 2001 From: ml Date: Sun, 23 Oct 2016 02:43:13 -0700 Subject: [PATCH] Fixed post processors and Command constructor (wasn't dealing with parameters being optional). --- src/Mod/Path/App/CommandPyImp.cpp | 14 +++++++------- src/Mod/Path/CMakeLists.txt | 2 ++ src/Mod/Path/PathScripts/PathJob.py | 1 + src/Mod/Path/PathScripts/comparams_post.py | 5 ++++- src/Mod/Path/PathScripts/dynapath_post.py | 2 +- src/Mod/Path/PathScripts/linuxcnc_post.py | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Mod/Path/App/CommandPyImp.cpp b/src/Mod/Path/App/CommandPyImp.cpp index 2054a1967..9f01e703e 100644 --- a/src/Mod/Path/App/CommandPyImp.cpp +++ b/src/Mod/Path/App/CommandPyImp.cpp @@ -52,18 +52,18 @@ std::string CommandPy::representation(void) const str << " ]"; return str.str(); } - + PyObject *CommandPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper { - // create a new instance of CommandPy and the Twin object + // create a new instance of CommandPy and the Twin object return new CommandPy(new Command); } // constructor method int CommandPy::PyInit(PyObject* args, PyObject* kwd) { - PyObject *parameters; + PyObject *parameters = NULL; char *name = ""; static char *kwlist[] = {"name", "parameters", NULL}; if ( PyArg_ParseTupleAndKeywords(args, kwd, "|sO!", kwlist, &name, &PyDict_Type, ¶meters) ) { @@ -73,7 +73,7 @@ int CommandPy::PyInit(PyObject* args, PyObject* kwd) getCommandPtr()->setFromGCode(name); PyObject *key, *value; Py_ssize_t pos = 0; - while (PyDict_Next(parameters, &pos, &key, &value)) { + while (parameters && PyDict_Next(parameters, &pos, &key, &value)) { if ( !PyObject_TypeCheck(key,&(PyString_Type)) || (!PyObject_TypeCheck(value,&(PyFloat_Type)) && !PyObject_TypeCheck(value,&(PyInt_Type))) ) { PyErr_SetString(PyExc_TypeError, "The dictionary can only contain string:number pairs"); return -1; @@ -91,7 +91,7 @@ int CommandPy::PyInit(PyObject* args, PyObject* kwd) return 0; } PyErr_Clear(); // set by PyArg_ParseTuple() - + if ( PyArg_ParseTupleAndKeywords(args, kwd, "|sO!", kwlist, &name, &(Base::PlacementPy::Type), ¶meters) ) { std::string sname(name); boost::to_upper(sname); @@ -222,8 +222,8 @@ PyObject *CommandPy::getCustomAttributes(const char* attr) const int CommandPy::setCustomAttributes(const char* attr, PyObject* obj) { std::string satt(attr); - if (satt.length() == 1) { - if (isalpha(satt[0])) { + if (satt.length() == 1) { + if (isalpha(satt[0])) { boost::to_upper(satt); double cvalue; if (PyObject_TypeCheck(obj,&(PyInt_Type))) { diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index 77ba5fcbb..3742c2170 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -25,6 +25,8 @@ SET(PathScripts_SRCS PathScripts/linuxcnc_post.py PathScripts/centroid_post.py PathScripts/comparams_post.py + PathScripts/dynapath_post.py + PathScripts/generic_post.py PathScripts/dumper_post.py PathScripts/rml_post.py PathScripts/TooltableEditor.py diff --git a/src/Mod/Path/PathScripts/PathJob.py b/src/Mod/Path/PathScripts/PathJob.py index d699d719e..6ea5aa99b 100644 --- a/src/Mod/Path/PathScripts/PathJob.py +++ b/src/Mod/Path/PathScripts/PathJob.py @@ -60,6 +60,7 @@ class ObjectPathJob: posts = glob.glob(path + '/*_post.py') allposts.extend([ str(os.path.split(os.path.splitext(p)[0])[1][:-5]) for p in posts]) + allposts.sort() # obj.addProperty("App::PropertyFile", "PostProcessor", "CodeOutput", "Select the Post Processor file for this project") obj.addProperty("App::PropertyFile", "OutputFile", "CodeOutput", QtCore.QT_TRANSLATE_NOOP("App::Property","The NC output file for this project")) diff --git a/src/Mod/Path/PathScripts/comparams_post.py b/src/Mod/Path/PathScripts/comparams_post.py index 0ac75faf9..766222705 100644 --- a/src/Mod/Path/PathScripts/comparams_post.py +++ b/src/Mod/Path/PathScripts/comparams_post.py @@ -27,6 +27,8 @@ import FreeCAD import Path, PathScripts from PathScripts import PostUtils +SHOW_EDITOR=True + def fmt(num): fnum = "" fnum += '%.3f' % (num) @@ -98,7 +100,8 @@ def export(obj,filename,argstring): gfile.close() else: FreeCAD.Console.PrintError('Select a path object and try again\n') - if obj[0].Editor: + + if SHOW_EDITOR: FreeCAD.Console.PrintMessage('Editor Activated\n') dia = PostUtils.GCodeEditorDialog() dia.editor.setText(gcode) diff --git a/src/Mod/Path/PathScripts/dynapath_post.py b/src/Mod/Path/PathScripts/dynapath_post.py index 427413c02..0571325ce 100644 --- a/src/Mod/Path/PathScripts/dynapath_post.py +++ b/src/Mod/Path/PathScripts/dynapath_post.py @@ -123,7 +123,7 @@ def export(objectslist,filename,argstring): #Find the machine. #The user my have overriden post processor defaults in the GUI. Make sure we're using the current values in the Machine Def. myMachine = None - for pathobj in selection: + for pathobj in objectslist: if hasattr(pathobj,"MachineName"): myMachine = pathobj.MachineName if hasattr(pathobj, "MachineUnits"): diff --git a/src/Mod/Path/PathScripts/linuxcnc_post.py b/src/Mod/Path/PathScripts/linuxcnc_post.py index a0c925084..1d9f00ac3 100644 --- a/src/Mod/Path/PathScripts/linuxcnc_post.py +++ b/src/Mod/Path/PathScripts/linuxcnc_post.py @@ -119,7 +119,7 @@ def export(objectslist, filename, argstring): # The user my have overriden post processor defaults in the GUI. Make # sure we're using the current values in the Machine Def. myMachine = None - for pathobj in selection: + for pathobj in objectslist: if hasattr(pathobj,"MachineName"): myMachine = pathobj.MachineName if hasattr(pathobj, "MachineUnits"):