2
# ***************************************************************************
3
# * Copyright (c) 2019 sliptonic <shopinthewoods@gmail.com> *
5
# * This program is free software; you can redistribute it and/or modify *
6
# * it under the terms of the GNU Lesser General Public License (LGPL) *
7
# * as published by the Free Software Foundation; either version 2 of *
8
# * the License, or (at your option) any later version. *
9
# * for detail see the LICENCE text file. *
11
# * This program is distributed in the hope that it will be useful, *
12
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
# * GNU Library General Public License for more details. *
16
# * You should have received a copy of the GNU Library General Public *
17
# * License along with this program; if not, write to the Free Software *
18
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
21
# ***************************************************************************
25
import Path.Op.ThreadMilling as PathThreadMilling
28
from Tests.PathTestUtils import PathTestBase
31
class TestObject(object):
32
def __init__(self, orientation, direction, zTop, zBottom):
33
self.ThreadOrientation = orientation
34
self.Direction = direction
35
self.StartDepth = FreeCAD.Units.Quantity(zTop, FreeCAD.Units.Length)
36
self.FinalDepth = FreeCAD.Units.Quantity(zBottom, FreeCAD.Units.Length)
39
def radii(internal, major, minor, toolDia, toolCrest):
40
"""test radii function for simple testing"""
46
class TestPathThreadMilling(PathTestBase):
47
"""Test thread milling basics."""
49
def assertRadii(self, have, want):
50
self.assertRoughly(have[0], want[0])
51
self.assertRoughly(have[1], want[1])
53
def assertList(self, have, want):
54
self.assertEqual(len(have), len(want))
55
for i in range(len(have)):
56
self.assertRoughly(have[i], want[i])
58
def assertSetupInternal(self, obj, c, begin, end):
59
cmd, zBegin, zEnd = PathThreadMilling.threadSetupInternal(
60
obj, obj.StartDepth.Value, obj.FinalDepth.Value
62
self.assertEqual(cmd, c)
63
self.assertEqual(zBegin, begin)
64
self.assertEqual(zEnd, end)
66
def assertSetupExternal(self, obj, c, begin, end):
67
cmd, zBegin, zEnd = PathThreadMilling.threadSetupExternal(
68
obj, obj.StartDepth.Value, obj.FinalDepth.Value
70
self.assertEqual(cmd, c)
71
self.assertEqual(zBegin, begin)
72
self.assertEqual(zEnd, end)
75
"""Verify internal radii."""
76
self.assertRadii(PathThreadMilling.threadRadii(True, 20, 18, 2, 0), (8, 9.2))
77
self.assertRadii(PathThreadMilling.threadRadii(True, 20, 19, 2, 0), (8.5, 9.1))
80
"""Verify internal radii with tool crest."""
81
self.assertRadii(PathThreadMilling.threadRadii(True, 20, 18, 2, 0.1), (8, 9.113397))
84
"""Verify internal thread passes."""
85
self.assertList(PathThreadMilling.threadPasses(1, radii, True, 10, 9, 0, 0), [10])
86
self.assertList(PathThreadMilling.threadPasses(2, radii, True, 10, 9, 0, 0), [9.707107, 10])
88
PathThreadMilling.threadPasses(5, radii, True, 10, 9, 0, 0),
89
[9.447214, 9.632456, 9.774597, 9.894427, 10],
93
"""Verify external radii."""
94
self.assertRadii(PathThreadMilling.threadRadii(False, 20, 18, 2, 0), (11, 9.6))
95
self.assertRadii(PathThreadMilling.threadRadii(False, 20, 19, 2, 0), (11, 10.3))
98
"""Verify external radii with tool crest."""
99
self.assertRadii(PathThreadMilling.threadRadii(False, 20, 18, 2, 0.1), (11, 9.513397))
102
"""Verify external thread passes."""
103
self.assertList(PathThreadMilling.threadPasses(1, radii, False, 10, 9, 0, 0), [9])
104
self.assertList(PathThreadMilling.threadPasses(2, radii, False, 10, 9, 0, 0), [9.292893, 9])
106
PathThreadMilling.threadPasses(5, radii, False, 10, 9, 0, 0),
107
[9.552786, 9.367544, 9.225403, 9.105573, 9],
111
"""Verify internal right hand thread setup."""
113
hand = PathThreadMilling.RightHand
115
self.assertSetupInternal(
116
TestObject(hand, PathThreadMilling.DirectionConventional, 1, 0), "G2", 1, 0
118
self.assertSetupInternal(
119
TestObject(hand, PathThreadMilling.DirectionClimb, 1, 0), "G3", 0, 1
123
"""Verify internal left hand thread setup."""
125
hand = PathThreadMilling.LeftHand
127
self.assertSetupInternal(
128
TestObject(hand, PathThreadMilling.DirectionConventional, 1, 0), "G2", 0, 1
130
self.assertSetupInternal(
131
TestObject(hand, PathThreadMilling.DirectionClimb, 1, 0), "G3", 1, 0
135
"""Verify exteranl right hand thread setup."""
137
hand = PathThreadMilling.RightHand
139
self.assertSetupExternal(
140
TestObject(hand, PathThreadMilling.DirectionClimb, 1, 0), "G2", 1, 0
142
self.assertSetupExternal(
143
TestObject(hand, PathThreadMilling.DirectionConventional, 1, 0), "G3", 0, 1
147
"""Verify exteranl left hand thread setup."""
149
hand = PathThreadMilling.LeftHand
151
self.assertSetupExternal(
152
TestObject(hand, PathThreadMilling.DirectionClimb, 1, 0), "G2", 0, 1
154
self.assertSetupExternal(
155
TestObject(hand, PathThreadMilling.DirectionConventional, 1, 0), "G3", 1, 0