1 # Copyright (C) 2014-2020 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 email : webmaster.salome@opencascade.com
24 from salome.shaper import model
26 #-----------------------------------------------------------------------------
29 class FeaturesAddRevolutionFixture(unittest.TestCase):
34 partset = model.moduleDocument()
35 self.part = model.addPart(partset).document()
40 assert(model.checkPythonDump())
44 class FeaturesRevolutionFixture(FeaturesAddRevolutionFixture):
47 FeaturesAddRevolutionFixture.setUp(self)
50 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
51 circle = base_sketch.addCircle(0, 0, 10)
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()
60 self.revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
65 FeaturesAddRevolutionFixture.tearDown(self)
67 #-----------------------------------------------------------------------------
70 class FeaturesAddRevolutionTestCase(FeaturesAddRevolutionFixture):
72 def test_add_revolution_by_face_and_angles(self):
74 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
75 circle = base_sketch.addCircle(0, 0, 10)
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()
84 revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
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)
92 def test_add_revolution_by_face_and_planes(self):
94 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
95 base_circle = base_sketch.addCircle(0, 0, 10)
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)
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)
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]
116 self.revolution = model.addRevolution(self.part, base, axis_object,
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)
127 class FeaturesRevolutionTestCase(FeaturesRevolutionFixture):
129 def test_revolution_feature_calls(self):
130 # call method of the feature
131 self.assertEqual(self.revolution.getKind(), "Revolution")
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))
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)
162 def test_revolution_set_planes_and_offsets(self):
164 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
165 base_circle = base_sketch.addCircle(0, 0, 10)
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)
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)
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]
186 self.revolution = model.addRevolution(self.part, base, axis_object, 0, 180)
187 self.revolution.setPlanesAndOffsets(to_obejct, 15, from_object, 20)
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)
196 if __name__ == "__main__":
197 test_program = unittest.main(exit=False)
198 assert test_program.result.wasSuccessful(), "Test failed"