Salome HOME
Stabilize unit test TestMoveArc by setting higher tolerance for double-values compare
[modules/shaper.git] / src / SketchPlugin / Test / TestMoveArc.py
1 ## Copyright (C) 2017  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 """
22     Test movement of the sketch arc of circle
23 """
24
25 import unittest
26 from GeomDataAPI import geomDataAPI_Point2D
27 from salome.shaper import model
28
29 __updated__ = "2017-05-11"
30
31 class TestMoveArc(unittest.TestCase):
32   def setUp(self):
33     model.begin()
34     self.myDocument = model.moduleDocument()
35     self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
36     self.myCenter = [50., 50.]
37     self.myStart = [70., 50.]
38     self.myEnd = [50., 70.]
39     self.myArc = self.mySketch.addArc(self.myCenter[0], self.myCenter[1], self.myStart[0], self.myStart[1], self.myEnd[0], self.myEnd[1], False)
40     self.myDOF = 5
41     model.do()
42     self.checkDOF()
43
44   def tearDown(self):
45     model.assertArcValidity(self.myArc)
46     self.checkDOF()
47     model.end()
48     assert(model.checkPythonDump())
49
50   def checkDOF(self):
51     self.assertEqual(model.dof(self.mySketch), self.myDOF)
52
53   def checkPointCoordinates(self, thePoint, theCoordinates):
54     self.assertAlmostEqual(thePoint.x(), theCoordinates[0], 5)
55     self.assertAlmostEqual(thePoint.y(), theCoordinates[1], 5)
56
57   def checkPointOnArc(self, theCoordinates):
58     distPC = model.distancePointPoint(self.myArc.center(),  theCoordinates)
59     radius = model.distancePointPoint(self.myArc.center(), self.myArc.startPoint())
60     self.assertAlmostEqual(distPC, radius, 5)
61
62   def checkArcRadius(self):
63     radius = model.distancePointPoint(self.myArc.center(), self.myArc.startPoint())
64     self.assertAlmostEqual(radius, self.myRadius, 5)
65
66   def fixArcRadius(self):
67     self.myRadius = 20.
68     self.mySketch.setRadius(self.myArc.results()[1], self.myRadius)
69     self.myDOF -= 1
70     model.do()
71     self.checkDOF()
72
73   def fixPoint(self, thePoint):
74     self.mySketch.setFixed(thePoint)
75     self.myDOF -= 2
76     model.do()
77     self.checkDOF()
78
79   def fixArc(self):
80     self.mySketch.setFixed(self.myArc.results()[1])
81     self.myDOF -= 5
82     model.do()
83     self.checkDOF()
84
85
86   def test_move_center_of_free_arc(self):
87     """ Test 1. Movement of center of a free arc
88     """
89     newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
90     self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
91     model.do()
92     self.checkPointCoordinates(self.myArc.center(), newPosition)
93
94   def test_move_start_of_free_arc(self):
95     """ Test 2. Movement of start point of a free arc
96     """
97     newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
98     self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
99     model.do()
100     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
101     self.checkPointCoordinates(self.myArc.startPoint(), newPosition)
102
103   def test_move_end_of_free_arc(self):
104     """ Test 3. Movement of end point of a free arc
105     """
106     newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
107     self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
108     model.do()
109     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
110     self.checkPointCoordinates(self.myArc.endPoint(), newPosition)
111
112   def test_move_free_arc(self):
113     """ Test 4. Movement of a free arc dragging the edge
114     """
115     newPosition = [100., 80.]
116     self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
117     model.do()
118     self.checkPointOnArc(newPosition)
119     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
120
121   def test_move_center_of_arc_fixed_center(self):
122     """ Test 5. Movement of center of the arc with fixed center (nothing should be changed)
123     """
124     self.fixPoint(self.myArc.center())
125
126     newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
127     self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
128     model.do()
129     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
130
131   def test_move_start_of_arc_fixed_center(self):
132     """ Test 6. Movement of start point of the arc with fixed center
133     """
134     self.fixPoint(self.myArc.center())
135
136     newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
137     self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
138     model.do()
139     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
140     self.checkPointCoordinates(self.myArc.startPoint(), newPosition)
141
142   def test_move_end_of_arc_fixed_center(self):
143     """ Test 7. Movement of end point of the arc with fixed center
144     """
145     self.fixPoint(self.myArc.center())
146
147     newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
148     self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
149     model.do()
150     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
151     self.checkPointCoordinates(self.myArc.endPoint(), newPosition)
152
153   def test_move_arc_fixed_center(self):
154     """ Test 8. Movement of the arc with fixed center dragging the edge
155     """
156     self.fixPoint(self.myArc.center())
157
158     newPosition = [100., 80.]
159     self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
160     model.do()
161     self.checkPointOnArc(newPosition)
162     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
163
164   def test_move_center_of_arc_fixed_start(self):
165     """ Test 9. Movement of center of the arc with fixed start point
166     """
167     self.fixPoint(self.myArc.startPoint())
168
169     newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
170     self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
171     model.do()
172     self.checkPointCoordinates(self.myArc.center(), newPosition)
173     self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
174
175   def test_move_start_of_arc_fixed_start(self):
176     """ Test 10. Movement of start point of the arc with fixed start point (nothing should be changed)
177     """
178     self.fixPoint(self.myArc.startPoint())
179
180     newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
181     self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
182     model.do()
183     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
184     self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
185     self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
186
187   def test_move_end_of_arc_fixed_start(self):
188     """ Test 11. Movement of end point of the arc with fixed start point
189     """
190     self.fixPoint(self.myArc.startPoint())
191
192     newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
193     self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
194     model.do()
195     self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
196     self.assertNotEqual(self.myArc.center().x(), self.myCenter[0])
197     self.assertNotEqual(self.myArc.center().y(), self.myCenter[1])
198
199   def test_move_arc_fixed_start(self):
200     """ Test 12. Movement of the arc with fixed start point dragging the edge
201     """
202     self.fixPoint(self.myArc.startPoint())
203
204     newPosition = [100., 80.]
205     self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
206     model.do()
207     self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
208     self.assertNotEqual(self.myArc.center().x(), self.myCenter[0])
209     self.assertNotEqual(self.myArc.center().y(), self.myCenter[1])
210
211   def test_move_center_of_arc_fixed_end(self):
212     """ Test 13. Movement of center of the arc with fixed end point
213     """
214     self.fixPoint(self.myArc.endPoint())
215
216     newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
217     self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
218     model.do()
219     self.checkPointCoordinates(self.myArc.center(), newPosition)
220     self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
221
222   def test_move_start_of_arc_fixed_end(self):
223     """ Test 14. Movement of start point of the arc with fixed end point
224     """
225     self.fixPoint(self.myArc.endPoint())
226
227     newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
228     self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
229     model.do()
230     self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
231     self.assertNotEqual(self.myArc.center().x(), self.myCenter[0])
232     self.assertNotEqual(self.myArc.center().y(), self.myCenter[1])
233
234   def test_move_end_of_arc_fixed_end(self):
235     """ Test 15. Movement of end point of the arc with fixed end point (nothing should be changed)
236     """
237     self.fixPoint(self.myArc.endPoint())
238
239     newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
240     self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
241     model.do()
242     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
243     self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
244     self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
245
246   def test_move_arc_fixed_end(self):
247     """ Test 16. Movement of the arc with fixed end point dragging the edge
248     """
249     self.fixPoint(self.myArc.endPoint())
250
251     newPosition = [100., 80.]
252     self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
253     model.do()
254     self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
255     self.assertNotEqual(self.myArc.center().x(), self.myCenter[0])
256     self.assertNotEqual(self.myArc.center().y(), self.myCenter[1])
257
258   def test_move_center_of_arc_fixed_radius(self):
259     """ Test 17. Movement of center of the arc with fixed radius
260     """
261     self.fixArcRadius()
262
263     newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
264     self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
265     model.do()
266     self.checkPointCoordinates(self.myArc.center(), newPosition)
267     self.checkArcRadius()
268
269   def test_move_start_of_arc_fixed_radius(self):
270     """ Test 18. Movement of start point of the arc with fixed radius
271     """
272     self.fixArcRadius()
273
274     newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
275     self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
276     model.do()
277     self.checkArcRadius()
278
279   def test_move_end_of_arc_fixed_radius(self):
280     """ Test 19. Movement of end point of the arc with fixed radius
281     """
282     self.fixArcRadius()
283
284     newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
285     self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
286     model.do()
287     self.checkArcRadius()
288
289   def test_move_arc_fixed_radius(self):
290     """ Test 20. Movement of the arc with fixed radius dragging the edge
291     """
292     self.fixArcRadius()
293
294     newPosition = [100., 80.]
295     self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
296     model.do()
297     self.checkArcRadius()
298
299   def test_move_center_of_fixed_arc(self):
300     """ Test 21. Movement of center of fully fixed arc (nothing should be changed)
301     """
302     self.fixArc()
303
304     newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
305     self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
306     model.do()
307     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
308     self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
309     self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
310
311   def test_move_start_of_fixed_arc(self):
312     """ Test 22. Movement of start point of fully fixed arc (nothing should be changed)
313     """
314     self.fixArc()
315
316     newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
317     self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
318     model.do()
319     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
320     self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
321     self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
322
323   def test_move_end_of_fixed_arc(self):
324     """ Test 23. Movement of end point of fully fixed arc (nothing should be changed)
325     """
326     self.fixArc()
327
328     newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
329     self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
330     model.do()
331     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
332     self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
333     self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
334
335   def test_move_fixed_arc(self):
336     """ Test 24. Movement of fully fixed arc (nothing should be changed)
337     """
338     self.fixArc()
339
340     newPosition = [100., 80.]
341     self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
342     model.do()
343     self.checkPointCoordinates(self.myArc.center(), self.myCenter)
344     self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
345     self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
346
347
348 if __name__ == "__main__":
349     test_program = unittest.main(exit=False)
350     assert test_program.result.wasSuccessful(), "Test failed"