2019-01-03 19:25:08 +00:00
|
|
|
from tclCommands.TclCommand import TclCommandSignaled
|
2019-10-24 23:10:52 +00:00
|
|
|
|
|
|
|
import collections
|
|
|
|
from copy import deepcopy
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TclCommandCncjob(TclCommandSignaled):
|
|
|
|
"""
|
|
|
|
Tcl shell command to Generates a CNC Job from a Geometry Object.
|
|
|
|
|
|
|
|
example:
|
|
|
|
set_sys units MM
|
|
|
|
new
|
|
|
|
open_gerber tests/gerber_files/simple1.gbr -outname margin
|
|
|
|
isolate margin -dia 3
|
|
|
|
cncjob margin_iso
|
|
|
|
"""
|
|
|
|
|
|
|
|
# array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
|
|
|
|
aliases = ['cncjob']
|
|
|
|
|
2020-04-13 16:15:20 +00:00
|
|
|
description = '%s %s' % ("--", "Generates a CNC Job object from a Geometry Object.")
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
# 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-16 14:20:56 +00:00
|
|
|
('dia', float),
|
2019-01-03 19:25:08 +00:00
|
|
|
('z_cut', float),
|
|
|
|
('z_move', float),
|
|
|
|
('feedrate', float),
|
2019-09-15 02:00:20 +00:00
|
|
|
('feedrate_z', float),
|
2019-01-03 19:25:08 +00:00
|
|
|
('feedrate_rapid', float),
|
2019-12-10 03:28:02 +00:00
|
|
|
('extracut_length', float),
|
2020-04-13 20:43:48 +00:00
|
|
|
('dpp', float),
|
2019-08-25 21:40:35 +00:00
|
|
|
('toolchangez', float),
|
|
|
|
('toolchangexy', tuple),
|
2019-09-15 02:00:20 +00:00
|
|
|
('startz', float),
|
2019-01-03 19:25:08 +00:00
|
|
|
('endz', float),
|
2019-09-15 02:00:20 +00:00
|
|
|
('spindlespeed', int),
|
|
|
|
('dwelltime', float),
|
2019-09-15 13:46:48 +00:00
|
|
|
('pp', str),
|
2020-04-13 16:15:20 +00:00
|
|
|
('muted', str),
|
2019-01-03 19:25:08 +00:00
|
|
|
('outname', str)
|
|
|
|
])
|
|
|
|
|
|
|
|
# array of mandatory options for current Tcl command: required = {'name','outname'}
|
2019-10-02 14:58:48 +00:00
|
|
|
required = []
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
# structured help for current command, args needs to be ordered
|
|
|
|
help = {
|
2020-04-13 16:15:20 +00:00
|
|
|
'main': "Generates a CNC Job object from a Geometry Object.",
|
2019-01-03 19:25:08 +00:00
|
|
|
'args': collections.OrderedDict([
|
|
|
|
('name', 'Name of the source object.'),
|
2019-09-16 14:20:56 +00:00
|
|
|
('dia', 'Tool diameter to show on screen.'),
|
2019-01-03 19:25:08 +00:00
|
|
|
('z_cut', 'Z-axis cutting position.'),
|
|
|
|
('z_move', 'Z-axis moving position.'),
|
2019-09-15 02:00:20 +00:00
|
|
|
('feedrate', 'Moving speed on X-Y plane when cutting.'),
|
|
|
|
('feedrate_z', 'Moving speed on Z plane when cutting.'),
|
2019-01-03 19:25:08 +00:00
|
|
|
('feedrate_rapid', 'Rapid moving at speed when cutting.'),
|
2020-01-01 19:17:47 +00:00
|
|
|
('extracut_length', 'The value for extra cnccut over the first point in path,in the job end; float'),
|
2020-04-13 20:43:48 +00:00
|
|
|
('dpp', 'If present then use multidepth cnc cut. Height of one layer for multidepth.'),
|
2020-01-01 18:42:59 +00:00
|
|
|
('toolchangez', 'Z distance for toolchange (example: 30.0).\n'
|
|
|
|
'If used in the command then a toolchange event will be included in gcode'),
|
2019-01-30 23:45:14 +00:00
|
|
|
('toolchangexy', 'X, Y coordonates for toolchange in format (x, y) (example: (2.0, 3.1) ).'),
|
2019-09-15 02:00:20 +00:00
|
|
|
('startz', 'Height before the first move.'),
|
2019-01-03 19:25:08 +00:00
|
|
|
('endz', 'Height where the last move will park.'),
|
2019-09-15 02:00:20 +00:00
|
|
|
('spindlespeed', 'Speed of the spindle in rpm (example: 4000).'),
|
2020-01-01 18:42:59 +00:00
|
|
|
('dwelltime', 'Time to pause to allow the spindle to reach the full speed.\n'
|
|
|
|
'If it is not used in command then it will not be included'),
|
2019-01-03 19:25:08 +00:00
|
|
|
('outname', 'Name of the resulting Geometry object.'),
|
2019-12-06 21:00:43 +00:00
|
|
|
('pp', 'Name of the Geometry preprocessor. No quotes, case sensitive'),
|
2020-04-13 16:15:20 +00:00
|
|
|
('muted', 'It will not put errors in the Shell. Can be True (1) or False (0)')
|
2019-01-03 19:25:08 +00:00
|
|
|
]),
|
2019-11-18 17:45:40 +00:00
|
|
|
'examples': ['cncjob geo_name -dia 0.5 -z_cut -1.7 -z_move 2 -feedrate 120 -pp default']
|
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-10-02 14:58:48 +00:00
|
|
|
name = ''
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-16 01:23:16 +00:00
|
|
|
if 'muted' in args:
|
2020-04-22 11:37:03 +00:00
|
|
|
try:
|
|
|
|
par = args['muted'].capitalize()
|
|
|
|
except AttributeError:
|
|
|
|
par = args['muted']
|
|
|
|
muted = bool(eval(par))
|
2019-09-16 14:20:56 +00:00
|
|
|
else:
|
2020-04-13 16:15:20 +00:00
|
|
|
muted = False
|
2019-09-16 01:23:16 +00:00
|
|
|
|
2019-10-02 14:58:48 +00:00
|
|
|
try:
|
|
|
|
name = args['name']
|
|
|
|
except KeyError:
|
2020-04-13 16:15:20 +00:00
|
|
|
if muted is False:
|
2019-10-02 14:58:48 +00:00
|
|
|
self.raise_tcl_error("Object name is missing")
|
|
|
|
else:
|
|
|
|
return "fail"
|
|
|
|
|
|
|
|
if 'outname' not in args:
|
|
|
|
args['outname'] = str(name) + "_cnc"
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
obj = self.app.collection.get_by_name(str(name), isCaseSensitive=False)
|
2019-09-15 13:46:48 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
if obj is None:
|
2020-04-13 16:15:20 +00:00
|
|
|
if muted is False:
|
2019-09-16 01:23:16 +00:00
|
|
|
self.raise_tcl_error("Object not found: %s" % str(name))
|
|
|
|
else:
|
2019-09-16 23:58:01 +00:00
|
|
|
return "fail"
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2020-04-27 09:34:56 +00:00
|
|
|
if obj.kind != 'geometry':
|
2020-04-13 16:15:20 +00:00
|
|
|
if muted is False:
|
2020-04-27 09:34:56 +00:00
|
|
|
self.raise_tcl_error('Expected GeometryObject, got %s %s.' % (str(name), type(obj)))
|
2019-09-16 01:23:16 +00:00
|
|
|
else:
|
|
|
|
return
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-16 20:27:02 +00:00
|
|
|
args["dia"] = args["dia"] if "dia" in args and args["dia"] else obj.options["cnctooldia"]
|
2019-09-15 10:37:06 +00:00
|
|
|
|
2019-09-16 20:27:02 +00:00
|
|
|
args["z_cut"] = args["z_cut"] if "z_cut" in args and args["z_cut"] else obj.options["cutz"]
|
|
|
|
args["z_move"] = args["z_move"] if "z_move" in args and args["z_move"] else obj.options["travelz"]
|
2019-09-15 10:37:06 +00:00
|
|
|
|
2019-09-16 20:27:02 +00:00
|
|
|
args["feedrate"] = args["feedrate"] if "feedrate" in args and args["feedrate"] else obj.options["feedrate"]
|
|
|
|
args["feedrate_z"] = args["feedrate_z"] if "feedrate_z" in args and args["feedrate_z"] else \
|
|
|
|
obj.options["feedrate_z"]
|
|
|
|
args["feedrate_rapid"] = args["feedrate_rapid"] if "feedrate_rapid" in args and args["feedrate_rapid"] else \
|
|
|
|
obj.options["feedrate_rapid"]
|
2019-09-15 10:37:06 +00:00
|
|
|
|
2020-01-01 18:42:59 +00:00
|
|
|
if "extracut_length" in args:
|
2020-01-01 19:17:47 +00:00
|
|
|
args["extracut"] = True
|
|
|
|
if args["extracut_length"] is None:
|
|
|
|
args["extracut_length"] = 0.0
|
|
|
|
else:
|
|
|
|
args["extracut_length"] = float(args["extracut_length"])
|
2020-01-01 18:42:59 +00:00
|
|
|
else:
|
2020-01-01 19:17:47 +00:00
|
|
|
args["extracut"] = False
|
2020-01-01 18:42:59 +00:00
|
|
|
|
2020-04-13 20:43:48 +00:00
|
|
|
if "dpp" in args:
|
2020-01-01 19:17:47 +00:00
|
|
|
args["multidepth"] = True
|
2020-04-13 20:43:48 +00:00
|
|
|
if args["dpp"] is None:
|
|
|
|
args["dpp"] = obj.options["dpp"]
|
2020-01-01 19:17:47 +00:00
|
|
|
else:
|
2020-04-13 20:43:48 +00:00
|
|
|
args["dpp"] = float(args["dpp"])
|
2020-01-01 19:17:47 +00:00
|
|
|
else:
|
|
|
|
args["multidepth"] = False
|
2019-09-15 10:37:06 +00:00
|
|
|
|
2019-09-16 20:27:02 +00:00
|
|
|
args["startz"] = args["startz"] if "startz" in args and args["startz"] else \
|
2019-09-15 10:37:06 +00:00
|
|
|
self.app.defaults["geometry_startz"]
|
2019-09-16 20:27:02 +00:00
|
|
|
args["endz"] = args["endz"] if "endz" in args and args["endz"] else obj.options["endz"]
|
2019-09-15 10:37:06 +00:00
|
|
|
|
2019-12-10 21:57:00 +00:00
|
|
|
args["spindlespeed"] = args["spindlespeed"] if "spindlespeed" in args and args["spindlespeed"] != 0 else None
|
2020-01-01 18:42:59 +00:00
|
|
|
|
|
|
|
if 'dwelltime' in args:
|
|
|
|
args["dwell"] = True
|
2020-01-01 19:17:47 +00:00
|
|
|
if args['dwelltime'] is None:
|
2020-01-01 18:42:59 +00:00
|
|
|
args["dwelltime"] = float(obj.options["dwelltime"])
|
2020-01-01 19:17:47 +00:00
|
|
|
else:
|
|
|
|
args["dwelltime"] = float(args['dwelltime'])
|
2020-01-01 18:42:59 +00:00
|
|
|
else:
|
|
|
|
args["dwell"] = False
|
|
|
|
args["dwelltime"] = 0.0
|
2019-09-15 10:37:06 +00:00
|
|
|
|
2019-09-16 20:27:02 +00:00
|
|
|
args["pp"] = args["pp"] if "pp" in args and args["pp"] else obj.options["ppname_g"]
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2020-01-01 18:42:59 +00:00
|
|
|
if "toolchangez" in args:
|
|
|
|
args["toolchange"] = True
|
|
|
|
if args["toolchangez"] is not None:
|
|
|
|
args["toolchangez"] = args["toolchangez"]
|
|
|
|
else:
|
|
|
|
args["toolchangez"] = obj.options["toolchangez"]
|
|
|
|
else:
|
|
|
|
args["toolchange"] = False
|
|
|
|
args["toolchangez"] = 0.0
|
|
|
|
|
2019-09-16 20:27:02 +00:00
|
|
|
args["toolchangexy"] = args["toolchangexy"] if "toolchangexy" in args and args["toolchangexy"] else \
|
2019-09-15 10:37:06 +00:00
|
|
|
self.app.defaults["geometry_toolchangexy"]
|
2019-01-30 23:45:14 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
del args['name']
|
|
|
|
|
2019-09-15 13:46:48 +00:00
|
|
|
for arg in args:
|
2019-09-16 14:20:56 +00:00
|
|
|
if arg == "toolchange_xy" or arg == "spindlespeed" or arg == "startz":
|
2019-09-15 13:46:48 +00:00
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if args[arg] is None:
|
2019-09-16 14:20:56 +00:00
|
|
|
print(arg, args[arg])
|
2020-04-13 16:15:20 +00:00
|
|
|
if muted is False:
|
2019-09-16 01:23:16 +00:00
|
|
|
self.raise_tcl_error('One of the command parameters that have to be not None, is None.\n'
|
|
|
|
'The parameter that is None is in the default values found in the list \n'
|
|
|
|
'generated by the TclCommand "list_sys geom". or in the arguments.')
|
|
|
|
else:
|
|
|
|
return
|
2019-09-15 13:46:48 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
# HACK !!! Should be solved elsewhere!!!
|
|
|
|
# default option for multidepth is False
|
|
|
|
obj.options['multidepth'] = False
|
2019-09-15 13:46:48 +00:00
|
|
|
|
2019-09-14 15:27:08 +00:00
|
|
|
if not obj.multigeo:
|
2019-09-15 22:39:11 +00:00
|
|
|
obj.generatecncjob(use_thread=False, plot=False, **args)
|
2019-09-14 15:27:08 +00:00
|
|
|
else:
|
2019-09-15 10:37:06 +00:00
|
|
|
# Update the local_tools_dict values with the args value
|
2019-09-15 02:12:57 +00:00
|
|
|
local_tools_dict = deepcopy(obj.tools)
|
2019-09-15 10:37:06 +00:00
|
|
|
|
|
|
|
for tool_uid in list(local_tools_dict.keys()):
|
|
|
|
if 'data' in local_tools_dict[tool_uid]:
|
|
|
|
local_tools_dict[tool_uid]['data']['cutz'] = args["z_cut"]
|
|
|
|
local_tools_dict[tool_uid]['data']['travelz'] = args["z_move"]
|
|
|
|
local_tools_dict[tool_uid]['data']['feedrate'] = args["feedrate"]
|
|
|
|
local_tools_dict[tool_uid]['data']['feedrate_z'] = args["feedrate_z"]
|
|
|
|
local_tools_dict[tool_uid]['data']['feedrate_rapid'] = args["feedrate_rapid"]
|
|
|
|
local_tools_dict[tool_uid]['data']['multidepth'] = args["multidepth"]
|
|
|
|
local_tools_dict[tool_uid]['data']['extracut'] = args["extracut"]
|
2020-03-20 15:12:20 +00:00
|
|
|
|
|
|
|
if args["extracut"] is True:
|
|
|
|
local_tools_dict[tool_uid]['data']['extracut_length'] = args["extracut_length"]
|
|
|
|
else:
|
|
|
|
local_tools_dict[tool_uid]['data']['extracut_length'] = None
|
|
|
|
|
2020-04-13 20:43:48 +00:00
|
|
|
local_tools_dict[tool_uid]['data']['depthperpass'] = args["dpp"]
|
2019-09-15 10:37:06 +00:00
|
|
|
local_tools_dict[tool_uid]['data']['toolchange'] = args["toolchange"]
|
|
|
|
local_tools_dict[tool_uid]['data']['toolchangez'] = args["toolchangez"]
|
|
|
|
local_tools_dict[tool_uid]['data']['toolchangexy'] = args["toolchangexy"]
|
|
|
|
local_tools_dict[tool_uid]['data']['startz'] = args["startz"]
|
|
|
|
local_tools_dict[tool_uid]['data']['endz'] = args["endz"]
|
|
|
|
local_tools_dict[tool_uid]['data']['spindlespeed'] = args["spindlespeed"]
|
|
|
|
local_tools_dict[tool_uid]['data']['dwell'] = args["dwell"]
|
|
|
|
local_tools_dict[tool_uid]['data']['dwelltime'] = args["dwelltime"]
|
2019-09-15 13:46:48 +00:00
|
|
|
local_tools_dict[tool_uid]['data']['ppname_g'] = args["pp"]
|
|
|
|
obj.mtool_gen_cncjob(
|
|
|
|
outname=args['outname'],
|
|
|
|
tools_dict=local_tools_dict,
|
|
|
|
tools_in_use=[],
|
2019-09-15 22:39:11 +00:00
|
|
|
use_thread=False,
|
|
|
|
plot=False)
|
2019-09-15 02:00:20 +00:00
|
|
|
# self.raise_tcl_error('The object is a multi-geo geometry which is not supported in cncjob Tcl Command')
|