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
|
2020-06-03 17:35:59 +00:00
|
|
|
import appTranslation as fcTranslate
|
2019-08-25 01:45:16 +00:00
|
|
|
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']
|
|
|
|
|
2020-04-13 16:15:20 +00:00
|
|
|
description = '%s %s' % ("--", "Clear excess copper.")
|
|
|
|
|
2019-08-25 01:45:16 +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([
|
|
|
|
('tooldia', str),
|
|
|
|
('overlap', float),
|
|
|
|
('order', str),
|
|
|
|
('margin', float),
|
|
|
|
('method', str),
|
2020-04-13 16:15:20 +00:00
|
|
|
('connect', str),
|
|
|
|
('contour', str),
|
2019-08-25 13:05:03 +00:00
|
|
|
('offset', float),
|
2020-04-13 16:15:20 +00:00
|
|
|
('rest', str),
|
2019-08-25 15:13:13 +00:00
|
|
|
('all', int),
|
2020-04-13 16:15:20 +00:00
|
|
|
('ref', str),
|
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.'),
|
2020-06-02 15:29:45 +00:00
|
|
|
('tooldia', 'Diameter of the tool to be used. Can be a comma separated list of diameters.\n'
|
|
|
|
'WARNING: No space is allowed between tool diameters. E.g: correct: 0.5,1 / incorrect: 0.5, 1'),
|
2019-12-30 21:33:22 +00:00
|
|
|
('overlap', 'Percentage of tool diameter to overlap current pass over previous pass. Float [0, 99.9999]\n'
|
|
|
|
'E.g: for a 25% from tool diameter overlap use -overlap 25'),
|
2019-08-25 01:45:16 +00:00
|
|
|
('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".'),
|
2020-04-13 16:15:20 +00:00
|
|
|
('connect', 'Draw lines to minimize tool lifts. True (1) or False (0)'),
|
|
|
|
('contour', 'Cut around the perimeter of the painting. True (1) or False (0)'),
|
|
|
|
('rest', 'Use rest-machining. True (1) or False (0)'),
|
2020-04-22 11:37:03 +00:00
|
|
|
('offset', 'If used, the copper clearing will finish to a distance from copper features. Float number.'),
|
|
|
|
('all', 'If used will copper clear the whole object. Either "-all" or "-box <value>" has to be used.'),
|
|
|
|
('box', 'Name of the object to be used as reference. Either "-all" or "-box <value>" has to be used. '
|
|
|
|
'String.'),
|
2020-06-02 15:29:45 +00:00
|
|
|
('outname', 'Name of the resulting Geometry object. String. No spaces.'),
|
2019-08-25 01:45:16 +00:00
|
|
|
]),
|
2020-04-22 11:37:03 +00:00
|
|
|
'examples': ["ncc obj_name -tooldia 0.3,1 -overlap 10 -margin 1.0 -method 'lines' -all"]
|
2019-08-25 01:45:16 +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
|
|
|
|
"""
|
|
|
|
|
|
|
|
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:
|
2020-10-28 11:15:38 +00:00
|
|
|
tooldia = str(self.app.defaults["tools_ncc_tools"])
|
2019-08-25 01:45:16 +00:00
|
|
|
|
|
|
|
if 'overlap' in args:
|
2019-12-30 20:04:39 +00:00
|
|
|
overlap = float(args['overlap']) / 100.0
|
2019-08-25 01:45:16 +00:00
|
|
|
else:
|
2020-10-22 12:09:12 +00:00
|
|
|
overlap = float(self.app.defaults["tools_ncc_overlap"]) / 100.0
|
2019-08-25 01:45:16 +00:00
|
|
|
|
|
|
|
if 'order' in args:
|
|
|
|
order = args['order']
|
|
|
|
else:
|
2020-10-22 12:09:12 +00:00
|
|
|
order = str(self.app.defaults["tools_ncc_order"])
|
2019-08-25 01:45:16 +00:00
|
|
|
|
|
|
|
if 'margin' in args:
|
|
|
|
margin = float(args['margin'])
|
|
|
|
else:
|
2020-10-22 12:09:12 +00:00
|
|
|
margin = float(self.app.defaults["tools_ncc_margin"])
|
2019-08-25 01:45:16 +00:00
|
|
|
|
|
|
|
if 'method' in args:
|
|
|
|
method = args['method']
|
2020-04-24 18:08:27 +00:00
|
|
|
if method == "standard":
|
2020-10-28 21:00:18 +00:00
|
|
|
method_data = 0
|
2020-04-24 18:08:27 +00:00
|
|
|
elif method == "seed":
|
2020-10-28 21:00:18 +00:00
|
|
|
method_data = 1
|
2020-04-24 18:08:27 +00:00
|
|
|
else:
|
2020-10-28 21:00:18 +00:00
|
|
|
method_data = 2
|
2019-08-25 01:45:16 +00:00
|
|
|
else:
|
2020-10-22 12:09:12 +00:00
|
|
|
method = str(self.app.defaults["tools_ncc_method"])
|
2020-04-24 18:08:27 +00:00
|
|
|
method_data = method
|
2019-08-25 01:45:16 +00:00
|
|
|
|
|
|
|
if 'connect' in args:
|
2020-04-22 11:37:03 +00:00
|
|
|
try:
|
|
|
|
par = args['connect'].capitalize()
|
|
|
|
except AttributeError:
|
|
|
|
par = args['connect']
|
|
|
|
connect = bool(eval(par))
|
2019-08-25 01:45:16 +00:00
|
|
|
else:
|
2020-10-22 12:09:12 +00:00
|
|
|
connect = bool(eval(str(self.app.defaults["tools_ncc_connect"])))
|
2019-08-25 01:45:16 +00:00
|
|
|
|
|
|
|
if 'contour' in args:
|
2020-04-22 11:37:03 +00:00
|
|
|
try:
|
|
|
|
par = args['contour'].capitalize()
|
|
|
|
except AttributeError:
|
|
|
|
par = args['contour']
|
|
|
|
contour = bool(eval(par))
|
2019-08-25 01:45:16 +00:00
|
|
|
else:
|
2020-10-22 12:09:12 +00:00
|
|
|
contour = bool(eval(str(self.app.defaults["tools_ncc_contour"])))
|
2019-08-25 01:45:16 +00:00
|
|
|
|
2019-08-25 13:05:03 +00:00
|
|
|
offset = 0.0
|
2020-04-22 11:37:03 +00:00
|
|
|
if 'offset' in args:
|
|
|
|
offset = float(args['offset'])
|
|
|
|
has_offset = True
|
2019-08-25 13:05:03 +00:00
|
|
|
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
|
|
|
|
2020-04-24 18:08:27 +00:00
|
|
|
if 'rest' in args:
|
|
|
|
try:
|
|
|
|
par = args['rest'].capitalize()
|
|
|
|
except AttributeError:
|
|
|
|
par = args['rest']
|
|
|
|
rest = bool(eval(par))
|
|
|
|
else:
|
2020-10-22 12:09:12 +00:00
|
|
|
rest = bool(eval(str(self.app.defaults["tools_ncc_rest"])))
|
2020-04-24 18:08:27 +00:00
|
|
|
|
|
|
|
if 'outname' in args:
|
|
|
|
outname = args['outname']
|
|
|
|
else:
|
|
|
|
if rest is True:
|
|
|
|
outname = name + "_ncc"
|
|
|
|
else:
|
|
|
|
outname = name + "_ncc_rm"
|
|
|
|
|
|
|
|
# used only to have correct information's in the obj.tools[tool]['data'] dict
|
|
|
|
if "all" in args:
|
2020-10-28 21:00:18 +00:00
|
|
|
select = 0 # 'ITSELF
|
2020-04-24 18:08:27 +00:00
|
|
|
else:
|
2020-10-28 21:00:18 +00:00
|
|
|
select = 2 # 'REFERENCE Object'
|
2020-04-24 18:08:27 +00:00
|
|
|
|
2019-08-25 01:45:16 +00:00
|
|
|
# store here the default data for Geometry Data
|
|
|
|
default_data = {}
|
|
|
|
default_data.update({
|
2020-06-14 12:59:06 +00:00
|
|
|
"name": outname,
|
|
|
|
"plot": False,
|
|
|
|
"cutz": self.app.defaults["geometry_cutz"],
|
|
|
|
"vtipdia": float(self.app.defaults["geometry_vtipdia"]),
|
|
|
|
"vtipangle": float(self.app.defaults["geometry_vtipangle"]),
|
|
|
|
"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"],
|
|
|
|
"extracut_length": self.app.defaults["geometry_extracut_length"],
|
|
|
|
"toolchange": self.app.defaults["geometry_toolchange"],
|
|
|
|
"toolchangez": self.app.defaults["geometry_toolchangez"],
|
|
|
|
"endz": self.app.defaults["geometry_endz"],
|
|
|
|
"endxy": self.app.defaults["geometry_endxy"],
|
|
|
|
"spindlespeed": self.app.defaults["geometry_spindlespeed"],
|
|
|
|
"toolchangexy": self.app.defaults["geometry_toolchangexy"],
|
|
|
|
"startz": self.app.defaults["geometry_startz"],
|
|
|
|
|
|
|
|
"area_exclusion": self.app.defaults["geometry_area_exclusion"],
|
|
|
|
"area_shape": self.app.defaults["geometry_area_shape"],
|
|
|
|
"area_strategy": self.app.defaults["geometry_area_strategy"],
|
|
|
|
"area_overz": float(self.app.defaults["geometry_area_overz"]),
|
|
|
|
|
2020-10-28 11:15:38 +00:00
|
|
|
"tooldia": tooldia,
|
|
|
|
"tools_ncc_operation": self.app.defaults["tools_ncc_operation"],
|
2020-06-14 12:59:06 +00:00
|
|
|
|
2020-10-22 12:09:12 +00:00
|
|
|
"tools_ncc_margin": margin,
|
|
|
|
"tools_ncc_method": method_data,
|
|
|
|
"tools_ncc_ref": select,
|
|
|
|
"tools_ncc_connect": connect,
|
|
|
|
"tools_ncc_contour": contour,
|
|
|
|
"tools_ncc_overlap": overlap,
|
2020-06-14 12:59:06 +00:00
|
|
|
|
|
|
|
"tools_ncc_offset_choice": self.app.defaults["tools_ncc_offset_choice"],
|
|
|
|
"tools_ncc_offset_value": self.app.defaults["tools_ncc_offset_value"],
|
2020-10-22 12:09:12 +00:00
|
|
|
"tools_ncc_milling_type": self.app.defaults["tools_ncc_milling_type"]
|
2019-08-25 01:45:16 +00:00
|
|
|
})
|
2020-02-29 22:52:24 +00:00
|
|
|
ncc_tools = {}
|
2019-08-25 01:45:16 +00:00
|
|
|
|
|
|
|
tooluid = 0
|
|
|
|
for tool in tools:
|
|
|
|
tooluid += 1
|
|
|
|
ncc_tools.update({
|
|
|
|
int(tooluid): {
|
2020-06-14 12:59:06 +00:00
|
|
|
'tooldia': float('%.*f' % (obj.decimals, tool)),
|
|
|
|
'offset': 'Path',
|
|
|
|
'offset_value': 0.0,
|
|
|
|
'type': 'Iso',
|
|
|
|
'tool_type': 'C1',
|
|
|
|
'data': dict(default_data),
|
|
|
|
'solid_geometry': []
|
2019-08-25 01:45:16 +00:00
|
|
|
}
|
|
|
|
})
|
2020-10-28 11:15:38 +00:00
|
|
|
ncc_tools[int(tooluid)]['data']['tooldia'] = self.app.dec_format(tool, obj.decimals)
|
2019-08-25 15:13:13 +00:00
|
|
|
|
|
|
|
# Non-Copper clear all polygons in the non-copper clear object
|
2020-04-22 11:37:03 +00:00
|
|
|
if 'all' in args:
|
2020-01-08 15:14:10 +00:00
|
|
|
self.app.ncclear_tool.clear_copper_tcl(ncc_obj=obj,
|
2020-10-28 21:00:18 +00:00
|
|
|
select_method=0, # ITSELF
|
2020-01-08 15:14:10 +00:00
|
|
|
ncctooldia=tooldia,
|
|
|
|
overlap=overlap,
|
|
|
|
order=order,
|
|
|
|
margin=margin,
|
|
|
|
has_offset=has_offset,
|
|
|
|
offset=offset,
|
|
|
|
method=method,
|
|
|
|
outname=outname,
|
|
|
|
connect=connect,
|
|
|
|
contour=contour,
|
|
|
|
rest=rest,
|
|
|
|
tools_storage=ncc_tools,
|
|
|
|
plot=False,
|
|
|
|
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
|
2020-10-28 21:00:18 +00:00
|
|
|
if 'box' in args: # Reference Object
|
2020-04-22 11:37:03 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
self.app.ncclear_tool.clear_copper_tcl(ncc_obj=obj,
|
|
|
|
sel_obj=box_obj,
|
2020-10-28 21:00:18 +00:00
|
|
|
select_method=2, # REFERENCE OBJECT
|
2020-04-22 11:37:03 +00:00
|
|
|
ncctooldia=tooldia,
|
|
|
|
overlap=overlap,
|
|
|
|
order=order,
|
|
|
|
margin=margin,
|
|
|
|
has_offset=has_offset,
|
|
|
|
offset=offset,
|
|
|
|
method=method,
|
|
|
|
outname=outname,
|
|
|
|
connect=connect,
|
|
|
|
contour=contour,
|
|
|
|
rest=rest,
|
|
|
|
tools_storage=ncc_tools,
|
|
|
|
plot=False,
|
|
|
|
run_threaded=False)
|
2019-08-25 01:45:16 +00:00
|
|
|
return
|
2020-04-22 11:37:03 +00:00
|
|
|
|
|
|
|
# if the program reached this then it's an error because neither -all or -box <value> was used.
|
|
|
|
self.raise_tcl_error('%s' % _("Expected either -box <value> or -all."))
|
|
|
|
return "Expected either -box <value> or -all. Copper clearing failed."
|