TclCommandFollow.py 2.3 KB

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