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