diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index 283f87a0546b..ceeba426f04e 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -73,6 +73,9 @@ SET(PathScripts_SRCS PathScripts/DogboneDressup.py PathScripts/PathPreferencesPathJob.py PathScripts/PathPreferences.py + PathTests/__init__.py + PathTests/test_linuxcnc_00.ngc + PathTests/TestPathDressupHoldingTags.py PathTests/TestPathPost.py TestPathApp.py ) diff --git a/src/Mod/Path/PathScripts/PathDressupHoldingTags.py b/src/Mod/Path/PathScripts/PathDressupHoldingTags.py index 199f46cc0c81..82f5a3eb21a3 100644 --- a/src/Mod/Path/PathScripts/PathDressupHoldingTags.py +++ b/src/Mod/Path/PathScripts/PathDressupHoldingTags.py @@ -132,7 +132,7 @@ def pathCommandForEdge(edge): class Tag: - def __init__(self, x, y, width, height, angle, enabled): + def __init__(self, x, y, width, height, angle, enabled=True): self.x = x self.y = y self.width = math.fabs(width) @@ -151,7 +151,7 @@ def createSolidsAt(self, z): height = self.height if self.angle == 90 and height > 0: self.solid = Part.makeCylinder(r1, height) - self.core = self.solid + self.core = self.solid.copy() elif self.angle > 0.0 and height > 0.0: tangens = math.tan(math.radians(self.angle)) dr = height / tangens diff --git a/src/Mod/Path/PathTests/TestPathDressupHoldingTags.py b/src/Mod/Path/PathTests/TestPathDressupHoldingTags.py new file mode 100644 index 000000000000..85c724a7e93c --- /dev/null +++ b/src/Mod/Path/PathTests/TestPathDressupHoldingTags.py @@ -0,0 +1,88 @@ +# -*- 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 FreeCAD +import Part +import Path +import PathScripts +import math +import unittest + +from PathScripts.PathDressupHoldingTags import Tag + +slack = 0.0000001 + +def pointsCoincide(pt1, pt2): + pt = pt1 - pt2 + if math.fabs(pt.x) > slack: + return False + if math.fabs(pt.y) > slack: + return False + if math.fabs(pt.z) > slack: + return False + return True + +class PathDressupHoldingTagsTestCases(unittest.TestCase): + """Unit tests for the HoldingTags dressup.""" + + def testTagBasics(self): + """Check Tag origin, serialization and de-serialization.""" + tag = Tag(77, 13, 4, 5, 90, True) + self.assertTrue(pointsCoincide(tag.originAt(3), FreeCAD.Vector(77, 13, 3))) + s = tag.toString() + tagCopy = Tag.FromString(s) + self.assertEqual(tag.x, tagCopy.x) + self.assertEqual(tag.y, tagCopy.y) + self.assertEqual(tag.height, tagCopy.height) + self.assertEqual(tag.width, tagCopy.width) + self.assertEqual(tag.enabled, tagCopy.enabled) + + + def testTagSolidBasic(self): + """For a 90 degree tag the core and solid are both defined and identical cylinders.""" + tag = Tag(100, 200, 4, 5, 90, True) + tag.createSolidsAt(17) + self.assertIsNotNone(tag.solid) + self.assertIsNotNone(tag.core) + + self.assertCylinderAt(tag.solid, FreeCAD.Vector(100, 200, 17), 2, 5) + self.assertCylinderAt(tag.core, FreeCAD.Vector(100, 200, 17), 2, 5) + + def assertCylinderAt(self, solid, pt, r, h): + """Verify that the argument is a cylinder at the specified location.""" + lid = solid.Edges[0].Curve + self.assertTrue(type(lid), Part.Circle) + self.assertEqual(lid.Center, FreeCAD.Vector(pt.x, pt.y, pt.z+h)) + self.assertEqual(lid.Radius, r) + + hull = solid.Edges[1].Curve + self.assertTrue(type(hull), Part.Line) + self.assertTrue(pointsCoincide(hull.StartPoint, FreeCAD.Vector(pt.x+r, pt.y, pt.z))) + self.assertTrue(pointsCoincide(hull.EndPoint, FreeCAD.Vector(pt.x+r, pt.y, pt.z+h))) + + base = solid.Edges[2].Curve + self.assertTrue(type(base), Part.Circle) + self.assertEqual(base.Center, FreeCAD.Vector(pt.x, pt.y, pt.z)) + self.assertEqual(base.Radius, r) + diff --git a/src/Mod/Path/TestPathApp.py b/src/Mod/Path/TestPathApp.py index 88850ea8db8c..90640ab54714 100644 --- a/src/Mod/Path/TestPathApp.py +++ b/src/Mod/Path/TestPathApp.py @@ -25,3 +25,4 @@ import TestApp from PathTests.TestPathPost import PathPostTestCases +from PathTests.TestPathDressupHoldingTags import PathDressupHoldingTagsTestCases