1 ## Copyright (C) 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>
22 Test movement of the sketch arc of circle
26 from GeomDataAPI import geomDataAPI_Point2D
27 from salome.shaper import model
29 __updated__ = "2017-05-11"
31 class TestMoveArc(unittest.TestCase):
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)
45 model.assertArcValidity(self.myArc)
48 assert(model.checkPythonDump())
51 self.assertEqual(model.dof(self.mySketch), self.myDOF)
53 def checkPointCoordinates(self, thePoint, theCoordinates):
54 self.assertAlmostEqual(thePoint.x(), theCoordinates[0], 5)
55 self.assertAlmostEqual(thePoint.y(), theCoordinates[1], 5)
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)
62 def checkArcRadius(self):
63 radius = model.distancePointPoint(self.myArc.center(), self.myArc.startPoint())
64 self.assertAlmostEqual(radius, self.myRadius, 5)
66 def fixArcRadius(self):
68 self.mySketch.setRadius(self.myArc.results()[1], self.myRadius)
73 def fixPoint(self, thePoint):
74 self.mySketch.setFixed(thePoint)
80 self.mySketch.setFixed(self.myArc.results()[1])
86 def test_move_center_of_free_arc(self):
87 """ Test 1. Movement of center of a free arc
89 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
90 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
92 self.checkPointCoordinates(self.myArc.center(), newPosition)
94 def test_move_start_of_free_arc(self):
95 """ Test 2. Movement of start point of a free arc
97 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
98 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
100 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
101 self.checkPointCoordinates(self.myArc.startPoint(), newPosition)
103 def test_move_end_of_free_arc(self):
104 """ Test 3. Movement of end point of a free arc
106 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
107 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
109 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
110 self.checkPointCoordinates(self.myArc.endPoint(), newPosition)
112 def test_move_free_arc(self):
113 """ Test 4. Movement of a free arc dragging the edge
115 newPosition = [100., 80.]
116 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
118 self.checkPointOnArc(newPosition)
119 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
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)
124 self.fixPoint(self.myArc.center())
126 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
127 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
129 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
131 def test_move_start_of_arc_fixed_center(self):
132 """ Test 6. Movement of start point of the arc with fixed center
134 self.fixPoint(self.myArc.center())
136 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
137 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
139 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
140 self.checkPointCoordinates(self.myArc.startPoint(), newPosition)
142 def test_move_end_of_arc_fixed_center(self):
143 """ Test 7. Movement of end point of the arc with fixed center
145 self.fixPoint(self.myArc.center())
147 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
148 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
150 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
151 self.checkPointCoordinates(self.myArc.endPoint(), newPosition)
153 def test_move_arc_fixed_center(self):
154 """ Test 8. Movement of the arc with fixed center dragging the edge
156 self.fixPoint(self.myArc.center())
158 newPosition = [100., 80.]
159 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
161 self.checkPointOnArc(newPosition)
162 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
164 def test_move_center_of_arc_fixed_start(self):
165 """ Test 9. Movement of center of the arc with fixed start point
167 self.fixPoint(self.myArc.startPoint())
169 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
170 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
172 self.checkPointCoordinates(self.myArc.center(), newPosition)
173 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
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)
178 self.fixPoint(self.myArc.startPoint())
180 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
181 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
183 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
184 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
185 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
187 def test_move_end_of_arc_fixed_start(self):
188 """ Test 11. Movement of end point of the arc with fixed start point
190 self.fixPoint(self.myArc.startPoint())
192 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
193 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
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])
199 def test_move_arc_fixed_start(self):
200 """ Test 12. Movement of the arc with fixed start point dragging the edge
202 self.fixPoint(self.myArc.startPoint())
204 newPosition = [100., 80.]
205 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
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])
211 def test_move_center_of_arc_fixed_end(self):
212 """ Test 13. Movement of center of the arc with fixed end point
214 self.fixPoint(self.myArc.endPoint())
216 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
217 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
219 self.checkPointCoordinates(self.myArc.center(), newPosition)
220 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
222 def test_move_start_of_arc_fixed_end(self):
223 """ Test 14. Movement of start point of the arc with fixed end point
225 self.fixPoint(self.myArc.endPoint())
227 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
228 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
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])
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)
237 self.fixPoint(self.myArc.endPoint())
239 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
240 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
242 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
243 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
244 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
246 def test_move_arc_fixed_end(self):
247 """ Test 16. Movement of the arc with fixed end point dragging the edge
249 self.fixPoint(self.myArc.endPoint())
251 newPosition = [100., 80.]
252 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
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])
258 def test_move_center_of_arc_fixed_radius(self):
259 """ Test 17. Movement of center of the arc with fixed radius
263 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
264 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
266 self.checkPointCoordinates(self.myArc.center(), newPosition)
267 self.checkArcRadius()
269 def test_move_start_of_arc_fixed_radius(self):
270 """ Test 18. Movement of start point of the arc with fixed radius
274 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
275 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
277 self.checkArcRadius()
279 def test_move_end_of_arc_fixed_radius(self):
280 """ Test 19. Movement of end point of the arc with fixed radius
284 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
285 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
287 self.checkArcRadius()
289 def test_move_arc_fixed_radius(self):
290 """ Test 20. Movement of the arc with fixed radius dragging the edge
294 newPosition = [100., 80.]
295 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
297 self.checkArcRadius()
299 def test_move_center_of_fixed_arc(self):
300 """ Test 21. Movement of center of fully fixed arc (nothing should be changed)
304 newPosition = [self.myCenter[0] + 10., self.myCenter[1] - 15.]
305 self.mySketch.move(self.myArc.center(), newPosition[0], newPosition[1])
307 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
308 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
309 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
311 def test_move_start_of_fixed_arc(self):
312 """ Test 22. Movement of start point of fully fixed arc (nothing should be changed)
316 newPosition = [self.myStart[0] - 10., self.myStart[1] + 5.]
317 self.mySketch.move(self.myArc.startPoint(), newPosition[0], newPosition[1])
319 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
320 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
321 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
323 def test_move_end_of_fixed_arc(self):
324 """ Test 23. Movement of end point of fully fixed arc (nothing should be changed)
328 newPosition = [self.myEnd[0] + 10., self.myEnd[1] + 5.]
329 self.mySketch.move(self.myArc.endPoint(), newPosition[0], newPosition[1])
331 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
332 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
333 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
335 def test_move_fixed_arc(self):
336 """ Test 24. Movement of fully fixed arc (nothing should be changed)
340 newPosition = [100., 80.]
341 self.mySketch.move(self.myArc.defaultResult(), newPosition[0], newPosition[1])
343 self.checkPointCoordinates(self.myArc.center(), self.myCenter)
344 self.checkPointCoordinates(self.myArc.startPoint(), self.myStart)
345 self.checkPointCoordinates(self.myArc.endPoint(), self.myEnd)
348 if __name__ == "__main__":
349 test_program = unittest.main(exit=False)
350 assert test_program.result.wasSuccessful(), "Test failed"