- fixed some bugs in the Tcl Commands

- modified the Tcl Commands to be able to use as boolean values keywords with lower case like 'false' instead of expected 'False'
This commit is contained in:
Marius Stanciu
2020-04-22 14:37:03 +03:00
committed by Marius
parent f690c2b09d
commit 66d9ddd402
14 changed files with 178 additions and 120 deletions

View File

@@ -10,6 +10,8 @@ CHANGELOG for FlatCAM beta
22.04.2020 22.04.2020
- added a new feature, project auto-saving controlled from Edit -> Preferences -> General -> APP. Preferences -> Enable Auto Save checkbox - added a new feature, project auto-saving controlled from Edit -> Preferences -> General -> APP. Preferences -> Enable Auto Save checkbox
- fixed some bugs in the Tcl Commands
- modified the Tcl Commands to be able to use as boolean values keywords with lower case like 'false' instead of expected 'False'
20.04.2020 20.04.2020

View File

@@ -79,9 +79,14 @@ class TclCommandBbox(TclCommand):
args['margin'] = float(self.app.defaults["gerber_bboxmargin"]) args['margin'] = float(self.app.defaults["gerber_bboxmargin"])
margin = args['margin'] margin = args['margin']
if 'rounded' not in args: if 'rounded' in args:
args['rounded'] = bool(eval(self.app.defaults["gerber_bboxrounded"])) try:
rounded = bool(eval(args['rounded'])) par = args['rounded'].capitalize()
except AttributeError:
par = args['rounded']
rounded = bool(eval(par))
else:
rounded = bool(eval(self.app.defaults["gerber_bboxrounded"]))
del args['name'] del args['name']

View File

@@ -92,7 +92,11 @@ class TclCommandCncjob(TclCommandSignaled):
name = '' name = ''
if 'muted' in args: if 'muted' in args:
muted = bool(eval(args['muted'])) try:
par = args['muted'].capitalize()
except AttributeError:
par = args['muted']
muted = bool(eval(par))
else: else:
muted = False muted = False

View File

@@ -38,7 +38,6 @@ class TclCommandCopperClear(TclCommand):
('method', str), ('method', str),
('connect', str), ('connect', str),
('contour', str), ('contour', str),
('has_offset', str),
('offset', float), ('offset', float),
('rest', str), ('rest', str),
('all', int), ('all', int),
@@ -69,15 +68,13 @@ class TclCommandCopperClear(TclCommand):
('connect', 'Draw lines to minimize tool lifts. True (1) or False (0)'), ('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)'), ('contour', 'Cut around the perimeter of the painting. True (1) or False (0)'),
('rest', 'Use rest-machining. True (1) or False (0)'), ('rest', 'Use rest-machining. True (1) or False (0)'),
('has_offset', 'The offset will used only if this is set True or present in args. True (1) or False (0).'), ('offset', 'If used, the copper clearing will finish to a distance from copper features. Float number.'),
('offset', '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.'),
('all', 'Will copper clear the whole object. 1 or True = enabled, anything else = disabled'), ('box', 'Name of the object to be used as reference. Either "-all" or "-box <value>" has to be used. '
('ref', 'Will clear of extra copper all polygons within a specified object with the name in "box" ' 'String.'),
'parameter. 1 or True = enabled, 0 or False = disabled'),
('box', 'Name of the object to be used as reference. Required when selecting "ref" = 1 or True. String.'),
('outname', 'Name of the resulting Geometry object. String.'), ('outname', 'Name of the resulting Geometry object. String.'),
]), ]),
'examples': ["ncc obj_name -tooldia 0.3,1 -overlap 10 -margin 1.0 -method 'lines' -all True"] 'examples': ["ncc obj_name -tooldia 0.3,1 -overlap 10 -margin 1.0 -method 'lines' -all"]
} }
def execute(self, args, unnamed_args): def execute(self, args, unnamed_args):
@@ -129,24 +126,27 @@ class TclCommandCopperClear(TclCommand):
method = str(self.app.defaults["tools_nccmethod"]) method = str(self.app.defaults["tools_nccmethod"])
if 'connect' in args: if 'connect' in args:
connect = bool(eval(args['connect'])) try:
par = args['connect'].capitalize()
except AttributeError:
par = args['connect']
connect = bool(eval(par))
else: else:
connect = bool(eval(str(self.app.defaults["tools_nccconnect"]))) connect = bool(eval(str(self.app.defaults["tools_nccconnect"])))
if 'contour' in args: if 'contour' in args:
contour = bool(eval(args['contour'])) try:
par = args['contour'].capitalize()
except AttributeError:
par = args['contour']
contour = bool(eval(par))
else: else:
contour = bool(eval(str(self.app.defaults["tools_ncccontour"]))) contour = bool(eval(str(self.app.defaults["tools_ncccontour"])))
offset = 0.0 offset = 0.0
if 'has_offset' in args: if 'offset' in args:
has_offset = bool(eval(args['has_offset'])) offset = float(args['offset'])
if args['has_offset'] is True: has_offset = 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: else:
has_offset = False has_offset = False
@@ -208,7 +208,11 @@ class TclCommandCopperClear(TclCommand):
}) })
if 'rest' in args: if 'rest' in args:
rest = bool(eval(args['rest'])) try:
par = args['rest'].capitalize()
except AttributeError:
par = args['rest']
rest = bool(eval(par))
else: else:
rest = bool(eval(str(self.app.defaults["tools_nccrest"]))) rest = bool(eval(str(self.app.defaults["tools_nccrest"])))
@@ -221,7 +225,7 @@ class TclCommandCopperClear(TclCommand):
outname = name + "_ncc_rm" outname = name + "_ncc_rm"
# Non-Copper clear all polygons in the non-copper clear object # Non-Copper clear all polygons in the non-copper clear object
if 'all' in args and bool(args['all']): if 'all' in args:
self.app.ncclear_tool.clear_copper_tcl(ncc_obj=obj, self.app.ncclear_tool.clear_copper_tcl(ncc_obj=obj,
select_method='itself', select_method='itself',
ncctooldia=tooldia, ncctooldia=tooldia,
@@ -241,40 +245,36 @@ class TclCommandCopperClear(TclCommand):
return return
# Non-Copper clear all polygons found within the box object from the the non_copper cleared object # Non-Copper clear all polygons found within the box object from the the non_copper cleared object
elif 'ref' in args and bool(eval(args['ref'])): if 'box' in args:
if 'box' not in args: box_name = args['box']
self.raise_tcl_error('%s' % _("Expected -box <value>."))
else:
box_name = args['box']
# Get box source object. # Get box source object.
try: try:
box_obj = self.app.collection.get_by_name(str(box_name)) box_obj = self.app.collection.get_by_name(str(box_name))
except Exception as e: except Exception as e:
log.debug("TclCommandCopperClear.execute() --> %s" % str(e)) log.debug("TclCommandCopperClear.execute() --> %s" % str(e))
self.raise_tcl_error("%s: %s" % (_("Could not retrieve box object"), name)) self.raise_tcl_error("%s: %s" % (_("Could not retrieve box object"), name))
return "Could not retrieve object: %s" % name return "Could not retrieve object: %s" % name
self.app.ncclear_tool.clear_copper_tcl(ncc_obj=obj, self.app.ncclear_tool.clear_copper_tcl(ncc_obj=obj,
sel_obj=box_obj, sel_obj=box_obj,
select_method='box', select_method='box',
ncctooldia=tooldia, ncctooldia=tooldia,
overlap=overlap, overlap=overlap,
order=order, order=order,
margin=margin, margin=margin,
has_offset=has_offset, has_offset=has_offset,
offset=offset, offset=offset,
method=method, method=method,
outname=outname, outname=outname,
connect=connect, connect=connect,
contour=contour, contour=contour,
rest=rest, rest=rest,
tools_storage=ncc_tools, tools_storage=ncc_tools,
plot=False, plot=False,
run_threaded=False) run_threaded=False)
return return
else:
self.raise_tcl_error("%s:" % _("None of the following args: 'ref', 'all' were found or none was set to 1.\n" # if the program reached this then it's an error because neither -all or -box <value> was used.
"Copper clearing failed.")) self.raise_tcl_error('%s' % _("Expected either -box <value> or -all."))
return "None of the following args: 'ref', 'all' were found or none was set to 1.\n" \ return "Expected either -box <value> or -all. Copper clearing failed."
"Copper clearing failed."

View File

@@ -65,7 +65,11 @@ class TclCommandDelete(TclCommand):
if args['f'] is None: if args['f'] is None:
is_forced = True is_forced = True
else: else:
is_forced = True if bool(eval(str(args['f']))) else False try:
par = args['f'].capitalize()
except AttributeError:
par = args['f']
is_forced = bool(eval(par))
except KeyError: except KeyError:
is_forced = True is_forced = True

View File

@@ -111,7 +111,11 @@ class TclCommandDrillcncjob(TclCommandSignaled):
args['outname'] = name + "_cnc" args['outname'] = name + "_cnc"
if 'muted' in args: if 'muted' in args:
muted = bool(eval(args['muted'])) try:
par = args['muted'].capitalize()
except AttributeError:
par = args['muted']
muted = bool(eval(par))
else: else:
muted = False muted = False

View File

@@ -83,8 +83,12 @@ class TclCommandIsolate(TclCommandSignaled):
args['follow'] = None args['follow'] = None
# evaluate this parameter so True, False, 0 and 1 works # evaluate this parameter so True, False, 0 and 1 works
if "combine" in args: if 'combine' in args:
args['combine'] = bool(eval(args['combine'])) try:
par = args['combine'].capitalize()
except AttributeError:
par = args['combine']
args['combine'] = bool(eval(par))
else: else:
args['combine'] = bool(eval(self.app.defaults["gerber_combine_passes"])) args['combine'] = bool(eval(self.app.defaults["gerber_combine_passes"]))

View File

@@ -86,7 +86,11 @@ class TclCommandMillDrills(TclCommandSignaled):
args['outname'] = name + "_mill_drills" args['outname'] = name + "_mill_drills"
if 'use_thread' in args: if 'use_thread' in args:
args['use_thread'] = bool(eval(args['use_thread'])) try:
par = args['use_thread'].capitalize()
except AttributeError:
par = args['use_thread']
args['use_thread'] = bool(eval(par))
else: else:
args['use_thread'] = False args['use_thread'] = False

View File

@@ -86,7 +86,11 @@ class TclCommandMillSlots(TclCommandSignaled):
args['outname'] = name + "_mill_slots" args['outname'] = name + "_mill_slots"
if 'use_thread' in args: if 'use_thread' in args:
args['use_thread'] = bool(eval(args['use_thread'])) try:
par = args['use_thread'].capitalize()
except AttributeError:
par = args['use_thread']
args['use_thread'] = bool(eval(par))
else: else:
args['use_thread'] = False args['use_thread'] = False

View File

@@ -78,9 +78,14 @@ class TclCommandNregions(TclCommand):
args['margin'] = float(self.app.defaults["gerber_noncoppermargin"]) args['margin'] = float(self.app.defaults["gerber_noncoppermargin"])
margin = float(args['margin']) margin = float(args['margin'])
if 'rounded' not in args: if 'rounded' in args:
args['rounded'] = self.app.defaults["gerber_noncopperrounded"] try:
rounded = bool(eval(args['rounded'])) par = args['rounded'].capitalize()
except AttributeError:
par = args['rounded']
rounded = bool(eval(par))
else:
rounded = bool(eval(self.app.defaults["gerber_noncopperrounded"]))
del args['name'] del args['name']

View File

@@ -69,16 +69,14 @@ class TclCommandPaint(TclCommand):
('method', 'Algorithm for painting. Can be: "standard", "seed" or "lines".'), ('method', 'Algorithm for painting. Can be: "standard", "seed" or "lines".'),
('connect', 'Draw lines to minimize tool lifts. True (1) or False (0)'), ('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)'), ('contour', 'Cut around the perimeter of the painting. True (1) or False (0)'),
('all', 'Paint all polygons in the object. True (1) or False (0)'), ('all', 'If used, paint all polygons in the object.'),
('box', 'name of the object to be used as paint reference. String.'),
('single', 'Paint a single polygon specified by "x" and "y" parameters. True (1) or False (0)'), ('single', 'Paint a single polygon specified by "x" and "y" parameters. True (1) or False (0)'),
('ref', 'Paint all polygons within a specified object with the name in "box" parameter. '
'True (1) or False (0)'),
('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.'), ('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.'), ('y', 'Y value of coordinate for the selection of a single polygon. Float number.'),
('outname', 'Name of the resulting Geometry object. String.'), ('outname', 'Name of the resulting Geometry object. String.'),
]), ]),
'examples': ["paint obj_name -tooldia 0.3 -margin 0.1 -method 'seed' -all True"] 'examples': ["paint obj_name -tooldia 0.3 -margin 0.1 -method 'seed' -all"]
} }
def execute(self, args, unnamed_args): def execute(self, args, unnamed_args):
@@ -127,14 +125,22 @@ class TclCommandPaint(TclCommand):
method = str(self.app.defaults["tools_paintmethod"]) method = str(self.app.defaults["tools_paintmethod"])
if 'connect' in args: if 'connect' in args:
connect = bool(eval(args['connect'])) try:
par = args['connect'].capitalize()
except AttributeError:
par = args['connect']
connect = bool(eval(par))
else: else:
connect = eval(str(self.app.defaults["tools_pathconnect"])) connect = bool(eval(str(self.app.defaults["tools_pathconnect"])))
if 'contour' in args: if 'contour' in args:
contour = bool(eval(args['contour'])) try:
par = args['contour'].capitalize()
except AttributeError:
par = args['contour']
contour = bool(eval(par))
else: else:
contour = eval(str(self.app.defaults["tools_paintcontour"])) contour = bool(eval(str(self.app.defaults["tools_paintcontour"])))
if 'outname' in args: if 'outname' in args:
outname = args['outname'] outname = args['outname']
@@ -202,7 +208,7 @@ class TclCommandPaint(TclCommand):
return "Object not found: %s" % name return "Object not found: %s" % name
# Paint all polygons in the painted object # Paint all polygons in the painted object
if 'all' in args and bool(eval(args['all'])) is True: if 'all' in args:
self.app.paint_tool.paint_poly_all(obj=obj, self.app.paint_tool.paint_poly_all(obj=obj,
tooldia=tooldia, tooldia=tooldia,
overlap=overlap, overlap=overlap,
@@ -218,8 +224,8 @@ class TclCommandPaint(TclCommand):
return return
# Paint single polygon in the painted object # Paint single polygon in the painted object
elif 'single' in args and bool(eval(args['single'])) is True: if 'single' in args:
if 'x' not in args or 'y' not in args: if 'x' not in args and 'y' not in args:
self.raise_tcl_error('%s' % _("Expected -x <value> and -y <value>.")) self.raise_tcl_error('%s' % _("Expected -x <value> and -y <value>."))
else: else:
x = args['x'] x = args['x']
@@ -241,37 +247,35 @@ class TclCommandPaint(TclCommand):
return return
# Paint all polygons found within the box object from the the painted object # Paint all polygons found within the box object from the the painted object
elif 'ref' in args and bool(eval(args['ref'])) is True: if 'box' in args:
if 'box' not in args: box_name = args['box']
if box_name is None:
self.raise_tcl_error('%s' % _("Expected -box <value>.")) self.raise_tcl_error('%s' % _("Expected -box <value>."))
else:
box_name = args['box']
# Get box source object. # Get box source object.
try: try:
box_obj = self.app.collection.get_by_name(str(box_name)) box_obj = self.app.collection.get_by_name(str(box_name))
except Exception as e: except Exception as e:
log.debug("TclCommandPaint.execute() --> %s" % str(e)) log.debug("TclCommandPaint.execute() --> %s" % str(e))
self.raise_tcl_error("%s: %s" % (_("Could not retrieve box object"), name)) self.raise_tcl_error("%s: %s" % (_("Could not retrieve box object"), name))
return "Could not retrieve object: %s" % name return "Could not retrieve object: %s" % name
self.app.paint_tool.paint_poly_ref(obj=obj, self.app.paint_tool.paint_poly_ref(obj=obj,
sel_obj=box_obj, sel_obj=box_obj,
tooldia=tooldia, tooldia=tooldia,
overlap=overlap, overlap=overlap,
order=order, order=order,
margin=margin, margin=margin,
method=method, method=method,
outname=outname, outname=outname,
connect=connect, connect=connect,
contour=contour, contour=contour,
tools_storage=paint_tools, tools_storage=paint_tools,
plot=False, plot=False,
run_threaded=False) run_threaded=False)
return return
else: self.raise_tcl_error("%s:" % _("None of the following args: 'box', 'single', 'all' were used.\n"
self.raise_tcl_error("%s:" % _("There was none of the following args: 'ref', 'single', 'all'.\n" "Paint failed."))
"Paint failed.")) return "None of the following args: 'box', 'single', 'all' were used. Paint failed."
return "There was none of the following args: 'ref', 'single', 'all'.\n" \
"Paint failed."

View File

@@ -37,7 +37,7 @@ class TclCommandPanelize(TclCommand):
('spacing_rows', float), ('spacing_rows', float),
('box', str), ('box', str),
('outname', str), ('outname', str),
('run_threaded', str) ('use_thread', str)
]) ])
# array of mandatory options for current Tcl command: required = {'name','outname'} # array of mandatory options for current Tcl command: required = {'name','outname'}
@@ -55,7 +55,7 @@ class TclCommandPanelize(TclCommand):
('columns', 'Number of columns.'), ('columns', 'Number of columns.'),
('rows', 'Number of rows;'), ('rows', 'Number of rows;'),
('outname', 'Name of the new geometry object.'), ('outname', 'Name of the new geometry object.'),
('run_threaded', 'False (0) = non-threaded execution or True (1) = threaded execution') ('use_thread', 'False (0) = non-threaded execution or True (1) = threaded execution')
]), ]),
'examples': [ 'examples': [
'panelize obj_name', 'panelize obj_name',
@@ -113,8 +113,12 @@ class TclCommandPanelize(TclCommand):
else: else:
outname = name + '_panelized' outname = name + '_panelized'
if 'run_threaded' in args: if 'use_thread' in args:
threaded = bool(eval(args['run_threaded'])) try:
par = args['use_thread'].capitalize()
except AttributeError:
par = args['use_thread']
threaded = bool(eval(par))
else: else:
threaded = False threaded = False

View File

@@ -49,17 +49,27 @@ class TclCommandPlotAll(TclCommandSignaled):
""" """
if 'use_thread' in args: if 'use_thread' in args:
threaded = bool(eval(args['use_thread'])) try:
par = args['use_thread'].capitalize()
except AttributeError:
par = args['use_thread']
threaded = bool(eval(par))
else: else:
threaded = False threaded = False
plot_status = True
if 'plot_status' in args: if 'plot_status' in args:
if args['plot_status'] is None: try:
if args['plot_status'] is None:
plot_status = True
else:
try:
par = args['plot_status'].capitalize()
except AttributeError:
par = args['plot_status']
plot_status = bool(eval(par))
except KeyError:
plot_status = True plot_status = True
else:
plot_status = bool(eval(args['plot_status']))
else:
plot_status = True
for obj in self.app.collection.get_list(): for obj in self.app.collection.get_list():
obj.options["plot"] = True if plot_status is True else False obj.options["plot"] = True if plot_status is True else False

View File

@@ -69,11 +69,15 @@ class TclCommandWriteGCode(TclCommandSignaled):
postamble = args['postamble'] if 'postamble' in args else '' postamble = args['postamble'] if 'postamble' in args else ''
if 'muted' in args: if 'muted' in args:
muted = bool(eval(args['muted'])) try:
par = args['muted'].capitalize()
except AttributeError:
par = args['muted']
muted = bool(eval(par))
else: else:
muted = False muted = False
# TODO: This is not needed any more? All targets should be present. # This is not needed any more? All targets should be present.
# If there are promised objects, wait until all promises have been fulfilled. # If there are promised objects, wait until all promises have been fulfilled.
# if self.collection.has_promises(): # if self.collection.has_promises():
# def write_gcode_on_object(new_object): # def write_gcode_on_object(new_object):