1 # Copyright (C) 2017-2020 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 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.floor(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 self.assertAlmostEqual(distPF1 + distPF2, 2.0 * theEllipticArc.majorRadius().value(), 7 - math.floor(math.log10(theEllipticArc.majorRadius().value())))
76 def fixMajorRadius(self):
77 self.mySketch.setDistance(self.myEllipticArc.center(), self.myEllipticArc.majorAxisPositive(), self.myMajorRadius)
82 def fixMinorRadius(self):
83 self.mySketch.setDistance(self.myEllipticArc.center(), self.myEllipticArc.minorAxisPositive(), self.myMinorRadius)
88 def fixPoint(self, thePoint):
89 self.mySketch.setFixed(thePoint)
95 def test_move_center_free_ellipse(self):
96 """ Test 1. Movement of central point of a free elliptic arc
98 newPosition = [self.myCenter.x() + 20., self.myCenter.y() + 10.]
99 self.mySketch.move(self.myEllipticArc.center(), newPosition[0], newPosition[1])
101 self.checkPointCoordinates(self.myEllipticArc.center(), newPosition)
103 def test_move_free_ellipse(self):
104 """ Test 2. Movement of a free ellipse dragging the edge
106 newPosition = GeomAPI_Pnt2d(110., 80.)
107 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition.x(), newPosition.y())
109 self.checkPointCoordinates(self.myEllipticArc.center(), self.myCenter)
110 self.checkPointOnEllipse(newPosition, self.myEllipticArc)
111 self.assertNotEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
112 self.assertNotEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
114 def test_move_center_ellipse_fixed_major_radius(self):
115 """ Test 3. Movement of central point of ellipse with fixed major radius
117 self.fixMajorRadius()
119 newPosition = [self.myCenter.x() + 20., self.myCenter.y() + 10.]
120 self.mySketch.move(self.myEllipticArc.center(), newPosition[0], newPosition[1])
122 self.checkPointCoordinates(self.myEllipticArc.center(), newPosition)
123 self.assertAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
125 def test_move_ellipse_fixed_major_radius(self):
126 """ Test 4. Movement of ellipse with fixed major radius
128 self.fixMajorRadius()
130 newPosition = GeomAPI_Pnt2d(80., 80.)
131 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition.x(), newPosition.y())
133 self.checkPointOnEllipse(newPosition, self.myEllipticArc)
134 self.assertNotEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
135 self.assertAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
137 def test_move_center_ellipse_fixed_minor_radius(self):
138 """ Test 5. Movement of central point of ellipse with fixed minor radius
140 self.fixMinorRadius()
142 newPosition = [self.myCenter.x() + 20., self.myCenter.y() + 10.]
143 self.mySketch.move(self.myEllipticArc.center(), newPosition[0], newPosition[1])
145 self.checkPointCoordinates(self.myEllipticArc.center(), newPosition)
146 self.assertAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
148 def test_move_ellipse_fixed_minor_radius(self):
149 """ Test 6. Movement of ellipse with fixed minor radius
151 self.fixMinorRadius()
153 newPosition = GeomAPI_Pnt2d(110., 80.)
154 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition.x(), newPosition.y())
156 self.checkPointOnEllipse(newPosition, self.myEllipticArc)
157 self.assertAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
158 self.assertNotEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
160 def test_move_center_ellipse_fixed_center(self):
161 """ Test 7. Movement of central point of ellipse with fixed center (nothing should be changed)
163 self.fixPoint(self.myEllipticArc.center())
165 newPosition = [self.myCenter.x() + 20., self.myCenter.y() + 10.]
166 self.mySketch.move(self.myEllipticArc.center(), newPosition[0], newPosition[1])
168 self.checkPointCoordinates(self.myEllipticArc.center(), self.myCenter)
169 self.assertAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
170 self.assertAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
172 def test_move_ellipse_fixed_center(self):
173 """ Test 8. Movement of ellipse with fixed center
175 self.fixPoint(self.myEllipticArc.center())
177 newPosition = GeomAPI_Pnt2d(110., 80.)
178 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition.x(), newPosition.y())
180 self.checkPointOnEllipse(newPosition, self.myEllipticArc)
181 self.assertNotEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
182 self.assertNotEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
184 def test_move_center_ellipse_fixed_focus(self):
185 """ Test 9. Movement of central point of ellipse with fixed focus
187 focus = [self.myEllipticArc.firstFocus().x(), self.myEllipticArc.firstFocus().y()]
188 self.fixPoint(self.myEllipticArc.firstFocus())
190 newPosition = GeomAPI_Pnt2d(self.myCenter.x() + 20., self.myCenter.y() + 10.)
191 self.mySketch.move(self.myEllipticArc.center(), newPosition.x(), newPosition.y())
193 self.checkPointCoordinates(self.myEllipticArc.center(), newPosition)
194 self.checkPointCoordinates(self.myEllipticArc.firstFocus(), focus)
195 self.assertNotEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
196 self.assertNotEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
198 def test_move_focus_ellipse_fixed_focus(self):
199 """ Test 10. Movement of a focus point of ellipse with fixed focus (nothing should be changed)
201 focus = [self.myEllipticArc.firstFocus().x(), self.myEllipticArc.firstFocus().y()]
202 self.fixPoint(self.myEllipticArc.firstFocus())
204 newPosition = GeomAPI_Pnt2d(focus[0] + 10., focus[1] + 10.)
205 self.mySketch.move(self.myEllipticArc.firstFocus(), newPosition.x(), newPosition.y())
207 self.checkPointCoordinates(self.myEllipticArc.firstFocus(), focus)
208 self.assertAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
209 self.assertAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
211 def test_move_ellipse_fixed_focus(self):
212 """ Test 11. Movement of ellipse with fixed focus
214 focus = [self.myEllipticArc.firstFocus().x(), self.myEllipticArc.firstFocus().y()]
215 self.fixPoint(self.myEllipticArc.firstFocus())
217 newPosition = GeomAPI_Pnt2d(80., 90.)
218 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition.x(), newPosition.y())
220 self.checkPointOnEllipse(newPosition, self.myEllipticArc)
221 self.checkPointCoordinates(self.myEllipticArc.firstFocus(), focus)
222 self.assertNotEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
223 self.assertNotEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
225 def test_move_fixed_ellipse(self):
226 """ Test 12. Trying to move fully fixed ellipse
228 self.mySketch.setFixed(self.myEllipticArc.results()[-1])
233 newPosition = [110., 80.]
234 self.mySketch.move(self.myEllipticArc.defaultResult(), newPosition[0], newPosition[1])
236 self.checkPointCoordinates(self.myEllipticArc.center(), self.myCenter)
237 self.checkPointCoordinates(self.myEllipticArc.majorAxisPositive(), self.myAxisPoint)
238 self.checkPointCoordinates(self.myEllipticArc.startPoint(), self.myStartPoint)
239 self.checkPointCoordinates(self.myEllipticArc.endPoint(), self.myEndPoint)
240 self.assertAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
241 self.assertAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
243 def test_move_start_point_free_ellipse(self):
244 """ Test 13. Trying to move start point of elliptic arc
246 newPosition = [self.myStartPoint.x() + 10., self.myStartPoint.y() + 10.]
247 self.mySketch.move(self.myEllipticArc.startPoint(), newPosition[0], newPosition[1])
249 self.checkPointCoordinates(self.myEllipticArc.startPoint(), newPosition)
251 def test_move_end_point_free_ellipse(self):
252 """ Test 14. Trying to move end point of elliptic arc
254 newPosition = [self.myEndPoint.x() - 10., self.myEndPoint.y() + 10.]
255 self.mySketch.move(self.myEllipticArc.endPoint(), newPosition[0], newPosition[1])
257 self.checkPointCoordinates(self.myEllipticArc.endPoint(), newPosition)
259 def test_move_start_point_fixed_ellipse(self):
260 """ Test 15. Trying to move start point of fully fixed ellipse
262 self.mySketch.setFixed(self.myEllipticArc.results()[-1])
267 newPosition = [self.myStartPoint.x() + 10., self.myStartPoint.y() + 10.]
268 self.mySketch.move(self.myEllipticArc.startPoint(), newPosition[0], newPosition[1])
270 self.checkPointCoordinates(self.myEllipticArc.center(), self.myCenter)
271 self.checkPointCoordinates(self.myEllipticArc.majorAxisPositive(), self.myAxisPoint)
272 self.checkPointCoordinates(self.myEllipticArc.startPoint(), self.myStartPoint)
273 self.checkPointCoordinates(self.myEllipticArc.endPoint(), self.myEndPoint)
274 self.assertAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
275 self.assertAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
277 def test_move_end_point_fixed_ellipse(self):
278 """ Test 16. Trying to move end point of fully fixed ellipse
280 self.mySketch.setFixed(self.myEllipticArc.results()[-1])
285 newPosition = [self.myEndPoint.x() - 10., self.myEndPoint.y() + 10.]
286 self.mySketch.move(self.myEllipticArc.endPoint(), newPosition[0], newPosition[1])
288 self.checkPointCoordinates(self.myEllipticArc.center(), self.myCenter)
289 self.checkPointCoordinates(self.myEllipticArc.majorAxisPositive(), self.myAxisPoint)
290 self.checkPointCoordinates(self.myEllipticArc.startPoint(), self.myStartPoint)
291 self.checkPointCoordinates(self.myEllipticArc.endPoint(), self.myEndPoint)
292 self.assertAlmostEqual(self.myEllipticArc.majorRadius().value(), self.myMajorRadius)
293 self.assertAlmostEqual(self.myEllipticArc.minorRadius().value(), self.myMinorRadius)
296 if __name__ == "__main__":
297 test_program = unittest.main(exit=False)
298 assert test_program.result.wasSuccessful(), "Test failed"