1 # Copyright (C) 2019-2021 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 elliptic arc by external feature
25 from salome.shaper import model
28 from SketchAPI import *
30 __updated__ = "2019-10-02"
33 CENTER_POINT = GeomAPI_Pnt2d(50., 50.)
34 MAJOR_AXIS_POINT = GeomAPI_Pnt2d(70., 60.)
35 START_POINT = GeomAPI_Pnt2d(60., 65.)
36 END_POINT = GeomAPI_Pnt2d(60., 42.535751)
40 class TestEllipticArcByExternal(unittest.TestCase):
43 self.myDocument = model.moduleDocument()
44 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
53 self.assertEqual(model.dof(self.mySketch), self.myDOF)
55 def checkPointsEqual(self, thePoint1, thePoint2):
56 self.assertAlmostEqual(thePoint1.x(), thePoint2.x(), 5)
57 self.assertAlmostEqual(thePoint1.y(), thePoint2.y(), 5)
60 def test_elliptic_arc_by_external_name_1(self):
61 """ Test 1. Create elliptic arc by name of external edge (direct)
63 self.myEllipse = self.mySketch.addEllipticArc("Sketch_1/SketchEllipticArc_1")
66 # check ellipse parameters
67 anArcEdge = self.myEllipse.defaultResult().shape().edge()
68 anEllipse = anArcEdge.ellipse()
69 self.checkPointsEqual(anEllipse.center(), CENTER_POINT)
70 self.checkPointsEqual(self.myEllipse.majorAxisPositive(), MAJOR_AXIS_POINT)
71 self.checkPointsEqual(self.myEllipse.startPoint(), START_POINT)
72 self.checkPointsEqual(self.myEllipse.endPoint(), END_POINT)
73 self.assertAlmostEqual(anArcEdge.length(), ARC_LENGTH_1)
75 def test_elliptic_arc_by_external_name_2(self):
76 """ Test 2. Create elliptic arc by name of external edge (reversed)
78 self.myEllipse = self.mySketch.addEllipticArc("Sketch_1/SketchEllipticArc_2")
81 # check ellipse parameters
82 anArcEdge = self.myEllipse.defaultResult().shape().edge()
83 anEllipse = anArcEdge.ellipse()
84 self.checkPointsEqual(anEllipse.center(), CENTER_POINT)
85 self.checkPointsEqual(self.myEllipse.majorAxisPositive(), MAJOR_AXIS_POINT)
86 self.checkPointsEqual(anArcEdge.firstPoint(), END_POINT)
87 self.checkPointsEqual(anArcEdge.lastPoint(), START_POINT)
88 self.assertAlmostEqual(anArcEdge.length(), ARC_LENGTH_2)
90 def test_elliptic_arc_by_external_selection_1(self):
91 """ Test 3. Create elliptic arc by selected edge (direct)
93 self.myEllipse = self.mySketch.addEllipticArc(ELLIPTIC_ARC_1.results()[-1])
96 # check ellipse parameters
97 anArcEdge = self.myEllipse.defaultResult().shape().edge()
98 anEllipse = anArcEdge.ellipse()
99 self.checkPointsEqual(anEllipse.center(), CENTER_POINT)
100 self.checkPointsEqual(self.myEllipse.majorAxisPositive(), MAJOR_AXIS_POINT)
101 self.checkPointsEqual(self.myEllipse.startPoint(), START_POINT)
102 self.checkPointsEqual(self.myEllipse.endPoint(), END_POINT)
103 self.assertAlmostEqual(anArcEdge.length(), ARC_LENGTH_1)
105 def test_elliptic_arc_by_external_selection_2(self):
106 """ Test 4. Create elliptic arc by selected edge (reversed)
108 self.myEllipse = self.mySketch.addEllipticArc(ELLIPTIC_ARC_2.results()[-1])
111 # check ellipse parameters
112 anArcEdge = self.myEllipse.defaultResult().shape().edge()
113 anEllipse = anArcEdge.ellipse()
114 self.checkPointsEqual(anEllipse.center(), CENTER_POINT)
115 self.checkPointsEqual(self.myEllipse.majorAxisPositive(), MAJOR_AXIS_POINT)
116 self.checkPointsEqual(self.myEllipse.startPoint(), END_POINT)
117 self.checkPointsEqual(self.myEllipse.endPoint(), START_POINT)
118 self.assertAlmostEqual(anArcEdge.length(), ARC_LENGTH_2)
121 if __name__ == "__main__":
123 aDocument = model.moduleDocument()
124 aSketch = model.addSketch(aDocument, model.defaultPlane("XOY"))
125 aSketch.addEllipticArc(CENTER_POINT, MAJOR_AXIS_POINT, START_POINT, END_POINT, False)
128 ELLIPTIC_ARC_1 = SketchAPI_EllipticArc(model.lastSubFeature(aSketch, "SketchEllipticArc"))
129 ARC_LENGTH_1 = ELLIPTIC_ARC_1.defaultResult().shape().edge().length()
131 aSketch.addEllipticArc(CENTER_POINT, MAJOR_AXIS_POINT, START_POINT, END_POINT, True)
134 ELLIPTIC_ARC_2 = SketchAPI_EllipticArc(model.lastSubFeature(aSketch, "SketchEllipticArc"))
135 ARC_LENGTH_2 = ELLIPTIC_ARC_2.defaultResult().shape().edge().length()
138 END_POINT = ELLIPTIC_ARC_2.endPoint()
140 test_program = unittest.main(exit=False)
141 assert test_program.result.wasSuccessful(), "Test failed"
142 assert model.checkPythonDump()