TclCommandFollow.py 2.3 KB

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