FreeCAD

Форк
0
/
TestPathCore.py 
136 строк · 5.0 Кб
1
# -*- coding: utf-8 -*-
2
# ***************************************************************************
3
# *   Copyright (c) 2016 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
from Tests.PathTestUtils import PathTestBase
26

27

28
class TestPathCore(PathTestBase):
29
    def test00(self):
30
        """Test Path command core functionality"""
31
        # create empty command
32
        c = Path.Command()
33
        self.assertIsInstance(c, Path.Command)
34

35
        # change name
36
        c.Name = "G1"
37
        self.assertEqual(c.Name, "G1")
38

39
        # Assign Parameters
40
        c.Parameters = {"X": 1, "Y": 0}
41
        self.assertEqual(c.Parameters, {"Y": 0.0, "X": 1.0})
42

43
        # change parameters
44
        c.Parameters = {"X": 1, "Y": 0.5}
45
        self.assertEqual(c.Parameters, {"Y": 0.5, "X": 1})
46

47
        # output gcode
48
        self.assertEqual(c.toGCode(), "G1 X1.000000 Y0.500000")
49

50
        # create and assign name in one
51
        c2 = Path.Command("G2")
52
        self.assertEqual(c2.Name, "G2")
53

54
        # Create Path and parameters in one
55
        c3 = Path.Command("G1", {"X": 34, "Y": 1.2})
56
        self.assertEqual(str(c3), "Command G1 [ X:34 Y:1.2 ]")
57
        c4 = Path.Command("G1X4Y5")
58
        self.assertEqual(str(c4), "Command G1 [ X:4 Y:5 ]")
59

60
        # use placement
61
        self.assertEqual(str(c3.Placement), "Placement [Pos=(34,1.2,0), Yaw-Pitch-Roll=(0,0,0)]")
62
        self.assertEqual(c3.toGCode(), "G1 X34.000000 Y1.200000")
63
        p1 = FreeCAD.Placement()
64
        p1.Base = FreeCAD.Vector(3, 2, 1)
65
        self.assertEqual(str(p1), "Placement [Pos=(3,2,1), Yaw-Pitch-Roll=(0,0,0)]")
66
        c5 = Path.Command("g1", p1)
67
        self.assertEqual(str(c5), "Command G1 [ X:3 Y:2 Z:1 ]")
68
        p2 = FreeCAD.Placement()
69
        p2.Base = FreeCAD.Vector(5, 0, 0)
70

71
        # overwrite placement
72
        c5.Placement = p2
73
        self.assertEqual(str(c5), "Command G1 [ X:5 ]")
74
        self.assertEqual(c5.x, 5.0)
75

76
        # overwrite individual parameters
77
        c5.x = 10
78
        self.assertEqual(c5.x, 10.0)
79
        c5.y = 2
80
        self.assertEqual(str(c5), "Command G1 [ X:10 Y:2 ]")
81

82
        # set from gcode
83
        c3.setFromGCode("G1X1Y0")
84
        self.assertEqual(str(c3), "Command G1 [ X:1 Y:0 ]")
85

86
    def test10(self):
87
        """Test Path Object core functionality"""
88

89
        c1 = Path.Command("g1", {"x": 1, "y": 0})
90
        c2 = Path.Command("g1", {"x": 0, "y": 2})
91
        p = Path.Path([c1, c2])
92
        self.assertAlmostEqual(str(p), "Path [ size:2 length:3.2361 ]", places=4)
93

94
        self.assertEqual(str(p.Commands), "[Command G1 [ X:1 Y:0 ], Command G1 [ X:0 Y:2 ]]")
95
        self.assertAlmostEqual(p.Length, 3.2361, places=4)
96
        p.addCommands(c1)
97
        self.assertEqual(
98
            p.toGCode(),
99
            "G1 X1.000000 Y0.000000\nG1 X0.000000 Y2.000000\nG1 X1.000000 Y0.000000\n",
100
        )
101

102
        lines = """
103
G0X-0.5905Y-0.3937S3000M03
104
G0Z0.125
105
G1Z-0.004F3
106
G1X0.9842Y-0.3937F14.17
107
G1X0.9842Y0.433
108
G1X-0.5905Y0.433
109
G1X-0.5905Y-0.3937
110
G0Z0.5
111
"""
112

113
        output = """G0 S3000.000000 X-0.590500 Y-0.393700
114
M03
115
G0 Z0.125000
116
G1 F3.000000 Z-0.004000
117
G1 F14.170000 X0.984200 Y-0.393700
118
G1 X0.984200 Y0.433000
119
G1 X-0.590500 Y0.433000
120
G1 X-0.590500 Y-0.393700
121
G0 Z0.500000
122
"""
123

124
        # create a path directly form a piece of gcode.
125
        p = Path.Path()
126
        p.setFromGCode(lines)
127
        self.assertEqual(p.toGCode(), output)
128

129
    def test50(self):
130
        """Test Path.Length calculation"""
131
        commands = []
132
        commands.append(Path.Command("G1", {"X": 1}))
133
        commands.append(Path.Command("G1", {"Y": 1}))
134
        path = Path.Path(commands)
135

136
        self.assertEqual(path.Length, 2)
137

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

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

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

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