1 # Copyright (C) 2017-2019 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
21 Test movement of the sketch arc of circle
25 from GeomDataAPI import geomDataAPI_Point2D
26 from salome.shaper import model
28 __updated__ = "2017-05-11"
30 class TestMoveArc(unittest.TestCase):
33 self.myDocument = model.moduleDocument()
34 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
35 self.myCenter = [50., 50.]
36 self.myStart = [70., 50.]
37 self.myEnd = [50., 70.]
38 self.myArc = self.mySketch.addArc(self.myCenter[0], self.myCenter[1], self.myStart[0], self.myStart[1], self.myEnd[0], self.myEnd[1], False)
44 model.assertArcValidity(self.myArc)
47 assert(model.checkPythonDump())
50 self.assertEqual(model.dof(self.mySketch), self.myDOF)
52 def checkPointCoordinates(self, thePoint, theCoordinates):
53 self.assertAlmostEqual(thePoint.x(), theCoordinates[0], 5)
54 self.assertAlmostEqual(thePoint.y(), theCoordinates[1], 5)
56 def checkPointOnArc(self, theCoordinates):
57 distPC = model.distancePointPoint(self.myArc.center(), theCoordinates)
58 radius = model.distancePointPoint(self.myArc.center(), self.myArc.startPoint())
59 self.assertAlmostEqual(distPC, radius, 5)
61 def checkArcRadius(self):
62 radius = model.distancePointPoint(self.myArc.center(), self.myArc.startPoint())
63 self.assertAlmostEqual(radius, self.myRadius, 5)
65 def fixArcRadius(self):
67 self.mySketch.setRadius(self.myArc.results()[1], self.myRadius)
72 def fixPoint(self, thePoint):
73 self.mySketch.setFixed(thePoint)
79 self.mySketch.setFixed(self.myArc.results()[1])
85 def test_move_center_of_free_arc(self):
86 """ Test 1. Movement of center of a free arc
88 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
89 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
91 self.checkPointCoordinates(self.myArc.center(), newPosition)
93 def test_move_start_of_free_arc(self):
94 """ Test 2. Movement of start point of a free arc
96 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
97 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
99 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
100 self.checkPointCoordinates(self.myArc.startPoint(), newPosition)
102 def test_move_end_of_free_arc(self):
103 """ Test 3. Movement of end point of a free arc
105 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
106 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
108 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
109 self.checkPointCoordinates(self.myArc.endPoint(), newPosition)
111 def test_move_free_arc(self):
112 """ Test 4. Movement of a free arc dragging the edge
114 newPosition = [100., 80.]
115 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
117 self.checkPointOnArc(newPosition)
118 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
120 def test_move_center_of_arc_fixed_center(self):
121 """ Test 5. Movement of center of the arc with fixed center (nothing should be changed)
123 self.fixPoint(self.myArc.center())
125 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
126 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
128 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
130 def test_move_start_of_arc_fixed_center(self):
131 """ Test 6. Movement of start point of the arc with fixed center
133 self.fixPoint(self.myArc.center())
135 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
136 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
138 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
139 self.checkPointCoordinates(self.myArc.startPoint(), newPosition)
141 def test_move_end_of_arc_fixed_center(self):
142 """ Test 7. Movement of end point of the arc with fixed center
144 self.fixPoint(self.myArc.center())
146 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
147 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
149 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
150 self.checkPointCoordinates(self.myArc.endPoint(), newPosition)
152 def test_move_arc_fixed_center(self):
153 """ Test 8. Movement of the arc with fixed center dragging the edge
155 self.fixPoint(self.myArc.center())
157 newPosition = [100., 80.]
158 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
160 self.checkPointOnArc(newPosition)
161 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
163 def test_move_center_of_arc_fixed_start(self):
164 """ Test 9. Movement of center of the arc with fixed start point
166 self.fixPoint(self.myArc.startPoint())
168 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
169 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
171 self.checkPointCoordinates(self.myArc.center(), newPosition)
172 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
174 def test_move_start_of_arc_fixed_start(self):
175 """ Test 10. Movement of start point of the arc with fixed start point (nothing should be changed)
177 self.fixPoint(self.myArc.startPoint())
179 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
180 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
182 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
183 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
184 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
186 def test_move_end_of_arc_fixed_start(self):
187 """ Test 11. Movement of end point of the arc with fixed start point
189 self.fixPoint(self.myArc.startPoint())
191 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
192 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
194 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
195 self.assertNotEqual(self.myArc.center().x(), self.myCenter[0])
196 self.assertNotEqual(self.myArc.center().y(), self.myCenter[1])
198 def test_move_arc_fixed_start(self):
199 """ Test 12. Movement of the arc with fixed start point dragging the edge
201 self.fixPoint(self.myArc.startPoint())
203 newPosition = [100., 80.]
204 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
206 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
207 self.assertNotEqual(self.myArc.center().x(), self.myCenter[0])
208 self.assertNotEqual(self.myArc.center().y(), self.myCenter[1])
210 def test_move_center_of_arc_fixed_end(self):
211 """ Test 13. Movement of center of the arc with fixed end point
213 self.fixPoint(self.myArc.endPoint())
215 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
216 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
218 self.checkPointCoordinates(self.myArc.center(), newPosition)
219 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
221 def test_move_start_of_arc_fixed_end(self):
222 """ Test 14. Movement of start point of the arc with fixed end point
224 self.fixPoint(self.myArc.endPoint())
226 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
227 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
229 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
230 self.assertNotEqual(self.myArc.center().x(), self.myCenter[0])
231 self.assertNotEqual(self.myArc.center().y(), self.myCenter[1])
233 def test_move_end_of_arc_fixed_end(self):
234 """ Test 15. Movement of end point of the arc with fixed end point (nothing should be changed)
236 self.fixPoint(self.myArc.endPoint())
238 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
239 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
241 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
242 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
243 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
245 def test_move_arc_fixed_end(self):
246 """ Test 16. Movement of the arc with fixed end point dragging the edge
248 self.fixPoint(self.myArc.endPoint())
250 newPosition = [100., 80.]
251 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
253 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
254 self.assertTrue(fabs(self.myArc.center().x() - self.myCenter[0]) > 1.e-5 or fabs(self.myArc.center().y() - self.myCenter[1]) > 1.e-5)
256 def test_move_center_of_arc_fixed_radius(self):
257 """ Test 17. Movement of center of the arc with fixed radius
261 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
262 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
264 self.checkPointCoordinates(self.myArc.center(), newPosition)
265 self.checkArcRadius()
267 def test_move_start_of_arc_fixed_radius(self):
268 """ Test 18. Movement of start point of the arc with fixed radius
272 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
273 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
275 self.checkArcRadius()
277 def test_move_end_of_arc_fixed_radius(self):
278 """ Test 19. Movement of end point of the arc with fixed radius
282 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
283 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
285 self.checkArcRadius()
287 def test_move_arc_fixed_radius(self):
288 """ Test 20. Movement of the arc with fixed radius dragging the edge
292 newPosition = [100., 80.]
293 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
295 self.checkArcRadius()
297 def test_move_center_of_fixed_arc(self):
298 """ Test 21. Movement of center of fully fixed arc (nothing should be changed)
302 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
303 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
305 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
306 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
307 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
309 def test_move_start_of_fixed_arc(self):
310 """ Test 22. Movement of start point of fully fixed arc (nothing should be changed)
314 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
315 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
317 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
318 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
319 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
321 def test_move_end_of_fixed_arc(self):
322 """ Test 23. Movement of end point of fully fixed arc (nothing should be changed)
326 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
327 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
329 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
330 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
331 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
333 def test_move_fixed_arc(self):
334 """ Test 24. Movement of fully fixed arc (nothing should be changed)
338 newPosition = [100., 80.]
339 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
341 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
342 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
343 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
346 if __name__ == "__main__":
347 test_program = unittest.main(exit=False)
348 assert test_program.result.wasSuccessful(), "Test failed"