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[0], axis_point2[0]).result()
61 self.revolution = model.addRevolution(self.part, base, axis_object[0],
67 FeaturesAddRevolutionFixture.tearDown(self)
69 #-----------------------------------------------------------------------------
72 class FeaturesAddRevolutionTestCase(FeaturesAddRevolutionFixture):
74 def test_add_revolution_by_face_and_angles(self):
76 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
77 circle = base_sketch.addCircle(0, 0, 10)
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()
86 revolution = model.addRevolution(self.part, base, axis_object[0],
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)
97 def test_add_revolution_by_face_and_planes(self):
99 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
100 base_circle = base_sketch.addCircle(0, 0, 10)
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)
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)
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]
121 revolution = model.addRevolution(self.part, base, axis_object[0],
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)
136 class FeaturesRevolutionTestCase(FeaturesRevolutionFixture):
138 def test_revolution_feature_calls(self):
139 # call method of the feature
140 self.assertEqual(self.revolution.getKind(), "Revolution")
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))
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)
173 def test_revolution_set_planes_and_offsets(self):
175 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
176 base_circle = base_sketch.addCircle(0, 0, 10)
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)
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)
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]
197 self.revolution.setPlanesAndOffsets(to_obejct, 15, from_object, 20)
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)
208 if __name__ == "__main__":
209 unittest.main(exit=False)