TclCommandOpenGerber.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from tclCommands.TclCommand import TclCommandSignaled
  2. from camlib import ParseError
  3. import collections
  4. class TclCommandOpenGerber(TclCommandSignaled):
  5. """
  6. Tcl shell command to opens a Gerber file
  7. """
  8. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  9. aliases = ['open_gerber']
  10. description = '%s %s' % ("--", "Opens an Gerber file, parse it and create a Gerber object from it.")
  11. # dictionary of types from Tcl command, needs to be ordered
  12. arg_names = collections.OrderedDict([
  13. ('filename', str)
  14. ])
  15. # dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  16. option_types = collections.OrderedDict([
  17. ('outname', str)
  18. ])
  19. # array of mandatory options for current Tcl command: required = {'name','outname'}
  20. required = ['filename']
  21. # structured help for current command, args needs to be ordered
  22. help = {
  23. 'main': "Opens a Gerber file.",
  24. 'args': collections.OrderedDict([
  25. ('filename', 'Absolute path to file to open. Required.\n'
  26. 'WARNING: no spaces are allowed. If unsure enclose the entire path with quotes.'),
  27. ('outname', 'Name of the resulting Gerber object.')
  28. ]),
  29. 'examples': ["open_gerber gerber_object_path -outname bla",
  30. 'open_gerber "D:\\my_gerber_file with spaces in the name.GRB"']
  31. }
  32. def execute(self, args, unnamed_args):
  33. """
  34. execute current TCL shell command
  35. :param args: array of known named arguments and options
  36. :param unnamed_args: array of other values which were passed into command
  37. without -somename and we do not have them in known arg_names
  38. :return: None or exception
  39. """
  40. if 'follow' in args:
  41. self.raise_tcl_error("The 'follow' parameter is obsolete. To create 'follow' geometry use the 'follow' "
  42. "parameter for the Tcl Command isolate()")
  43. filename = args.pop('filename')
  44. if ' ' in filename:
  45. return "The absolute path to the project file contain spaces which is not allowed.\n" \
  46. "Please enclose the path within quotes."
  47. if 'outname' in args:
  48. outname = args['outname']
  49. else:
  50. outname = filename.split('/')[-1].split('\\')[-1]
  51. args['plot'] = False
  52. args['from_tcl'] = True
  53. self.app.open_gerber(filename, outname, **args)