25
from Tests.PathTestUtils import PathTestBase
28
class TestPathCore(PathTestBase):
30
"""Test Path command core functionality"""
33
self.assertIsInstance(c, Path.Command)
37
self.assertEqual(c.Name, "G1")
40
c.Parameters = {"X": 1, "Y": 0}
41
self.assertEqual(c.Parameters, {"Y": 0.0, "X": 1.0})
44
c.Parameters = {"X": 1, "Y": 0.5}
45
self.assertEqual(c.Parameters, {"Y": 0.5, "X": 1})
48
self.assertEqual(c.toGCode(), "G1 X1.000000 Y0.500000")
51
c2 = Path.Command("G2")
52
self.assertEqual(c2.Name, "G2")
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 ]")
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)
73
self.assertEqual(str(c5), "Command G1 [ X:5 ]")
74
self.assertEqual(c5.x, 5.0)
78
self.assertEqual(c5.x, 10.0)
80
self.assertEqual(str(c5), "Command G1 [ X:10 Y:2 ]")
83
c3.setFromGCode("G1X1Y0")
84
self.assertEqual(str(c3), "Command G1 [ X:1 Y:0 ]")
87
"""Test Path Object core functionality"""
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)
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)
99
"G1 X1.000000 Y0.000000\nG1 X0.000000 Y2.000000\nG1 X1.000000 Y0.000000\n",
103
G0X-0.5905Y-0.3937S3000M03
106
G1X0.9842Y-0.3937F14.17
113
output = """G0 S3000.000000 X-0.590500 Y-0.393700
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
126
p.setFromGCode(lines)
127
self.assertEqual(p.toGCode(), output)
130
"""Test Path.Length calculation"""
132
commands.append(Path.Command("G1", {"X": 1}))
133
commands.append(Path.Command("G1", {"Y": 1}))
134
path = Path.Path(commands)
136
self.assertEqual(path.Length, 2)