2019-01-03 19:25:08 +00:00
|
|
|
from ObjectCollection import *
|
|
|
|
from tclCommands.TclCommand import TclCommandSignaled
|
|
|
|
|
2019-09-15 13:46:48 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
class TclCommandDrillcncjob(TclCommandSignaled):
|
|
|
|
"""
|
|
|
|
Tcl shell command to Generates a Drill CNC Job from a Excellon Object.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
|
|
|
|
aliases = ['drillcncjob']
|
|
|
|
|
|
|
|
# dictionary of types from Tcl command, needs to be ordered
|
|
|
|
arg_names = collections.OrderedDict([
|
|
|
|
('name', str)
|
|
|
|
])
|
|
|
|
|
|
|
|
# dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
|
|
|
|
option_types = collections.OrderedDict([
|
2019-09-11 18:40:18 +00:00
|
|
|
('drilled_dias', str),
|
2019-01-03 19:25:08 +00:00
|
|
|
('drillz', float),
|
|
|
|
('travelz', float),
|
|
|
|
('feedrate', float),
|
|
|
|
('feedrate_rapid', float),
|
|
|
|
('spindlespeed', int),
|
|
|
|
('toolchange', bool),
|
|
|
|
('toolchangez', float),
|
2019-09-11 18:40:18 +00:00
|
|
|
('toolchangexy', tuple),
|
2019-01-03 19:25:08 +00:00
|
|
|
('endz', float),
|
2019-09-15 13:46:48 +00:00
|
|
|
('pp', str),
|
2019-01-03 19:25:08 +00:00
|
|
|
('outname', str),
|
2019-09-11 23:07:32 +00:00
|
|
|
('opt_type', str),
|
2019-09-16 01:23:16 +00:00
|
|
|
('diatol', float),
|
|
|
|
('muted', int)
|
2019-01-03 19:25:08 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
# array of mandatory options for current Tcl command: required = {'name','outname'}
|
|
|
|
required = ['name']
|
|
|
|
|
|
|
|
# structured help for current command, args needs to be ordered
|
|
|
|
help = {
|
|
|
|
'main': "Generates a Drill CNC Job from a Excellon Object.",
|
|
|
|
'args': collections.OrderedDict([
|
|
|
|
('name', 'Name of the source object.'),
|
2019-09-11 18:40:18 +00:00
|
|
|
('drilled_dias',
|
|
|
|
'Comma separated tool diameters of the drills to be drilled (example: 0.6, 1.0 or 3.125).'),
|
2019-01-03 19:25:08 +00:00
|
|
|
('drillz', 'Drill depth into material (example: -2.0).'),
|
|
|
|
('travelz', 'Travel distance above material (example: 2.0).'),
|
|
|
|
('feedrate', 'Drilling feed rate.'),
|
|
|
|
('feedrate_rapid', 'Rapid drilling feed rate.'),
|
|
|
|
('spindlespeed', 'Speed of the spindle in rpm (example: 4000).'),
|
|
|
|
('toolchange', 'Enable tool changes (example: True).'),
|
|
|
|
('toolchangez', 'Z distance for toolchange (example: 30.0).'),
|
2019-01-30 23:45:14 +00:00
|
|
|
('toolchangexy', 'X, Y coordonates for toolchange in format (x, y) (example: (2.0, 3.1) ).'),
|
2019-01-03 19:25:08 +00:00
|
|
|
('endz', 'Z distance at job end (example: 30.0).'),
|
2019-09-15 13:46:48 +00:00
|
|
|
('pp', 'This is the Excellon postprocessor name: case_sensitive, no_quotes'),
|
2019-01-03 19:25:08 +00:00
|
|
|
('outname', 'Name of the resulting Geometry object.'),
|
2019-09-11 23:07:32 +00:00
|
|
|
('opt_type', 'Name of move optimization type. B by default for Basic OR-Tools, M for Metaheuristic OR-Tools'
|
|
|
|
'T from Travelling Salesman Algorithm. B and M works only for 64bit version of FlatCAM and '
|
|
|
|
'T works only for 32bit version of FlatCAM'),
|
2019-09-12 14:28:56 +00:00
|
|
|
('diatol', 'Tolerance. Percentange (0.0 ... 100.0) within which dias in drilled_dias will be judged to be '
|
|
|
|
'the same as the ones in the tools from the Excellon object. E.g: if in drill_dias we have a '
|
|
|
|
'diameter with value 1.0, in the Excellon we have a tool with dia = 1.05 and we set a tolerance '
|
|
|
|
'diatol = 5.0 then the drills with the dia = (0.95 ... 1.05) '
|
2019-09-16 01:23:16 +00:00
|
|
|
'in Excellon will be processed. Float number.'),
|
|
|
|
('muted', 'It will not put errors in the Shell or status bar.')
|
2019-01-03 19:25:08 +00:00
|
|
|
]),
|
|
|
|
'examples': ['drillcncjob test.TXT -drillz -1.5 -travelz 14 -feedrate 222 -feedrate_rapid 456 -spindlespeed 777'
|
2019-09-15 13:46:48 +00:00
|
|
|
' -toolchange True -toolchangez 33 -endz 22 -pp default\n'
|
2019-01-03 19:25:08 +00:00
|
|
|
'Usage of -feedrate_rapid matter only when the posptocessor is using it, like -marlin-.']
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
|
|
|
|
name = args['name']
|
|
|
|
|
|
|
|
if 'outname' not in args:
|
|
|
|
args['outname'] = name + "_cnc"
|
|
|
|
|
2019-09-16 01:23:16 +00:00
|
|
|
if 'muted' in args:
|
|
|
|
muted = args['muted']
|
2019-09-16 14:20:56 +00:00
|
|
|
else:
|
|
|
|
muted = 0
|
2019-09-16 01:23:16 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
obj = self.app.collection.get_by_name(name)
|
|
|
|
if obj is None:
|
2019-09-16 23:58:01 +00:00
|
|
|
if muted == 0:
|
|
|
|
self.raise_tcl_error("Object not found: %s" % name)
|
|
|
|
else:
|
|
|
|
return "fail"
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
if not isinstance(obj, FlatCAMExcellon):
|
2019-09-16 23:58:01 +00:00
|
|
|
if muted == 0:
|
2019-09-16 01:23:16 +00:00
|
|
|
self.raise_tcl_error('Expected FlatCAMExcellon, got %s %s.' % (name, type(obj)))
|
|
|
|
else:
|
2019-09-16 23:58:01 +00:00
|
|
|
return "fail"
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-03-17 13:47:17 +00:00
|
|
|
xmin = obj.options['xmin']
|
|
|
|
ymin = obj.options['ymin']
|
|
|
|
xmax = obj.options['xmax']
|
|
|
|
ymax = obj.options['ymax']
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
def job_init(job_obj, app_obj):
|
2019-09-11 18:40:18 +00:00
|
|
|
# tools = args["tools"] if "tools" in args else 'all'
|
|
|
|
units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper()
|
|
|
|
|
|
|
|
try:
|
|
|
|
if 'drilled_dias' in args and args['drilled_dias'] != 'all':
|
|
|
|
diameters = [x.strip() for x in args['drilled_dias'].split(",") if x!= '']
|
|
|
|
nr_diameters = len(diameters)
|
|
|
|
|
2019-09-11 23:07:32 +00:00
|
|
|
req_tools = set()
|
2019-09-11 18:40:18 +00:00
|
|
|
for tool in obj.tools:
|
|
|
|
for req_dia in diameters:
|
|
|
|
obj_dia_form = float('%.2f' % float(obj.tools[tool]["C"])) if units == 'MM' else \
|
|
|
|
float('%.4f' % float(obj.tools[tool]["C"]))
|
|
|
|
req_dia_form = float('%.2f' % float(req_dia)) if units == 'MM' else \
|
|
|
|
float('%.4f' % float(req_dia))
|
|
|
|
|
2019-09-12 14:28:56 +00:00
|
|
|
if 'diatol' in args:
|
|
|
|
tolerance = args['diatol'] / 100
|
2019-09-11 23:07:32 +00:00
|
|
|
|
|
|
|
tolerance = 0.0 if tolerance < 0.0 else tolerance
|
|
|
|
tolerance = 1.0 if tolerance > 1.0 else tolerance
|
|
|
|
if math.isclose(obj_dia_form, req_dia_form, rel_tol=tolerance):
|
|
|
|
req_tools.add(tool)
|
|
|
|
nr_diameters -= 1
|
|
|
|
else:
|
|
|
|
if obj_dia_form == req_dia_form:
|
|
|
|
req_tools.add(tool)
|
|
|
|
nr_diameters -= 1
|
2019-09-11 18:40:18 +00:00
|
|
|
|
|
|
|
if nr_diameters > 0:
|
2019-09-16 23:58:01 +00:00
|
|
|
if muted == 0:
|
2019-09-16 01:23:16 +00:00
|
|
|
self.raise_tcl_error("One or more tool diameters of the drills to be drilled passed to the "
|
|
|
|
"TclCommand are not actual tool diameters in the Excellon object.")
|
|
|
|
else:
|
2019-09-16 23:58:01 +00:00
|
|
|
return "fail"
|
2019-09-11 18:40:18 +00:00
|
|
|
|
|
|
|
# make a string of diameters separated by comma; this is what generate_from_excellon_by_tool() is
|
|
|
|
# expecting as tools parameter
|
|
|
|
tools = ','.join(req_tools)
|
|
|
|
|
|
|
|
# no longer needed
|
|
|
|
del args['drilled_dias']
|
2019-09-12 14:28:56 +00:00
|
|
|
del args['diatol']
|
2019-09-11 18:40:18 +00:00
|
|
|
|
|
|
|
# Split and put back. We are passing the whole dictionary later.
|
|
|
|
# args['milled_dias'] = [x.strip() for x in args['tools'].split(",")]
|
|
|
|
else:
|
|
|
|
tools = 'all'
|
|
|
|
except Exception as e:
|
|
|
|
tools = 'all'
|
2019-09-16 23:58:01 +00:00
|
|
|
|
|
|
|
if muted == 0:
|
|
|
|
self.raise_tcl_error("Bad tools: %s" % str(e))
|
|
|
|
else:
|
|
|
|
return "fail"
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-16 20:27:02 +00:00
|
|
|
drillz = args["drillz"] if "drillz" in args and args["drillz"] else obj.options["drillz"]
|
|
|
|
toolchangez = args["toolchangez"] if "toolchangez" in args and args["toolchangez"] else \
|
|
|
|
obj.options["toolchangez"]
|
|
|
|
endz = args["endz"] if "endz" in args and args["endz"] else obj.options["endz"]
|
2019-09-11 18:40:18 +00:00
|
|
|
toolchange = True if "toolchange" in args and args["toolchange"] == 1 else False
|
2019-09-16 20:27:02 +00:00
|
|
|
opt_type = args["opt_type"] if "opt_type" in args and args["opt_type"] else 'B'
|
2019-09-11 18:40:18 +00:00
|
|
|
|
2019-09-16 20:27:02 +00:00
|
|
|
job_obj.z_move = args["travelz"] if "travelz" in args and args["travelz"] else obj.options["travelz"]
|
|
|
|
job_obj.feedrate = args["feedrate"] if "feedrate" in args and args["feedrate"] else obj.options["feedrate"]
|
2019-01-31 00:50:03 +00:00
|
|
|
job_obj.feedrate_rapid = args["feedrate_rapid"] \
|
2019-09-16 20:27:02 +00:00
|
|
|
if "feedrate_rapid" in args and args["feedrate_rapid"] else obj.options["feedrate_rapid"]
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
job_obj.spindlespeed = args["spindlespeed"] if "spindlespeed" in args else None
|
2019-09-16 20:27:02 +00:00
|
|
|
job_obj.pp_excellon_name = args["pp"] if "pp" in args and args["pp"] \
|
2019-01-03 19:25:08 +00:00
|
|
|
else obj.options["ppname_e"]
|
|
|
|
|
2019-03-17 13:47:17 +00:00
|
|
|
job_obj.coords_decimals = int(self.app.defaults["cncjob_coords_decimals"])
|
|
|
|
job_obj.fr_decimals = int(self.app.defaults["cncjob_fr_decimals"])
|
|
|
|
|
|
|
|
job_obj.options['type'] = 'Excellon'
|
|
|
|
|
2019-09-16 20:27:02 +00:00
|
|
|
job_obj.toolchangexy = args["toolchangexy"] if "toolchangexy" in args and args["toolchangexy"] else \
|
|
|
|
obj.options["toolchangexy"]
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-03-17 13:47:17 +00:00
|
|
|
job_obj.toolchange_xy_type = "excellon"
|
|
|
|
|
|
|
|
job_obj.options['xmin'] = xmin
|
|
|
|
job_obj.options['ymin'] = ymin
|
|
|
|
job_obj.options['xmax'] = xmax
|
|
|
|
job_obj.options['ymax'] = ymax
|
|
|
|
|
2019-01-30 23:45:14 +00:00
|
|
|
job_obj.generate_from_excellon_by_tool(obj, tools, drillz=drillz, toolchangez=toolchangez,
|
|
|
|
endz=endz,
|
2019-01-03 19:25:08 +00:00
|
|
|
toolchange=toolchange, excellon_optimization_type=opt_type)
|
|
|
|
job_obj.gcode_parse()
|
|
|
|
job_obj.create_geometry()
|
|
|
|
|
2019-09-15 22:39:11 +00:00
|
|
|
self.app.new_object("cncjob", args['outname'], job_init, plot=False)
|