TclCommandIsolate.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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', 'Percentage of tool diameter to overlap current pass over previous pass. Float [0, 99.9999]\n'
  40. 'E.g: for a 25% from tool diameter overlap use -overlap 25'),
  41. ('combine', 'Combine all passes into one geometry.'),
  42. ('outname', 'Name of the resulting Geometry object.'),
  43. ('follow', 'Create a Geometry that follows the Gerber path.'),
  44. ('iso_type', 'A value of 0 will isolate exteriors, a value of 1 will isolate interiors '
  45. 'and a value of 2 will do full isolation.')
  46. ]),
  47. 'examples': []
  48. }
  49. def execute(self, args, unnamed_args):
  50. """
  51. execute current TCL shell command
  52. :param args: array of known named arguments and options
  53. :param unnamed_args: array of other values which were passed into command
  54. without -somename and we do not have them in known arg_names
  55. :return: None or exception
  56. """
  57. name = args['name']
  58. if 'outname' not in args:
  59. args['outname'] = name + "_iso"
  60. # if 'timeout' in args:
  61. # timeout = args['timeout']
  62. # else:
  63. # timeout = 10000
  64. if 'follow' not in args:
  65. args['follow'] = None
  66. obj = self.app.collection.get_by_name(name)
  67. if obj is None:
  68. self.raise_tcl_error("Object not found: %s" % name)
  69. if not isinstance(obj, FlatCAMGerber):
  70. self.raise_tcl_error('Expected FlatCAMGerber, got %s %s.' % (name, type(obj)))
  71. del args['name']
  72. obj.isolate(plot=False, **args)