Salome HOME
Copyright update 2022
[modules/shaper.git] / src / SketchPlugin / Test / TestCreateEllipseByExternal.py
1 # Copyright (C) 2019-2022  CEA/DEN, EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 """
21     Test creation of ellipse by external feature
22 """
23
24 import unittest
25 from salome.shaper import model
26
27 from GeomAPI import *
28 from SketchAPI import *
29
30 __updated__ = "2019-09-12"
31
32 # reference data
33 CENTER_POINT = GeomAPI_Pnt2d(50., 50.)
34 FOCUS_POINT = GeomAPI_Pnt2d(70., 60.)
35 MINOR_RADIUS = 10.
36
37 class TestEllipse(unittest.TestCase):
38   def setUp(self):
39     model.begin()
40     self.myDocument = model.moduleDocument()
41     self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
42     self.myDOF = 0
43
44   def tearDown(self):
45     self.checkDOF()
46     model.end()
47
48
49   def checkDOF(self):
50     self.assertEqual(model.dof(self.mySketch), self.myDOF)
51
52   def checkPointsEqual(self, thePoint1, thePoint2):
53     self.assertAlmostEqual(thePoint1.x(), thePoint2.x(), 5)
54     self.assertAlmostEqual(thePoint1.y(), thePoint2.y(), 5)
55
56
57   def test_ellipse_by_external_name(self):
58     """ Test 1. Create ellipse by name of external edge
59     """
60     self.myEllipse = self.mySketch.addEllipse("Sketch_1/SketchEllipse_1")
61     model.do()
62
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)
68
69   def test_ellipse_by_external_selection(self):
70     """ Test 2. Create ellipse by selected edge
71     """
72     self.myEllipse = self.mySketch.addEllipse(ELLIPSE.results()[-1])
73     model.do()
74
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)
80
81
82 if __name__ == "__main__":
83     model.begin()
84     aDocument = model.moduleDocument()
85     aSketch = model.addSketch(aDocument, model.defaultPlane("XOY"))
86     ELLIPSE = aSketch.addEllipse(CENTER_POINT, FOCUS_POINT, MINOR_RADIUS)
87     model.end()
88
89     test_program = unittest.main(exit=False)
90     assert test_program.result.wasSuccessful(), "Test failed"
91     assert model.checkPythonDump()