TclCommandFollow.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from tclCommands.TclCommand import *
  2. class TclCommandFollow(TclCommandSignaled):
  3. """
  4. Tcl shell command to follow a Gerber file
  5. """
  6. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  7. aliases = ['follow']
  8. # dictionary of types from Tcl command, needs to be ordered
  9. arg_names = collections.OrderedDict([
  10. ('name', str)
  11. ])
  12. # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  13. option_types = collections.OrderedDict([
  14. ('outname', str)
  15. ])
  16. # array of mandatory options for current Tcl command: required = {'name','outname'}
  17. required = ['name']
  18. # structured help for current command, args needs to be ordered
  19. help = {
  20. 'main': "Creates a geometry object following gerber paths.",
  21. 'args': collections.OrderedDict([
  22. ('name', 'Object name to follow.'),
  23. ('outname', 'Name of the resulting Geometry object.')
  24. ]),
  25. 'examples': ['follow name -outname name_follow']
  26. }
  27. def execute(self, args, unnamed_args):
  28. """
  29. execute current TCL shell command
  30. :param args: array of known named arguments and options
  31. :param unnamed_args: array of other values which were passed into command
  32. without -somename and we do not have them in known arg_names
  33. :return: None or exception
  34. """
  35. name = args['name']
  36. if 'outname' not in args:
  37. follow_name = name + "_follow"
  38. obj = self.app.collection.get_by_name(name)
  39. if obj is None:
  40. self.raise_tcl_error("Object not found: %s" % name)
  41. if not isinstance(obj, FlatCAMGerber):
  42. self.raise_tcl_error('Expected FlatCAMGerber, got %s %s.' % (name, type(obj)))
  43. del args['name']
  44. obj.follow(**args)