1 # Copyright (C) 2017-2024 CEA, EDF
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 ellipse
26 from GeomAPI import GeomAPI_Pnt2d
27 from SketchAPI import *
28 from salome.shaper import model
30 __updated__ = "2019-10-15"
32 class TestMoveEllipticArc(unittest.TestCase):
35 self.myDocument = model.moduleDocument()
36 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
37 self.myCenter = GeomAPI_Pnt2d(70., 50.)
38 self.myAxisPoint = GeomAPI_Pnt2d(100., 70.)
39 self.myStartPoint = GeomAPI_Pnt2d(75., 75.)
40 self.myEndPoint = GeomAPI_Pnt2d(45., 55.)
41 macroEllipticArc = self.mySketch.addEllipticArc(self.myCenter, self.myAxisPoint, self.myStartPoint, self.myEndPoint, False)
45 self.myEllipticArc = SketchAPI_EllipticArc(model.lastSubFeature(self.mySketch, "SketchEllipticArc"))
46 self.myMajorRadius = self.myEllipticArc.majorRadius().value()
47 self.myMinorRadius = self.myEllipticArc.minorRadius().value()
51 self.checkPointOnEllipse(self.myEllipticArc.startPoint(), self.myEllipticArc)
52 self.checkPointOnEllipse(self.myEllipticArc.endPoint(), self.myEllipticArc)
56 self.assertEqual(model.dof(self.mySketch), self.myDOF)
58 def checkPointCoordinates(self, thePoint, theCoordinates):
60 if issubclass(type(theCoordinates), GeomAPI_Pnt2d):
61 aCoord = [theCoordinates.x(), theCoordinates.y()]
63 aCoord = theCoordinates
64 DIGITS = 7 - math.ceil(math.log10(math.hypot(aCoord[0], aCoord[1])))
65 self.assertAlmostEqual(thePoint.x(), aCoord[0], DIGITS)
66 self.assertAlmostEqual(thePoint.y(), aCoord[1], DIGITS)
68 def checkPointOnEllipse(self, theCoordinates, theEllipticArc):
69 point = GeomAPI_Pnt2d(theCoordinates.x(), theCoordinates.y())
70 firstFocus2d = GeomAPI_Pnt2d(theEllipticArc.firstFocus().x(), theEllipticArc.firstFocus().y())
71 distPF1 = model.distancePointPoint(firstFocus2d, point)
72 secondFocus2d = GeomAPI_Pnt2d(theEllipticArc.secondFocus().x(), theEllipticArc.secondFocus().y())
73 distPF2 = model.distancePointPoint(secondFocus2d, point)
74 DIGITS = 7 - math.ceil(math.log10(theEllipticArc.majorRadius().value()))
75 self.assertAlmostEqual(distPF1 + distPF2, 2.0 * theEllipticArc.majorRadius().value(), DIGITS)
77 def checkAlmostEqual(self, theValue1, theValue2):
78 DIGITS = 7 - math.ceil(math.log10(theValue1))
79 self.assertAlmostEqual(theValue1, theValue2, DIGITS)
81 def fixMajorRadius(self):
82 self.mySketch.setDistance(self.myEllipticArc.center(), self.myEllipticArc.majorAxisPositive(), self.myMajorRadius)
87 def fixMinorRadius(self):
88 self.mySketch.setDistance(self.myEllipticArc.center(), self.myEllipticArc.minorAxisPositive(), self.myMinorRadius)
93 def fixPoint(self, thePoint):
94 self.mySketch.setFixed(thePoint)
100 def test_move_center_free_ellipse(self):
101 """ Test 1. Movement of central point of a free elliptic arc
103 newPosition = [self.myCenter.x() + 20., self.myCenter.y() + 10.]
104 self.mySketch.move(self.myEllipticArc.center(), newPosition[0], newPosition[1])
106 self.checkPointCoordinates(self.myEllipticArc.center(), newPosition)
108 def test_move_free_ellipse(self):
109 """ Test 2. Movement of a free ellipse dragging the edge
111 newPosition = GeomAPI_Pnt2d(110., 80.)
112 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition.x(), newPosition.y())
114 self.checkPointCoordinates(self.myEllipticArc.center(), self.myCenter)
115 self.checkPointOnEllipse(newPosition, self.myEllipticArc)
116 self.assertNotEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
117 self.assertNotEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
119 def test_move_center_ellipse_fixed_major_radius(self):
120 """ Test 3. Movement of central point of ellipse with fixed major radius
122 self.fixMajorRadius()
124 newPosition = [self.myCenter.x() + 20., self.myCenter.y() + 10.]
125 self.mySketch.move(self.myEllipticArc.center(), newPosition[0], newPosition[1])
127 self.checkPointCoordinates(self.myEllipticArc.center(), newPosition)
128 self.checkAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
130 def test_move_ellipse_fixed_major_radius(self):
131 """ Test 4. Movement of ellipse with fixed major radius
133 self.fixMajorRadius()
135 newPosition = GeomAPI_Pnt2d(80., 80.)
136 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition.x(), newPosition.y())
138 self.checkPointOnEllipse(newPosition, self.myEllipticArc)
139 self.assertNotEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
140 self.checkAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
142 def test_move_center_ellipse_fixed_minor_radius(self):
143 """ Test 5. Movement of central point of ellipse with fixed minor radius
145 self.fixMinorRadius()
147 newPosition = [self.myCenter.x() + 20., self.myCenter.y() + 10.]
148 self.mySketch.move(self.myEllipticArc.center(), newPosition[0], newPosition[1])
150 self.checkPointCoordinates(self.myEllipticArc.center(), newPosition)
151 self.checkAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
153 def test_move_ellipse_fixed_minor_radius(self):
154 """ Test 6. Movement of ellipse with fixed minor radius
156 self.fixMinorRadius()
158 newPosition = GeomAPI_Pnt2d(110., 80.)
159 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition.x(), newPosition.y())
161 self.checkPointOnEllipse(newPosition, self.myEllipticArc)
162 self.checkAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
163 self.assertNotEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
165 def test_move_center_ellipse_fixed_center(self):
166 """ Test 7. Movement of central point of ellipse with fixed center (nothing should be changed)
168 self.fixPoint(self.myEllipticArc.center())
170 newPosition = [self.myCenter.x() + 20., self.myCenter.y() + 10.]
171 self.mySketch.move(self.myEllipticArc.center(), newPosition[0], newPosition[1])
173 self.checkPointCoordinates(self.myEllipticArc.center(), self.myCenter)
174 self.checkAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
175 self.checkAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
177 def test_move_ellipse_fixed_center(self):
178 """ Test 8. Movement of ellipse with fixed center
180 self.fixPoint(self.myEllipticArc.center())
182 newPosition = GeomAPI_Pnt2d(110., 80.)
183 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition.x(), newPosition.y())
185 self.checkPointOnEllipse(newPosition, self.myEllipticArc)
186 self.assertNotEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
187 self.assertNotEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
189 def test_move_center_ellipse_fixed_focus(self):
190 """ Test 9. Movement of central point of ellipse with fixed focus
192 focus = [self.myEllipticArc.firstFocus().x(), self.myEllipticArc.firstFocus().y()]
193 self.fixPoint(self.myEllipticArc.firstFocus())
195 newPosition = GeomAPI_Pnt2d(self.myCenter.x() + 20., self.myCenter.y() + 10.)
196 self.mySketch.move(self.myEllipticArc.center(), newPosition.x(), newPosition.y())
198 self.checkPointCoordinates(self.myEllipticArc.center(), newPosition)
199 self.checkPointCoordinates(self.myEllipticArc.firstFocus(), focus)
200 self.assertNotEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
201 self.assertNotEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
203 def test_move_focus_ellipse_fixed_focus(self):
204 """ Test 10. Movement of a focus point of ellipse with fixed focus (nothing should be changed)
206 focus = [self.myEllipticArc.firstFocus().x(), self.myEllipticArc.firstFocus().y()]
207 self.fixPoint(self.myEllipticArc.firstFocus())
209 newPosition = GeomAPI_Pnt2d(focus[0] + 10., focus[1] + 10.)
210 self.mySketch.move(self.myEllipticArc.firstFocus(), newPosition.x(), newPosition.y())
212 self.checkPointCoordinates(self.myEllipticArc.firstFocus(), focus)
213 self.checkAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
214 self.checkAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
216 def test_move_ellipse_fixed_focus(self):
217 """ Test 11. Movement of ellipse with fixed focus
219 focus = [self.myEllipticArc.firstFocus().x(), self.myEllipticArc.firstFocus().y()]
220 self.fixPoint(self.myEllipticArc.firstFocus())
222 newPosition = GeomAPI_Pnt2d(80., 90.)
223 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition.x(), newPosition.y())
225 self.checkPointOnEllipse(newPosition, self.myEllipticArc)
226 self.checkPointCoordinates(self.myEllipticArc.firstFocus(), focus)
227 self.assertNotEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
228 self.assertNotEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
230 def test_move_fixed_ellipse(self):
231 """ Test 12. Trying to move fully fixed ellipse
233 self.mySketch.setFixed(self.myEllipticArc.results()[-1])
238 newPosition = [110., 80.]
239 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition[0], newPosition[1])
241 self.checkPointCoordinates(self.myEllipticArc.center(), self.myCenter)
242 self.checkPointCoordinates(self.myEllipticArc.majorAxisPositive(), self.myAxisPoint)
243 self.checkPointCoordinates(self.myEllipticArc.startPoint(), self.myStartPoint)
244 self.checkPointCoordinates(self.myEllipticArc.endPoint(), self.myEndPoint)
245 self.checkAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
246 self.checkAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
248 def test_move_start_point_free_ellipse(self):
249 """ Test 13. Trying to move start point of elliptic arc
251 newPosition = [self.myStartPoint.x() + 10., self.myStartPoint.y() + 10.]
252 self.mySketch.move(self.myEllipticArc.startPoint(), newPosition[0], newPosition[1])
254 self.checkPointCoordinates(self.myEllipticArc.startPoint(), newPosition)
256 def test_move_end_point_free_ellipse(self):
257 """ Test 14. Trying to move end point of elliptic arc
259 newPosition = [self.myEndPoint.x() - 10., self.myEndPoint.y() + 10.]
260 self.mySketch.move(self.myEllipticArc.endPoint(), newPosition[0], newPosition[1])
262 self.checkPointCoordinates(self.myEllipticArc.endPoint(), newPosition)
264 def test_move_start_point_fixed_ellipse(self):
265 """ Test 15. Trying to move start point of fully fixed ellipse
267 self.mySketch.setFixed(self.myEllipticArc.results()[-1])
272 newPosition = [self.myStartPoint.x() + 10., self.myStartPoint.y() + 10.]
273 self.mySketch.move(self.myEllipticArc.startPoint(), newPosition[0], newPosition[1])
275 self.checkPointCoordinates(self.myEllipticArc.center(), self.myCenter)
276 self.checkPointCoordinates(self.myEllipticArc.majorAxisPositive(), self.myAxisPoint)
277 self.checkPointCoordinates(self.myEllipticArc.startPoint(), self.myStartPoint)
278 self.checkPointCoordinates(self.myEllipticArc.endPoint(), self.myEndPoint)
279 self.checkAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
280 self.checkAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
282 def test_move_end_point_fixed_ellipse(self):
283 """ Test 16. Trying to move end point of fully fixed ellipse
285 self.mySketch.setFixed(self.myEllipticArc.results()[-1])
290 newPosition = [self.myEndPoint.x() - 10., self.myEndPoint.y() + 10.]
291 self.mySketch.move(self.myEllipticArc.endPoint(), newPosition[0], newPosition[1])
293 self.checkPointCoordinates(self.myEllipticArc.center(), self.myCenter)
294 self.checkPointCoordinates(self.myEllipticArc.majorAxisPositive(), self.myAxisPoint)
295 self.checkPointCoordinates(self.myEllipticArc.startPoint(), self.myStartPoint)
296 self.checkPointCoordinates(self.myEllipticArc.endPoint(), self.myEndPoint)
297 self.checkAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
298 self.checkAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
301 if __name__ == "__main__":
302 test_program = unittest.main(exit=False)
303 assert test_program.result.wasSuccessful(), "Test failed"