Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #467 from mlampert/path-unit-test-fixes
Path: Path unit test fixes issue #2870
  • Loading branch information
wwmayer committed Jan 28, 2017
2 parents 33a3c5f + d4da536 commit 175d177
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 35 deletions.
39 changes: 30 additions & 9 deletions src/Mod/Path/CMakeLists.txt
Expand Up @@ -10,6 +10,7 @@ INSTALL(
Init.py
InitGui.py
PathCommands.py
TestPathApp.py
DESTINATION
Mod/Path
)
Expand Down Expand Up @@ -76,15 +77,6 @@ SET(PathScripts_SRCS
PathScripts/opensbp_pre.py
PathScripts/rml_post.py
PathScripts/slic3r_pre.py
PathTests/PathTestUtils.py
PathTests/TestPathDepthParams.py
PathTests/TestPathDressupHoldingTags.py
PathTests/TestPathGeom.py
PathTests/TestPathLog.py
PathTests/TestPathPost.py
PathTests/__init__.py
PathTests/test_linuxcnc_00.ngc
TestPathApp.py
)

SET(PathScripts_NC_SRCS
Expand All @@ -95,6 +87,18 @@ SET(PathScripts_NC_SRCS
PathScripts/nc/iso_codes.py
)

SET(PathTests_SRCS
PathTests/PathTestUtils.py
PathTests/TestPathCore.py
PathTests/TestPathDepthParams.py
PathTests/TestPathDressupHoldingTags.py
PathTests/TestPathGeom.py
PathTests/TestPathLog.py
PathTests/TestPathPost.py
PathTests/__init__.py
PathTests/test_linuxcnc_00.ngc
)

SET(all_files
${PathScripts_SRCS}
${PathScripts_NC_SRCS}
Expand All @@ -104,7 +108,17 @@ ADD_CUSTOM_TARGET(PathScripts ALL
SOURCES ${all_files}
)

SET(test_files
TestPathApp.py
${PathTests_SRCS}
)

ADD_CUSTOM_TARGET(PathTests ALL
SOURCES ${test_files}
)

fc_copy_sources(PathScripts "${CMAKE_BINARY_DIR}/Mod/Path" ${all_files})
fc_copy_sources(PathTests "${CMAKE_BINARY_DIR}/Mod/Path" ${test_files})

INSTALL(
FILES
Expand All @@ -120,3 +134,10 @@ INSTALL(
Mod/Path/PathScripts/nc
)

INSTALL(
FILES
${PathTests_SRCS}
DESTINATION
Mod/Path/PathTests
)

17 changes: 10 additions & 7 deletions src/Mod/Path/PathScripts/PathDressupHoldingTags.py
Expand Up @@ -25,20 +25,17 @@
import FreeCADGui
import Draft
import DraftGeomUtils
import DraftGui
import Path
import PathScripts.PathLog as PathLog
import PathScripts.PathPreferencesPathDressup as PathPreferencesPathDressup
import Part
import copy
import math

from DraftGui import todo
from PathScripts import PathUtils
from PathScripts.PathGeom import PathGeom
from PathScripts.PathPreferences import PathPreferences
from PySide import QtCore, QtGui
from pivy import coin
from PySide import QtCore

"""Holding Tags Dressup object and FreeCAD command"""

Expand All @@ -50,6 +47,10 @@ def translate(text, context = "PathDressup_HoldingTags", disambig=None):
LOG_MODULE = 'PathDressupHoldingTags'
#PathLog.setLevel(PathLog.Level.DEBUG, LOG_MODULE)

if FreeCAD.GuiUp:
from pivy import coin
from PySide import QtCore

def debugEdge(edge, prefix, force = False):
if force or PathLog.getLevel(LOG_MODULE) == PathLog.Level.DEBUG:
pf = edge.valueAt(edge.FirstParameter)
Expand Down Expand Up @@ -131,7 +132,7 @@ def defaultCount(cls, ifNotSet = 4):
@classmethod
def defaultRadius(cls, ifNotSet = 0.0):
return PathPreferences.preferences().GetFloat(cls.DefaultHoldingTagRadius, ifNotSet)


def __init__(self):
self.form = FreeCADGui.PySideUic.loadUi(":/preferences/PathDressupHoldingTags.ui")
Expand Down Expand Up @@ -221,8 +222,10 @@ def createSolidsAt(self, z, R):
angle = -PathGeom.getAngle(self.originAt(0)) * 180 / math.pi
PathLog.debug("solid.rotate(%f)" % angle)
self.solid.rotate(FreeCAD.Vector(0,0,0), FreeCAD.Vector(0,0,1), angle)
PathLog.debug("solid.translate(%s)" % self.originAt(z))
self.solid.translate(self.originAt(z - 0.01 * self.actualHeight))
orig = self.originAt(z - 0.01 * self.actualHeight)
PathLog.debug("solid.translate(%s)" % orig)
self.solid.translate(orig)
radius = min(self.radius, radius)
self.realRadius = radius
if radius != 0:
PathLog.debug("makeFillet(%.4f)" % radius)
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Path/PathTests/PathTestUtils.py
Expand Up @@ -45,7 +45,8 @@ def assertCoincide(self, pt1, pt2):

def assertLine(self, edge, pt1, pt2):
"""Verify that edge is a line from pt1 to pt2."""
self.assertIs(type(edge.Curve), Part.Line)
# Depending on the setting of LineOld ....
self.assertTrue(type(edge.Curve) is Part.Line or type(edge.Curve) is Part.LineSegment)
self.assertCoincide(edge.valueAt(edge.FirstParameter), pt1)
self.assertCoincide(edge.valueAt(edge.LastParameter), pt2)

Expand Down
28 changes: 12 additions & 16 deletions src/Mod/Path/PathTests/TestPathDressupHoldingTags.py
Expand Up @@ -37,45 +37,41 @@ class TestHoldingTags(PathTestBase):
"""Unit tests for the HoldingTags dressup."""

def test00(self):
"""Check Tag origin, serialization and de-serialization."""
"""Check Tag origin."""
tag = Tag(77, 13, 4, 5, 90, True)
self.assertCoincide(tag.originAt(3), 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 test01(self):
"""Verify solid for a 90 degree tag is a cylinder."""
tag = Tag(100, 200, 4, 5, 90, True)
tag = Tag(100, 200, 4, 5, 90, 0, True)
tag.createSolidsAt(17, 0)

self.assertIsNotNone(tag.solid)
self.assertCylinderAt(tag.solid, Vector(100, 200, 17), 2, 5)
self.assertCylinderAt(tag.solid, Vector(100, 200, 17 - 5 * 0.01), 2, 5 * 1.01)

def test02(self):
"""Verify trapezoidal tag has a cone shape with a lid."""
tag = Tag(0, 0, 18, 5, 45, True)
tag = Tag(0, 0, 18, 5, 45, 0, True)
tag.createSolidsAt(0, 0)

self.assertIsNotNone(tag.solid)
self.assertConeAt(tag.solid, Vector(0,0,0), 9, 4, 5)
self.assertConeAt(tag.solid, Vector(0,0,-0.05), 9, 3.95, 5.05)

def test03(self):
"""Verify pointy cone shape of tag with pointy end if width, angle and height match up."""
tag = Tag(0, 0, 10, 5, 45, True)
tag = Tag(0, 0, 10, 5, 45, 0, True)
tag.createSolidsAt(0, 0)
self.assertIsNotNone(tag.solid)
self.assertConeAt(tag.solid, Vector(0,0,0), 5, 0, 5)
h = 5 * 1.01
self.assertConeAt(tag.solid, Vector(0,0,-h * 0.01), 5, 0, h)

def test04(self):
"""Verify height adjustment if tag isn't wide eough for angle."""
tag = Tag(0, 0, 5, 17, 60, True)
tag = Tag(0, 0, 5, 17, 60, 0, True)
tag.createSolidsAt(0, 0)
self.assertIsNotNone(tag.solid)
self.assertConeAt(tag.solid, Vector(0,0,0), 2.5, 0, 2.5 * math.tan((60/180.0)*math.pi))
h = 2.5 * math.tan((60/180.0)*math.pi) * 1.01
print(h)
self.assertConeAt(tag.solid, Vector(0,0,-h * 0.01), 2.5, 0, h)

2 changes: 1 addition & 1 deletion src/Mod/Path/TestPathApp.py
Expand Up @@ -31,4 +31,4 @@
from PathTests.TestPathGeom import TestPathGeom
from PathTests.TestPathDepthParams import depthTestCases

#from PathTests.TestPathDressupHoldingTags import TestHoldingTags
from PathTests.TestPathDressupHoldingTags import TestHoldingTags
3 changes: 2 additions & 1 deletion src/Mod/Test/TestApp.py
Expand Up @@ -72,7 +72,8 @@ def All():
"TestPartApp",
"TestPartDesignApp",
"TestSpreadsheet",
"TestTechDrawApp" ]
"TestTechDrawApp",
"TestPathApp" ]

# gui tests of modules
if (FreeCAD.GuiUp == 1):
Expand Down

0 comments on commit 175d177

Please sign in to comment.