1 # Copyright (C) 2019-2020 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 "Collinear" applied for ellipse's axes
27 from salome.shaper import model
30 from SketchAPI import *
32 __updated__ = "2019-09-18"
34 class TestCollinearEllipse(unittest.TestCase):
36 axisStart = GeomAPI_Pnt2d(30., 60.)
37 axisEnd = GeomAPI_Pnt2d(80., 50.)
38 passedPoint = GeomAPI_Pnt2d(60., 60.)
41 self.myDocument = model.moduleDocument()
42 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
43 macroEllipse = self.mySketch.addEllipse(axisStart, axisEnd, passedPoint, False)
45 self.myOX = self.mySketch.addLine("OX")
47 self.myEllipse = SketchAPI_Ellipse(model.lastSubFeature(self.mySketch, "SketchEllipse"))
48 self.myCenter = macroEllipse.center()
49 self.myFocus1 = macroEllipse.focus1()
50 self.myFocus2 = macroEllipse.focus2()
51 self.myMajorAxis = macroEllipse.majorAxis()
52 self.myMajorStart = macroEllipse.majorAxisStart()
53 self.myMajorEnd = macroEllipse.majorAxisEnd()
54 self.myMinorAxis = macroEllipse.minorAxis()
55 self.myMinorStart = macroEllipse.minorAxisStart()
56 self.myMinorEnd = macroEllipse.minorAxisEnd()
62 self.assertPoints(self.myCenter.coordinates(), self.myEllipse.center())
63 self.assertPoints(self.myFocus1.coordinates(), self.myEllipse.firstFocus())
64 self.assertPoints(self.myFocus2.coordinates(), self.myEllipse.secondFocus())
65 self.assertPoints(self.myMajorStart.coordinates(), self.myEllipse.majorAxisNegative())
66 self.assertPoints(self.myMajorEnd.coordinates(), self.myEllipse.majorAxisPositive())
67 self.assertPoints(self.myMajorAxis.startPoint(), self.myEllipse.majorAxisNegative())
68 self.assertPoints(self.myMajorAxis.endPoint(), self.myEllipse.majorAxisPositive())
69 self.assertPoints(self.myMinorStart.coordinates(), self.myEllipse.minorAxisNegative())
70 self.assertPoints(self.myMinorEnd.coordinates(), self.myEllipse.minorAxisPositive())
71 self.assertPoints(self.myMinorAxis.startPoint(), self.myEllipse.minorAxisNegative())
72 self.assertPoints(self.myMinorAxis.endPoint(), self.myEllipse.minorAxisPositive())
73 model.testNbSubFeatures(self.mySketch, "SketchPoint", 7)
74 model.testNbSubFeatures(self.mySketch, "SketchLine", 3)
75 model.testNbSubFeatures(self.mySketch, "SketchEllipse", 1)
76 model.testNbSubFeatures(self.mySketch, "SketchConstraintCoincidenceInternal", 11)
80 self.assertEqual(model.dof(self.mySketch), self.myDOF)
82 def assertPoints(self, thePoint1, thePoint2):
83 self.assertAlmostEqual(thePoint1.x(), thePoint2.x())
84 self.assertAlmostEqual(thePoint1.y(), thePoint2.y())
87 def test_collinear_major_axis(self):
88 """ Test 1. Make major axis of ellipse collinear with OX
90 self.mySketch.setCollinear(self.myOX.result(), self.myMajorAxis.result())
93 self.assertAlmostEqual(self.myMajorAxis.startPoint().y(), 0)
94 self.assertAlmostEqual(self.myMajorAxis.endPoint().y(), 0)
95 self.assertAlmostEqual(self.myMajorStart.coordinates().y(), 0)
96 self.assertAlmostEqual(self.myMajorEnd.coordinates().y(), 0)
97 model.testNbSubFeatures(self.mySketch, "SketchConstraintCollinear", 1)
99 def test_collinear_minor_axis(self):
100 """ Test 2. Make minor axis of ellipse collinear with OX
102 self.mySketch.setCollinear(self.myOX.result(), self.myMinorAxis.result())
105 # solver shows wrong result
106 assert(self.mySketch.solverError() != ""), "PlaneGCS limitation: if you see this message, then PlaneGCS has solved the set of constraints correctly"
110 self.mySketch.move(self.myMinorStart.coordinates(), 0, 70)
111 self.mySketch.move(self.myMinorEnd.coordinates(), 50, 70)
113 self.mySketch.setCollinear(self.myOX.result(), self.myMinorAxis.result())
115 self.assertAlmostEqual(self.myMinorAxis.startPoint().y(), 0)
116 self.assertAlmostEqual(self.myMinorAxis.endPoint().y(), 0)
117 self.assertAlmostEqual(self.myMinorStart.coordinates().y(), 0)
118 self.assertAlmostEqual(self.myMinorEnd.coordinates().y(), 0)
119 model.testNbSubFeatures(self.mySketch, "SketchConstraintCollinear", 1)
121 def test_collinear_ellipse_axes(self):
122 """ Test 3. Set collinear axes of an ellipse. Check conflicting constraints.
124 self.mySketch.setCollinear(self.myMajorAxis, self.myMinorAxis)
126 self.assertNotEqual(self.mySketch.solverError(), "")
131 if __name__ == "__main__":
132 test_program = unittest.main(exit=False)
133 assert test_program.result.wasSuccessful(), "Test failed"
134 assert model.checkPythonDump()