From e28aad0282028fe056d93081eed9995dee895cac Mon Sep 17 00:00:00 2001 From: WHPThomas Date: Thu, 26 Sep 2013 16:24:16 +1000 Subject: [PATCH] Extended macro syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To make macro support in kisslicer easier, GPX macro syntax can either be ;@macro ... or (@macro …) --- gpx.c | 27 +++++++++++++++++++++------ gpx.py | 3 ++- macro-example.gcode | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/gpx.c b/gpx.c index 3a3eb33..f3974b9 100644 --- a/gpx.c +++ b/gpx.c @@ -2610,16 +2610,30 @@ int main(int argc, char * argv[]) // null terminate if(*s) *s++ = 0; parse_macro(macro, normalize_comment(s)); + *p = 0; + break; } } - else { - // Comment - command.comment = normalize_comment(p + 1); - command.flag |= COMMENT_IS_SET; - } + // Comment + command.comment = normalize_comment(p + 1); + command.flag |= COMMENT_IS_SET; *p = 0; + break; } else if(*p == '(') { + if(*(p + 1) == '@') { + char *s = p + 2; + if(isalpha(*s)) { + char *macro = s; + // skip any no space characters + while(*s && !isspace(*s)) s++; + // null terminate + if(*s) *s++ = 0; + parse_macro(macro, normalize_comment(s)); + *p = 0; + break; + } + } // Comment char *s = strchr(p + 1, '('); char *e = strchr(p + 1, ')'); @@ -2638,7 +2652,8 @@ int main(int argc, char * argv[]) fprintf(stderr, "(line %u) Syntax warning: comment is missing closing ')'" EOL, lineNumber); command.comment = normalize_comment(p + 1); command.flag |= COMMENT_IS_SET; - *p = 0; + *p = 0; + break; } } else if(*p == '*') { diff --git a/gpx.py b/gpx.py index d9d0d34..0f3a470 100755 --- a/gpx.py +++ b/gpx.py @@ -24,7 +24,8 @@ x3gFile = profile.getPreference('lastFile') x3gFile = x3gFile[0:x3gFile.rfind('.')] + '.x3g' commandList = [getGpxAppName(), '-p', '-r'] -commandList += ['-m', machineType] +if machineType is not None and machineType != '': + commandList += ['-m', machineType] commandList += [filename, x3gFile] call(commandList) diff --git a/macro-example.gcode b/macro-example.gcode index c3d76ae..54acee8 100644 --- a/macro-example.gcode +++ b/macro-example.gcode @@ -26,7 +26,6 @@ G4 P3500 (pre-prime extruder) G1 X140 Y70 Z0.2 F1100 (do a slow wipe...) G1 X140 Y70 Z0.5 F1100 (...and lift) M108 R0.0 (stop extruder) -;@body (notify GPX body has started) (**** PAUSE @ ZPOS MACROS ****) ;@slicer 1.70mm ;@filament white 1.75mm 230c #FFFFFF (white filament) @@ -35,6 +34,7 @@ M108 R0.0 (stop extruder) ;@start white ;@pause 6.0 blue ;@pause 3.0 red +;@body (notify GPX body has started) (**** end of start.gcode ****) G92 E0 (**** Select Extruder.gcode ****)