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 constraint "Angle" applied for ellipse's axes
27 from salome.shaper import model
30 from SketchAPI import *
32 __updated__ = "2019-09-12"
34 class TestAngleEllipse(unittest.TestCase):
36 axisStart = GeomAPI_Pnt2d(30., 60.)
37 axisEnd = GeomAPI_Pnt2d(80., 50.)
38 passedPoint = GeomAPI_Pnt2d(60., 60.)
42 self.myDocument = model.moduleDocument()
43 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
44 macroEllipse = self.mySketch.addEllipse(axisStart, axisEnd, passedPoint, False)
46 self.myOX = self.mySketch.addLine("OX")
48 self.myEllipse = SketchAPI_Ellipse(model.lastSubFeature(self.mySketch, "SketchEllipse"))
49 self.myCenter = macroEllipse.center()
50 self.myFocus1 = macroEllipse.focus1()
51 self.myFocus2 = macroEllipse.focus2()
52 self.myMajorAxis = macroEllipse.majorAxis()
53 self.myMajorStart = macroEllipse.majorAxisStart()
54 self.myMajorEnd = macroEllipse.majorAxisEnd()
55 self.myMinorAxis = macroEllipse.minorAxis()
56 self.myMinorStart = macroEllipse.minorAxisStart()
57 self.myMinorEnd = macroEllipse.minorAxisEnd()
63 self.assertPoints(self.myCenter.coordinates(), self.myEllipse.center())
64 self.assertPoints(self.myFocus1.coordinates(), self.myEllipse.firstFocus())
65 self.assertPoints(self.myFocus2.coordinates(), self.myEllipse.secondFocus())
66 self.assertPoints(self.myMajorStart.coordinates(), self.myEllipse.majorAxisNegative())
67 self.assertPoints(self.myMajorEnd.coordinates(), self.myEllipse.majorAxisPositive())
68 self.assertPoints(self.myMajorAxis.startPoint(), self.myEllipse.majorAxisNegative())
69 self.assertPoints(self.myMajorAxis.endPoint(), self.myEllipse.majorAxisPositive())
70 self.assertPoints(self.myMinorStart.coordinates(), self.myEllipse.minorAxisNegative())
71 self.assertPoints(self.myMinorEnd.coordinates(), self.myEllipse.minorAxisPositive())
72 self.assertPoints(self.myMinorAxis.startPoint(), self.myEllipse.minorAxisNegative())
73 self.assertPoints(self.myMinorAxis.endPoint(), self.myEllipse.minorAxisPositive())
74 model.testNbSubFeatures(self.mySketch, "SketchPoint", 7)
75 model.testNbSubFeatures(self.mySketch, "SketchLine", 3)
76 model.testNbSubFeatures(self.mySketch, "SketchEllipse", 1)
77 model.testNbSubFeatures(self.mySketch, "SketchConstraintCoincidenceInternal", 11)
81 self.assertEqual(model.dof(self.mySketch), self.myDOF)
83 def assertPoints(self, thePoint1, thePoint2):
84 self.assertAlmostEqual(thePoint1.x(), thePoint2.x())
85 self.assertAlmostEqual(thePoint1.y(), thePoint2.y())
87 def assertAngle(self, theStart, theEnd, theAngle):
88 dirX = (theEnd.x() - theStart.x()) / math.hypot(theEnd.x() - theStart.x(), theEnd.y() - theStart.y())
89 self.assertAlmostEqual(math.fabs(dirX), math.cos(theAngle * math.pi / 180))
92 def test_angle_major_axis(self):
93 """ Test 1. Make angle between major axis of ellipse and OX
95 self.mySketch.setAngle(self.myOX.result(), self.myMajorAxis.result(), self.myAngle)
98 self.assertAngle(self.myMajorAxis.startPoint(), self.myMajorAxis.endPoint(), self.myAngle)
99 self.assertAngle(self.myMajorStart.coordinates(), self.myMajorEnd.coordinates(), self.myAngle)
100 model.testNbSubFeatures(self.mySketch, "SketchConstraintAngle", 1)
102 def test_angle_minor_axis(self):
103 """ Test 2. Make angle between minor axis of ellipse and OX
105 self.mySketch.setAngle(self.myOX.result(), self.myMinorAxis.result(), self.myAngle)
108 self.assertAngle(self.myMinorAxis.startPoint(), self.myMinorAxis.endPoint(), self.myAngle)
109 self.assertAngle(self.myMinorStart.coordinates(), self.myMinorEnd.coordinates(), self.myAngle)
110 model.testNbSubFeatures(self.mySketch, "SketchConstraintAngle", 1)
112 def test_angle_ellipse_axes(self):
113 """ Test 3. Set angle between axes of an ellipse. Check conflicting constraints.
115 self.mySketch.setAngle(self.myMajorAxis.result(), self.myMinorAxis.result(), self.myAngle)
117 self.assertNotEqual(self.mySketch.solverError(), "")
122 if __name__ == "__main__":
123 test_program = unittest.main(exit=False)
124 assert test_program.result.wasSuccessful(), "Test failed"
125 assert model.checkPythonDump()