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