FreeCAD

Форк
0
/
TestPathDrillable.py 
259 строк · 9.4 Кб
1
# -*- coding: utf-8 -*-
2
# ***************************************************************************
3
# *   Copyright (c) 2021 sliptonic <shopinthewoods@gmail.com>               *
4
# *                                                                         *
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.                                 *
10
# *                                                                         *
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.                  *
15
# *                                                                         *
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  *
19
# *   USA                                                                   *
20
# *                                                                         *
21
# ***************************************************************************
22

23
import FreeCAD as App
24
import Path
25
import Path.Base.Drillable as Drillable
26
import Tests.PathTestUtils as PathTestUtils
27

28

29
if False:
30
    Path.Log.setLevel(Path.Log.Level.DEBUG, Path.Log.thisModule())
31
    Path.Log.trackModule(Path.Log.thisModule())
32
else:
33
    Path.Log.setLevel(Path.Log.Level.INFO, Path.Log.thisModule())
34

35

36
class TestPathDrillable(PathTestUtils.PathTestBase):
37
    def setUp(self):
38
        App.ConfigSet("SuppressRecomputeRequiredDialog", "True")
39
        self.doc = App.open(App.getHomePath() + "/Mod/CAM/Tests/Drilling_1.FCStd")
40
        App.ConfigSet("SuppressRecomputeRequiredDialog", "")
41
        self.obj = self.doc.getObject("Pocket011")
42

43
    def tearDown(self):
44
        App.closeDocument(self.doc.Name)
45

46
    def test00(self):
47
        """Test CompareVecs"""
48

49
        # Vec and origin
50
        v1 = App.Vector(0, 0, 10)
51
        v2 = App.Vector(0, 0, 0)
52
        self.assertTrue(Drillable.compareVecs(v1, v2))
53

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

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

64
    def test10(self):
65
        """Test isDrillable"""
66

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

71
        # Test cylinder faces
72

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

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

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

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

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

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

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

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

99
        # Drilling with smaller bit
100
        self.assertTrue(
101
            Drillable.isDrillable(
102
                self.obj.Shape, candidate, tooldiameter=10, vector=App.Vector(0, -1, 0)
103
            )
104
        )
105

106
        # Drilling with bit too large
107
        self.assertFalse(
108
            Drillable.isDrillable(
109
                self.obj.Shape, candidate, tooldiameter=30, vector=App.Vector(0, -1, 0)
110
            )
111
        )
112

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

197
        # Test edges
198
        # circular edge
199
        candidate = self.obj.getSubObject("Edge55")
200

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

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

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

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

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

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

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

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

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

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

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

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

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

250
    def test20(self):
251
        """Test getDrillableTargets"""
252
        results = Drillable.getDrillableTargets(self.obj)
253
        self.assertEqual(len(results), 15)
254

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

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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.