2
# ***************************************************************************
3
# * Copyright (c) 2017 sliptonic <shopinthewoods@gmail.com> *
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. *
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. *
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 *
21
# ***************************************************************************
24
import Path.Main.Stock as PathStock
26
from Tests.PathTestUtils import PathTestBase
30
def baseObject(self, obj):
37
class TestPathStock(PathTestBase):
39
self.doc = FreeCAD.newDocument("TestPathStock")
40
self.base = self.doc.addObject("Part::Box", "Box")
41
self.base.Length = 100
43
self.base.Height = 300
44
self.job = self.doc.addObject("App::FeaturePython", "Job")
45
self.job.addProperty("App::PropertyLink", "Model")
46
model = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "Model")
47
model.addObject(self.base)
48
self.job.Model = model
49
self.job.Proxy = FakeJobProxy()
52
FreeCAD.closeDocument("TestPathStock")
57
stock = PathStock.CreateBox(self.job)
58
self.assertTrue(hasattr(stock, "Length"))
59
self.assertTrue(hasattr(stock, "Width"))
60
self.assertTrue(hasattr(stock, "Height"))
61
self.assertEqual(100, stock.Length)
62
self.assertEqual(200, stock.Width)
63
self.assertEqual(300, stock.Height)
65
extent = FreeCAD.Vector(17, 13, 77)
66
stock = PathStock.CreateBox(self.job, extent)
67
self.assertEqual(17, stock.Length)
68
self.assertEqual(13, stock.Width)
69
self.assertEqual(77, stock.Height)
71
placement = FreeCAD.Placement(FreeCAD.Vector(-3, 88, 4), FreeCAD.Vector(0, 0, 1), 180)
72
stock = PathStock.CreateBox(self.job, extent, placement)
73
self.assertEqual(17, stock.Length)
74
self.assertEqual(13, stock.Width)
75
self.assertEqual(77, stock.Height)
76
self.assertPlacement(placement, stock.Placement)
79
"""Test CreateCylinder"""
81
stock = PathStock.CreateCylinder(self.job)
82
self.assertTrue(hasattr(stock, "Radius"))
83
self.assertTrue(hasattr(stock, "Height"))
84
self.assertRoughly(R, stock.Radius.Value)
85
self.assertEqual(300, stock.Height)
87
stock = PathStock.CreateCylinder(self.job, 37, 24)
88
self.assertEqual(37, stock.Radius)
89
self.assertEqual(24, stock.Height)
91
placement = FreeCAD.Placement(FreeCAD.Vector(3, 8, -4), FreeCAD.Vector(0, 0, 1), -90)
92
stock = PathStock.CreateCylinder(self.job, 1, 88, placement)
93
self.assertEqual(1, stock.Radius)
94
self.assertEqual(88, stock.Height)
95
self.assertPlacement(placement, stock.Placement)
98
"""Verify FromTemplate box creation."""
100
extent = FreeCAD.Vector(17, 13, 77)
101
placement = FreeCAD.Placement(FreeCAD.Vector(3, 8, -4), FreeCAD.Vector(0, 0, 1), -90)
102
orig = PathStock.CreateBox(self.job, extent, placement)
104
# collect full template
105
template = PathStock.TemplateAttributes(orig)
106
stock = PathStock.CreateFromTemplate(self.job, template)
108
self.assertEqual(PathStock.StockType.CreateBox, PathStock.StockType.FromStock(stock))
109
self.assertEqual(orig.Length, stock.Length)
110
self.assertEqual(orig.Width, stock.Width)
111
self.assertEqual(orig.Height, stock.Height)
112
self.assertPlacement(orig.Placement, stock.Placement)
114
# don't store extent in template
115
template = PathStock.TemplateAttributes(orig, False, True)
116
stock = PathStock.CreateFromTemplate(self.job, template)
118
self.assertEqual(PathStock.StockType.CreateBox, PathStock.StockType.FromStock(stock))
119
self.assertEqual(100, stock.Length)
120
self.assertEqual(200, stock.Width)
121
self.assertEqual(300, stock.Height)
122
self.assertPlacement(orig.Placement, stock.Placement)
124
# don't store placement in template
125
template = PathStock.TemplateAttributes(orig, True, False)
126
stock = PathStock.CreateFromTemplate(self.job, template)
128
self.assertEqual(PathStock.StockType.CreateBox, PathStock.StockType.FromStock(stock))
129
self.assertEqual(orig.Length, stock.Length)
130
self.assertEqual(orig.Width, stock.Width)
131
self.assertEqual(orig.Height, stock.Height)
132
self.assertPlacement(FreeCAD.Placement(), stock.Placement)
135
"""Verify FromTemplate cylinder creation."""
138
placement = FreeCAD.Placement(FreeCAD.Vector(99, 88, 77), FreeCAD.Vector(1, 1, 1), 123)
139
orig = PathStock.CreateCylinder(self.job, radius, height, placement)
142
template = PathStock.TemplateAttributes(orig)
143
stock = PathStock.CreateFromTemplate(self.job, template)
145
self.assertEqual(PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock))
146
self.assertEqual(orig.Radius, stock.Radius)
147
self.assertEqual(orig.Height, stock.Height)
148
self.assertPlacement(orig.Placement, stock.Placement)
150
# no extent in template
151
template = PathStock.TemplateAttributes(orig, False, True)
152
stock = PathStock.CreateFromTemplate(self.job, template)
154
self.assertEqual(PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock))
155
self.assertRoughly(R, stock.Radius.Value)
156
self.assertEqual(300, stock.Height)
157
self.assertPlacement(orig.Placement, stock.Placement)
159
# no placement template - and no base
160
template = PathStock.TemplateAttributes(orig, True, False)
161
stock = PathStock.CreateFromTemplate(None, template)
163
self.assertEqual(PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock))
164
self.assertEqual(orig.Radius, stock.Radius)
165
self.assertEqual(orig.Height, stock.Height)
166
self.assertPlacement(FreeCAD.Placement(), stock.Placement)
168
# no placement template - but base
169
template = PathStock.TemplateAttributes(orig, True, False)
170
stock = PathStock.CreateFromTemplate(self.job, template)
172
self.assertEqual(PathStock.StockType.CreateCylinder, PathStock.StockType.FromStock(stock))
173
self.assertEqual(orig.Radius, stock.Radius)
174
self.assertEqual(orig.Height, stock.Height)
175
self.assertPlacement(
176
FreeCAD.Placement(FreeCAD.Vector(50, 100, 0), FreeCAD.Rotation()),
181
"""Verify FromTemplate from Base creation."""
182
neg = FreeCAD.Vector(1, 2, 3)
183
pos = FreeCAD.Vector(9, 8, 7)
184
orig = PathStock.CreateFromBase(self.job, neg, pos)
186
# Make sure we have a different base object for the creation
187
self.base.Length = 11
189
self.base.Height = 13
192
template = PathStock.TemplateAttributes(orig)
193
stock = PathStock.CreateFromTemplate(self.job, template)
194
self.assertEqual(PathStock.StockType.FromBase, PathStock.StockType.FromStock(stock))
195
self.assertEqual(orig.ExtXneg, stock.ExtXneg)
196
self.assertEqual(orig.ExtXpos, stock.ExtXpos)
197
self.assertEqual(orig.ExtYneg, stock.ExtYneg)
198
self.assertEqual(orig.ExtYpos, stock.ExtYpos)
199
self.assertEqual(orig.ExtZneg, stock.ExtZneg)
200
self.assertEqual(orig.ExtZpos, stock.ExtZpos)
202
bb = stock.Shape.BoundBox
203
self.assertEqual(neg.x + pos.x + 11, bb.XLength)
204
self.assertEqual(neg.y + pos.y + 12, bb.YLength)
205
self.assertEqual(neg.z + pos.z + 13, bb.ZLength)