TclCommandIsolate.py 2.9 KB

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