diff --git a/src/Mod/Path/PathScripts/post/smoothie_post.py b/src/Mod/Path/PathScripts/post/smoothie_post.py index f07d151762..1bc8218350 100644 --- a/src/Mod/Path/PathScripts/post/smoothie_post.py +++ b/src/Mod/Path/PathScripts/post/smoothie_post.py @@ -33,22 +33,31 @@ import smoothie_post linuxcnc_post.export(object,"/path/to/file.ncc","") ''' -TOOLTIP_ARGS=''' -Arguments for smoothieboard: - --header,--no-header ... output headers (--header) - --comments,--no-comments ... output comments (--comments) - --line-numbers,--no-line-numbers ... prefix with line numbers (--no-lin-numbers) - --show-editor, --no-show-editor ... pop up editor before writing output(--show-editor) - --IP_ADDR ... IP Address for remote sending of gcode - -''' -import FreeCAD -from FreeCAD import Units +import argparse import datetime from PathScripts import PostUtils +import FreeCAD +from FreeCAD import Units +import shlex now = datetime.datetime.now() +parser = argparse.ArgumentParser(prog='linuxcnc', add_help=False) +parser.add_argument('--header', action='store_true', help='output headers (default)') +parser.add_argument('--no-header', action='store_true', help='suppress header output') +parser.add_argument('--comments', action='store_true', help='output comment (default)') +parser.add_argument('--no-comments', action='store_true', help='suppress comment output') +parser.add_argument('--line-numbers', action='store_true', help='prefix with line numbers') +parser.add_argument('--no-line-numbers', action='store_true', help='don\'t prefix with line numbers (default)') +parser.add_argument('--show-editor', action='store_true', help='pop up editor before writing output (default)') +parser.add_argument('--no-show-editor', action='store_true', help='don\'t pop up editor before writing output') +parser.add_argument('--precision', default='4', help='number of digits of precision, default=4') +parser.add_argument('--preamble', help='set commands to be issued before the first command, default="G17\nG90"') +parser.add_argument('--postamble', help='set commands to be issued after the last command, default="M05\nG17 G90\nM2"') +parser.add_argument('--IP_ADDR', help='IP Address for machine target machine') +parser.add_argument('--verbose', action='store_false', help='verbose output for debugging, default="False"') +TOOLTIP_ARGS=parser.format_help() + # These globals set common customization preferences OUTPUT_COMMENTS = True OUTPUT_HEADER = True @@ -79,7 +88,6 @@ PREAMBLE = '''G17 G90 # Postamble text will appear following the last operation. POSTAMBLE = '''M05 -G00 X-1.0 Y1.0 G17 G90 M2 ''' @@ -106,28 +114,44 @@ def processArguments(argstring): global SHOW_EDITOR global IP_ADDR global VERBOSE + global PRECISION + global PREAMBLE + global POSTAMBLE - for arg in argstring.split(): - if arg == '--header': - OUTPUT_HEADER = True - elif arg == '--no-header': + try: + args = parser.parse_args(shlex.split(argstring)) + + if args.no_header: OUTPUT_HEADER = False - elif arg == '--comments': - OUTPUT_COMMENTS = True - elif arg == '--no-comments': + if args.header: + OUTPUT_HEADER = True + if args.no_comments: OUTPUT_COMMENTS = False - elif arg == '--line-numbers': - OUTPUT_LINE_NUMBERS = True - elif arg == '--no-line-numbers': + if args.comments: + OUTPUT_COMMENTS = True + if args.no_line_numbers: OUTPUT_LINE_NUMBERS = False - elif arg == '--show-editor': - SHOW_EDITOR = True - elif arg == '--no-show-editor': + if args.line_numbers: + OUTPUT_LINE_NUMBERS = True + if args.no_show_editor: SHOW_EDITOR = False - elif arg.split('=')[0] == '--IP_ADDR': - IP_ADDR = arg.split('=')[1] - elif arg == '--verbose': - VERBOSE = True + if args.show_editor: + SHOW_EDITOR = True + print("Show editor = %d" % SHOW_EDITOR) + PRECISION = args.precision + if args.preamble is not None: + PREAMBLE = args.preamble + if args.postamble is not None: + POSTAMBLE = args.postamble + + IP_ADDR = args.IP_ADDR + VERBOSE = args.verbose + # elif arg == '--verbose': + # VERBOSE = True + except: + return False + + return True def export(objectslist, filename, argstring): processArguments(argstring)