From 56875b21375b1e90446067dc8c13338f3c0c90e5 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Sun, 7 Nov 2021 13:34:18 -0600 Subject: [PATCH 1/3] Drill Generator and testing --- src/Mod/Path/CMakeLists.txt | 7 +- src/Mod/Path/Generators/drill_generator.py | 91 ++++++++++++++ .../Path/PathTests/TestPathDrillGenerator.py | 112 ++++++++++++++++++ src/Mod/Path/TestPathApp.py | 8 +- 4 files changed, 214 insertions(+), 4 deletions(-) create mode 100644 src/Mod/Path/Generators/drill_generator.py create mode 100644 src/Mod/Path/PathTests/TestPathDrillGenerator.py diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index 764faf99b3..6cf814b764 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -142,6 +142,10 @@ SET(PathScripts_SRCS PathScripts/__init__.py ) +SET(PathScripts_generator_SRCS + Generators/drill_generator.py +) + SET(PathScripts_post_SRCS PathScripts/post/__init__.py PathScripts/post/centroid_post.py @@ -211,6 +215,7 @@ SET(PathTests_SRCS PathTests/TestPathDepthParams.py PathTests/TestPathDressupDogbone.py PathTests/TestPathDressupHoldingTags.py + PathTests/TestPathDrillGenerator.py PathTests/TestPathGeom.py PathTests/TestPathHelix.py PathTests/TestPathLog.py @@ -304,7 +309,7 @@ INSTALL( DESTINATION Mod/Path/PathTests ) - + INSTALL( FILES diff --git a/src/Mod/Path/Generators/drill_generator.py b/src/Mod/Path/Generators/drill_generator.py new file mode 100644 index 0000000000..0018b3d7e4 --- /dev/null +++ b/src/Mod/Path/Generators/drill_generator.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +# *************************************************************************** +# * Copyright (c) 2021 sliptonic shopinthewoods@gmail.com * +# * * +# * 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.PathLog as PathLog +import Path +import numpy + +__title__ = "Drilling Path Generator" +__author__ = "sliptonic (Brad Collette)" +__url__ = "http://www.freecadweb.org" +__doc__ = "Generates the drilling toolpath for a single spotshape" + + +if False: + PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) + PathLog.trackModule(PathLog.thisModule()) +else: + PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) + + +def generate(edge, dwelltime=0.0, peckdepth=0.0, repeat=1): + + + startPoint = edge.Vertexes[0].Point + endPoint = edge.Vertexes[1].Point + + PathLog.debug(startPoint) + PathLog.debug(endPoint) + + PathLog.debug(numpy.isclose(startPoint.sub(endPoint).x, 0, rtol=1e-05, atol=1e-06)) + PathLog.debug(numpy.isclose(startPoint.sub(endPoint).y, 0, rtol=1e-05, atol=1e-06)) + PathLog.debug(endPoint) + + if repeat < 1: + raise ValueError("repeat must be 1 or greater") + + if not type(repeat) is int: + raise ValueError("repeat value must be an integer") + + if not type(peckdepth) is float: + raise ValueError("peckdepth must be a float") + + if not type(dwelltime) is float: + raise ValueError("dwelltime must be a float") + + if not ( + numpy.isclose(startPoint.sub(endPoint).x, 0, rtol=1e-05, atol=1e-06) + and (numpy.isclose(startPoint.sub(endPoint).y, 0, rtol=1e-05, atol=1e-06)) + ): + raise ValueError("edge is not aligned with Z axis") + + cmdParams = {} + cmdParams["X"] = startPoint.x + cmdParams["Y"] = startPoint.y + cmdParams["Z"] = endPoint.z + cmdParams["R"] = startPoint.z + + if repeat > 1: + cmdParams["L"] = repeat + + if peckdepth == 0.0: + if dwelltime > 0.0: + cmd = "G82" + cmdParams["P"] = dwelltime + else: + cmd = "G81" + else: + cmd = "G83" + cmdParams["Q"] = peckdepth + + return [Path.Command(cmd, cmdParams)] diff --git a/src/Mod/Path/PathTests/TestPathDrillGenerator.py b/src/Mod/Path/PathTests/TestPathDrillGenerator.py new file mode 100644 index 0000000000..8414c5d2e6 --- /dev/null +++ b/src/Mod/Path/PathTests/TestPathDrillGenerator.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +# *************************************************************************** +# * Copyright (c) 2021 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 Path +import FreeCAD +import Generators.drill_generator as generator +import PathScripts.PathLog as PathLog +import PathTests.PathTestUtils as PathTestUtils +import Part + +PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) +PathLog.trackModule(PathLog.thisModule()) + + +class TestPathDrillGenerator(PathTestUtils.PathTestBase): + def test00(self): + """Test Basic Drill Generator Return""" + v1 = FreeCAD.Vector(0, 0, 10) + v2 = FreeCAD.Vector(0, 0, 0) + + e = Part.makeLine(v1, v2) + + result = generator.generate(e) + + self.assertTrue(type(result) is list) + self.assertTrue(type(result[0]) is Path.Command) + + command = result[0] + + self.assertTrue(command.Name == "G81") + self.assertTrue(command.Parameters["R"] == 10) + self.assertTrue(command.Parameters["X"] == 0) + self.assertTrue(command.Parameters["Y"] == 0) + self.assertTrue(command.Parameters["Z"] == 0) + + # repeat must be > 0 + args = {"edge": e, "repeat": 0} + self.assertRaises(ValueError, generator.generate, **args) + + # repeat must be integer + args = {"edge": e, "repeat": 1.5} + self.assertRaises(ValueError, generator.generate, **args) + + def test10(self): + """Test edge alignment check""" + v1 = FreeCAD.Vector(0, 10, 10) + v2 = FreeCAD.Vector(0, 0, 0) + + e = Part.makeLine(v1, v2) + + self.assertRaises(ValueError, generator.generate, e) + + def test20(self): + """Test Basic Peck Drill Generator Return""" + v1 = FreeCAD.Vector(0, 0, 10) + v2 = FreeCAD.Vector(0, 0, 0) + + e = Part.makeLine(v1, v2) + + result = generator.generate(e, peckdepth=1.2) + + self.assertTrue(type(result) is list) + self.assertTrue(type(result[0]) is Path.Command) + + command = result[0] + + self.assertTrue(command.Name == "G83") + self.assertTrue(command.Parameters["Q"] == 1.2) + + # peckdepth must be a float + args = {"edge": e, "peckdepth": 1} + self.assertRaises(ValueError, generator.generate, **args) + + def test30(self): + """Test Basic Dwell Drill Generator Return""" + v1 = FreeCAD.Vector(0, 0, 10) + v2 = FreeCAD.Vector(0, 0, 0) + + e = Part.makeLine(v1, v2) + + result = generator.generate(e, dwelltime=0.5) + + self.assertTrue(type(result) is list) + self.assertTrue(type(result[0]) is Path.Command) + + command = result[0] + + self.assertTrue(command.Name == "G82") + self.assertTrue(command.Parameters["P"] == 0.5) + + # dwelltime should be a float + args = {"edge": e, "dwelltime": 1} + self.assertRaises(ValueError, generator.generate, **args) diff --git a/src/Mod/Path/TestPathApp.py b/src/Mod/Path/TestPathApp.py index 961046d948..6f34e71c5a 100644 --- a/src/Mod/Path/TestPathApp.py +++ b/src/Mod/Path/TestPathApp.py @@ -22,17 +22,18 @@ import TestApp -# from PathTests.TestPathPost import PathPostTestCases from PathTests.TestPathAdaptive import TestPathAdaptive from PathTests.TestPathCore import TestPathCore from PathTests.TestPathDeburr import TestPathDeburr from PathTests.TestPathDepthParams import depthTestCases from PathTests.TestPathDressupDogbone import TestDressupDogbone from PathTests.TestPathDressupHoldingTags import TestHoldingTags +from PathTests.TestPathDrillGenerator import TestPathDrillGenerator from PathTests.TestPathGeom import TestPathGeom -from PathTests.TestPathHelix import TestPathHelix +# from PathTests.TestPathHelix import TestPathHelix from PathTests.TestPathLog import TestPathLog from PathTests.TestPathOpTools import TestPathOpTools +# from PathTests.TestPathPost import PathPostTestCases from PathTests.TestPathPreferences import TestPathPreferences from PathTests.TestPathPropertyBag import TestPathPropertyBag from PathTests.TestPathSetupSheet import TestPathSetupSheet @@ -55,7 +56,7 @@ False if TestPathAdaptive.__name__ else True False if TestPathCore.__name__ else True False if TestPathDeburr.__name__ else True False if TestPathGeom.__name__ else True -False if TestPathHelix.__name__ else True +# False if TestPathHelix.__name__ else True False if TestPathLog.__name__ else True False if TestPathOpTools.__name__ else True False if TestPathPreferences.__name__ else True @@ -70,3 +71,4 @@ False if TestPathTooltable.__name__ else True False if TestPathUtil.__name__ else True False if TestPathVcarve.__name__ else True False if TestPathVoronoi.__name__ else True +False if TestPathDrillGenerator.__name__ else True From 4a7cdd5095aa08e077901824ad73e7ad7c91faf4 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Tue, 9 Nov 2021 09:04:01 -0600 Subject: [PATCH 2/3] fixing comment errors --- src/Mod/Path/Generators/drill_generator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/Path/Generators/drill_generator.py b/src/Mod/Path/Generators/drill_generator.py index 0018b3d7e4..74d8238305 100644 --- a/src/Mod/Path/Generators/drill_generator.py +++ b/src/Mod/Path/Generators/drill_generator.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # *************************************************************************** -# * Copyright (c) 2021 sliptonic shopinthewoods@gmail.com * +# * Copyright (c) 2021 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) * @@ -27,7 +27,7 @@ import numpy __title__ = "Drilling Path Generator" __author__ = "sliptonic (Brad Collette)" -__url__ = "http://www.freecadweb.org" +__url__ = "https://www.freecadweb.org" __doc__ = "Generates the drilling toolpath for a single spotshape" From 73c01a4196ebf4396971bf6a75a05bcd5f8141f4 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Wed, 10 Nov 2021 13:33:20 -0600 Subject: [PATCH 3/3] cmake error --- src/Mod/Path/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index 6cf814b764..23c91b2f57 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -142,7 +142,7 @@ SET(PathScripts_SRCS PathScripts/__init__.py ) -SET(PathScripts_generator_SRCS +SET(Generator_SRCS Generators/drill_generator.py ) @@ -264,6 +264,7 @@ SET(Path_Data SET(all_files ${PathScripts_SRCS} + ${Generator_SRCS} ${PathScripts_post_SRCS} ${Tools_SRCS} ${Tools_Bit_SRCS} @@ -296,6 +297,13 @@ INSTALL( Mod/Path/PathScripts ) +INSTALL( + FILES + ${Generator_SRCS} + DESTINATION + Mod/Path/Generators +) + INSTALL( FILES ${PathTests_SRCS}