1 # Copyright (C) 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 creation of ellipse by external feature
25 from salome.shaper import model
28 from SketchAPI import *
30 __updated__ = "2019-09-12"
33 CENTER_POINT = GeomAPI_Pnt2d(50., 50.)
34 FOCUS_POINT = GeomAPI_Pnt2d(70., 60.)
37 class TestEllipse(unittest.TestCase):
40 self.myDocument = model.moduleDocument()
41 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
50 self.assertEqual(model.dof(self.mySketch), self.myDOF)
52 def checkPointsEqual(self, thePoint1, thePoint2):
53 self.assertAlmostEqual(thePoint1.x(), thePoint2.x(), 5)
54 self.assertAlmostEqual(thePoint1.y(), thePoint2.y(), 5)
57 def test_ellipse_by_external_name(self):
58 """ Test 1. Create ellipse by name of external edge
60 self.myEllipse = self.mySketch.addEllipse("Sketch_1/SketchEllipse_1")
63 # check ellipse parameters
64 anEllipse = self.myEllipse.defaultResult().shape().edge().ellipse()
65 self.checkPointsEqual(anEllipse.center(), CENTER_POINT)
66 self.checkPointsEqual(anEllipse.firstFocus(), FOCUS_POINT)
67 self.assertAlmostEqual(anEllipse.minorRadius(), MINOR_RADIUS)
69 def test_ellipse_by_external_selection(self):
70 """ Test 2. Create ellipse by selected edge
72 self.myEllipse = self.mySketch.addEllipse(ELLIPSE.results()[-1])
75 # check ellipse parameters
76 anEllipse = self.myEllipse.defaultResult().shape().edge().ellipse()
77 self.checkPointsEqual(anEllipse.center(), CENTER_POINT)
78 self.checkPointsEqual(anEllipse.firstFocus(), FOCUS_POINT)
79 self.assertAlmostEqual(anEllipse.minorRadius(), MINOR_RADIUS)
82 if __name__ == "__main__":
84 aDocument = model.moduleDocument()
85 aSketch = model.addSketch(aDocument, model.defaultPlane("XOY"))
86 ELLIPSE = aSketch.addEllipse(CENTER_POINT, FOCUS_POINT, MINOR_RADIUS)
89 test_program = unittest.main(exit=False)
90 assert test_program.result.wasSuccessful(), "Test failed"
91 assert model.checkPythonDump()