]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/Test/TestFeaturesExtrusion.py
Salome HOME
Update copyrights
[modules/shaper.git] / src / PythonAPI / Test / TestFeaturesExtrusion.py
1 # Copyright (C) 2014-2019  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 FeaturesAddExtrusionFixture(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 FeaturesExtrusionFixture(FeaturesAddExtrusionFixture):
45
46     def setUp(self):
47         FeaturesAddExtrusionFixture.setUp(self)
48         # Create extrusion
49         sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
50         circle = sketch.addCircle(0, 0, 10)
51         model.do()
52
53         base = sketch.selectFace()
54         self.extrusion = model.addExtrusion(self.part, base, 10, 0)
55         model.do()
56
57     def tearDown(self):
58         FeaturesAddExtrusionFixture.tearDown(self)
59
60 #-----------------------------------------------------------------------------
61 # TestCases
62
63 class FeaturesAddExtrusionTestCase(FeaturesAddExtrusionFixture):
64
65     def test_add_extrusion_by_face_and_size(self):
66         sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
67         circle = sketch.addCircle(0, 0, 10)
68         model.do()
69
70         base = sketch.selectFace()
71         extrusion = model.addExtrusion(self.part, base, 10, 0)
72         model.do()
73
74         self.assertEqual(extrusion.creationMethod().value(), "BySizes")
75         self.assertEqual(extrusion.toSize().value(), 10)
76         self.assertEqual(extrusion.fromSize().value(), 0)
77         self.assertEqual(extrusion.toObject().context(), None)
78         self.assertEqual(extrusion.toOffset().isInitialized(), False)
79         self.assertEqual(extrusion.fromObject().context(), None)
80         self.assertEqual(extrusion.fromOffset().isInitialized(), False)
81
82     def test_add_extrusion_by_face_and_planes(self):
83         # base
84         base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
85         base_circle = base_sketch.addCircle(0, 0, 10)
86         # to
87         to_plane = model.defaultPlane("XOY")
88         to_plane.origin().setZ(10)
89         to_sketch = model.addSketch(self.part, to_plane)
90         to_circle = to_sketch.addCircle(0, 0, 10)
91         # from
92         from_plane = model.defaultPlane("XOY")
93         from_plane.origin().setZ(-10)
94         from_sketch = model.addSketch(self.part, from_plane)
95         from_circle = from_sketch.addCircle(0, 0, 10)
96
97         model.do()
98
99         base = base_sketch.selectFace()
100         to_object = to_sketch.selectFace()[0]
101         from_object = from_sketch.selectFace()[0]
102         extrusion = model.addExtrusion(self.part, base,
103                                        to_object, 15,
104                                        from_object, 20)
105
106         self.assertEqual(extrusion.creationMethod().value(), "ByPlanesAndOffsets")
107         self.assertEqual(extrusion.toSize().isInitialized(), False)
108         self.assertEqual(extrusion.fromSize().isInitialized(), False)
109 #         self.assertEqual(extrusion.getToObject().context(),
110 #                          to_sketch.result())
111         self.assertEqual(extrusion.toOffset().value(), 15)
112 #         self.assertEqual(extrusion.getFromObject().context(),
113 #                          from_sketch.result())
114         self.assertEqual(extrusion.fromOffset().value(), 20)
115
116
117 class FeaturesExtrusionTestCase(FeaturesExtrusionFixture):
118
119     def test_extrusion_feature_calls(self):
120         # call method of the feature
121         self.assertEqual(self.extrusion.getKind(), "Extrusion")
122
123     def test_extrusion_get_attribute(self):
124         # call method of the feature
125         self.assertTrue(isinstance(self.extrusion.baseObjects(),
126                                    ModelAPI.ModelAPI_AttributeSelectionList))
127         self.assertTrue(isinstance(self.extrusion.creationMethod(),
128                                    ModelAPI.ModelAPI_AttributeString))
129         self.assertTrue(isinstance(self.extrusion.toSize(),
130                                    ModelAPI.ModelAPI_AttributeDouble))
131         self.assertTrue(isinstance(self.extrusion.fromSize(),
132                                    ModelAPI.ModelAPI_AttributeDouble))
133         self.assertTrue(isinstance(self.extrusion.toObject(),
134                                    ModelAPI.ModelAPI_AttributeSelection))
135         self.assertTrue(isinstance(self.extrusion.toOffset(),
136                                    ModelAPI.ModelAPI_AttributeDouble))
137         self.assertTrue(isinstance(self.extrusion.fromObject(),
138                                    ModelAPI.ModelAPI_AttributeSelection))
139         self.assertTrue(isinstance(self.extrusion.fromOffset(),
140                                    ModelAPI.ModelAPI_AttributeDouble))
141
142     def test_extrusion_set_sizes(self):
143         self.extrusion.setSizes(15, 20)
144         self.assertEqual(self.extrusion.creationMethod().value(), "BySizes")
145         self.assertEqual(self.extrusion.toSize().value(), 15)
146         self.assertEqual(self.extrusion.fromSize().value(), 20)
147         self.assertEqual(self.extrusion.toObject().context(), None)
148         self.assertEqual(self.extrusion.toOffset().isInitialized(), False)
149         self.assertEqual(self.extrusion.fromObject().context(), None)
150         self.assertEqual(self.extrusion.fromOffset().isInitialized(), False)
151
152     def test_extrusion_set_planes_and_offsets(self):
153         # to
154         to_plane = model.defaultPlane("XOY")
155         to_plane.origin().setZ(10)
156         to_sketch = model.addSketch(self.part, to_plane)
157         to_circle = to_sketch.addCircle(0, 0, 10)
158         # from
159         from_plane = model.defaultPlane("XOY")
160         from_plane.origin().setZ(-10)
161         from_sketch = model.addSketch(self.part, from_plane)
162         from_circle = from_sketch.addCircle(0, 0, 10)
163
164         model.do()
165
166         to_object = to_sketch.selectFace()[0]
167         from_object = from_sketch.selectFace()[0]
168
169         self.part.moveFeature(self.extrusion.feature(), from_sketch.feature())
170
171         self.extrusion.setPlanesAndOffsets(to_object, 15, from_object, 20)
172
173
174 if __name__ == "__main__":
175     test_program = unittest.main(exit=False)
176     assert test_program.result.wasSuccessful(), "Test failed"