1 # Copyright (C) 2017-2019 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 GeomDataAPI import geomDataAPI_Point2D
28 from salome.shaper import model
30 __updated__ = "2019-09-12"
32 class TestMoveEllipse(unittest.TestCase):
35 self.myDocument = model.moduleDocument()
36 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
37 self.myCenter = [70., 50.]
38 self.myFocus = [100., 70.]
39 self.myMinorRadius = 20.
40 self.myEllipse = self.mySketch.addEllipse(self.myCenter[0], self.myCenter[1], self.myFocus[0], self.myFocus[1], self.myMinorRadius)
44 self.myMajorRadius = self.myEllipse.majorRadius().value()
45 self.NB_DIGITS_RADIUS = 7 - math.floor(math.log10(self.myMinorRadius))
52 self.assertEqual(model.dof(self.mySketch), self.myDOF)
54 def checkPointCoordinates(self, thePoint, theCoordinates):
56 if issubclass(type(theCoordinates), GeomAPI_Pnt2d):
57 aCoord = [theCoordinates.x(), theCoordinates.y()]
59 aCoord = theCoordinates
60 DIGITS = 7 - math.floor(math.log10(math.hypot(aCoord[0], aCoord[1])))
61 self.assertAlmostEqual(thePoint.x(), aCoord[0], DIGITS)
62 self.assertAlmostEqual(thePoint.y(), aCoord[1], DIGITS)
64 def checkPointOnEllipse(self, theCoordinates, theEllipse):
65 point = GeomAPI_Pnt2d(theCoordinates.x(), theCoordinates.y())
66 firstFocus2d = GeomAPI_Pnt2d(theEllipse.firstFocus().x(), theEllipse.firstFocus().y())
67 distPF1 = model.distancePointPoint(firstFocus2d, point)
68 secondFocus2d = GeomAPI_Pnt2d(theEllipse.secondFocus().x(), theEllipse.secondFocus().y())
69 distPF2 = model.distancePointPoint(secondFocus2d, point)
70 self.assertAlmostEqual(distPF1 + distPF2, 2.0 * theEllipse.majorRadius().value(), 7 - math.floor(math.log10(2.0 * theEllipse.majorRadius().value())))
72 def fixMajorRadius(self):
73 self.mySketch.setDistance(self.myEllipse.center(), self.myEllipse.majorAxisPositive(), self.myMajorRadius)
78 def fixMinorRadius(self):
79 self.mySketch.setDistance(self.myEllipse.center(), self.myEllipse.minorAxisPositive(), self.myMinorRadius)
84 def fixPoint(self, thePoint):
85 self.mySketch.setFixed(thePoint)
91 def test_move_center_free_ellipse(self):
92 """ Test 1. Movement of central point of a free ellipse
94 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
95 self.mySketch.move(self.myEllipse.center(), newPosition[0], newPosition[1])
97 self.checkPointCoordinates(self.myEllipse.center(), newPosition)
98 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius, self.NB_DIGITS_RADIUS)
99 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius, self.NB_DIGITS_RADIUS)
101 def test_move_free_ellipse(self):
102 """ Test 2. Movement of a free ellipse dragging the edge
104 newPosition = GeomAPI_Pnt2d(120., 90.)
105 self.mySketch.move(self.myEllipse.defaultResult(), newPosition.x(), newPosition.y())
107 self.checkPointCoordinates(self.myEllipse.center(), self.myCenter)
108 self.checkPointOnEllipse(newPosition, self.myEllipse)
109 self.assertNotEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
110 self.assertNotEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
112 def test_move_center_ellipse_fixed_major_radius(self):
113 """ Test 3. Movement of central point of ellipse with fixed major radius
115 self.fixMajorRadius()
117 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
118 self.mySketch.move(self.myEllipse.center(), newPosition[0], newPosition[1])
120 self.checkPointCoordinates(self.myEllipse.center(), newPosition)
121 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius, self.NB_DIGITS_RADIUS)
122 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius, self.NB_DIGITS_RADIUS)
124 def test_move_ellipse_fixed_major_radius(self):
125 """ Test 4. Movement of ellipse with fixed major radius
127 self.fixMajorRadius()
129 newPosition = GeomAPI_Pnt2d(80., 80.)
130 self.mySketch.move(self.myEllipse.defaultResult(), newPosition.x(), newPosition.y())
132 self.checkPointOnEllipse(newPosition, self.myEllipse)
133 self.assertNotEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
134 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius, self.NB_DIGITS_RADIUS)
136 def test_move_center_ellipse_fixed_minor_radius(self):
137 """ Test 5. Movement of central point of ellipse with fixed minor radius
139 self.fixMinorRadius()
141 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
142 self.mySketch.move(self.myEllipse.center(), newPosition[0], newPosition[1])
144 self.checkPointCoordinates(self.myEllipse.center(), newPosition)
145 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius, self.NB_DIGITS_RADIUS)
146 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius, self.NB_DIGITS_RADIUS)
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(120., 90.)
154 self.mySketch.move(self.myEllipse.defaultResult(), newPosition.x(), newPosition.y())
156 self.checkPointOnEllipse(newPosition, self.myEllipse)
157 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius, self.NB_DIGITS_RADIUS)
158 self.assertNotEqual(self.myEllipse.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.myEllipse.center())
165 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
166 self.mySketch.move(self.myEllipse.center(), newPosition[0], newPosition[1])
168 self.checkPointCoordinates(self.myEllipse.center(), self.myCenter)
169 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius, self.NB_DIGITS_RADIUS)
170 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius, self.NB_DIGITS_RADIUS)
172 def test_move_ellipse_fixed_center(self):
173 """ Test 8. Movement of ellipse with fixed center
175 self.fixPoint(self.myEllipse.center())
177 newPosition = GeomAPI_Pnt2d(120., 90.)
178 self.mySketch.move(self.myEllipse.defaultResult(), newPosition.x(), newPosition.y())
180 self.checkPointOnEllipse(newPosition, self.myEllipse)
181 self.assertNotEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
182 self.assertNotEqual(self.myEllipse.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 self.fixPoint(self.myEllipse.firstFocus())
189 newPosition = GeomAPI_Pnt2d(self.myCenter[0] + 20., self.myCenter[1] + 10.)
190 self.mySketch.move(self.myEllipse.center(), newPosition.x(), newPosition.y())
192 self.checkPointCoordinates(self.myEllipse.center(), newPosition)
193 self.checkPointCoordinates(self.myEllipse.firstFocus(), self.myFocus)
194 self.assertNotEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
195 self.assertNotEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
197 def test_move_focus_ellipse_fixed_focus(self):
198 """ Test 10. Movement of a focus point of ellipse with fixed focus (nothing should be changed)
200 self.fixPoint(self.myEllipse.firstFocus())
202 newPosition = GeomAPI_Pnt2d(self.myFocus[0] + 10., self.myFocus[1] + 10.)
203 self.mySketch.move(self.myEllipse.firstFocus(), newPosition.x(), newPosition.y())
205 self.checkPointCoordinates(self.myEllipse.firstFocus(), self.myFocus)
206 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius, self.NB_DIGITS_RADIUS)
207 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius, self.NB_DIGITS_RADIUS)
209 def test_move_ellipse_fixed_focus(self):
210 """ Test 11. Movement of ellipse with fixed focus
212 self.fixPoint(self.myEllipse.firstFocus())
214 newPosition = GeomAPI_Pnt2d(80., 90.)
215 self.mySketch.move(self.myEllipse.defaultResult(), newPosition.x(), newPosition.y())
217 self.checkPointOnEllipse(newPosition, self.myEllipse)
218 self.checkPointCoordinates(self.myEllipse.firstFocus(), self.myFocus)
219 self.assertNotEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
220 self.assertNotEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
222 def test_move_fixed_ellipse(self):
223 """ Test 12. Trying to move fully fixed ellipse
225 self.mySketch.setFixed(self.myEllipse.results()[-1])
230 newPosition = [120., 90.]
231 self.mySketch.move(self.myEllipse.defaultResult(), newPosition[0], newPosition[1])
233 self.checkPointCoordinates(self.myEllipse.center(), self.myCenter)
234 self.checkPointCoordinates(self.myEllipse.firstFocus(), self.myFocus)
235 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius, self.NB_DIGITS_RADIUS)
238 if __name__ == "__main__":
239 test_program = unittest.main(exit=False)
240 assert test_program.result.wasSuccessful(), "Test failed"