From c67d2f00288b2c1c09f78f98a1943d3a41000009 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Thu, 31 May 2018 02:09:15 +0300 Subject: [PATCH] - modified the TCL comamand follow to the new architecture. Tested it and it works without crashes. It can be safely pulled in. --- FlatCAMApp.py | 56 ++++++++++++++--------------- tclCommands/TclCommandFollow.py | 62 +++++++++++++++++++++++++++++++++ tclCommands/__init__.py | 1 + 3 files changed, 91 insertions(+), 28 deletions(-) create mode 100644 tclCommands/TclCommandFollow.py diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 84aa5dea..e9e710ac 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -3632,27 +3632,27 @@ class App(QtCore.QObject): return output - def follow(obj_name, *args): - a, kwa = h(*args) - - types = {'outname': str} - - for key in kwa: - if key not in types: - return 'Unknown parameter: %s' % key - kwa[key] = types[key](kwa[key]) - - try: - obj = self.collection.get_by_name(str(obj_name)) - except: - return "Could not retrieve object: %s" % obj_name - if obj is None: - return "Object not found: %s" % obj_name - - try: - obj.follow(**kwa) - except Exception, e: - return "ERROR: %s" % str(e) + # def follow(obj_name, *args): + # a, kwa = h(*args) + # + # types = {'outname': str} + # + # for key in kwa: + # if key not in types: + # return 'Unknown parameter: %s' % key + # kwa[key] = types[key](kwa[key]) + # + # try: + # obj = self.collection.get_by_name(str(obj_name)) + # except: + # return "Could not retrieve object: %s" % obj_name + # if obj is None: + # return "Object not found: %s" % obj_name + # + # try: + # obj.follow(**kwa) + # except Exception, e: + # return "ERROR: %s" % str(e) # def get_sys(param): # if param in self.defaults: @@ -4096,13 +4096,13 @@ class App(QtCore.QObject): 'fcn': make_docs, 'help': 'Prints command rererence in reStructuredText format.' }, - 'follow': { - 'fcn': follow, - 'help': 'Creates a geometry object following gerber paths.\n' + - '> follow [-outname ]\n' + - ' name: Name of the gerber object.\n' + - ' outname: Name of the output geometry object.' - }, + # 'follow': { + # 'fcn': follow, + # 'help': 'Creates a geometry object following gerber paths.\n' + + # '> follow [-outname ]\n' + + # ' name: Name of the gerber object.\n' + + # ' outname: Name of the output geometry object.' + # }, # 'get_sys': { # 'fcn': get_sys, diff --git a/tclCommands/TclCommandFollow.py b/tclCommands/TclCommandFollow.py new file mode 100644 index 00000000..46bc4cb3 --- /dev/null +++ b/tclCommands/TclCommandFollow.py @@ -0,0 +1,62 @@ +from ObjectCollection import * +import TclCommand + + +class TclCommandFollow(TclCommand.TclCommandSignaled): + """ + Tcl shell command to follow a Gerber file + """ + + # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon) + aliases = ['follow'] + + # dictionary of types from Tcl command, needs to be ordered + arg_names = collections.OrderedDict([ + ('name', str) + ]) + + # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value + option_types = collections.OrderedDict([ + ('outname', str) + ]) + + # array of mandatory options for current Tcl command: required = {'name','outname'} + required = ['name'] + + # structured help for current command, args needs to be ordered + help = { + 'main': "Creates a geometry object following gerber paths.", + 'args': collections.OrderedDict([ + ('name', 'Object name to follow.'), + ('outname', 'Name of the resulting Geometry object.') + ]), + 'examples': ['follow name -outname name_follow'] + } + + def execute(self, args, unnamed_args): + """ + execute current TCL shell command + + :param args: array of known named arguments and options + :param unnamed_args: array of other values which were passed into command + without -somename and we do not have them in known arg_names + :return: None or exception + """ + + name = args['name'] + + if 'outname' not in args: + follow_name = name + "_follow" + + obj = self.app.collection.get_by_name(name) + + if obj is None: + self.raise_tcl_error("Object not found: %s" % name) + + if not isinstance(obj, FlatCAMGerber): + self.raise_tcl_error('Expected FlatCAMGerber, got %s %s.' % (name, type(obj))) + + del args['name'] + obj.follow(**args) + + diff --git a/tclCommands/__init__.py b/tclCommands/__init__.py index eaa2c327..37c59131 100644 --- a/tclCommands/__init__.py +++ b/tclCommands/__init__.py @@ -16,6 +16,7 @@ import tclCommands.TclCommandDrillcncjob import tclCommands.TclCommandExportGcode import tclCommands.TclCommandExportSVG import tclCommands.TclCommandExteriors +import tclCommands.TclCommandFollow import tclCommands.TclCommandGeoCutout import tclCommands.TclCommandGeoUnion import tclCommands.TclCommandGetNames