2019-01-03 19:25:08 +00:00
|
|
|
from tclCommands.TclCommand import TclCommand
|
2020-04-27 09:34:56 +00:00
|
|
|
from flatcamObjects.FlatCAMExcellon import ExcellonObject
|
2019-10-24 23:10:52 +00:00
|
|
|
|
|
|
|
import collections
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TclCommandJoinExcellon(TclCommand):
|
|
|
|
"""
|
|
|
|
Tcl shell command to merge Excellon objects.
|
|
|
|
|
|
|
|
example:
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
# List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
|
|
|
|
aliases = ['join_excellon', 'join_excellons']
|
|
|
|
|
2020-04-13 16:15:20 +00:00
|
|
|
description = '%s %s' % ("--", "Merge two or more Excellon objects drills and create "
|
|
|
|
"a new Excellon object with them.")
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
# Dictionary of types from Tcl command, needs to be ordered
|
|
|
|
arg_names = collections.OrderedDict([
|
|
|
|
('outname', str),
|
|
|
|
])
|
|
|
|
|
|
|
|
# Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
|
|
|
|
option_types = collections.OrderedDict([
|
|
|
|
])
|
|
|
|
|
|
|
|
# array of mandatory options for current Tcl command: required = {'name','outname'}
|
|
|
|
required = ['outname']
|
|
|
|
|
|
|
|
# structured help for current command, args needs to be ordered
|
|
|
|
help = {
|
2020-04-09 01:13:04 +00:00
|
|
|
'main': "Runs a merge operation (join) on the Excellon objects.\n"
|
|
|
|
"The names of the Excellon objects to be merged will be entered after the outname,\n"
|
2020-05-02 12:56:30 +00:00
|
|
|
"separated by spaces. See the example below.\n"
|
2020-04-09 01:13:04 +00:00
|
|
|
"WARNING: if the name of an Excellon objects has spaces, enclose the name with quotes.",
|
2019-01-03 19:25:08 +00:00
|
|
|
'args': collections.OrderedDict([
|
2020-04-09 01:13:04 +00:00
|
|
|
('outname', 'Name of the new Excellon Object made by joining of other Excellon objects. Required'),
|
2019-01-03 19:25:08 +00:00
|
|
|
]),
|
2020-04-09 01:13:04 +00:00
|
|
|
'examples': ['join_excellons merged_new_excellon exc_name_1 "exc name_2"']
|
2019-01-03 19:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def execute(self, args, unnamed_args):
|
|
|
|
"""
|
|
|
|
|
|
|
|
:param args:
|
|
|
|
:param unnamed_args:
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
|
2020-04-09 01:13:04 +00:00
|
|
|
outname = args['outname']
|
2019-01-03 19:25:08 +00:00
|
|
|
obj_names = unnamed_args
|
|
|
|
|
|
|
|
objs = []
|
|
|
|
for obj_n in obj_names:
|
|
|
|
obj = self.app.collection.get_by_name(str(obj_n))
|
|
|
|
if obj is None:
|
|
|
|
return "Object not found: %s" % obj_n
|
|
|
|
else:
|
|
|
|
objs.append(obj)
|
|
|
|
|
|
|
|
def initialize(obj_, app):
|
2020-04-29 08:10:43 +00:00
|
|
|
ExcellonObject.merge(objs, obj_, decimals=self.app.decimals)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2020-04-13 16:15:20 +00:00
|
|
|
if objs and len(objs) >= 2:
|
2019-09-15 22:39:11 +00:00
|
|
|
self.app.new_object("excellon", outname, initialize, plot=False)
|
2020-04-09 01:13:04 +00:00
|
|
|
else:
|
2020-04-13 16:15:20 +00:00
|
|
|
return "No Excellon objects to be joined or less than two Excellon objects specified for merging."
|