- initial add of a new Tcl COmmand named CopperClear

- remade the NCC Tool in preparation for the newly added TclCommand CopperClear
This commit is contained in:
Marius Stanciu 2019-08-25 04:45:16 +03:00 committed by Marius
parent d606c836f4
commit 8c0b8ed13d
7 changed files with 908 additions and 208 deletions

View File

@ -1761,8 +1761,8 @@ class App(QtCore.QObject):
'export_svg', 'ext', 'exteriors', 'follow', 'geo_union', 'geocutout', 'get_names', 'export_svg', 'ext', 'exteriors', 'follow', 'geo_union', 'geocutout', 'get_names',
'get_sys', 'getsys', 'help', 'import_svg', 'interiors', 'isolate', 'join_excellon', 'get_sys', 'getsys', 'help', 'import_svg', 'interiors', 'isolate', 'join_excellon',
'join_excellons', 'join_geometries', 'join_geometry', 'list_sys', 'listsys', 'mill', 'join_excellons', 'join_geometries', 'join_geometry', 'list_sys', 'listsys', 'mill',
'millholes', 'mirror', 'new', 'new_geometry', 'non_copper_regions', 'ncr', 'millholes', 'mirror', 'new', 'new_geometry', 'non_copper_regions', 'ncr', 'ncc',
'offset', 'open_excellon', 'open_gcode', 'ncc_clear', 'offset', 'open_excellon', 'open_gcode',
'open_gerber', 'open_project', 'options', 'paint', 'pan', 'panel', 'panelize', 'plot', 'open_gerber', 'open_project', 'options', 'paint', 'pan', 'panel', 'panelize', 'plot',
'save', 'save_project', 'save_sys', 'scale', 'set_active', 'set_sys', 'setsys', 'save', 'save_project', 'save_sys', 'scale', 'set_active', 'set_sys', 'setsys',
'skew', 'subtract_poly', 'subtract_rectangle', 'version', 'write_gcode' 'skew', 'subtract_poly', 'subtract_rectangle', 'version', 'write_gcode'

View File

@ -9,6 +9,11 @@ CAD program, and create G-Code for Isolation routing.
================================================= =================================================
25.08.2019
- initial add of a new Tcl COmmand named CopperClear
- remade the NCC Tool in preparation for the newly added TclCommand CopperClear
24.08.2019 24.08.2019
- modified CutOut Tool so now the manual gaps adding will continue until the user is clicking the RMB - modified CutOut Tool so now the manual gaps adding will continue until the user is clicking the RMB

File diff suppressed because it is too large Load Diff

View File

@ -894,7 +894,7 @@ class ToolPaint(FlatCAMTool, Gerber):
# init values for the next usage # init values for the next usage
self.reset_usage() self.reset_usage()
self.app.report_usage(_("geometry_on_paint_button")) self.app.report_usage(_("on_paint_button_click"))
# self.app.call_source = 'paint' # self.app.call_source = 'paint'
try: try:
@ -1608,8 +1608,8 @@ class ToolPaint(FlatCAMTool, Gerber):
# Initializes the new geometry object # Initializes the new geometry object
def gen_paintarea_rest_machining(geo_obj, app_obj): def gen_paintarea_rest_machining(geo_obj, app_obj):
# assert isinstance(geo_obj, FlatCAMGeometry), \ assert isinstance(geo_obj, FlatCAMGeometry), \
# "Initializer expected a FlatCAMGeometry, got %s" % type(geo_obj) "Initializer expected a FlatCAMGeometry, got %s" % type(geo_obj)
tool_dia = None tool_dia = None
sorted_tools.sort(reverse=True) sorted_tools.sort(reverse=True)

View File

@ -0,0 +1,246 @@
from ObjectCollection import *
from tclCommands.TclCommand import TclCommand
import gettext
import FlatCAMTranslation as fcTranslate
import builtins
fcTranslate.apply_language('strings')
if '_' not in builtins.__dict__:
_ = gettext.gettext
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),
('all', bool),
('ref', bool),
('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'),
('offset', 'The copper clearing will finish to a distance from copper features. True or False.'),
('all', 'Will copper clear the whole object. True or False'),
('ref', 'Will clear of extra copper all polygons within a specified object with the name in "box" '
'parameter. True or False'),
('box', 'name of the object to be used as reference when selecting "ref"" True. String.'),
('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']
if 'tooldia' in args:
tooldia = str(args['tooldia'])
else:
tooldia = float(self.app.defaults["tools_ncctools"])
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:
connect = eval(str(args['connect']).capitalize())
else:
connect = eval(str(self.app.defaults["tools_nccconnect"]))
if 'contour' in args:
contour = eval(str(args['contour']).capitalize())
else:
contour = eval(str(self.app.defaults["tools_ncccontour"]))
if 'rest' in args:
rest = eval(str(args['rest']).capitalize())
else:
rest = eval(str(self.app.defaults["tools_nccrest"]))
# if 'offset' not in args then not use it
offset = None
if 'offset' in args:
offset = float(args['margin'])
if 'outname' in args:
outname = args['outname']
else:
outname = name + "_ncc"
# 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
try:
tools = [float(eval(dia)) for dia in tooldia.split(",") if dia != '']
except AttributeError:
tools = [float(tooldia)]
# 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"],
"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): {
'tooldia': float('%.4f' % tool),
'offset': 'Path',
'offset_value': 0.0,
'type': 'Iso',
'tool_type': 'C1',
'data': dict(default_data),
'solid_geometry': []
}
})
if obj is None:
return "Object not found: %s" % name
# Paint all polygons in the painted object
if 'all' in args and args['all'] is True:
self.app.ncclear_tool.clear_copper(obj=obj,
tooldia=tooldia,
overlap=overlap,
order=order,
margin=margin,
method=method,
outname=outname,
connect=connect,
contour=contour,
tools_storage=ncc_tools)
return
# Paint all polygons found within the box object from the the painted object
elif 'ref' in args and args['ref'] is True:
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
self.app.ncclear_tool.clear_copper(obj=obj,
sel_obj=box_obj,
tooldia=tooldia,
overlap=overlap,
order=order,
margin=margin,
method=method,
outname=outname,
connect=connect,
contour=contour,
tools_storage=ncc_tools)
return
else:
self.raise_tcl_error("%s:" % _("There was none of the following args: 'ref', 'single', 'all'.\n"
"Paint failed."))
return "There was none of the following args: 'ref', 'single', 'all'.\n" \
"Paint failed."

View File

@ -53,6 +53,7 @@ class TclCommandPaint(TclCommand):
('tooldia', 'Diameter of the tool to be used. Can be a comma separated list of diameters. No space is ' ('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'), '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.'), ('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.' ('order', 'Can have the values: "no", "fwd" and "rev". String.'
'It is useful when there are multiple tools in tooldia parameter.' 'It is useful when there are multiple tools in tooldia parameter.'
'"no" -> the order used is the one provided.' '"no" -> the order used is the one provided.'

View File

@ -12,6 +12,7 @@ import tclCommands.TclCommandAlignDrillGrid
import tclCommands.TclCommandBbox import tclCommands.TclCommandBbox
import tclCommands.TclCommandClearShell import tclCommands.TclCommandClearShell
import tclCommands.TclCommandCncjob import tclCommands.TclCommandCncjob
import tclCommands.TclCommandCopperClear
import tclCommands.TclCommandCutout import tclCommands.TclCommandCutout
import tclCommands.TclCommandDelete import tclCommands.TclCommandDelete
import tclCommands.TclCommandDrillcncjob import tclCommands.TclCommandDrillcncjob