diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index bd68251899..c00eeb4d30 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -84,7 +84,9 @@ SET(PathScripts_SRCS SET(PathTests_SRCS PathTests/__init__.py + PathTests/boxtest.fcstd PathTests/PathTestUtils.py + PathTests/test_centroid_00.ngc PathTests/test_linuxcnc_00.ngc PathTests/TestPathCore.py PathTests/TestPathDepthParams.py diff --git a/src/Mod/Path/PathTests/TestPathPost.py b/src/Mod/Path/PathTests/TestPathPost.py index 6129a50ca4..bb6dd4c674 100644 --- a/src/Mod/Path/PathTests/TestPathPost.py +++ b/src/Mod/Path/PathTests/TestPathPost.py @@ -23,72 +23,39 @@ # *************************************************************************** import FreeCAD -import Path import PathScripts import PathScripts.PathContour import PathScripts.PathJob import PathScripts.PathPost import PathScripts.PathToolController -import PathScripts.PathUtils +import PathScripts.PathUtil import difflib import unittest + class PathPostTestCases(unittest.TestCase): def setUp(self): - self.doc = FreeCAD.newDocument("PathPostTest") - box = self.doc.addObject("Part::Box", "Box") - - # Create job and setup tool library + default tool - self.job = self.doc.addObject("Path::FeatureCompoundPython", "Job") - PathScripts.PathJob.ObjectPathJob(self.job, box, None) - PathScripts.PathToolController.CommandPathToolController.Create(self.job.Name, False) - tool1 = Path.Tool() - tool1.Diameter = 5.0 - tool1.Name = "Default Tool" - tool1.CuttingEdgeHeight = 15.0 - tool1.ToolType = "EndMill" - tool1.Material = "HighSpeedSteel" - - tc = FreeCAD.ActiveDocument.addObject("Path::FeaturePython",'TC') - PathScripts.PathToolController.ToolController(tc) - PathScripts.PathUtils.addToJob(tc, "Job") - tc.Tool = tool1 - tc.ToolNumber = 2 - - self.failUnless(True) - - self.doc.getObject("TC").ToolNumber = 2 - self.doc.recompute() - - contour = self.doc.addObject("Path::FeaturePython", "Contour") - PathScripts.PathContour.ObjectContour(contour) - contour.Active = True - contour.ClearanceHeight = 20.0 - contour.StepDown = 1.0 - contour.StartDepth= 10.0 - contour.FinalDepth=0.0 - contour.SafeHeight = 12.0 - contour.OffsetExtra = 0.0 - contour.Direction = 'CW' - contour.ToolController = tc - contour.UseComp = False - PathScripts.PathUtils.addToJob(contour) - PathScripts.PathContour.ObjectContour.setDepths(contour.Proxy, contour) - self.doc.recompute() + testfile = FreeCAD.getHomePath() + 'Mod/Path/PathTests/boxtest.fcstd' + self.doc = FreeCAD.open(testfile) + self.job = FreeCAD.ActiveDocument.getObject("Job") + self.postlist = [] + currTool = None + for obj in self.job.Group: + if not isinstance(obj.Proxy, PathScripts.PathToolController.ToolController): + tc = PathScripts.PathUtil.toolControllerForOp(obj) + if tc is not None: + if tc.ToolNumber != currTool: + self.postlist.append(tc) + self.postlist.append(obj) def tearDown(self): - FreeCAD.closeDocument("PathPostTest") + FreeCAD.closeDocument("boxtest") def testLinuxCNC(self): - # first create something to generate a path for - - self.job.PostProcessor = 'linuxcnc' - self.job.PostProcessorArgs = '--no-header --no-line-numbers --no-comments --no-show-editor --output-precision=2' - - post = PathScripts.PathPost.CommandPathPost() - (fail, gcode) = post.exportObjectsWith([self.job], self.job, False) - self.assertFalse(fail) + from PathScripts.post import linuxcnc_post as postprocessor + args = '--no-header --no-line-numbers --no-comments --no-show-editor --output-precision=2' + gcode = postprocessor.export(self.postlist, 'gcode.tmp', args) referenceFile = FreeCAD.getHomePath() + 'Mod/Path/PathTests/test_linuxcnc_00.ngc' with open(referenceFile, 'r') as fp: @@ -99,8 +66,24 @@ class PathPostTestCases(unittest.TestCase): with open('tab.tmp', 'w') as fp: fp.write(gcode) - if gcode != refGCode: msg = ''.join(difflib.ndiff(gcode.splitlines(True), refGCode.splitlines(True))) self.fail("linuxcnc output doesn't match: " + msg) + def testCentroid(self): + from PathScripts.post import centroid_post as postprocessor + args = '--no-header --no-line-numbers --no-comments --no-show-editor --axis-precision=2 --feed-precision=2' + gcode = postprocessor.export(self.postlist, 'gcode.tmp', args) + + referenceFile = FreeCAD.getHomePath() + 'Mod/Path/PathTests/test_centroid_00.ngc' + with open(referenceFile, 'r') as fp: + refGCode = fp.read() + + # Use if this test fails in order to have a real good look at the changes + if False: + with open('tab.tmp', 'w') as fp: + fp.write(gcode) + + if gcode != refGCode: + msg = ''.join(difflib.ndiff(gcode.splitlines(True), refGCode.splitlines(True))) + self.fail("linuxcnc output doesn't match: " + msg) diff --git a/src/Mod/Path/PathTests/boxtest.fcstd b/src/Mod/Path/PathTests/boxtest.fcstd new file mode 100644 index 0000000000..fc8f2bf740 Binary files /dev/null and b/src/Mod/Path/PathTests/boxtest.fcstd differ diff --git a/src/Mod/Path/PathTests/test_centroid_00.ngc b/src/Mod/Path/PathTests/test_centroid_00.ngc new file mode 100644 index 0000000000..974c8a6250 --- /dev/null +++ b/src/Mod/Path/PathTests/test_centroid_00.ngc @@ -0,0 +1,69 @@ +G90 G80 G40 G49 +G53 G00 G17 +G20 +;Default_Tool +M6 T2 +M3 S0 +;Contour +;Uncompensated Tool Path +G0 Z15.00 +G90 +G17 +G0 Z15.00 +G0 X10.00 Y10.00 +G0 Z10.00 +G1 X10.00 Y10.00 Z9.00 +G1 X10.00 Y0.00 Z9.00 +G1 X0.00 Y0.00 Z9.00 +G1 X0.00 Y10.00 Z9.00 +G1 X10.00 Y10.00 Z9.00 +G1 X10.00 Y10.00 Z8.00 +G1 X10.00 Y0.00 Z8.00 +G1 X0.00 Y0.00 Z8.00 +G1 X0.00 Y10.00 Z8.00 +G1 X10.00 Y10.00 Z8.00 +G1 X10.00 Y10.00 Z7.00 +G1 X10.00 Y0.00 Z7.00 +G1 X0.00 Y0.00 Z7.00 +G1 X0.00 Y10.00 Z7.00 +G1 X10.00 Y10.00 Z7.00 +G1 X10.00 Y10.00 Z6.00 +G1 X10.00 Y0.00 Z6.00 +G1 X0.00 Y0.00 Z6.00 +G1 X0.00 Y10.00 Z6.00 +G1 X10.00 Y10.00 Z6.00 +G1 X10.00 Y10.00 Z5.00 +G1 X10.00 Y0.00 Z5.00 +G1 X0.00 Y0.00 Z5.00 +G1 X0.00 Y10.00 Z5.00 +G1 X10.00 Y10.00 Z5.00 +G1 X10.00 Y10.00 Z4.00 +G1 X10.00 Y0.00 Z4.00 +G1 X0.00 Y0.00 Z4.00 +G1 X0.00 Y10.00 Z4.00 +G1 X10.00 Y10.00 Z4.00 +G1 X10.00 Y10.00 Z3.00 +G1 X10.00 Y0.00 Z3.00 +G1 X0.00 Y0.00 Z3.00 +G1 X0.00 Y10.00 Z3.00 +G1 X10.00 Y10.00 Z3.00 +G1 X10.00 Y10.00 Z2.00 +G1 X10.00 Y0.00 Z2.00 +G1 X0.00 Y0.00 Z2.00 +G1 X0.00 Y10.00 Z2.00 +G1 X10.00 Y10.00 Z2.00 +G1 X10.00 Y10.00 Z1.00 +G1 X10.00 Y0.00 Z1.00 +G1 X0.00 Y0.00 Z1.00 +G1 X0.00 Y10.00 Z1.00 +G1 X10.00 Y10.00 Z1.00 +G1 X10.00 Y10.00 Z0.00 +G1 X10.00 Y0.00 Z0.00 +G1 X0.00 Y0.00 Z0.00 +G1 X0.00 Y10.00 Z0.00 +G1 X10.00 Y10.00 Z0.00 +G0 Z15.00 +M5 M25 +G49 H0 +G90 G80 G40 G49 +M99 diff --git a/src/Mod/Path/PathTests/test_linuxcnc_00.ngc b/src/Mod/Path/PathTests/test_linuxcnc_00.ngc index 3fb2a21c47..6256f88731 100644 --- a/src/Mod/Path/PathTests/test_linuxcnc_00.ngc +++ b/src/Mod/Path/PathTests/test_linuxcnc_00.ngc @@ -1,9 +1,6 @@ G17 G90 G21 (Default_Tool) -M6 T1 -M3 S0.00 -(TC) M6 T2 M3 S0.00 (Contour) @@ -11,9 +8,9 @@ M3 S0.00 G0 Z15.00 G90 G17 -G0 X0.00 Y0.00 Z15.00 -G0 X10.00 Y10.00 Z15.00 -G0 X10.00 Y10.00 Z10.00 +G0 Z15.00 +G0 X10.00 Y10.00 +G0 Z10.00 G1 X10.00 Y10.00 Z9.00 G1 X10.00 Y0.00 Z9.00 G1 X0.00 Y0.00 Z9.00