Support to mill all holes from the command line. Fixes #218.

This commit is contained in:
Juan Pablo Caram 2017-05-05 16:20:14 -04:00
parent 626176a9a4
commit 62f0662083
4 changed files with 42 additions and 21 deletions

View File

@ -824,7 +824,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
""" """
Note: This method is a good template for generic operations as Note: This method is a good template for generic operations as
it takes it's options from parameters or otherwise from the it takes it's options from parameters or otherwise from the
object's options and returns a success, msg tuple as feedback object's options and returns a (success, msg) tuple as feedback
for shell operations. for shell operations.
:return: Success/failure condition tuple (bool, str). :return: Success/failure condition tuple (bool, str).
@ -842,6 +842,13 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
if tooldia is None: if tooldia is None:
tooldia = self.options["tooldia"] tooldia = self.options["tooldia"]
# Sort tools by diameter. items() -> [('name', diameter), ...]
sorted_tools = sorted(self.tools.items(), key=lambda tl: tl[1])
if tools == "all":
tools = [i[0] for i in sorted_tools] # List if ordered tool names.
log.debug("Tools 'all' and sorted are: %s" % str(tools))
if len(tools) == 0: if len(tools) == 0:
self.app.inform.emit("Please select one or more tools from the list and try again.") self.app.inform.emit("Please select one or more tools from the list and try again.")
return False, "Error: No tools." return False, "Error: No tools."

View File

@ -2508,7 +2508,8 @@ class Excellon(Geometry):
""" """
Geometry.__init__(self) Geometry.__init__(self)
# self.tools[name] = {"C": diameter<float>}
self.tools = {} self.tools = {}
self.drills = [] self.drills = []
@ -2958,6 +2959,10 @@ class CNCjob(Geometry):
:type exobj: Excellon :type exobj: Excellon
:param tools: Comma separated tool names :param tools: Comma separated tool names
:type: tools: str :type: tools: str
:param toolchange: Use tool change sequence between tools.
:type toolchange: bool
:param toolchangez: Height at which to perform the tool change.
:type toolchangez: float
:return: None :return: None
:rtype: None :rtype: None
""" """
@ -2966,15 +2971,15 @@ class CNCjob(Geometry):
# Tools # Tools
# sort the tools list by the second item in tuple (here we have a dict with diameter of the tool) # Sort tools by diameter. items() -> [('name', diameter), ...]
# so we actually are sorting the tools by diameter sorted_tools = sorted(exobj.tools.items(), key=lambda tl: tl[1])
sorted_tools = sorted(exobj.tools.items(), key = lambda x: x[1])
if tools == "all": if tools == "all":
tools = [i[0] for i in sorted_tools] # we get a array of ordered tools tools = [i[0] for i in sorted_tools] # List if ordered tool names.
log.debug("Tools 'all' and sorted are: %s" % str(tools)) log.debug("Tools 'all' and sorted are: %s" % str(tools))
else: else:
selected_tools = [x.strip() for x in tools.split(",")] # we strip spaces and also separate the tools by ',' selected_tools = [x.strip() for x in tools.split(",")]
selected_tools = filter(lambda i: i in selected_tools, selected_tools) selected_tools = filter(lambda tl: tl in selected_tools, selected_tools)
# Create a sorted list of selected tools from the sorted_tools list # Create a sorted list of selected tools from the sorted_tools list
tools = [i for i, j in sorted_tools for k in selected_tools if i == k] tools = [i for i, j in sorted_tools for k in selected_tools if i == k]

View File

@ -11,8 +11,8 @@ class TclCommandExportGcode(TclCommand.TclCommandSignaled):
promises and send to background if there are promises. promises and send to background if there are promises.
this export may be catched by tcl and past as preable to another export_gcode or write_gcode This export may be captured and passed as preable
this can be used to join GCODES to another "export_gcode" or "write_gcode" call to join G-Code.
example: example:
set_sys units MM set_sys units MM

View File

@ -15,15 +15,15 @@ class TclCommandMillHoles(TclCommand.TclCommandSignaled):
# Dictionary of types from Tcl command, needs to be ordered # Dictionary of types from Tcl command, needs to be ordered
arg_names = collections.OrderedDict([ arg_names = collections.OrderedDict([
('name', str), ('name', str)
('tools', str),
('tooldia', float),
('outname', str)
]) ])
# Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value # Dictionary of types from Tcl command, needs to be ordered.
# This is for options like -optionname value
option_types = collections.OrderedDict([ option_types = collections.OrderedDict([
('tools', str),
('outname', str),
('tooldia', float)
]) ])
# array of mandatory options for current Tcl command: required = {'name','outname'} # array of mandatory options for current Tcl command: required = {'name','outname'}
@ -38,23 +38,29 @@ class TclCommandMillHoles(TclCommand.TclCommandSignaled):
('tooldia', 'Diameter of the milling tool (example: 0.1).'), ('tooldia', 'Diameter of the milling tool (example: 0.1).'),
('outname', 'Name of object to create.') ('outname', 'Name of object to create.')
]), ]),
'examples': ['scale my_geometry 4.2'] 'examples': ['millholes mydrills']
} }
def execute(self, args, unnamed_args): def execute(self, args, unnamed_args):
""" """
:param args: :param args: array of known named arguments and options
:param unnamed_args: :param unnamed_args: array of other values which were passed into command
:return: without -somename and we do not have them in known arg_names
:return: None or exception
""" """
name = args['name'] name = args['name']
if 'outname' not in args:
args['outname'] = name + "_mill"
try: try:
if 'tools' in args: if 'tools' in args and args['tools'] != 'all':
# Split and put back. We are passing the whole dictionary later. # Split and put back. We are passing the whole dictionary later.
args['tools'] = [x.strip() for x in args['tools'].split(",")] args['tools'] = [x.strip() for x in args['tools'].split(",")]
else:
args['tools'] = 'all'
except Exception as e: except Exception as e:
self.raise_tcl_error("Bad tools: %s" % str(e)) self.raise_tcl_error("Bad tools: %s" % str(e))
@ -67,6 +73,9 @@ class TclCommandMillHoles(TclCommand.TclCommandSignaled):
self.raise_tcl_error('Only Excellon objects can be mill-drilled, got %s %s.' % (name, type(obj))) self.raise_tcl_error('Only Excellon objects can be mill-drilled, got %s %s.' % (name, type(obj)))
try: try:
# 'name' is not an argument of obj.generate_milling()
del args['name']
# This runs in the background... Is blocking handled? # This runs in the background... Is blocking handled?
success, msg = obj.generate_milling(**args) success, msg = obj.generate_milling(**args)