- modified the MillDrills and MillSlots TclCommands to accept as parameter a list of tool dimaeters to be milled instead of tool indexes

This commit is contained in:
Marius Stanciu 2019-09-11 17:50:52 +03:00
parent 1ef9e95143
commit 0fc3743e91
3 changed files with 60 additions and 24 deletions

View File

@ -17,6 +17,7 @@ CAD program, and create G-Code for Isolation routing.
- updated code in self.on_view_source() to make it more responsive
- fixed the TclCommand MillHoles
- changed the name of TclCommand MillHoles to MillDrills and added a new TclCommand named MillSlots
- modified the MillDrills and MillSlots TclCommands to accept as parameter a list of tool dimaeters to be milled instead of tool indexes
10.09.2019

View File

@ -21,7 +21,7 @@ class TclCommandMillDrills(TclCommandSignaled):
# Dictionary of types from Tcl command, needs to be ordered.
# This is for options like -optionname value
option_types = collections.OrderedDict([
('tools', str),
('milled_dias', str),
('outname', str),
('tooldia', float),
('use_threads', bool)
@ -35,12 +35,12 @@ class TclCommandMillDrills(TclCommandSignaled):
'main': "Create Geometry Object for milling drill holes from Excellon.",
'args': collections.OrderedDict([
('name', 'Name of the Excellon Object.'),
('tools', 'Comma separated indexes of tools (example: 1,3 or 2).'),
('milled_dias', 'Comma separated tool diameters of the drills to be milled (example: 0.6, 1.0 or 3.125).'),
('tooldia', 'Diameter of the milling tool (example: 0.1).'),
('outname', 'Name of object to create.'),
('use_thread', 'If to use multithreading: True or False.')
]),
'examples': ['millholes mydrills']
'examples': ['milldrills mydrills']
}
def execute(self, args, unnamed_args):
@ -55,22 +55,38 @@ class TclCommandMillDrills(TclCommandSignaled):
name = args['name']
if 'outname' not in args:
args['outname'] = name + "_mill"
try:
if 'tools' in args and args['tools'] != 'all':
# Split and put back. We are passing the whole dictionary later.
args['tools'] = [x.strip() for x in args['tools'].split(",")]
else:
args['tools'] = 'all'
except Exception as e:
self.raise_tcl_error("Bad tools: %s" % str(e))
args['outname'] = name + "_mill_drills"
try:
obj = self.app.collection.get_by_name(str(name))
except:
obj = None
self.raise_tcl_error("Could not retrieve object: %s" % name)
if not obj.drills:
self.raise_tcl_error("The Excellon object has no drills: %s" % name)
try:
if 'milled_dias' in args and args['milled_dias'] != 'all':
diameters = [x.strip() for x in args['tools'].split(",")]
req_tools = []
for tool in obj.tools:
for req_dia in diameters:
if float('%.4f' % float(obj.tools[tool]["C"])) == float('%.4f' % float(req_dia)):
req_tools.append(tool)
args['tools'] = req_tools
# no longer needed
del args['milled_dias']
# Split and put back. We are passing the whole dictionary later.
# args['milled_dias'] = [x.strip() for x in args['tools'].split(",")]
else:
args['tools'] = 'all'
except Exception as e:
self.raise_tcl_error("Bad tools: %s" % str(e))
if not isinstance(obj, FlatCAMExcellon):
self.raise_tcl_error('Only Excellon objects can be mill-drilled, got %s %s.' % (name, type(obj)))
@ -83,8 +99,9 @@ class TclCommandMillDrills(TclCommandSignaled):
# This runs in the background... Is blocking handled?
success, msg = obj.generate_milling_drills(**args)
except Exception as e:
success = None
msg = None
self.raise_tcl_error("Operation failed: %s" % str(e))
if not success:

View File

@ -21,7 +21,7 @@ class TclCommandMillSlots(TclCommandSignaled):
# Dictionary of types from Tcl command, needs to be ordered.
# This is for options like -optionname value
option_types = collections.OrderedDict([
('tools', str),
('milled_dias', str),
('outname', str),
('tooldia', float),
('use_threads', bool)
@ -35,7 +35,7 @@ class TclCommandMillSlots(TclCommandSignaled):
'main': "Create Geometry Object for milling slot holes from Excellon.",
'args': collections.OrderedDict([
('name', 'Name of the Excellon Object.'),
('tools', 'Comma separated indexes of tools (example: 1,3 or 2).'),
('milled_dias', 'Comma separated tool diameters of the slots to be milled (example: 0.6, 1.0 or 3.125).'),
('tooldia', 'Diameter of the milling tool (example: 0.1).'),
('outname', 'Name of object to create.'),
('use_thread', 'If to use multithreading: True or False.')
@ -58,21 +58,37 @@ class TclCommandMillSlots(TclCommandSignaled):
args['outname'] = name + "_mill"
try:
if 'tools' in args and args['tools'] != 'all':
obj = self.app.collection.get_by_name(str(name))
except:
obj = None
self.raise_tcl_error("Could not retrieve object: %s" % name)
if not obj.slots:
self.raise_tcl_error("The Excellon object has no slots: %s" % name)
try:
if 'milled_dias' in args and args['milled_dias'] != 'all':
diameters = [x.strip() for x in args['tools'].split(",")]
req_tools = []
for tool in obj.tools:
for req_dia in diameters:
if float('%.4f' % float(obj.tools[tool]["C"])) == float('%.4f' % float(req_dia)):
req_tools.append(tool)
args['tools'] = req_tools
# no longer needed
del args['milled_dias']
# Split and put back. We are passing the whole dictionary later.
args['tools'] = [x.strip() for x in args['tools'].split(",")]
# args['milled_dias'] = [x.strip() for x in args['tools'].split(",")]
else:
args['tools'] = 'all'
except Exception as e:
self.raise_tcl_error("Bad tools: %s" % str(e))
try:
obj = self.app.collection.get_by_name(str(name))
except:
self.raise_tcl_error("Could not retrieve object: %s" % name)
if not isinstance(obj, FlatCAMExcellon):
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 have mill-slots, got %s %s.' % (name, type(obj)))
if self.app.collection.has_promises():
self.raise_tcl_error('!!!Promises exists, but should not here!!!')
@ -85,6 +101,8 @@ class TclCommandMillSlots(TclCommandSignaled):
success, msg = obj.generate_milling_slots(**args)
except Exception as e:
success = None
msg = None
self.raise_tcl_error("Operation failed: %s" % str(e))
if not success: