2019-10-24 23:10:52 +00:00
|
|
|
import collections
|
2019-01-03 19:25:08 +00:00
|
|
|
from tclCommands.TclCommand import TclCommandSignaled
|
|
|
|
|
2019-10-24 23:10:52 +00:00
|
|
|
from shapely.geometry import Point
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
class TclCommandAlignDrillGrid(TclCommandSignaled):
|
|
|
|
"""
|
|
|
|
Tcl shell command to create an Excellon object
|
|
|
|
with drills for aligment grid.
|
|
|
|
|
|
|
|
Todo: What is an alignment grid?
|
|
|
|
"""
|
|
|
|
|
|
|
|
# array of all command aliases, to be able use old names for
|
|
|
|
# backward compatibility (add_poly, add_polygon)
|
|
|
|
aliases = ['aligndrillgrid']
|
|
|
|
|
|
|
|
# Dictionary of types from Tcl command, needs to be ordered.
|
|
|
|
# For positional arguments
|
|
|
|
arg_names = collections.OrderedDict([
|
2019-09-16 00:12:37 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
# Dictionary of types from Tcl command, needs to be ordered.
|
|
|
|
# For options like -optionname value
|
|
|
|
option_types = collections.OrderedDict([
|
|
|
|
('dia', float),
|
|
|
|
('gridx', float),
|
|
|
|
('gridoffsetx', float),
|
|
|
|
('gridy', float),
|
|
|
|
('gridoffsety', float),
|
|
|
|
('columns', int),
|
2019-09-16 00:12:37 +00:00
|
|
|
('rows', int),
|
|
|
|
('outname', str)
|
2019-01-03 19:25:08 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
# array of mandatory options for current Tcl command: required = {'name','outname'}
|
2019-09-16 00:12:37 +00:00
|
|
|
required = ['gridx', 'gridy', 'columns', 'rows']
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
# structured help for current command, args needs to be ordered
|
|
|
|
help = {
|
|
|
|
'main': "Create excellon with drills for aligment grid.",
|
|
|
|
'args': collections.OrderedDict([
|
|
|
|
('outname', 'Name of the object to create.'),
|
|
|
|
('dia', 'Tool diameter.'),
|
|
|
|
('gridx', 'Grid size in X axis.'),
|
|
|
|
('gridoffsetx', 'Move grid from origin.'),
|
|
|
|
('gridy', 'Grid size in Y axis.'),
|
|
|
|
('gridoffsety', 'Move grid from origin.'),
|
|
|
|
('colums', 'Number of grid holes on X axis.'),
|
|
|
|
('rows', 'Number of grid holes on Y axis.'),
|
|
|
|
]),
|
2019-09-16 00:12:37 +00:00
|
|
|
'examples': ['aligndrillgrid -rows 2 -columns 2 -gridoffsetx 10 -gridoffsety 10 -gridx 2.54 -gridy 5.08']
|
2019-01-03 19:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def execute(self, args, unnamed_args):
|
|
|
|
"""
|
|
|
|
execute current TCL shell command
|
|
|
|
|
|
|
|
:param args: array of known named arguments and options
|
|
|
|
:param unnamed_args: array of other values which were passed into command
|
|
|
|
without -somename and we do not have them in known arg_names
|
|
|
|
:return: None or exception
|
|
|
|
"""
|
|
|
|
|
2019-09-16 00:12:37 +00:00
|
|
|
if 'outname' in args:
|
|
|
|
outname = args['outname']
|
|
|
|
else:
|
|
|
|
outname = "new_aligndrill_grid"
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
if 'gridoffsetx' not in args:
|
|
|
|
gridoffsetx = 0
|
|
|
|
else:
|
|
|
|
gridoffsetx = args['gridoffsetx']
|
|
|
|
|
|
|
|
if 'gridoffsety' not in args:
|
|
|
|
gridoffsety = 0
|
|
|
|
else:
|
|
|
|
gridoffsety = args['gridoffsety']
|
|
|
|
|
|
|
|
# Tools
|
|
|
|
tools = {"1": {"C": args['dia']}}
|
|
|
|
|
|
|
|
def aligndrillgrid_init_me(init_obj, app_obj):
|
|
|
|
"""
|
|
|
|
This function is used to initialize the new
|
|
|
|
object once it's created.
|
|
|
|
|
|
|
|
:param init_obj: The new object.
|
|
|
|
:param app_obj: The application (FlatCAMApp)
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
drills = []
|
|
|
|
currenty = 0
|
|
|
|
|
|
|
|
for row in range(args['rows']):
|
|
|
|
currentx = 0
|
|
|
|
|
|
|
|
for col in range(args['columns']):
|
|
|
|
point = Point(currentx + gridoffsetx, currenty + gridoffsety)
|
|
|
|
drills.append({"point": point, "tool": "1"})
|
|
|
|
currentx = currentx + args['gridx']
|
|
|
|
|
|
|
|
currenty = currenty + args['gridy']
|
|
|
|
|
|
|
|
init_obj.tools = tools
|
|
|
|
init_obj.drills = drills
|
|
|
|
init_obj.create_geometry()
|
|
|
|
|
|
|
|
# Create the new object
|
2019-09-16 00:12:37 +00:00
|
|
|
self.app.new_object("excellon", outname, aligndrillgrid_init_me, plot=False)
|