FreeCAD

Форк
0
/
TestPathStock.py 
205 строк · 8.9 Кб
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.Main.Stock as PathStock
25

26
from Tests.PathTestUtils import PathTestBase
27

28

29
class FakeJobProxy:
30
    def baseObject(self, obj):
31
        return obj.Base
32

33

34
R = 223.606798 / 2
35

36

37
class TestPathStock(PathTestBase):
38
    def setUp(self):
39
        self.doc = FreeCAD.newDocument("TestPathStock")
40
        self.base = self.doc.addObject("Part::Box", "Box")
41
        self.base.Length = 100
42
        self.base.Width = 200
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()
50

51
    def tearDown(self):
52
        FreeCAD.closeDocument("TestPathStock")
53

54
    def test00(self):
55
        """Test CreateBox"""
56

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)
64

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)
70

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)
77

78
    def test01(self):
79
        """Test CreateCylinder"""
80

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)
86

87
        stock = PathStock.CreateCylinder(self.job, 37, 24)
88
        self.assertEqual(37, stock.Radius)
89
        self.assertEqual(24, stock.Height)
90

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)
96

97
    def test10(self):
98
        """Verify FromTemplate box creation."""
99

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)
103

104
        # collect full template
105
        template = PathStock.TemplateAttributes(orig)
106
        stock = PathStock.CreateFromTemplate(self.job, template)
107

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)
113

114
        # don't store extent in template
115
        template = PathStock.TemplateAttributes(orig, False, True)
116
        stock = PathStock.CreateFromTemplate(self.job, template)
117

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)
123

124
        # don't store placement in template
125
        template = PathStock.TemplateAttributes(orig, True, False)
126
        stock = PathStock.CreateFromTemplate(self.job, template)
127

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)
133

134
    def test11(self):
135
        """Verify FromTemplate cylinder creation."""
136
        radius = 7
137
        height = 12
138
        placement = FreeCAD.Placement(FreeCAD.Vector(99, 88, 77), FreeCAD.Vector(1, 1, 1), 123)
139
        orig = PathStock.CreateCylinder(self.job, radius, height, placement)
140

141
        # full template
142
        template = PathStock.TemplateAttributes(orig)
143
        stock = PathStock.CreateFromTemplate(self.job, template)
144

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)
149

150
        # no extent in template
151
        template = PathStock.TemplateAttributes(orig, False, True)
152
        stock = PathStock.CreateFromTemplate(self.job, template)
153

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)
158

159
        # no placement template - and no base
160
        template = PathStock.TemplateAttributes(orig, True, False)
161
        stock = PathStock.CreateFromTemplate(None, template)
162

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)
167

168
        # no placement template - but base
169
        template = PathStock.TemplateAttributes(orig, True, False)
170
        stock = PathStock.CreateFromTemplate(self.job, template)
171

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()),
177
            stock.Placement,
178
        )
179

180
    def test12(self):
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)
185

186
        # Make sure we have a different base object for the creation
187
        self.base.Length = 11
188
        self.base.Width = 12
189
        self.base.Height = 13
190

191
        # full template
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)
201

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)
206

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

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

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

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