Salome HOME
Copyright update 2022
[modules/shaper.git] / src / PythonAPI / Test / TestFeaturesRevolution.py
1 # Copyright (C) 2014-2022  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 email : webmaster.salome@opencascade.com
18 #
19
20 import unittest
21
22 import ModelAPI
23
24 from salome.shaper import model
25
26 #-----------------------------------------------------------------------------
27 # Fixtures
28
29 class FeaturesAddRevolutionFixture(unittest.TestCase):
30
31     def setUp(self):
32         model.begin()
33         # Create part
34         partset = model.moduleDocument()
35         self.part = model.addPart(partset).document()
36         model.do()
37
38     def tearDown(self):
39         model.end()
40         assert(model.checkPythonDump())
41         model.reset()
42
43
44 class FeaturesRevolutionFixture(FeaturesAddRevolutionFixture):
45
46     def setUp(self):
47         FeaturesAddRevolutionFixture.setUp(self)
48         # Create revolution
49         # base
50         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
51         circle = base_sketch.addCircle(0, 0, 10)
52
53         model.do()
54
55         base = base_sketch.selectFace()
56         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
57         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
58         axis_object = model.addAxis(self.part, axis_point1, axis_point2).result()
59
60         self.revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
61
62         model.do()
63
64     def tearDown(self):
65         FeaturesAddRevolutionFixture.tearDown(self)
66
67 #-----------------------------------------------------------------------------
68 # TestCases
69
70 class FeaturesAddRevolutionTestCase(FeaturesAddRevolutionFixture):
71
72     def test_add_revolution_by_face_and_angles(self):
73         # base
74         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
75         circle = base_sketch.addCircle(0, 0, 10)
76
77         model.do()
78
79         base = base_sketch.selectFace()
80         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
81         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
82         axis_object = model.addAxis(self.part, axis_point1, axis_point2).result()
83
84         revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
85
86         self.assertEqual(revolution.creationMethod().value(), "ByAngles")
87         self.assertEqual(revolution.toAngle().value(), 0)
88         self.assertEqual(revolution.fromAngle().value(), 180)
89         self.assertEqual(revolution.toObject().context(), None)
90         self.assertEqual(revolution.fromObject().context(), None)
91
92     def test_add_revolution_by_face_and_planes(self):
93         # base
94         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
95         base_circle = base_sketch.addCircle(0, 0, 10)
96         # to
97         to_plane = model.defaultPlane("XOY")
98         to_plane.origin().setZ(10)
99         to_sketch = model.addSketch(self.part, to_plane)
100         to_circle = to_sketch.addCircle(0, 0, 10)
101         # from
102         from_plane = model.defaultPlane("XOY")
103         from_plane.origin().setZ(-10)
104         from_sketch = model.addSketch(self.part, from_plane)
105         from_circle = from_sketch.addCircle(0, 0, 10)
106
107         model.do()
108
109         base = base_sketch.selectFace()
110         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
111         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
112         axis_object = model.addAxis(self.part, axis_point1, axis_point2).result()
113         to_obejct = to_sketch.selectFace()[0]
114         from_object = from_sketch.selectFace()[0]
115
116         self.revolution = model.addRevolution(self.part, base, axis_object,
117                                               to_obejct, 15,
118                                               from_object, 20)
119
120         self.assertEqual(self.revolution.creationMethod().value(), "ByPlanesAndOffsets")
121         self.assertNotEqual(self.revolution.toObject().context(), None)
122         self.assertEqual(self.revolution.toOffset().value(), 15)
123         self.assertNotEqual(self.revolution.fromObject().context(), None)
124         self.assertEqual(self.revolution.fromOffset().value(), 20)
125
126
127 class FeaturesRevolutionTestCase(FeaturesRevolutionFixture):
128
129     def test_revolution_feature_calls(self):
130         # call method of the feature
131         self.assertEqual(self.revolution.getKind(), "Revolution")
132
133     def test_revolution_get_attribute(self):
134         # call method of the feature
135         self.assertTrue(isinstance(self.revolution.baseObjects(),
136                                    ModelAPI.ModelAPI_AttributeSelectionList))
137         self.assertTrue(isinstance(self.revolution.axis(),
138                                    ModelAPI.ModelAPI_AttributeSelection))
139         self.assertTrue(isinstance(self.revolution.creationMethod(),
140                                    ModelAPI.ModelAPI_AttributeString))
141         self.assertTrue(isinstance(self.revolution.toAngle(),
142                                    ModelAPI.ModelAPI_AttributeDouble))
143         self.assertTrue(isinstance(self.revolution.fromAngle(),
144                                    ModelAPI.ModelAPI_AttributeDouble))
145         self.assertTrue(isinstance(self.revolution.toObject(),
146                                    ModelAPI.ModelAPI_AttributeSelection))
147         self.assertTrue(isinstance(self.revolution.toOffset(),
148                                    ModelAPI.ModelAPI_AttributeDouble))
149         self.assertTrue(isinstance(self.revolution.fromObject(),
150                                    ModelAPI.ModelAPI_AttributeSelection))
151         self.assertTrue(isinstance(self.revolution.fromOffset(),
152                                    ModelAPI.ModelAPI_AttributeDouble))
153
154     def test_revolution_set_angles(self):
155         self.revolution.setAngles(90, 270)
156         self.assertEqual(self.revolution.creationMethod().value(), "ByAngles")
157         self.assertEqual(self.revolution.toAngle().value(), 90)
158         self.assertEqual(self.revolution.fromAngle().value(), 270)
159         self.assertEqual(self.revolution.toObject().context(), None)
160         self.assertEqual(self.revolution.fromObject().context(), None)
161
162     def test_revolution_set_planes_and_offsets(self):
163         # base
164         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
165         base_circle = base_sketch.addCircle(0, 0, 10)
166         # to
167         to_plane = model.defaultPlane("XOY")
168         to_plane.origin().setZ(10)
169         to_sketch = model.addSketch(self.part, to_plane)
170         to_circle = to_sketch.addCircle(0, 0, 10)
171         # from
172         from_plane = model.defaultPlane("XOY")
173         from_plane.origin().setZ(-10)
174         from_sketch = model.addSketch(self.part, from_plane)
175         from_circle = from_sketch.addCircle(0, 0, 10)
176
177         model.do()
178
179         base = base_sketch.selectFace()
180         axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
181         axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
182         axis_object = model.addAxis(self.part, axis_point1, axis_point2).result()
183         to_obejct = to_sketch.selectFace()[0]
184         from_object = from_sketch.selectFace()[0]
185
186         self.revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
187         self.revolution.setPlanesAndOffsets(to_obejct, 15, from_object, 20)
188
189         self.assertEqual(self.revolution.creationMethod().value(), "ByPlanesAndOffsets")
190         self.assertNotEqual(self.revolution.toObject().context(), None)
191         self.assertEqual(self.revolution.toOffset().value(), 15)
192         self.assertNotEqual(self.revolution.fromObject().context(), None)
193         self.assertEqual(self.revolution.fromOffset().value(), 20)
194
195
196 if __name__ == "__main__":
197     test_program = unittest.main(exit=False)
198     assert test_program.result.wasSuccessful(), "Test failed"