From 262e795f2ebe6deb280bc6e965d650f9cda4f2f5 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sun, 30 Jan 2022 22:26:14 +0200 Subject: [PATCH] - fixed the `drillcncjob` Tcl command to use the parameters: `endz` and `endxy` --- CHANGELOG.md | 1 + camlib.py | 33 ++++++++++++++++++----- tclCommands/TclCommandDrillcncjob.py | 39 +++++++++++++++++++--------- 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8345ff32..808c46e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ CHANGELOG for FlatCAM beta - fixed some UI issues for the Milling and Drilling plugins when using a `laser` preprocessor - finished implementing the new feature that add a new parameter `laser minimum power` for the Drillin, Milling Plugins and for the `cncjob` and `drillcncjob` Tcl commands: - modified all the preprocessors that are for `laser` to use the new parameter: `laser minimum power` +- fixed the `drillcncjob` Tcl command to use the parameters: `endz` and `endxy` 29.01.2022 diff --git a/camlib.py b/camlib.py index 38953681..0b50f891 100644 --- a/camlib.py +++ b/camlib.py @@ -4268,10 +4268,10 @@ class CNCjob(Geometry): if current_platform == '64bit': used_excellon_optimization_type = self.excellon_optimization_type else: - used_excellon_optimization_type = 'T' + used_excellon_optimization_type = 'R' if not HAS_ORTOOLS: - used_excellon_optimization_type = 'T' + used_excellon_optimization_type = 'R' # ############################################################################################################# # ############################################################################################################# @@ -4279,13 +4279,15 @@ class CNCjob(Geometry): # ############################################################################################################# # ############################################################################################################# if used_excellon_optimization_type == 'M': - log.debug("Using OR-Tools Metaheuristic Guided Local Search drill path optimization.") + self.app.log.debug("Using OR-Tools Metaheuristic Guided Local Search drill path optimization.") elif used_excellon_optimization_type == 'B': - log.debug("Using OR-Tools Basic drill path optimization.") + self.app.log.debug("Using OR-Tools Basic drill path optimization.") elif used_excellon_optimization_type == 'T': - log.debug("Using Travelling Salesman drill path optimization.") + self.app.log.debug("Using Travelling Salesman drill path optimization.") + elif used_excellon_optimization_type == 'R': + self.app.log.debug("Using RTree drill path optimization.") else: - log.debug("Using no path optimization.") + self.app.log.debug("Using no path optimization.") if self.toolchange is True: for tool in tools: @@ -4531,6 +4533,12 @@ class CNCjob(Geometry): self.app.inform.emit('[ERROR_NOTCL] %s...' % _('G91 coordinates not implemented')) return 'fail' self.z_cut = deepcopy(old_zcut) + + # add to the last tool the end_gcode + end_gcode = self.doformat(p.spindle_stop_code) + # Move to End position + end_gcode += self.doformat(p.end_code, x=0, y=0) + self.tools[tool]['gcode'] += end_gcode else: # We are not using Toolchange therefore we need to decide which tool properties to use one_tool = 1 @@ -4611,6 +4619,8 @@ class CNCjob(Geometry): for point in all_points: altPoints.append((point.coords.xy[0][0], point.coords.xy[1][0])) optimized_path = self.optimized_travelling_salesman(altPoints) + elif used_excellon_optimization_type == 'R': + optimized_path = self.exc_optimized_rtree(all_points) else: # it's actually not optimized path but here we build a list of (x,y) coordinates # out of the tool's drills @@ -4673,6 +4683,9 @@ class CNCjob(Geometry): if used_excellon_optimization_type == 'T': locx = point[0] locy = point[1] + elif used_excellon_optimization_type == 'R': + locx = point[0][0] + locy = point[0][1] else: locx = locations[point][0] locy = locations[point][1] @@ -4759,19 +4772,25 @@ class CNCjob(Geometry): if old_disp_number < disp_number <= 100: self.app.proc_container.update_view_text(' %d%%' % disp_number) old_disp_number = disp_number - else: self.app.inform.emit('[ERROR_NOTCL] %s...' % _('G91 coordinates not implemented')) return 'fail' self.z_cut = deepcopy(old_zcut) self.tools[one_tool]['gcode'] = gcode + # add the end_gcode + end_gcode = self.doformat(p.spindle_stop_code) + end_gcode += self.doformat(p.end_code, x=0, y=0) + self.tools[one_tool]['gcode'] += end_gcode + if used_excellon_optimization_type == 'M': log.debug("The total travel distance with OR-TOOLS Metaheuristics is: %s" % str(measured_distance)) elif used_excellon_optimization_type == 'B': log.debug("The total travel distance with OR-TOOLS Basic Algorithm is: %s" % str(measured_distance)) elif used_excellon_optimization_type == 'T': log.debug("The total travel distance with Travelling Salesman Algorithm is: %s" % str(measured_distance)) + elif used_excellon_optimization_type == 'R': + log.debug("The total travel distance with Rtree Algorithm is: %s" % str(measured_distance)) else: log.debug("The total travel distance with with no optimization is: %s" % str(measured_distance)) diff --git a/tclCommands/TclCommandDrillcncjob.py b/tclCommands/TclCommandDrillcncjob.py index 35315bb7..a4a3591e 100644 --- a/tclCommands/TclCommandDrillcncjob.py +++ b/tclCommands/TclCommandDrillcncjob.py @@ -350,9 +350,9 @@ class TclCommandDrillcncjob(TclCommandSignaled): else: job_obj.startz = self.app.defaults["tools_drill_travelz"] # end Z - job_obj.endz = float(endz) + job_obj.z_end = float(endz) # end X-Y location - job_obj.xy_end = xy_end + job_obj.xy_end = eval(str(xy_end)) # Excellon optimization job_obj.excellon_optimization_type = opt_type @@ -364,20 +364,35 @@ class TclCommandDrillcncjob(TclCommandSignaled): job_obj.gc_start = ret_val[1] total_gcode_parsed = [] - # from Excellon attribute self.tools - for t_item in job_obj.tools: - job_obj.tools[t_item]['data']['tools_drill_offset'] = \ - float(job_obj.tools[t_item]['offset_z']) + float(drillz) - job_obj.tools[t_item]['data']['tools_drill_ppname_e'] = job_obj.options['ppname_e'] + if job_obj.toolchange is True: + # from Excellon attribute self.tools + for t_item in job_obj.tools: + job_obj.tools[t_item]['data']['tools_drill_offset'] = \ + float(job_obj.tools[t_item]['offset_z']) + float(drillz) + job_obj.tools[t_item]['data']['tools_drill_ppname_e'] = job_obj.options['ppname_e'] - used_tooldia = obj.tools[t_item]['tooldia'] - job_obj.tools[t_item]['tooldia'] = used_tooldia - tool_gcode = job_obj.tools[t_item]['gcode'] - first_drill_point = job_obj.tools[t_item]['last_point'] + used_tooldia = obj.tools[t_item]['tooldia'] + job_obj.tools[t_item]['tooldia'] = used_tooldia + tool_gcode = job_obj.tools[t_item]['gcode'] + first_drill_point = job_obj.tools[t_item]['last_point'] + gcode_parsed = job_obj.excellon_tool_gcode_parse(used_tooldia, gcode=tool_gcode, + start_pt=first_drill_point) + total_gcode_parsed += gcode_parsed + job_obj.tools[t_item]['gcode_parsed'] = gcode_parsed + else: + first_tool = 1 + job_obj.tools[first_tool]['data']['tools_drill_offset'] = \ + float(job_obj.tools[first_tool]['offset_z']) + float(drillz) + job_obj.tools[first_tool]['data']['tools_drill_ppname_e'] = job_obj.options['ppname_e'] + + used_tooldia = obj.tools[first_tool]['tooldia'] + job_obj.tools[first_tool]['tooldia'] = used_tooldia + tool_gcode = job_obj.tools[first_tool]['gcode'] + first_drill_point = job_obj.tools[first_tool]['last_point'] gcode_parsed = job_obj.excellon_tool_gcode_parse(used_tooldia, gcode=tool_gcode, start_pt=first_drill_point) total_gcode_parsed += gcode_parsed - job_obj.tools[t_item]['gcode_parsed'] = gcode_parsed + job_obj.tools[first_tool]['gcode_parsed'] = gcode_parsed job_obj.gcode_parsed = total_gcode_parsed # job_obj.gcode_parse()