TclCommandIsolate.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. from tclCommands.TclCommand import TclCommandSignaled
  2. import collections
  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. description = '%s %s' % ("--", "Creates isolation routing Geometry for the specified Gerber object.")
  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', str),
  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 specified Gerber object.",
  35. 'args': collections.OrderedDict([
  36. ('name', 'Name of the Gerber source object to be isolated. Required.'),
  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. Can be True (1) or False (0)'),
  42. ('outname', 'Name of the resulting Geometry object.'),
  43. ('follow', 'Create a Geometry that follows the Gerber path. Can be True (1) or False (0).'),
  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': ['isolate my_gerber -dia 0.1 -passes 2 -overlap 10 -combine True -iso_type 2 -outname out_geo']
  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. # evaluate this parameter so True, False, 0 and 1 works
  67. if 'combine' in args:
  68. try:
  69. par = args['combine'].capitalize()
  70. except AttributeError:
  71. par = args['combine']
  72. args['combine'] = bool(eval(par))
  73. else:
  74. args['combine'] = bool(eval(self.app.defaults["tools_iso_combine_passes"]))
  75. obj = self.app.collection.get_by_name(name)
  76. if obj is None:
  77. self.raise_tcl_error("Object not found: %s" % name)
  78. if obj.kind != 'gerber':
  79. self.raise_tcl_error('Expected GerberObject, got %s %s.' % (name, type(obj)))
  80. del args['name']
  81. obj.isolate(plot=False, **args)