TclCommandIsolate.py 2.5 KB

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