TclCommandIsolate.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from tclCommands.TclCommand import TclCommandSignaled
  2. from FlatCAMObj import FlatCAMGerber
  3. import collections
  4. class TclCommandIsolate(TclCommandSignaled):
  5. """
  6. Tcl shell command to Creates isolation routing geometry for the given Gerber.
  7. example:
  8. set_sys units MM
  9. new
  10. open_gerber tests/gerber_files/simple1.gbr -outname margin
  11. isolate margin -dia 3
  12. cncjob margin_iso
  13. """
  14. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  15. aliases = ['isolate']
  16. # dictionary of types from Tcl command, needs to be ordered
  17. arg_names = collections.OrderedDict([
  18. ('name', str)
  19. ])
  20. # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  21. option_types = collections.OrderedDict([
  22. ('dia', float),
  23. ('passes', int),
  24. ('overlap', float),
  25. ('combine', int),
  26. ('outname', str),
  27. ('follow', str),
  28. ('iso_type', int)
  29. ])
  30. # array of mandatory options for current Tcl command: required = {'name','outname'}
  31. required = ['name']
  32. # structured help for current command, args needs to be ordered
  33. help = {
  34. 'main': "Creates isolation routing geometry for the given Gerber.",
  35. 'args': collections.OrderedDict([
  36. ('name', 'Name of the source object.'),
  37. ('dia', 'Tool diameter.'),
  38. ('passes', 'Passes of tool width.'),
  39. ('overlap', 'Fraction of tool diameter to overlap passes.'),
  40. ('combine', 'Combine all passes into one geometry.'),
  41. ('outname', 'Name of the resulting Geometry object.'),
  42. ('follow', 'Create a Geometry that follows the Gerber path.'),
  43. ('iso_type', 'A value of 0 will isolate exteriors, a value of 1 will isolate interiors '
  44. 'and a value of 2 will do full isolation.')
  45. ]),
  46. 'examples': []
  47. }
  48. def execute(self, args, unnamed_args):
  49. """
  50. execute current TCL shell command
  51. :param args: array of known named arguments and options
  52. :param unnamed_args: array of other values which were passed into command
  53. without -somename and we do not have them in known arg_names
  54. :return: None or exception
  55. """
  56. name = args['name']
  57. if 'outname' not in args:
  58. args['outname'] = name + "_iso"
  59. # if 'timeout' in args:
  60. # timeout = args['timeout']
  61. # else:
  62. # timeout = 10000
  63. if 'follow' not in args:
  64. args['follow'] = None
  65. obj = self.app.collection.get_by_name(name)
  66. if obj is None:
  67. self.raise_tcl_error("Object not found: %s" % name)
  68. if not isinstance(obj, FlatCAMGerber):
  69. self.raise_tcl_error('Expected FlatCAMGerber, got %s %s.' % (name, type(obj)))
  70. del args['name']
  71. obj.isolate(plot=False, **args)