TclCommandAlignDrillGrid.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. from tclCommands.TclCommand import *
  2. class TclCommandAlignDrillGrid(TclCommandSignaled):
  3. """
  4. Tcl shell command to create an Excellon object
  5. with drills for aligment grid.
  6. Todo: What is an alignment grid?
  7. """
  8. # array of all command aliases, to be able use old names for
  9. # backward compatibility (add_poly, add_polygon)
  10. aliases = ['aligndrillgrid']
  11. # Dictionary of types from Tcl command, needs to be ordered.
  12. # For positional arguments
  13. arg_names = collections.OrderedDict([
  14. ('outname', str)
  15. ])
  16. # Dictionary of types from Tcl command, needs to be ordered.
  17. # For options like -optionname value
  18. option_types = collections.OrderedDict([
  19. ('dia', float),
  20. ('gridx', float),
  21. ('gridxoffset', float),
  22. ('gridy', float),
  23. ('gridyoffset', float),
  24. ('columns', int),
  25. ('rows', int)
  26. ])
  27. # array of mandatory options for current Tcl command: required = {'name','outname'}
  28. required = ['outname', 'gridx', 'gridy', 'columns', 'rows']
  29. # structured help for current command, args needs to be ordered
  30. help = {
  31. 'main': "Create excellon with drills for aligment grid.",
  32. 'args': collections.OrderedDict([
  33. ('outname', 'Name of the object to create.'),
  34. ('dia', 'Tool diameter.'),
  35. ('gridx', 'Grid size in X axis.'),
  36. ('gridoffsetx', 'Move grid from origin.'),
  37. ('gridy', 'Grid size in Y axis.'),
  38. ('gridoffsety', 'Move grid from origin.'),
  39. ('colums', 'Number of grid holes on X axis.'),
  40. ('rows', 'Number of grid holes on Y axis.'),
  41. ]),
  42. 'examples': []
  43. }
  44. def execute(self, args, unnamed_args):
  45. """
  46. execute current TCL shell command
  47. :param args: array of known named arguments and options
  48. :param unnamed_args: array of other values which were passed into command
  49. without -somename and we do not have them in known arg_names
  50. :return: None or exception
  51. """
  52. if 'gridoffsetx' not in args:
  53. gridoffsetx = 0
  54. else:
  55. gridoffsetx = args['gridoffsetx']
  56. if 'gridoffsety' not in args:
  57. gridoffsety = 0
  58. else:
  59. gridoffsety = args['gridoffsety']
  60. # Tools
  61. tools = {"1": {"C": args['dia']}}
  62. def aligndrillgrid_init_me(init_obj, app_obj):
  63. """
  64. This function is used to initialize the new
  65. object once it's created.
  66. :param init_obj: The new object.
  67. :param app_obj: The application (FlatCAMApp)
  68. :return: None
  69. """
  70. drills = []
  71. currenty = 0
  72. for row in range(args['rows']):
  73. currentx = 0
  74. for col in range(args['columns']):
  75. point = Point(currentx + gridoffsetx, currenty + gridoffsety)
  76. drills.append({"point": point, "tool": "1"})
  77. currentx = currentx + args['gridx']
  78. currenty = currenty + args['gridy']
  79. init_obj.tools = tools
  80. init_obj.drills = drills
  81. init_obj.create_geometry()
  82. # Create the new object
  83. self.new_object("excellon", args['outname'], aligndrillgrid_init_me)