From 6a447d6d462938a4c42ce280d9c65f1abee76f35 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Sat, 3 Dec 2016 14:37:21 -0600 Subject: [PATCH] PATH: improved stepdown calculation and test --- src/Mod/Path/PathScripts/PathUtils.py | 63 +++++-- src/Mod/Path/PathTests/TestPathDepthParams.py | 163 ++++++++++++++++++ src/Mod/Path/TestPathApp.py | 4 +- 3 files changed, 210 insertions(+), 20 deletions(-) create mode 100644 src/Mod/Path/PathTests/TestPathDepthParams.py diff --git a/src/Mod/Path/PathScripts/PathUtils.py b/src/Mod/Path/PathScripts/PathUtils.py index 3ad6e4354..2f6763b4d 100644 --- a/src/Mod/Path/PathScripts/PathUtils.py +++ b/src/Mod/Path/PathScripts/PathUtils.py @@ -26,7 +26,9 @@ import FreeCAD import FreeCADGui import Part import math +# import Draft # import Path +# import TechDraw from DraftGeomUtils import geomType # from DraftGeomUtils import findWires # import DraftVecUtils @@ -103,7 +105,6 @@ def fmt(val): return format(val, '.4f') # def silhouette(obj): # from FreeCAD import Vector # s = getProjected(obj.Shape, Vector(0,0,1)) -# print s # w = TechDraw.findOuterWire(s.Edges) # return w @@ -808,34 +809,58 @@ def rampPlunge(edge, rampangle, destZ, startZ): class depth_params: - '''calculates the intermediate depth values for various operations given the starting, ending, and stepdown parameters''' + '''calculates the intermediate depth values for various operations given the starting, ending, and stepdown parameters + (self, clearance_height, rapid_safety_space, start_depth, step_down, z_finish_depth, final_depth, [user_depths=None]) + + Note: if user_depths are supplied, only user_depths will be used. + + clearance_height: Height to clear all obstacles + rapid_safety_space: Height to rapid between locations + start_depth: Top of Stock + step_down: Distance to step down between passes (always positive) + z_finish_step: Maximum amount of material to remove on the final pass + final_depth: Lowest point of the cutting operation + user_depths: List of specified depths + ''' + + def __init__(self, clearance_height, rapid_safety_space, start_depth, step_down, z_finish_step, final_depth, user_depths=None): + '''self, clearance_height, rapid_safety_space, start_depth, step_down, z_finish_depth, final_depth, [user_depths=None]''' + if z_finish_step > step_down: + raise ValueError('z_finish_step must be less than step_down') - def __init__(self, clearance_height, rapid_safety_space, start_depth, step_down, z_finish_depth, final_depth, user_depths=None): self.clearance_height = clearance_height self.rapid_safety_space = math.fabs(rapid_safety_space) self.start_depth = start_depth self.step_down = math.fabs(step_down) - self.z_finish_depth = math.fabs(z_finish_depth) + self.z_finish_step = math.fabs(z_finish_step) self.final_depth = final_depth self.user_depths = user_depths - def get_depths(self): + def get_depths(self, equalstep=False): + '''returns a list of depths to be used in order from first to last. + equalstep=True: all steps down before the finish pass will be equalized.''' + depths = [] if self.user_depths is not None: depths = self.user_depths else: - depth = self.final_depth - depths = [depth] - depth += self.z_finish_depth - if depth + 0.0000001 < self.start_depth: - if self.z_finish_depth > 0.0000001: - depths.insert(0, depth) - layer_count = int((self.start_depth - depth) / - self.step_down - 0.0000001) + 1 - if layer_count > 0: - layer_depth = (self.start_depth - depth) / layer_count - for i in range(1, layer_count): - depth += layer_depth - depths.append(depth) - depths.reverse() + total_depth = self.start_depth - self.final_depth + if total_depth <= 0: + return depths + layers_required = int((total_depth - self.z_finish_step) / self.step_down) + partial_steplayer = (total_depth - self.z_finish_step) % self.step_down + if equalstep is True and partial_steplayer > 0: + layerstep = float((total_depth - self.z_finish_step) / (layers_required + 1)) + else: + layerstep = self.step_down + + for step in range(layers_required): + d = self.start_depth - ((step +1) * layerstep) + depths.append(d) + + if self.z_finish_step != 0 and depths[-1] != self.final_depth + self.z_finish_step: + depths.append(self.final_depth + self.z_finish_step) + if depths[-1] != self.final_depth: + depths.append(self.final_depth) + return depths diff --git a/src/Mod/Path/PathTests/TestPathDepthParams.py b/src/Mod/Path/PathTests/TestPathDepthParams.py new file mode 100644 index 000000000..244bb700e --- /dev/null +++ b/src/Mod/Path/PathTests/TestPathDepthParams.py @@ -0,0 +1,163 @@ +# -*- coding: utf-8 -*- + +# *************************************************************************** +# * * +# * Copyright (c) 2016 sliptonic * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +import PathScripts.PathUtils as PU +import unittest + + +class depthTestCases(unittest.TestCase): + def test00(self): + '''Stepping down to zero ''' + clearance_height= 15 + rapid_safety_space = 12 + + start_depth = 10 + step_down = 2 + z_finish_step = 1 + final_depth = 0 + user_depths = None + + expected =[8,6,4,2,1,0] + + d = PU.depth_params(clearance_height, rapid_safety_space, start_depth, step_down, z_finish_step, final_depth, user_depths) + r = d.get_depths() + self.assertListEqual (r, expected) + + def test10(self): + '''Stepping from zero to a negative depth ''' + + clearance_height= 10 + rapid_safety_space = 5 + + start_depth = 0 + step_down = 2 + z_finish_step = 0 + final_depth = -10 + user_depths = None + + expected =[-2, -4, -6, -8, -10] + + d = PU.depth_params(clearance_height, rapid_safety_space, start_depth, step_down, z_finish_step, final_depth, user_depths) + r = d.get_depths() + self.assertListEqual (r, expected) + + def test20(self): + '''Start and end are equal or start lower than finish ''' + clearance_height= 15 + rapid_safety_space = 12 + + start_depth = 10 + step_down = 2 + z_finish_step = 0 + final_depth = 10 + user_depths = None + + expected =[] + + d = PU.depth_params(clearance_height, rapid_safety_space, start_depth, step_down, z_finish_step, final_depth, user_depths) + r = d.get_depths() + self.assertListEqual (r, expected) + + start_depth = 10 + final_depth = 15 + + expected =[] + + d = PU.depth_params(clearance_height, rapid_safety_space, start_depth, step_down, z_finish_step, final_depth, user_depths) + r = d.get_depths() + self.assertListEqual (r, expected) + + + + + def test30(self): + '''User Parameters passed in''' + clearance_height= 10 + rapid_safety_space = 5 + + start_depth = 0 + step_down = 2 + z_finish_step = 0 + final_depth = -10 + user_depths = [2, 4, 8, 10, 11, 12] + + expected =[2, 4, 8, 10, 11, 12] + + d = PU.depth_params(clearance_height, rapid_safety_space, start_depth, step_down, z_finish_step, final_depth, user_depths) + r = d.get_depths() + self.assertListEqual (r, expected) + + def test40(self): + '''Finish depth passed in.''' + clearance_height= 10 + rapid_safety_space = 5 + + start_depth = 0 + step_down = 2 + z_finish_step = 1 + final_depth = -10 + user_depths = None + + expected =[-2, -4, -6, -8, -9, -10] + + d = PU.depth_params(clearance_height, rapid_safety_space, start_depth, step_down, z_finish_step, final_depth, user_depths) + r = d.get_depths() + self.assertListEqual (r, expected) + + + def test50(self): + '''stepping down with equalstep=True''' + clearance_height= 10 + rapid_safety_space = 5 + + start_depth = 10 + step_down = 3 + z_finish_step = 0 + final_depth = 0 + user_depths = None + + expected =[7.5, 5.0, 2.5, 0] + + d = PU.depth_params(clearance_height, rapid_safety_space, start_depth, step_down, z_finish_step, final_depth, user_depths) + r = d.get_depths(equalstep=True) + self.assertListEqual (r, expected) + + + def test60(self): + '''stepping down with equalstep=True and a finish depth''' + clearance_height= 10 + rapid_safety_space = 5 + + start_depth = 10 + step_down = 3 + z_finish_step = 1 + final_depth = 0 + user_depths = None + + expected =[7.0, 4.0, 1.0, 0] + + d = PU.depth_params(clearance_height, rapid_safety_space, start_depth, step_down, z_finish_step, final_depth, user_depths) + r = d.get_depths(equalstep=True) + self.assertListEqual (r, expected) + diff --git a/src/Mod/Path/TestPathApp.py b/src/Mod/Path/TestPathApp.py index 5f246e8c7..82174b3bf 100644 --- a/src/Mod/Path/TestPathApp.py +++ b/src/Mod/Path/TestPathApp.py @@ -26,4 +26,6 @@ import TestApp from PathTests.TestPathPost import PathPostTestCases -from PathTests.TestPathGeom import TestPathGeom +#from PathTests.TestPathGeom import TestPathGeom +from PathTests.TestPathDepthParams import depthTestCases +