Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / PythonAPI / Test / TestFeaturesRevolution.py
1 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 ##
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
7 ##
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## Lesser General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 ##
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 import unittest
22
23 import ModelAPI
24
25 from salome.shaper import model
26
27 #-----------------------------------------------------------------------------
28 # Fixtures
29
30 class FeaturesAddRevolutionFixture(unittest.TestCase):
31
32     def setUp(self):
33         model.begin()
34         # Create part
35         partset = model.moduleDocument()
36         self.part = model.addPart(partset).document()
37         model.do()
38
39     def tearDown(self):
40         model.end()
41         assert(model.checkPythonDump())
42         model.reset()
43
44
45 class FeaturesRevolutionFixture(FeaturesAddRevolutionFixture):
46
47     def setUp(self):
48         FeaturesAddRevolutionFixture.setUp(self)
49         # Create revolution
50         # base
51         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
52         circle = base_sketch.addCircle(0, 0, 10)
53
54         model.do()
55
56         base = base_sketch.selectFace()
57         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
58         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
59         axis_object = model.addAxis(self.part, axis_point1[0], axis_point2[0]).result()
60
61         self.revolution = model.addRevolution(self.part, base, axis_object[0],
62                                               0, 180)
63
64         model.do()
65
66     def tearDown(self):
67         FeaturesAddRevolutionFixture.tearDown(self)
68
69 #-----------------------------------------------------------------------------
70 # TestCases
71
72 class FeaturesAddRevolutionTestCase(FeaturesAddRevolutionFixture):
73
74     def test_add_revolution_by_face_and_angles(self):
75         # base
76         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
77         circle = base_sketch.addCircle(0, 0, 10)
78
79         model.do()
80
81         base = base_sketch.selectFace()
82         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
83         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
84         axis_object = model.addAxis(self.part, axis_point1[0], axis_point2[0]).result()
85
86         revolution = model.addRevolution(self.part, base, axis_object[0],
87                                          0, 180)
88
89         self.assertEqual(revolution.creationMethod().value(), "ByAngles")
90         self.assertEqual(revolution.toAngle().value(), 0)
91         self.assertEqual(revolution.fromAngle().value(), 180)
92         self.assertEqual(revolution.toObject().context(), None)
93         self.assertEqual(revolution.toOffset().value(), 0)
94         self.assertEqual(revolution.fromObject().context(), None)
95         self.assertEqual(revolution.fromOffset().value(), 0)
96
97     def test_add_revolution_by_face_and_planes(self):
98         # base
99         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
100         base_circle = base_sketch.addCircle(0, 0, 10)
101         # to
102         to_plane = model.defaultPlane("XOY")
103         to_plane.origin().setZ(10)
104         to_sketch = model.addSketch(self.part, to_plane)
105         to_circle = to_sketch.addCircle(0, 0, 10)
106         # from
107         from_plane = model.defaultPlane("XOY")
108         from_plane.origin().setZ(-10)
109         from_sketch = model.addSketch(self.part, from_plane)
110         from_circle = from_sketch.addCircle(0, 0, 10)
111
112         model.do()
113
114         base = base_sketch.selectFace()
115         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
116         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
117         axis_object = model.addAxis(self.part, axis_point1[0], axis_point2[0]).result()
118         to_obejct = to_sketch.selectFace()[0]
119         from_object = from_sketch.selectFace()[0]
120
121         revolution = model.addRevolution(self.part, base, axis_object[0],
122                                          to_obejct, 15,
123                                          from_object, 20)
124
125         self.assertEqual(revolution.creationMethod().value(), "ByPlanesAndOffsets")
126         self.assertEqual(revolution.toAngle().value(), 0)
127         self.assertEqual(revolution.fromAngle().value(), 0)
128 #         self.assertEqual(revolution.getToObject().context(),
129 #                          to_sketch.result())
130         self.assertEqual(revolution.toOffset().value(), 15)
131 #         self.assertEqual(revolution.getFromObject().context(),
132 #                          from_sketch.result())
133         self.assertEqual(revolution.fromOffset().value(), 20)
134
135
136 class FeaturesRevolutionTestCase(FeaturesRevolutionFixture):
137
138     def test_revolution_feature_calls(self):
139         # call method of the feature
140         self.assertEqual(self.revolution.getKind(), "Revolution")
141
142     def test_revolution_get_attribute(self):
143         # call method of the feature
144         self.assertTrue(isinstance(self.revolution.baseObjects(),
145                                    ModelAPI.ModelAPI_AttributeSelectionList))
146         self.assertTrue(isinstance(self.revolution.axis(),
147                                    ModelAPI.ModelAPI_AttributeSelection))
148         self.assertTrue(isinstance(self.revolution.creationMethod(),
149                                    ModelAPI.ModelAPI_AttributeString))
150         self.assertTrue(isinstance(self.revolution.toAngle(),
151                                    ModelAPI.ModelAPI_AttributeDouble))
152         self.assertTrue(isinstance(self.revolution.fromAngle(),
153                                    ModelAPI.ModelAPI_AttributeDouble))
154         self.assertTrue(isinstance(self.revolution.toObject(),
155                                    ModelAPI.ModelAPI_AttributeSelection))
156         self.assertTrue(isinstance(self.revolution.toOffset(),
157                                    ModelAPI.ModelAPI_AttributeDouble))
158         self.assertTrue(isinstance(self.revolution.fromObject(),
159                                    ModelAPI.ModelAPI_AttributeSelection))
160         self.assertTrue(isinstance(self.revolution.fromOffset(),
161                                    ModelAPI.ModelAPI_AttributeDouble))
162
163     def test_revolution_set_angles(self):
164         self.revolution.setAngles(90, 270)
165         self.assertEqual(self.revolution.creationMethod().value(), "ByAngles")
166         self.assertEqual(self.revolution.toAngle().value(), 90)
167         self.assertEqual(self.revolution.fromAngle().value(), 270)
168         self.assertEqual(self.revolution.toObject().context(), None)
169         self.assertEqual(self.revolution.toOffset().value(), 0)
170         self.assertEqual(self.revolution.fromObject().context(), None)
171         self.assertEqual(self.revolution.fromOffset().value(), 0)
172
173     def test_revolution_set_planes_and_offsets(self):
174         # base
175         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
176         base_circle = base_sketch.addCircle(0, 0, 10)
177         # to
178         to_plane = model.defaultPlane("XOY")
179         to_plane.origin().setZ(10)
180         to_sketch = model.addSketch(self.part, to_plane)
181         to_circle = to_sketch.addCircle(0, 0, 10)
182         # from
183         from_plane = model.defaultPlane("XOY")
184         from_plane.origin().setZ(-10)
185         from_sketch = model.addSketch(self.part, from_plane)
186         from_circle = from_sketch.addCircle(0, 0, 10)
187
188         model.do()
189
190         base = base_sketch.selectFace()
191         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
192         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
193         axis_object = model.addAxis(self.part, axis_point1[0], axis_point2[0]).result()
194         to_obejct = to_sketch.selectFace()[0]
195         from_object = from_sketch.selectFace()[0]
196
197         self.revolution.setPlanesAndOffsets(to_obejct, 15, from_object, 20)
198
199         self.assertEqual(self.revolution.creationMethod().value(), "ByPlanesAndOffsets")
200         # self.assertEqual(self.revolution.toAngle().value(), 0)
201         # self.assertEqual(self.revolution.fromAngle().value(), 0)
202 #         self.assertEqual(self.revolution.getToObject().context(), None)
203         self.assertEqual(self.revolution.toOffset().value(), 15)
204 #         self.assertEqual(self.revolution.getFromObject().context(), None)
205         self.assertEqual(self.revolution.fromOffset().value(), 20)
206
207
208 if __name__ == "__main__":
209     unittest.main()