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()
51 self.assertEqual(model.dof(self.mySketch), self.myDOF)
53 def checkPointCoordinates(self, thePoint, theCoordinates):
55 if issubclass(type(theCoordinates), GeomAPI_Pnt2d):
56 aCoord = [theCoordinates.x(), theCoordinates.y()]
58 aCoord = theCoordinates
59 DIGITS = 7 - math.floor(math.log10(math.hypot(aCoord[0], aCoord[1])))
60 self.assertAlmostEqual(thePoint.x(), aCoord[0], DIGITS)
61 self.assertAlmostEqual(thePoint.y(), aCoord[1], DIGITS)
63 def checkPointOnEllipse(self, theCoordinates, theEllipse):
64 point = GeomAPI_Pnt2d(theCoordinates.x(), theCoordinates.y())
65 firstFocus2d = GeomAPI_Pnt2d(theEllipse.firstFocus().x(), theEllipse.firstFocus().y())
66 distPF1 = model.distancePointPoint(firstFocus2d, point)
67 secondFocus2d = GeomAPI_Pnt2d(theEllipse.secondFocus().x(), theEllipse.secondFocus().y())
68 distPF2 = model.distancePointPoint(secondFocus2d, point)
69 self.assertAlmostEqual(distPF1 + distPF2, 2.0 * theEllipse.majorRadius().value(), 7 - math.floor(math.log10(theEllipse.majorRadius().value())))
71 def fixMajorRadius(self):
72 self.mySketch.setDistance(self.myEllipse.center(), self.myEllipse.majorAxisPositive(), self.myMajorRadius)
77 def fixMinorRadius(self):
78 self.mySketch.setDistance(self.myEllipse.center(), self.myEllipse.minorAxisPositive(), self.myMinorRadius)
83 def fixPoint(self, thePoint):
84 self.mySketch.setFixed(thePoint)
90 def test_move_center_free_ellipse(self):
91 """ Test 1. Movement of central point of a free ellipse
93 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
94 self.mySketch.move(self.myEllipse.center(), newPosition[0], newPosition[1])
96 self.checkPointCoordinates(self.myEllipse.center(), newPosition)
97 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
98 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
100 def test_move_free_ellipse(self):
101 """ Test 2. Movement of a free ellipse dragging the edge
103 newPosition = GeomAPI_Pnt2d(120., 90.)
104 self.mySketch.move(self.myEllipse.defaultResult(), newPosition.x(), newPosition.y())
106 self.checkPointCoordinates(self.myEllipse.center(), self.myCenter)
107 self.checkPointOnEllipse(newPosition, self.myEllipse)
108 self.assertNotEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
109 self.assertNotEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
111 def test_move_center_ellipse_fixed_major_radius(self):
112 """ Test 3. Movement of central point of ellipse with fixed major radius
114 self.fixMajorRadius()
116 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
117 self.mySketch.move(self.myEllipse.center(), newPosition[0], newPosition[1])
119 self.checkPointCoordinates(self.myEllipse.center(), newPosition)
120 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
121 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
123 def test_move_ellipse_fixed_major_radius(self):
124 """ Test 4. Movement of ellipse with fixed major radius
126 self.fixMajorRadius()
128 newPosition = GeomAPI_Pnt2d(80., 80.)
129 self.mySketch.move(self.myEllipse.defaultResult(), newPosition.x(), newPosition.y())
131 self.checkPointOnEllipse(newPosition, self.myEllipse)
132 self.assertNotEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
133 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
135 def test_move_center_ellipse_fixed_minor_radius(self):
136 """ Test 5. Movement of central point of ellipse with fixed minor radius
138 self.fixMinorRadius()
140 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
141 self.mySketch.move(self.myEllipse.center(), newPosition[0], newPosition[1])
143 self.checkPointCoordinates(self.myEllipse.center(), newPosition)
144 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
145 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
147 def test_move_ellipse_fixed_minor_radius(self):
148 """ Test 6. Movement of ellipse with fixed minor radius
150 self.fixMinorRadius()
152 newPosition = GeomAPI_Pnt2d(120., 90.)
153 self.mySketch.move(self.myEllipse.defaultResult(), newPosition.x(), newPosition.y())
155 self.checkPointOnEllipse(newPosition, self.myEllipse)
156 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
157 self.assertNotEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
159 def test_move_center_ellipse_fixed_center(self):
160 """ Test 7. Movement of central point of ellipse with fixed center (nothing should be changed)
162 self.fixPoint(self.myEllipse.center())
164 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
165 self.mySketch.move(self.myEllipse.center(), newPosition[0], newPosition[1])
167 self.checkPointCoordinates(self.myEllipse.center(), self.myCenter)
168 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
169 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
171 def test_move_ellipse_fixed_center(self):
172 """ Test 8. Movement of ellipse with fixed center
174 self.fixPoint(self.myEllipse.center())
176 newPosition = GeomAPI_Pnt2d(120., 90.)
177 self.mySketch.move(self.myEllipse.defaultResult(), newPosition.x(), newPosition.y())
179 self.checkPointOnEllipse(newPosition, self.myEllipse)
180 self.assertNotEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
181 self.assertNotEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
183 def test_move_center_ellipse_fixed_focus(self):
184 """ Test 9. Movement of central point of ellipse with fixed focus
186 self.fixPoint(self.myEllipse.firstFocus())
188 newPosition = GeomAPI_Pnt2d(self.myCenter[0] + 20., self.myCenter[1] + 10.)
189 self.mySketch.move(self.myEllipse.center(), newPosition.x(), newPosition.y())
191 self.checkPointCoordinates(self.myEllipse.center(), newPosition)
192 self.checkPointCoordinates(self.myEllipse.firstFocus(), self.myFocus)
193 self.assertNotEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
194 self.assertNotEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
196 def test_move_focus_ellipse_fixed_focus(self):
197 """ Test 10. Movement of a focus point of ellipse with fixed focus (nothing should be changed)
199 self.fixPoint(self.myEllipse.firstFocus())
201 newPosition = GeomAPI_Pnt2d(self.myFocus[0] + 10., self.myFocus[1] + 10.)
202 self.mySketch.move(self.myEllipse.firstFocus(), newPosition.x(), newPosition.y())
204 self.checkPointCoordinates(self.myEllipse.firstFocus(), self.myFocus)
205 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
206 self.assertAlmostEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
208 def test_move_ellipse_fixed_focus(self):
209 """ Test 11. Movement of ellipse with fixed focus
211 self.fixPoint(self.myEllipse.firstFocus())
213 newPosition = GeomAPI_Pnt2d(80., 90.)
214 self.mySketch.move(self.myEllipse.defaultResult(), newPosition.x(), newPosition.y())
216 self.checkPointOnEllipse(newPosition, self.myEllipse)
217 self.checkPointCoordinates(self.myEllipse.firstFocus(), self.myFocus)
218 self.assertNotEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
219 self.assertNotEqual(self.myEllipse.majorRadius().value(), self.myMajorRadius)
221 def test_move_fixed_ellipse(self):
222 """ Test 12. Trying to move fully fixed ellipse
224 self.mySketch.setFixed(self.myEllipse.results()[-1])
229 newPosition = [120., 90.]
230 self.mySketch.move(self.myEllipse.defaultResult(), newPosition[0], newPosition[1])
232 self.checkPointCoordinates(self.myEllipse.center(), self.myCenter)
233 self.checkPointCoordinates(self.myEllipse.firstFocus(), self.myFocus)
234 self.assertAlmostEqual(self.myEllipse.minorRadius().value(), self.myMinorRadius)
237 if __name__ == "__main__":
238 test_program = unittest.main(exit=False)
239 assert test_program.result.wasSuccessful(), "Test failed"
240 assert(model.checkPythonDump())