2019-08-25 01:45:16 +00:00
|
|
|
from tclCommands.TclCommand import TclCommand
|
|
|
|
|
2019-10-24 23:10:52 +00:00
|
|
|
import collections
|
|
|
|
import logging
|
|
|
|
|
2019-08-25 01:45:16 +00:00
|
|
|
import gettext
|
|
|
|
import FlatCAMTranslation as fcTranslate
|
|
|
|
import builtins
|
|
|
|
|
|
|
|
fcTranslate.apply_language('strings')
|
|
|
|
if '_' not in builtins.__dict__:
|
|
|
|
_ = gettext.gettext
|
|
|
|
|
2019-10-24 23:10:52 +00:00
|
|
|
log = logging.getLogger('base')
|
|
|
|
|
2019-08-25 01:45:16 +00:00
|
|
|
|
|
|
|
class TclCommandCopperClear(TclCommand):
|
|
|
|
"""
|
|
|
|
Clear the non-copper areas.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Array of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
|
|
|
|
aliases = ['ncc_clear', 'ncc']
|
|
|
|
|
|
|
|
# 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([
|
|
|
|
('tooldia', str),
|
|
|
|
('overlap', float),
|
|
|
|
('order', str),
|
|
|
|
('margin', float),
|
|
|
|
('method', str),
|
|
|
|
('connect', bool),
|
|
|
|
('contour', bool),
|
2019-08-25 13:05:03 +00:00
|
|
|
('has_offset', bool),
|
|
|
|
('offset', float),
|
|
|
|
('rest', bool),
|
2019-08-25 15:13:13 +00:00
|
|
|
('all', int),
|
|
|
|
('ref', int),
|
2019-08-25 01:45:16 +00:00
|
|
|
('box', str),
|
|
|
|
('outname', str),
|
|
|
|
])
|
|
|
|
|
|
|
|
# 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': "Clear excess copper in polygons. Basically it's a negative Paint.",
|
|
|
|
'args': collections.OrderedDict([
|
|
|
|
('name', 'Name of the source Geometry object. String.'),
|
|
|
|
('tooldia', 'Diameter of the tool to be used. Can be a comma separated list of diameters. No space is '
|
|
|
|
'allowed between tool diameters. E.g: correct: 0.5,1 / incorrect: 0.5, 1'),
|
|
|
|
('overlap', 'Fraction of the tool diameter to overlap cuts. Float number.'),
|
|
|
|
('margin', 'Bounding box margin. Float number.'),
|
|
|
|
('order', 'Can have the values: "no", "fwd" and "rev". String.'
|
|
|
|
'It is useful when there are multiple tools in tooldia parameter.'
|
|
|
|
'"no" -> the order used is the one provided.'
|
|
|
|
'"fwd" -> tools are ordered from smallest to biggest.'
|
|
|
|
'"rev" -> tools are ordered from biggest to smallest.'),
|
|
|
|
('method', 'Algorithm for copper clearing. Can be: "standard", "seed" or "lines".'),
|
|
|
|
('connect', 'Draw lines to minimize tool lifts. True or False'),
|
|
|
|
('contour', 'Cut around the perimeter of the painting. True or False'),
|
|
|
|
('rest', 'Use rest-machining. True or False'),
|
2019-08-25 13:05:03 +00:00
|
|
|
('has_offset', 'The offset will used only if this is set True or present in args. True or False.'),
|
|
|
|
('offset', 'The copper clearing will finish to a distance from copper features. Float number.'),
|
2019-08-25 15:13:13 +00:00
|
|
|
('all', 'Will copper clear the whole object. 1 = enabled, anything else = disabled'),
|
2019-08-25 01:45:16 +00:00
|
|
|
('ref', 'Will clear of extra copper all polygons within a specified object with the name in "box" '
|
2019-08-25 15:13:13 +00:00
|
|
|
'parameter. 1 = enabled, anything else = disabled'),
|
|
|
|
('box', 'Name of the object to be used as reference. Required when selecting "ref" = 1. String.'),
|
2019-08-25 01:45:16 +00:00
|
|
|
('outname', 'Name of the resulting Geometry object. String.'),
|
|
|
|
]),
|
|
|
|
'examples': []
|
|
|
|
}
|
|
|
|
|
|
|
|
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']
|
|
|
|
|
2019-12-05 13:18:54 +00:00
|
|
|
# Get source object.
|
|
|
|
try:
|
|
|
|
obj = self.app.collection.get_by_name(str(name))
|
|
|
|
except Exception as e:
|
|
|
|
log.debug("TclCommandCopperClear.execute() --> %s" % str(e))
|
|
|
|
self.raise_tcl_error("%s: %s" % (_("Could not retrieve object"), name))
|
|
|
|
return "Could not retrieve object: %s" % name
|
|
|
|
|
|
|
|
if obj is None:
|
|
|
|
return "Object not found: %s" % name
|
|
|
|
|
2019-08-25 01:45:16 +00:00
|
|
|
if 'tooldia' in args:
|
|
|
|
tooldia = str(args['tooldia'])
|
|
|
|
else:
|
2019-08-25 13:05:03 +00:00
|
|
|
tooldia = self.app.defaults["tools_ncctools"]
|
2019-08-25 01:45:16 +00:00
|
|
|
|
|
|
|
if 'overlap' in args:
|
|
|
|
overlap = float(args['overlap'])
|
|
|
|
else:
|
|
|
|
overlap = float(self.app.defaults["tools_nccoverlap"])
|
|
|
|
|
|
|
|
if 'order' in args:
|
|
|
|
order = args['order']
|
|
|
|
else:
|
|
|
|
order = str(self.app.defaults["tools_nccorder"])
|
|
|
|
|
|
|
|
if 'margin' in args:
|
|
|
|
margin = float(args['margin'])
|
|
|
|
else:
|
|
|
|
margin = float(self.app.defaults["tools_nccmargin"])
|
|
|
|
|
|
|
|
if 'method' in args:
|
|
|
|
method = args['method']
|
|
|
|
else:
|
|
|
|
method = str(self.app.defaults["tools_nccmethod"])
|
|
|
|
|
|
|
|
if 'connect' in args:
|
2019-12-08 20:11:39 +00:00
|
|
|
connect = bool(args['connect'])
|
2019-08-25 01:45:16 +00:00
|
|
|
else:
|
|
|
|
connect = eval(str(self.app.defaults["tools_nccconnect"]))
|
|
|
|
|
|
|
|
if 'contour' in args:
|
2019-12-08 20:11:39 +00:00
|
|
|
contour = bool(args['contour'])
|
2019-08-25 01:45:16 +00:00
|
|
|
else:
|
|
|
|
contour = eval(str(self.app.defaults["tools_ncccontour"]))
|
|
|
|
|
2019-08-25 13:05:03 +00:00
|
|
|
offset = 0.0
|
|
|
|
if 'has_offset' in args:
|
2019-12-08 20:11:39 +00:00
|
|
|
has_offset = bool(args['has_offset'])
|
2019-08-25 13:05:03 +00:00
|
|
|
if args['has_offset'] is True:
|
|
|
|
if 'offset' in args:
|
|
|
|
offset = float(args['margin'])
|
|
|
|
else:
|
|
|
|
# 'offset' has to be in args if 'has_offset' is and it is set True
|
|
|
|
self.raise_tcl_error("%s: %s" % (_("Could not retrieve object"), name))
|
|
|
|
else:
|
|
|
|
has_offset = False
|
|
|
|
|
2019-08-25 01:45:16 +00:00
|
|
|
try:
|
|
|
|
tools = [float(eval(dia)) for dia in tooldia.split(",") if dia != '']
|
|
|
|
except AttributeError:
|
|
|
|
tools = [float(tooldia)]
|
2019-09-23 01:07:24 +00:00
|
|
|
|
2019-08-25 01:45:16 +00:00
|
|
|
# store here the default data for Geometry Data
|
|
|
|
default_data = {}
|
|
|
|
default_data.update({
|
|
|
|
"name": '_paint',
|
|
|
|
"plot": self.app.defaults["geometry_plot"],
|
|
|
|
"cutz": self.app.defaults["geometry_cutz"],
|
|
|
|
"vtipdia": 0.1,
|
|
|
|
"vtipangle": 30,
|
|
|
|
"travelz": self.app.defaults["geometry_travelz"],
|
|
|
|
"feedrate": self.app.defaults["geometry_feedrate"],
|
|
|
|
"feedrate_z": self.app.defaults["geometry_feedrate_z"],
|
|
|
|
"feedrate_rapid": self.app.defaults["geometry_feedrate_rapid"],
|
|
|
|
"dwell": self.app.defaults["geometry_dwell"],
|
|
|
|
"dwelltime": self.app.defaults["geometry_dwelltime"],
|
|
|
|
"multidepth": self.app.defaults["geometry_multidepth"],
|
|
|
|
"ppname_g": self.app.defaults["geometry_ppname_g"],
|
|
|
|
"depthperpass": self.app.defaults["geometry_depthperpass"],
|
|
|
|
"extracut": self.app.defaults["geometry_extracut"],
|
2019-12-10 03:28:02 +00:00
|
|
|
"extracut_length": self.app.defaults["geometry_extracut_length"],
|
2019-08-25 01:45:16 +00:00
|
|
|
"toolchange": self.app.defaults["geometry_toolchange"],
|
|
|
|
"toolchangez": self.app.defaults["geometry_toolchangez"],
|
|
|
|
"endz": self.app.defaults["geometry_endz"],
|
|
|
|
"spindlespeed": self.app.defaults["geometry_spindlespeed"],
|
|
|
|
"toolchangexy": self.app.defaults["geometry_toolchangexy"],
|
|
|
|
"startz": self.app.defaults["geometry_startz"],
|
|
|
|
|
|
|
|
"tooldia": self.app.defaults["tools_painttooldia"],
|
|
|
|
"paintmargin": self.app.defaults["tools_paintmargin"],
|
|
|
|
"paintmethod": self.app.defaults["tools_paintmethod"],
|
|
|
|
"selectmethod": self.app.defaults["tools_selectmethod"],
|
|
|
|
"pathconnect": self.app.defaults["tools_pathconnect"],
|
|
|
|
"paintcontour": self.app.defaults["tools_paintcontour"],
|
|
|
|
"paintoverlap": self.app.defaults["tools_paintoverlap"]
|
|
|
|
})
|
|
|
|
ncc_tools = dict()
|
|
|
|
|
|
|
|
tooluid = 0
|
|
|
|
for tool in tools:
|
|
|
|
tooluid += 1
|
|
|
|
ncc_tools.update({
|
|
|
|
int(tooluid): {
|
2019-12-05 13:18:54 +00:00
|
|
|
'tooldia': float('%.*f' % (obj.decimals, tool)),
|
2019-08-25 01:45:16 +00:00
|
|
|
'offset': 'Path',
|
|
|
|
'offset_value': 0.0,
|
|
|
|
'type': 'Iso',
|
|
|
|
'tool_type': 'C1',
|
|
|
|
'data': dict(default_data),
|
|
|
|
'solid_geometry': []
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-08-25 15:13:13 +00:00
|
|
|
if 'rest' in args:
|
2019-12-08 20:11:39 +00:00
|
|
|
rest = bool(args['rest'])
|
2019-08-25 15:13:13 +00:00
|
|
|
else:
|
|
|
|
rest = eval(str(self.app.defaults["tools_nccrest"]))
|
|
|
|
|
|
|
|
if 'outname' in args:
|
|
|
|
outname = args['outname']
|
|
|
|
else:
|
|
|
|
if rest is True:
|
|
|
|
outname = name + "_ncc"
|
|
|
|
else:
|
|
|
|
outname = name + "_ncc_rm"
|
|
|
|
|
|
|
|
# Non-Copper clear all polygons in the non-copper clear object
|
|
|
|
if 'all' in args and args['all'] == 1:
|
2019-08-25 13:05:03 +00:00
|
|
|
self.app.ncclear_tool.clear_copper(ncc_obj=obj,
|
2019-08-25 15:13:13 +00:00
|
|
|
select_method='itself',
|
2019-09-10 01:37:00 +00:00
|
|
|
ncctooldia=tooldia,
|
2019-08-25 01:45:16 +00:00
|
|
|
overlap=overlap,
|
|
|
|
order=order,
|
|
|
|
margin=margin,
|
2019-08-25 13:05:03 +00:00
|
|
|
has_offset=has_offset,
|
|
|
|
offset=offset,
|
2019-08-25 01:45:16 +00:00
|
|
|
method=method,
|
|
|
|
outname=outname,
|
|
|
|
connect=connect,
|
|
|
|
contour=contour,
|
2019-08-25 13:05:03 +00:00
|
|
|
rest=rest,
|
2019-09-14 15:27:08 +00:00
|
|
|
tools_storage=ncc_tools,
|
2019-09-15 22:39:11 +00:00
|
|
|
plot=False,
|
2019-09-14 15:27:08 +00:00
|
|
|
run_threaded=False)
|
2019-08-25 01:45:16 +00:00
|
|
|
return
|
|
|
|
|
2019-08-25 15:13:13 +00:00
|
|
|
# Non-Copper clear all polygons found within the box object from the the non_copper cleared object
|
|
|
|
elif 'ref' in args and args['ref'] == 1:
|
2019-08-25 01:45:16 +00:00
|
|
|
if 'box' not in args:
|
|
|
|
self.raise_tcl_error('%s' % _("Expected -box <value>."))
|
|
|
|
else:
|
|
|
|
box_name = args['box']
|
|
|
|
|
|
|
|
# Get box source object.
|
|
|
|
try:
|
|
|
|
box_obj = self.app.collection.get_by_name(str(box_name))
|
|
|
|
except Exception as e:
|
|
|
|
log.debug("TclCommandCopperClear.execute() --> %s" % str(e))
|
|
|
|
self.raise_tcl_error("%s: %s" % (_("Could not retrieve box object"), name))
|
|
|
|
return "Could not retrieve object: %s" % name
|
|
|
|
|
2019-08-25 13:05:03 +00:00
|
|
|
self.app.ncclear_tool.clear_copper(ncc_obj=obj,
|
2019-08-25 01:45:16 +00:00
|
|
|
sel_obj=box_obj,
|
2019-08-25 15:13:13 +00:00
|
|
|
select_method='box',
|
2019-11-18 17:45:40 +00:00
|
|
|
ncctooldia=tooldia,
|
2019-08-25 01:45:16 +00:00
|
|
|
overlap=overlap,
|
|
|
|
order=order,
|
|
|
|
margin=margin,
|
2019-08-25 13:05:03 +00:00
|
|
|
has_offset=has_offset,
|
|
|
|
offset=offset,
|
2019-08-25 01:45:16 +00:00
|
|
|
method=method,
|
|
|
|
outname=outname,
|
|
|
|
connect=connect,
|
|
|
|
contour=contour,
|
2019-08-25 13:05:03 +00:00
|
|
|
rest=rest,
|
2019-09-14 15:27:08 +00:00
|
|
|
tools_storage=ncc_tools,
|
2019-09-15 22:39:11 +00:00
|
|
|
plot=False,
|
2019-09-14 15:27:08 +00:00
|
|
|
run_threaded=False)
|
2019-08-25 01:45:16 +00:00
|
|
|
return
|
|
|
|
else:
|
2019-08-25 15:13:13 +00:00
|
|
|
self.raise_tcl_error("%s:" % _("None of the following args: 'ref', 'all' were found or none was set to 1.\n"
|
|
|
|
"Copper clearing failed."))
|
|
|
|
return "None of the following args: 'ref', 'all' were found or none was set to 1.\n" \
|
|
|
|
"Copper clearing failed."
|