TclCommandAlignDrillGrid.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. ('outname', str)
  16. ])
  17. # Dictionary of types from Tcl command, needs to be ordered.
  18. # For options like -optionname value
  19. option_types = collections.OrderedDict([
  20. ('dia', float),
  21. ('gridx', float),
  22. ('gridxoffset', float),
  23. ('gridy', float),
  24. ('gridyoffset', float),
  25. ('columns', int),
  26. ('rows', int)
  27. ])
  28. # array of mandatory options for current Tcl command: required = {'name','outname'}
  29. required = ['outname', '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': []
  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 'gridoffsetx' not in args:
  54. gridoffsetx = 0
  55. else:
  56. gridoffsetx = args['gridoffsetx']
  57. if 'gridoffsety' not in args:
  58. gridoffsety = 0
  59. else:
  60. gridoffsety = args['gridoffsety']
  61. # Tools
  62. tools = {"1": {"C": args['dia']}}
  63. def aligndrillgrid_init_me(init_obj, app_obj):
  64. """
  65. This function is used to initialize the new
  66. object once it's created.
  67. :param init_obj: The new object.
  68. :param app_obj: The application (FlatCAMApp)
  69. :return: None
  70. """
  71. drills = []
  72. currenty = 0
  73. for row in range(args['rows']):
  74. currentx = 0
  75. for col in range(args['columns']):
  76. point = Point(currentx + gridoffsetx, currenty + gridoffsety)
  77. drills.append({"point": point, "tool": "1"})
  78. currentx = currentx + args['gridx']
  79. currenty = currenty + args['gridy']
  80. init_obj.tools = tools
  81. init_obj.drills = drills
  82. init_obj.create_geometry()
  83. # Create the new object
  84. self.new_object("excellon", args['outname'], aligndrillgrid_init_me)