TclCommandFollow.py 2.2 KB

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