File size: 9,691 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# SPDX-License-Identifier: LGPL-2.1-or-later

# ***************************************************************************
# *   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 FreeCAD as App
import Path
import Path.Base.Drillable as Drillable
import CAMTests.PathTestUtils as PathTestUtils


if False:
    Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule())
    Path.Log.trackModule(Path.Log.thisModule())
else:
    Path.Log.setLevel(Path.Log.Level.INFO, Path.Log.thisModule())


class TestPathDrillable(PathTestUtils.PathTestBase):
    def setUp(self):
        App.ConfigSet("SuppressRecomputeRequiredDialog", "True")
        self.doc = App.open(App.getHomePath() + "/Mod/CAM/CAMTests/Drilling_1.FCStd")
        App.ConfigSet("SuppressRecomputeRequiredDialog", "")
        self.obj = self.doc.getObject("Pocket011")

    def tearDown(self):
        App.closeDocument(self.doc.Name)

    def test00(self):
        """Test CompareVecs"""

        # Vec and origin
        v1 = App.Vector(0, 0, 10)
        v2 = App.Vector(0, 0, 0)
        self.assertTrue(Drillable.compareVecs(v1, v2))

        # two valid vectors
        v1 = App.Vector(0, 10, 0)
        v2 = App.Vector(0, 20, 0)
        self.assertTrue(Drillable.compareVecs(v1, v2))

        # two valid vectors not aligned
        v1 = App.Vector(0, 10, 0)
        v2 = App.Vector(10, 0, 0)
        self.assertFalse(Drillable.compareVecs(v1, v2))

    def test10(self):
        """Test isDrillable"""

        # Invalid types
        candidate = self.obj.getSubObject("Vertex1")
        self.assertRaises(TypeError, lambda: Drillable.isDrillable(self.obj.Shape, candidate))

        # Test cylinder faces

        # thru-hole
        candidate = self.obj.getSubObject("Face30")

        # Typical drilling
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate))

        # Drilling with smaller bit
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate, tooldiameter=20))

        # Drilling with bit too large
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate, tooldiameter=30))

        # off-axis hole
        candidate = self.obj.getSubObject("Face44")

        # Typical drilling
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # Passing explicit vector
        self.assertTrue(
            Drillable.isDrillable(self.obj.Shape, candidate, vector=App.Vector(0, -1, 0))
        )

        # Drilling with smaller bit
        self.assertTrue(
            Drillable.isDrillable(
                self.obj.Shape, candidate, tooldiameter=10, vector=App.Vector(0, -1, 0)
            )
        )

        # Drilling with bit too large
        self.assertFalse(
            Drillable.isDrillable(
                self.obj.Shape, candidate, tooldiameter=30, vector=App.Vector(0, -1, 0)
            )
        )

        # ellipse hole
        candidate = self.obj.getSubObject("Face29")

        # Typical drilling
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # raised cylinder
        candidate = self.obj.getSubObject("Face32")

        # Typical drilling
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # cylinder on slope
        candidate = self.obj.getSubObject("Face24")
        # Typical drilling
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # Circular Faces
        candidate = self.obj.getSubObject("Face54")

        # Typical drilling
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # Passing explicit vector
        self.assertTrue(
            Drillable.isDrillable(self.obj.Shape, candidate, vector=App.Vector(0, 0, 1))
        )

        # Drilling with smaller bit
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate, tooldiameter=10))

        # Drilling with bit too large
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate, tooldiameter=30))

        # off-axis circular face hole
        candidate = self.obj.getSubObject("Face58")

        # Typical drilling
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # Passing explicit vector
        self.assertTrue(
            Drillable.isDrillable(self.obj.Shape, candidate, vector=App.Vector(0, -1, 0))
        )

        # raised face
        candidate = self.obj.getSubObject("Face49")
        # Typical drilling
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # interrupted Face
        candidate = self.obj.getSubObject("Face50")
        # Typical drilling
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # donut face
        candidate = self.obj.getSubObject("Face48")
        # Typical drilling
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # Test edges
        # circular edge
        candidate = self.obj.getSubObject("Edge55")

        # Typical drilling
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # Passing explicit vector
        self.assertTrue(
            Drillable.isDrillable(self.obj.Shape, candidate, vector=App.Vector(0, 0, 1))
        )

        # Drilling with smaller bit
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate, tooldiameter=10))

        # Drilling with bit too large
        self.assertFalse(
            Drillable.isDrillable(self.obj.Shape, candidate, tooldiameter=30, vector=None)
        )

        # off-axis circular edge
        candidate = self.obj.getSubObject("Edge74")

        # Typical drilling
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertTrue(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # Passing explicit vector
        self.assertTrue(
            Drillable.isDrillable(self.obj.Shape, candidate, vector=App.Vector(0, 1, 0))
        )

        # incomplete circular edge
        candidate = self.obj.getSubObject("Edge39")
        # Typical drilling
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

        # elliptical edge
        candidate = self.obj.getSubObject("Edge56")
        # Typical drilling
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate))

        # Passing None as vector
        self.assertFalse(Drillable.isDrillable(self.obj.Shape, candidate, vector=None))

    def test20(self):
        """Test getDrillableTargets"""
        results = Drillable.getDrillableTargets(self.obj)
        self.assertEqual(len(results), 15)

        results = Drillable.getDrillableTargets(self.obj, vector=None)
        self.assertEqual(len(results), 20)

        results = Drillable.getDrillableTargets(self.obj, ToolDiameter=20, vector=None)
        self.assertEqual(len(results), 5)