FreeCAD

Форк
0
/
TestPathDressupDogbone.py 
292 строки · 10.1 Кб
1
# -*- coding: utf-8 -*-
2
# ***************************************************************************
3
# *   Copyright (c) 2017 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
24
import Path
25
import Path.Dressup.Gui.Dogbone as PathDressupDogbone
26
import Path.Main.Job as PathJob
27
import Path.Op.Profile as PathProfile
28

29
from Tests.PathTestUtils import PathTestBase
30

31

32
class TestProfile:
33
    def __init__(self, side, direction, path):
34
        self.Side = side
35
        self.Direction = direction
36
        self.Path = Path.Path(path)
37
        self.ToolController = None  # default tool 5mm
38
        self.Name = "Profile"
39

40

41
class TestFeature:
42
    def __init__(self):
43
        self.Path = Path.Path()
44

45
    def addProperty(self, typ, name, category, tip):
46
        setattr(self, name, None)
47

48
    def setEditorMode(self, prop, mode):
49
        pass
50

51

52
class TestDressupDogbone(PathTestBase):
53
    """Unit tests for the Dogbone dressup."""
54

55
    def formatBone(self, bone):
56
        return "%d: (%.2f, %.2f)" % (bone[0], bone[1][0], bone[1][1])
57

58
    def test00(self):
59
        """Verify bones are inserted for simple moves."""
60
        base = TestProfile(
61
            "Inside",
62
            "Climb",
63
            """
64
        G0 X10 Y10 Z10
65
        G1 Z0
66
        G1 Y100
67
        G1 X12
68
        G1 Y10
69
        G1 X10
70
        G1 Z10
71
        """,
72
        )
73
        obj = TestFeature()
74
        db = PathDressupDogbone.ObjectDressup(obj, base)
75
        db.setup(obj, True)
76
        db.execute(obj, False)
77
        self.assertEqual(len(db.bones), 4)
78
        self.assertEqual("1: (10.00, 100.00)", self.formatBone(db.bones[0]))
79
        self.assertEqual("2: (12.00, 100.00)", self.formatBone(db.bones[1]))
80
        self.assertEqual("3: (12.00, 10.00)", self.formatBone(db.bones[2]))
81
        self.assertEqual("4: (10.00, 10.00)", self.formatBone(db.bones[3]))
82

83
    def test01(self):
84
        """Verify bones are inserted if hole ends with rapid move out."""
85
        base = TestProfile(
86
            "Inside",
87
            "Climb",
88
            """
89
        G0 X10 Y10 Z10
90
        G1 Z0
91
        G1 Y100
92
        G1 X12
93
        G1 Y10
94
        G1 X10
95
        G0 Z10
96
        """,
97
        )
98
        obj = TestFeature()
99
        db = PathDressupDogbone.ObjectDressup(obj, base)
100
        db.setup(obj, True)
101
        db.execute(obj, False)
102
        self.assertEqual(len(db.bones), 4)
103
        self.assertEqual("1: (10.00, 100.00)", self.formatBone(db.bones[0]))
104
        self.assertEqual("2: (12.00, 100.00)", self.formatBone(db.bones[1]))
105
        self.assertEqual("3: (12.00, 10.00)", self.formatBone(db.bones[2]))
106
        self.assertEqual("4: (10.00, 10.00)", self.formatBone(db.bones[3]))
107

108
    def test02(self):
109
        """Verify bones are correctly generated for a Profile."""
110
        doc = FreeCAD.newDocument("TestDressupDogbone")
111

112
        # This is a real world test to make sure none of the tool chain broke
113
        box0 = doc.addObject("Part::Box", "Box")
114
        box0.Width = 100
115
        box0.Length = 100
116
        box0.Height = 10
117
        box1 = doc.addObject("Part::Box", "Box")
118
        box1.Width = 50
119
        box1.Length = 50
120
        box1.Height = 20
121
        box1.Placement = FreeCAD.Placement(
122
            FreeCAD.Vector(25, 25, -5), FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), 0)
123
        )
124
        doc.recompute()
125
        cut = doc.addObject("Part::Cut", "Cut")
126
        cut.Base = box0
127
        cut.Tool = box1
128
        doc.recompute()
129

130
        for i in range(11):
131
            face = "Face%d" % (i + 1)
132
            f = cut.Shape.getElement(face)
133
            if f.Surface.Axis == FreeCAD.Vector(0, 0, 1) and f.Orientation == "Forward":
134
                break
135

136
        PathJob.Create("Job", [cut], None)
137

138
        profile = PathProfile.Create("Profile")
139
        profile.Base = (cut, face)
140
        profile.StepDown = 5
141
        # set start and final depth in order to eliminate effects of stock (and its default values)
142
        profile.setExpression("StartDepth", None)
143
        profile.StartDepth = 10
144
        profile.setExpression("FinalDepth", None)
145
        profile.FinalDepth = 0
146

147
        profile.processHoles = True
148
        profile.processPerimeter = True
149
        doc.recompute()
150

151
        dogbone = PathDressupDogbone.Create(profile)
152
        doc.recompute()
153

154
        dog = dogbone.Proxy
155
        locs = sorted([bone[1] for bone in dog.bones], key=lambda xy: xy[0] * 1000 + xy[1])
156

157
        def formatBoneLoc(pt):
158
            return "(%.2f, %.2f)" % (pt[0], pt[1])
159

160
        # Make sure we get 8 bones, 2 in each corner (different heights)
161
        # with start point changes it passes back over the same spot multiple times, so just make sure they are in the right locations
162
        # self.assertEqual(len(locs), 8)
163
        self.assertEqual("(27.50, 27.50)", formatBoneLoc(locs[0]))
164
        self.assertEqual("(27.50, 27.50)", formatBoneLoc(locs[1]))
165
        self.assertEqual("(27.50, 72.50)", formatBoneLoc(locs[2]))
166
        self.assertEqual("(27.50, 72.50)", formatBoneLoc(locs[3]))
167
        self.assertEqual("(72.50, 27.50)", formatBoneLoc(locs[4]))
168
        self.assertEqual("(72.50, 27.50)", formatBoneLoc(locs[5]))
169
        self.assertEqual("(72.50, 72.50)", formatBoneLoc(locs[6]))
170
        self.assertEqual("(72.50, 72.50)", formatBoneLoc(locs[7]))
171

172
        FreeCAD.closeDocument("TestDressupDogbone")
173

174
    def test03(self):
175
        """Verify no bone is inserted for straight move interrupted by plunge."""
176
        base = TestProfile(
177
            "Inside",
178
            "Climb",
179
            """
180
        G0 X10 Y10 Z10
181
        G1 Z0
182
        G1 X0   ( start)
183
        G1 Y0
184
        G1 X15
185
        G1 Y10
186
        G1 X10  ( straight line move to start)
187
        G0 Z10
188
        """,
189
        )
190
        obj = TestFeature()
191
        db = PathDressupDogbone.ObjectDressup(obj, base)
192
        db.setup(obj, True)
193
        db.execute(obj, False)
194
        self.assertEqual(len(db.bones), 0)
195

196
    def test04(self):
197
        """Verify can handle comments between moves"""
198
        base = TestProfile(
199
            "Inside",
200
            "Climb",
201
            """
202
        G0 X10 Y10 Z10
203
        G1 Z0
204
        G1 X20
205
        G1 Y0
206
        G1 X10
207
        G1 Y10
208
        G1 Z10
209
        """,
210
        )
211
        obj = TestFeature()
212
        db = PathDressupDogbone.ObjectDressup(obj, base)
213
        db.setup(obj, True)
214
        db.execute(obj, False)
215
        self.assertEqual(len(db.bones), 4)
216
        self.assertEqual("1: (20.00, 10.00)", self.formatBone(db.bones[0]))
217
        self.assertEqual("2: (20.00, 0.00)", self.formatBone(db.bones[1]))
218
        self.assertEqual("3: (10.00, 0.00)", self.formatBone(db.bones[2]))
219
        self.assertEqual("4: (10.00, 10.00)", self.formatBone(db.bones[3]))
220

221
        base = TestProfile(
222
            "Inside",
223
            "Climb",
224
            """
225
        G0 X10 Y10 Z10
226
        G1 Z0
227
        G1 X20
228
        G1 Y0
229
        G1 X10
230
        (some comment or other should not change the output)
231
        G1 Y10
232
        G1 Z10
233
        """,
234
        )
235
        obj = TestFeature()
236
        db = PathDressupDogbone.ObjectDressup(obj, base)
237
        db.setup(obj, True)
238
        db.execute(obj, False)
239
        self.assertEqual(len(db.bones), 4)
240
        self.assertEqual("1: (20.00, 10.00)", self.formatBone(db.bones[0]))
241
        self.assertEqual("2: (20.00, 0.00)", self.formatBone(db.bones[1]))
242
        self.assertEqual("3: (10.00, 0.00)", self.formatBone(db.bones[2]))
243
        self.assertEqual("4: (10.00, 10.00)", self.formatBone(db.bones[3]))
244

245
    def test05(self):
246
        """Verify can handle noops between moves"""
247
        base = TestProfile(
248
            "Inside",
249
            "Climb",
250
            """
251
        G0 X10 Y10 Z10
252
        G1 Z0
253
        G1 X20
254
        G1 Y0
255
        G1 X10
256
        G1 Y10
257
        G1 Z10
258
        """,
259
        )
260
        obj = TestFeature()
261
        db = PathDressupDogbone.ObjectDressup(obj, base)
262
        db.setup(obj, True)
263
        db.execute(obj, False)
264
        self.assertEqual(len(db.bones), 4)
265
        self.assertEqual("1: (20.00, 10.00)", self.formatBone(db.bones[0]))
266
        self.assertEqual("2: (20.00, 0.00)", self.formatBone(db.bones[1]))
267
        self.assertEqual("3: (10.00, 0.00)", self.formatBone(db.bones[2]))
268
        self.assertEqual("4: (10.00, 10.00)", self.formatBone(db.bones[3]))
269

270
        base = TestProfile(
271
            "Inside",
272
            "Climb",
273
            """
274
        G0 X10 Y10 Z10
275
        G1 Z0
276
        G1 X20
277
        G1 Y0
278
        G1 X10
279
        G1 X10
280
        G1 Y10
281
        G1 Z10
282
        """,
283
        )
284
        obj = TestFeature()
285
        db = PathDressupDogbone.ObjectDressup(obj, base)
286
        db.setup(obj, True)
287
        db.execute(obj, False)
288
        self.assertEqual(len(db.bones), 4)
289
        self.assertEqual("1: (20.00, 10.00)", self.formatBone(db.bones[0]))
290
        self.assertEqual("2: (20.00, 0.00)", self.formatBone(db.bones[1]))
291
        self.assertEqual("3: (10.00, 0.00)", self.formatBone(db.bones[2]))
292
        self.assertEqual("4: (10.00, 10.00)", self.formatBone(db.bones[3]))
293

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

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

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

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