25
import Path.Dressup.Gui.Dogbone as PathDressupDogbone
26
import Path.Main.Job as PathJob
27
import Path.Op.Profile as PathProfile
29
from Tests.PathTestUtils import PathTestBase
33
def __init__(self, side, direction, path):
35
self.Direction = direction
36
self.Path = Path.Path(path)
37
self.ToolController = None
43
self.Path = Path.Path()
45
def addProperty(self, typ, name, category, tip):
46
setattr(self, name, None)
48
def setEditorMode(self, prop, mode):
52
class TestDressupDogbone(PathTestBase):
53
"""Unit tests for the Dogbone dressup."""
55
def formatBone(self, bone):
56
return "%d: (%.2f, %.2f)" % (bone[0], bone[1][0], bone[1][1])
59
"""Verify bones are inserted for simple moves."""
74
db = PathDressupDogbone.ObjectDressup(obj, base)
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]))
84
"""Verify bones are inserted if hole ends with rapid move out."""
99
db = PathDressupDogbone.ObjectDressup(obj, base)
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]))
109
"""Verify bones are correctly generated for a Profile."""
110
doc = FreeCAD.newDocument("TestDressupDogbone")
113
box0 = doc.addObject("Part::Box", "Box")
117
box1 = doc.addObject("Part::Box", "Box")
121
box1.Placement = FreeCAD.Placement(
122
FreeCAD.Vector(25, 25, -5), FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), 0)
125
cut = doc.addObject("Part::Cut", "Cut")
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":
136
PathJob.Create("Job", [cut], None)
138
profile = PathProfile.Create("Profile")
139
profile.Base = (cut, face)
142
profile.setExpression("StartDepth", None)
143
profile.StartDepth = 10
144
profile.setExpression("FinalDepth", None)
145
profile.FinalDepth = 0
147
profile.processHoles = True
148
profile.processPerimeter = True
151
dogbone = PathDressupDogbone.Create(profile)
155
locs = sorted([bone[1] for bone in dog.bones], key=lambda xy: xy[0] * 1000 + xy[1])
157
def formatBoneLoc(pt):
158
return "(%.2f, %.2f)" % (pt[0], pt[1])
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]))
172
FreeCAD.closeDocument("TestDressupDogbone")
175
"""Verify no bone is inserted for straight move interrupted by plunge."""
186
G1 X10 ( straight line move to start)
191
db = PathDressupDogbone.ObjectDressup(obj, base)
193
db.execute(obj, False)
194
self.assertEqual(len(db.bones), 0)
197
"""Verify can handle comments between moves"""
212
db = PathDressupDogbone.ObjectDressup(obj, base)
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]))
230
(some comment or other should not change the output)
236
db = PathDressupDogbone.ObjectDressup(obj, base)
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]))
246
"""Verify can handle noops between moves"""
261
db = PathDressupDogbone.ObjectDressup(obj, base)
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]))
285
db = PathDressupDogbone.ObjectDressup(obj, base)
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]))