- modified the Paint Tool. Now the Single Polygon and Area/Reference Object painting works with multiple tools too. The tools have to be selected in the Tool Table.

- remade the TclCommand Paint to work in the new configuration of the the app (the painting functions are now in their own tool, Paint Tool)
- fixed a bug in the Properties Tool
This commit is contained in:
Marius Stanciu
2019-08-24 19:55:03 +03:00
committed by Marius
parent 82b39d64d2
commit 87d1558977
5 changed files with 621 additions and 207 deletions

View File

@@ -202,7 +202,6 @@ class TclCommand(object):
"""
arguments, options = self.parse_arguments(args)
named_args = {}
unnamed_args = []
@@ -274,7 +273,7 @@ class TclCommand(object):
:return: None, output text or exception
"""
#self.worker_task.emit({'fcn': self.exec_command_test, 'params': [text, False]})
# self.worker_task.emit({'fcn': self.exec_command_test, 'params': [text, False]})
try:
self.log.debug("TCL command '%s' executed." % str(self.__class__))
@@ -283,7 +282,7 @@ class TclCommand(object):
return self.execute(args, unnamed_args)
except Exception as unknown:
error_info = sys.exc_info()
self.log.error("TCL command '%s' failed." % str(self))
self.log.error("TCL command '%s' failed. Error text: %s" % (str(self), str(unknown)))
self.app.display_tcl_error(unknown, error_info)
self.raise_tcl_unknown_error(unknown)

View File

@@ -1,8 +1,16 @@
from ObjectCollection import *
from tclCommands.TclCommand import TclCommandSignaled
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 TclCommandPaint(TclCommandSignaled):
class TclCommandPaint(TclCommand):
"""
Paint the interior of polygons
"""
@@ -13,32 +21,53 @@ class TclCommandPaint(TclCommandSignaled):
# dictionary of types from Tcl command, needs to be ordered
arg_names = collections.OrderedDict([
('name', str),
('tooldia', float),
('overlap', float)
])
# dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
option_types = collections.OrderedDict([
('outname', str),
('tooldia', str),
('overlap', float),
('order', str),
('margin', float),
('method', str),
('connect', bool),
('contour', bool),
('all', bool),
('single', bool),
('ref', bool),
('box', str),
('x', float),
('y', float)
('y', float),
('outname', str),
])
# array of mandatory options for current Tcl command: required = {'name','outname'}
required = ['name', 'tooldia', 'overlap']
required = ['name']
# structured help for current command, args needs to be ordered
help = {
'main': "Paint polygons",
'args': collections.OrderedDict([
('name', 'Name of the source Geometry object.'),
('tooldia', 'Diameter of the tool to be used.'),
('overlap', 'Fraction of the tool diameter to overlap cuts.'),
('outname', 'Name of the resulting Geometry object.'),
('all', 'Paint all polygons in the object.'),
('x', 'X value of coordinate for the selection of a single polygon.'),
('y', 'Y value of coordinate for the selection of a single polygon.')
('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.'),
('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 painting. 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'),
('all', 'Paint all polygons in the object. True or False'),
('single', 'Paint a single polygon specified by "x" and "y" parameters. True or False'),
('ref', 'Paint all polygons within a specified object with the name in "box" parameter. True or False'),
('box', 'name of the object to be used as paint reference when selecting "ref"" True. String.'),
('x', 'X value of coordinate for the selection of a single polygon. Float number.'),
('y', 'Y value of coordinate for the selection of a single polygon. Float number.'),
('outname', 'Name of the resulting Geometry object. String.'),
]),
'examples': []
}
@@ -54,31 +83,177 @@ class TclCommandPaint(TclCommandSignaled):
"""
name = args['name']
tooldia = args['tooldia']
overlap = args['overlap']
if 'tooldia' in args:
tooldia = str(args['tooldia'])
else:
tooldia = float(self.app.defaults["tools_paintoverlap"])
if 'overlap' in args:
overlap = float(args['overlap'])
else:
overlap = float(self.app.defaults["tools_paintoverlap"])
if 'order' in args:
order = args['order']
else:
order = str(self.app.defaults["tools_paintorder"])
if 'margin' in args:
margin = float(args['margin'])
else:
margin = float(self.app.defaults["tools_paintmargin"])
if 'method' in args:
method = args['method']
else:
method = str(self.app.defaults["tools_paintmethod"])
if 'connect' in args:
connect = eval(str(args['connect']).capitalize())
else:
connect = eval(str(self.app.defaults["tools_pathconnect"]))
if 'contour' in args:
contour = eval(str(args['contour']).capitalize())
else:
contour = eval(str(self.app.defaults["tools_paintcontour"]))
if 'outname' in args:
outname = args['outname']
else:
outname = name + "_paint"
obj = self.app.collection.get_by_name(name)
# Get source object.
try:
obj = self.app.collection.get_by_name(str(name))
except Exception as e:
log.debug("TclCommandPaint.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"]
})
paint_tools = dict()
tooluid = 0
for tool in tools:
tooluid += 1
paint_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:
self.raise_tcl_error("Object not found: %s" % name)
return "Object not found: %s" % name
if not isinstance(obj, Geometry):
self.raise_tcl_error('Expected Geometry, got %s %s.' % (name, type(obj)))
if 'all' in args and args['all']:
obj.paint_poly_all(tooldia, overlap, outname)
# Paint all polygons in the painted object
if 'all' in args and args['all'] is True:
self.app.paint_tool.paint_poly_all(obj=obj,
tooldia=tooldia,
overlap=overlap,
order=order,
margin=margin,
method=method,
outname=outname,
connect=connect,
contour=contour,
tools_storage=paint_tools)
return
if 'x' not in args or 'y' not in args:
self.raise_tcl_error('Expected -all 1 or -x <value> and -y <value>.')
# Paint single polygon in the painted object
elif 'single' in args and args['single'] is True:
if 'x' not in args or 'y' not in args:
self.raise_tcl_error('%s' % _("Expected -x <value> and -y <value>."))
else:
x = args['x']
y = args['y']
x = args['x']
y = args['y']
self.app.paint_tool.paint_poly(obj=obj,
inside_pt=[x, y],
tooldia=tooldia,
overlap=overlap,
order=order,
margin=margin,
method=method,
outname=outname,
connect=connect,
contour=contour,
tools_storage=paint_tools)
return
obj.paint_poly_single_click([x, y], tooldia, overlap, outname)
# 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("TclCommandPaint.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.paint_tool.paint_poly_ref(obj=obj,
sel_obj=box_obj,
tooldia=tooldia,
overlap=overlap,
order=order,
margin=margin,
method=method,
outname=outname,
connect=connect,
contour=contour,
tools_storage=paint_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."