TclCommandOpenExcellon.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. description = '%s %s' % ("--", "Opens an Excellon file, parse it and create a Excellon object from it.")
  10. # Dictionary of types from Tcl command, needs to be ordered.
  11. # For positional arguments
  12. arg_names = collections.OrderedDict([
  13. ('filename', str)
  14. ])
  15. # Dictionary of types from Tcl command, needs to be ordered.
  16. # For options like -optionname value
  17. option_types = collections.OrderedDict([
  18. ('outname', str)
  19. ])
  20. # array of mandatory options for current Tcl command: required = {'name','outname'}
  21. required = ['filename']
  22. # structured help for current command, args needs to be ordered
  23. help = {
  24. 'main': "Opens an Excellon file, parse it and create a Excellon object from it.",
  25. 'args': collections.OrderedDict([
  26. ('filename', 'Absolute path to file to open. Required.\n'
  27. 'WARNING: no spaces are allowed. If unsure enclose the entire path with quotes.'),
  28. ('outname', 'Name of the resulting Excellon object.')
  29. ]),
  30. 'examples': ['open_excellon D:\\my_excellon_file.DRL',
  31. 'open_excellon "D:\\my_excellon_file with spaces in the name.DRL"',
  32. 'open_excellon path_to_file']
  33. }
  34. def execute(self, args, unnamed_args):
  35. """
  36. execute current TCL shell command
  37. :param args: array of known named arguments and options
  38. :param unnamed_args: array of other values which were passed into command
  39. without -somename and we do not have them in known arg_names
  40. :return: None or exception
  41. """
  42. filename = args.pop('filename')
  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. args['from_tcl'] = True
  48. self.app.f_handlers.open_excellon(filename, **args)