- fixed some issues in the paint Tcl command

This commit is contained in:
Marius Stanciu
2022-01-29 22:36:56 +02:00
committed by Marius
parent 1467c5e0bc
commit 7e927b9626
2 changed files with 58 additions and 45 deletions

View File

@@ -15,6 +15,7 @@ CHANGELOG for FlatCAM beta
- in the `panelize`, `cutout` and `geocutout` Tcl commands updated the error strings and made sure that if an error occur then a potential script execution in chain is aborted - in the `panelize`, `cutout` and `geocutout` Tcl commands updated the error strings and made sure that if an error occur then a potential script execution in chain is aborted
- updated the `new` Tcl command: now it has an argument `-keep_scripts` that when True, will keep the loaded scripts in the new project - updated the `new` Tcl command: now it has an argument `-keep_scripts` that when True, will keep the loaded scripts in the new project
- fixed some issues in the `ncc` Tcl command - fixed some issues in the `ncc` Tcl command
- fixed some issues in the `paint` Tcl command
28.01.2022 28.01.2022

View File

@@ -95,9 +95,10 @@ class TclCommandPaint(TclCommand):
try: try:
obj = self.app.collection.get_by_name(str(name)) obj = self.app.collection.get_by_name(str(name))
except Exception as e: except Exception as e:
log.error("TclCommandPaint.execute() --> %s" % str(e)) self.app.log.error("TclCommandPaint.execute() --> %s" % str(e))
self.app.log.error("Could not retrieve object: %s" % name)
self.raise_tcl_error("%s: %s" % (_("Could not retrieve object"), name)) self.raise_tcl_error("%s: %s" % (_("Could not retrieve object"), name))
return "Could not retrieve object: %s" % name return "fail"
if 'tooldia' in args: if 'tooldia' in args:
tooldia = str(args['tooldia']) tooldia = str(args['tooldia'])
@@ -132,8 +133,10 @@ class TclCommandPaint(TclCommand):
elif method == "combo": elif method == "combo":
method = 4 method = 4
else: else:
return "Method not supported or typo.\n" \ msg = "Method not supported or typo.\n" \
"Supported methods are: 'standard', 'seed', 'lines', 'laser_lines' and 'combo'." "Supported methods are: 'standard', 'seed', 'lines', 'laser_lines' and 'combo'."
self.app.log.error(msg)
return "fail"
else: else:
method = str(self.app.defaults["tools_paint_method"]) method = str(self.app.defaults["tools_paint_method"])
@@ -173,37 +176,37 @@ class TclCommandPaint(TclCommand):
except AttributeError: except AttributeError:
tools = [float(tooldia)] tools = [float(tooldia)]
# store here the default data for Geometry Data # store here the default data for Geometry Data
default_data = {} default_data = self.app.options.copy()
default_data.update({ default_data.update({
"name": outname, "name": outname,
"plot": False, "plot": False,
"cutz": self.app.defaults["geometry_cutz"], "cutz": self.app.defaults["tools_mill_cutz"],
"vtipdia": float(self.app.defaults["tools_paint_tipdia"]), "vtipdia": float(self.app.defaults["tools_paint_tipdia"]),
"vtipangle": float(self.app.defaults["tools_paint_tipangle"]), "vtipangle": float(self.app.defaults["tools_paint_tipangle"]),
"travelz": self.app.defaults["geometry_travelz"], "travelz": self.app.defaults["tools_mill_travelz"],
"feedrate": self.app.defaults["geometry_feedrate"], "feedrate": self.app.defaults["tools_mill_feedrate"],
"feedrate_z": self.app.defaults["geometry_feedrate_z"], "feedrate_z": self.app.defaults["tools_mill_feedrate_z"],
"feedrate_rapid": self.app.defaults["geometry_feedrate_rapid"], "feedrate_rapid": self.app.defaults["tools_mill_feedrate_rapid"],
"dwell": self.app.defaults["geometry_dwell"], "dwell": self.app.defaults["tools_mill_dwell"],
"dwelltime": self.app.defaults["geometry_dwelltime"], "dwelltime": self.app.defaults["tools_mill_dwelltime"],
"multidepth": self.app.defaults["geometry_multidepth"], "multidepth": self.app.defaults["tools_mill_multidepth"],
"ppname_g": self.app.defaults["geometry_ppname_g"], "ppname_g": self.app.defaults["tools_mill_ppname_g"],
"depthperpass": self.app.defaults["geometry_depthperpass"], "depthperpass": self.app.defaults["tools_mill_depthperpass"],
"extracut": self.app.defaults["geometry_extracut"], "extracut": self.app.defaults["tools_mill_extracut"],
"extracut_length": self.app.defaults["geometry_extracut_length"], "extracut_length": self.app.defaults["tools_mill_extracut_length"],
"toolchange": self.app.defaults["geometry_toolchange"], "toolchange": self.app.defaults["tools_mill_toolchange"],
"toolchangez": self.app.defaults["geometry_toolchangez"], "toolchangez": self.app.defaults["tools_mill_toolchangez"],
"endz": self.app.defaults["geometry_endz"], "endz": self.app.defaults["tools_mill_endz"],
"endxy": self.app.defaults["geometry_endxy"], "endxy": self.app.defaults["tools_mill_endxy"],
"spindlespeed": self.app.defaults["geometry_spindlespeed"], "spindlespeed": self.app.defaults["tools_mill_spindlespeed"],
"toolchangexy": self.app.defaults["geometry_toolchangexy"], "toolchangexy": self.app.defaults["tools_mill_toolchangexy"],
"startz": self.app.defaults["geometry_startz"], "startz": self.app.defaults["tools_mill_startz"],
"area_exclusion": self.app.defaults["geometry_area_exclusion"], "area_exclusion": self.app.defaults["tools_mill_area_exclusion"],
"area_shape": self.app.defaults["geometry_area_shape"], "area_shape": self.app.defaults["tools_mill_area_shape"],
"area_strategy": self.app.defaults["geometry_area_strategy"], "area_strategy": self.app.defaults["tools_mill_area_strategy"],
"area_overz": float(self.app.defaults["geometry_area_overz"]), "area_overz": float(self.app.defaults["tools_mill_area_overz"]),
"tooldia": tooldia, "tooldia": tooldia,
"tools_paint_offset": offset, "tools_paint_offset": offset,
@@ -232,7 +235,8 @@ class TclCommandPaint(TclCommand):
paint_tools[int(tooluid)]['data']['tooldia'] = self.app.dec_format(float(tool), self.app.decimals) paint_tools[int(tooluid)]['data']['tooldia'] = self.app.dec_format(float(tool), self.app.decimals)
if obj is None: if obj is None:
return "Object not found: %s" % name self.app.log.error("Object not found: %s" % name)
return "fail"
# Paint all polygons in the painted object # Paint all polygons in the painted object
if select == 0: # 'all' in args if select == 0: # 'all' in args
@@ -251,12 +255,15 @@ class TclCommandPaint(TclCommand):
if not args['single'] or args['single'] == '': if not args['single'] or args['single'] == '':
self.raise_tcl_error('%s Got: %s' % self.raise_tcl_error('%s Got: %s' %
(_("Expected a tuple value like -single 3.2,0.1."), str(args['single']))) (_("Expected a tuple value like -single 3.2,0.1."), str(args['single'])))
return "fail"
else: else:
coords_xy = [float(eval(a)) for a in args['single'].split(",") if a != ''] coords_xy = [float(eval(a)) for a in args['single'].split(",") if a != '']
if coords_xy and len(coords_xy) != 2: if coords_xy and len(coords_xy) != 2:
self.raise_tcl_error('%s Got: %s' % self.raise_tcl_error('%s Got: %s' %
(_("Expected a tuple value like -single 3.2,0.1."), str(coords_xy))) (_("Expected a tuple value like -single 3.2,0.1."), str(coords_xy)))
return "fail"
x = coords_xy[0] x = coords_xy[0]
y = coords_xy[1] y = coords_xy[1]
@@ -270,7 +277,8 @@ class TclCommandPaint(TclCommand):
plot=False, plot=False,
run_threaded=False) run_threaded=False)
if ret_val == 'fail': if ret_val == 'fail':
return "Could not find a Polygon at the specified location." self.app.log.error("Could not find a Polygon at the specified location.")
return "fail"
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
@@ -278,15 +286,18 @@ class TclCommandPaint(TclCommand):
box_name = args['box'] box_name = args['box']
if box_name is None: if box_name is None:
self.app.log.error('%s' % _("Expected -box <value>."))
self.raise_tcl_error('%s' % _("Expected -box <value>.")) self.raise_tcl_error('%s' % _("Expected -box <value>."))
return "fail"
# 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.error("TclCommandPaint.execute() --> %s" % str(e)) self.app.log.error("TclCommandPaint.execute() --> %s" % str(e))
self.app.log.error("Could not retrieve object: %s" % name)
self.raise_tcl_error("%s: %s" % (_("Could not retrieve object"), name)) self.raise_tcl_error("%s: %s" % (_("Could not retrieve object"), name))
return "Could not retrieve object: %s" % name return "fail"
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,
@@ -299,6 +310,7 @@ class TclCommandPaint(TclCommand):
run_threaded=False) run_threaded=False)
return return
self.app.log.error("None of the following args: 'box', 'single', 'all' were used. Paint failed.")
self.raise_tcl_error("%s:" % _("None of the following args: 'box', 'single', 'all' were used.\n" self.raise_tcl_error("%s:" % _("None of the following args: 'box', 'single', 'all' were used.\n"
"Paint failed.")) "Paint failed."))
return "None of the following args: 'box', 'single', 'all' were used. Paint failed." return "fail"