From ef223fc71ce916ce93a73c355a5a997ed1db59d5 Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Fri, 5 Jun 2020 18:16:38 -0700 Subject: [PATCH] Path: Use _optimizeLinearSegments utility in _planarSinglePassProcess Slightly clean up the code by separating linear segment optimization from gcode generation. While the current optimization is not very effective once there is any kind of meshing noise, having a single method performing the optimization will make it easier to tweak tolerances or strategies. --- src/Mod/Path/PathScripts/PathSurface.py | 51 +++++++------------------ 1 file changed, 13 insertions(+), 38 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathSurface.py b/src/Mod/Path/PathScripts/PathSurface.py index e06749274b..373f95bde9 100644 --- a/src/Mod/Path/PathScripts/PathSurface.py +++ b/src/Mod/Path/PathScripts/PathSurface.py @@ -1076,45 +1076,20 @@ class ObjectSurface(PathOp.ObjectOp): return GCODE - def _planarSinglepassProcess(self, obj, PNTS): - output = [] - optimize = obj.OptimizeLinearPaths - lenPNTS = len(PNTS) - lop = None - onLine = False - - # Initialize first three points - nxt = None - pnt = PNTS[0] - prev = FreeCAD.Vector(-442064564.6, 258539656553.27, 3538553425.847) - - # Add temp end point - PNTS.append(FreeCAD.Vector(-4895747464.6, -25855763553.2, 35865763425)) - + def _planarSinglepassProcess(self, obj, points): + if obj.OptimizeLinearPaths: + points = self._optimizeLinearSegments(points) # Begin processing ocl points list into gcode - for i in range(0, lenPNTS): - # Calculate next point for consideration with current point - nxt = PNTS[i + 1] - - # Process point - if optimize: - if pnt.isOnLineSegment(prev, nxt): - onLine = True - else: - onLine = False - output.append(Path.Command('G1', {'X': pnt.x, 'Y': pnt.y, 'Z': pnt.z, 'F': self.horizFeed})) - else: - output.append(Path.Command('G1', {'X': pnt.x, 'Y': pnt.y, 'Z': pnt.z, 'F': self.horizFeed})) - - # Rotate point data - if onLine is False: - prev = pnt - pnt = nxt - # Efor - - PNTS.pop() # Remove temp end point - - return output + commands = [] + for pnt in points: + commands.append( + Path.Command('G1', { + 'X': pnt.x, + 'Y': pnt.y, + 'Z': pnt.z, + 'F': self.horizFeed + })) + return commands def _planarDropCutMulti(self, JOB, obj, pdc, safePDC, depthparams, SCANDATA): GCODE = [Path.Command('N (Beginning of Multi-pass layers.)', {})]