1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
25 from salome.shaper import model
27 #-----------------------------------------------------------------------------
30 class FeaturesAddRevolutionFixture(unittest.TestCase):
35 partset = model.moduleDocument()
36 self.part = model.addPart(partset).document()
41 assert(model.checkPythonDump())
45 class FeaturesRevolutionFixture(FeaturesAddRevolutionFixture):
48 FeaturesAddRevolutionFixture.setUp(self)
51 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
52 circle = base_sketch.addCircle(0, 0, 10)
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, axis_point2).result()
61 self.revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
66 FeaturesAddRevolutionFixture.tearDown(self)
68 #-----------------------------------------------------------------------------
71 class FeaturesAddRevolutionTestCase(FeaturesAddRevolutionFixture):
73 def test_add_revolution_by_face_and_angles(self):
75 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
76 circle = base_sketch.addCircle(0, 0, 10)
80 base = base_sketch.selectFace()
81 axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
82 axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
83 axis_object = model.addAxis(self.part, axis_point1, axis_point2).result()
85 revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
87 self.assertEqual(revolution.creationMethod().value(), "ByAngles")
88 self.assertEqual(revolution.toAngle().value(), 0)
89 self.assertEqual(revolution.fromAngle().value(), 180)
90 self.assertEqual(revolution.toObject().context(), None)
91 self.assertEqual(revolution.fromObject().context(), None)
93 def test_add_revolution_by_face_and_planes(self):
95 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
96 base_circle = base_sketch.addCircle(0, 0, 10)
98 to_plane = model.defaultPlane("XOY")
99 to_plane.origin().setZ(10)
100 to_sketch = model.addSketch(self.part, to_plane)
101 to_circle = to_sketch.addCircle(0, 0, 10)
103 from_plane = model.defaultPlane("XOY")
104 from_plane.origin().setZ(-10)
105 from_sketch = model.addSketch(self.part, from_plane)
106 from_circle = from_sketch.addCircle(0, 0, 10)
110 base = base_sketch.selectFace()
111 axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
112 axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
113 axis_object = model.addAxis(self.part, axis_point1, axis_point2).result()
114 to_obejct = to_sketch.selectFace()[0]
115 from_object = from_sketch.selectFace()[0]
117 self.revolution = model.addRevolution(self.part, base, axis_object,
121 self.assertEqual(self.revolution.creationMethod().value(), "ByPlanesAndOffsets")
122 self.assertNotEqual(self.revolution.toObject().context(), None)
123 self.assertEqual(self.revolution.toOffset().value(), 15)
124 self.assertNotEqual(self.revolution.fromObject().context(), None)
125 self.assertEqual(self.revolution.fromOffset().value(), 20)
128 class FeaturesRevolutionTestCase(FeaturesRevolutionFixture):
130 def test_revolution_feature_calls(self):
131 # call method of the feature
132 self.assertEqual(self.revolution.getKind(), "Revolution")
134 def test_revolution_get_attribute(self):
135 # call method of the feature
136 self.assertTrue(isinstance(self.revolution.baseObjects(),
137 ModelAPI.ModelAPI_AttributeSelectionList))
138 self.assertTrue(isinstance(self.revolution.axis(),
139 ModelAPI.ModelAPI_AttributeSelection))
140 self.assertTrue(isinstance(self.revolution.creationMethod(),
141 ModelAPI.ModelAPI_AttributeString))
142 self.assertTrue(isinstance(self.revolution.toAngle(),
143 ModelAPI.ModelAPI_AttributeDouble))
144 self.assertTrue(isinstance(self.revolution.fromAngle(),
145 ModelAPI.ModelAPI_AttributeDouble))
146 self.assertTrue(isinstance(self.revolution.toObject(),
147 ModelAPI.ModelAPI_AttributeSelection))
148 self.assertTrue(isinstance(self.revolution.toOffset(),
149 ModelAPI.ModelAPI_AttributeDouble))
150 self.assertTrue(isinstance(self.revolution.fromObject(),
151 ModelAPI.ModelAPI_AttributeSelection))
152 self.assertTrue(isinstance(self.revolution.fromOffset(),
153 ModelAPI.ModelAPI_AttributeDouble))
155 def test_revolution_set_angles(self):
156 self.revolution.setAngles(90, 270)
157 self.assertEqual(self.revolution.creationMethod().value(), "ByAngles")
158 self.assertEqual(self.revolution.toAngle().value(), 90)
159 self.assertEqual(self.revolution.fromAngle().value(), 270)
160 self.assertEqual(self.revolution.toObject().context(), None)
161 self.assertEqual(self.revolution.fromObject().context(), None)
163 def test_revolution_set_planes_and_offsets(self):
165 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
166 base_circle = base_sketch.addCircle(0, 0, 10)
168 to_plane = model.defaultPlane("XOY")
169 to_plane.origin().setZ(10)
170 to_sketch = model.addSketch(self.part, to_plane)
171 to_circle = to_sketch.addCircle(0, 0, 10)
173 from_plane = model.defaultPlane("XOY")
174 from_plane.origin().setZ(-10)
175 from_sketch = model.addSketch(self.part, from_plane)
176 from_circle = from_sketch.addCircle(0, 0, 10)
180 base = base_sketch.selectFace()
181 axis_point1 = model.addPoint(self.part, 20, -10, 0).result()
182 axis_point2 = model.addPoint(self.part, 20, 10, 0).result()
183 axis_object = model.addAxis(self.part, axis_point1, axis_point2).result()
184 to_obejct = to_sketch.selectFace()[0]
185 from_object = from_sketch.selectFace()[0]
187 self.revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
188 self.revolution.setPlanesAndOffsets(to_obejct, 15, from_object, 20)
190 self.assertEqual(self.revolution.creationMethod().value(), "ByPlanesAndOffsets")
191 self.assertNotEqual(self.revolution.toObject().context(), None)
192 self.assertEqual(self.revolution.toOffset().value(), 15)
193 self.assertNotEqual(self.revolution.fromObject().context(), None)
194 self.assertEqual(self.revolution.fromOffset().value(), 20)
197 if __name__ == "__main__":
198 test_program = unittest.main(exit=False)
199 assert test_program.result.wasSuccessful(), "Test failed"