TclCommandAlignDrillGrid.py 3.5 KB

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