TclCommandIsolate.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. description = '%s %s' % ("--", "Creates isolation routing Geometry for the specified Gerber object.")
  17. # dictionary of types from Tcl command, needs to be ordered
  18. arg_names = collections.OrderedDict([
  19. ('name', str)
  20. ])
  21. # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  22. option_types = collections.OrderedDict([
  23. ('dia', float),
  24. ('passes', int),
  25. ('overlap', float),
  26. ('combine', str),
  27. ('outname', str),
  28. ('follow', str),
  29. ('iso_type', int)
  30. ])
  31. # array of mandatory options for current Tcl command: required = {'name','outname'}
  32. required = ['name']
  33. # structured help for current command, args needs to be ordered
  34. help = {
  35. 'main': "Creates isolation routing Geometry for the specified Gerber object.",
  36. 'args': collections.OrderedDict([
  37. ('name', 'Name of the source object. Required.'),
  38. ('dia', 'Tool diameter.'),
  39. ('passes', 'Passes of tool width.'),
  40. ('overlap', 'Percentage of tool diameter to overlap current pass over previous pass. Float [0, 99.9999]\n'
  41. 'E.g: for a 25% from tool diameter overlap use -overlap 25'),
  42. ('combine', 'Combine all passes into one geometry. Can be True (1) or False (0)'),
  43. ('outname', 'Name of the resulting Geometry object.'),
  44. ('follow', 'Create a Geometry that follows the Gerber path. Can be True (1) or False (0).'),
  45. ('iso_type', 'A value of 0 will isolate exteriors, a value of 1 will isolate interiors '
  46. 'and a value of 2 will do full isolation.')
  47. ]),
  48. 'examples': ['isolate my_geo -dia 0.1 -passes 2 -overlap 10 -combine True -iso_type 2 -outname out_geo']
  49. }
  50. def execute(self, args, unnamed_args):
  51. """
  52. execute current TCL shell command
  53. :param args: array of known named arguments and options
  54. :param unnamed_args: array of other values which were passed into command
  55. without -somename and we do not have them in known arg_names
  56. :return: None or exception
  57. """
  58. name = args['name']
  59. if 'outname' not in args:
  60. args['outname'] = name + "_iso"
  61. # if 'timeout' in args:
  62. # timeout = args['timeout']
  63. # else:
  64. # timeout = 10000
  65. if 'follow' not in args:
  66. args['follow'] = None
  67. # evaluate this parameter so True, False, 0 and 1 works
  68. if "combine" in args:
  69. args['combine'] = bool(eval(args['combine']))
  70. else:
  71. args['combine'] = bool(eval(self.app.defaults["gerber_combine_passes"]))
  72. obj = self.app.collection.get_by_name(name)
  73. if obj is None:
  74. self.raise_tcl_error("Object not found: %s" % name)
  75. if not isinstance(obj, FlatCAMGerber):
  76. self.raise_tcl_error('Expected FlatCAMGerber, got %s %s.' % (name, type(obj)))
  77. del args['name']
  78. obj.isolate(plot=False, **args)