TclCommandOpenExcellon.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from tclCommands.TclCommand import TclCommandSignaled
  2. import collections
  3. class TclCommandOpenExcellon(TclCommandSignaled):
  4. """
  5. Tcl shell command to open an Excellon file.
  6. """
  7. # array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  8. aliases = ['open_excellon']
  9. # Dictionary of types from Tcl command, needs to be ordered.
  10. # For positional arguments
  11. arg_names = collections.OrderedDict([
  12. ('filename', str)
  13. ])
  14. # Dictionary of types from Tcl command, needs to be ordered.
  15. # 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 an Excellon 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 Excellon object.')
  28. ]),
  29. 'examples': ['open_excellon D:\\my_excellon_file.DRL',
  30. 'open_excellon "D:\\my_excellon_file with spaces in the name.DRL"',
  31. 'open_excellon path_to_file']
  32. }
  33. def execute(self, args, unnamed_args):
  34. """
  35. execute current TCL shell command
  36. :param args: array of known named arguments and options
  37. :param unnamed_args: array of other values which were passed into command
  38. without -somename and we do not have them in known arg_names
  39. :return: None or exception
  40. """
  41. filename = args.pop('filename')
  42. # filename = filename.replace(' ', '')
  43. if ' ' in filename:
  44. return "The absolute path to the project file contain spaces which is not allowed.\n" \
  45. "Please enclose the path within quotes."
  46. args['plot'] = False
  47. self.app.open_excellon(filename, **args)