소스 검색

- modified the TCL comamand follow to the new architecture. Tested it and
it works without crashes. It can be safely pulled in.

Marius Stanciu 7 년 전
부모
커밋
c67d2f0028
3개의 변경된 파일91개의 추가작업 그리고 28개의 파일을 삭제
  1. 28 28
      FlatCAMApp.py
  2. 62 0
      tclCommands/TclCommandFollow.py
  3. 1 0
      tclCommands/__init__.py

+ 28 - 28
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 <name> [-outname <oname>]\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 <name> [-outname <oname>]\n' +
+            #             '   name: Name of the gerber object.\n' +
+            #             '   outname: Name of the output geometry object.'
+            # },
 
             # 'get_sys': {
             #     'fcn': get_sys,

+ 62 - 0
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)
+
+

+ 1 - 0
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