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 "Distance" applied sub-elements of an ellipse
27 from salome.shaper import model
30 from SketchAPI import *
32 __updated__ = "2019-09-12"
34 class TestDistanceEllipse(unittest.TestCase):
36 axisStart = GeomAPI_Pnt2d(20., 60.)
37 axisEnd = GeomAPI_Pnt2d(80., 50.)
38 passedPoint = GeomAPI_Pnt2d(60., 70.)
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.myOrigin = self.mySketch.addPoint("Origin")
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()
58 self.myExpectFailure = False
63 if self.myExpectFailure:
64 assert(self.mySketch.solverError() != ""), "PlaneGCS limitation: if you see this message, then PlaneGCS has solved the set of constraints correctly"
68 self.assertPoints(self.myCenter.coordinates(), self.myEllipse.center())
69 self.assertPoints(self.myFocus1.coordinates(), self.myEllipse.firstFocus())
70 self.assertPoints(self.myFocus2.coordinates(), self.myEllipse.secondFocus())
71 self.assertPoints(self.myMajorStart.coordinates(), self.myEllipse.majorAxisNegative())
72 self.assertPoints(self.myMajorEnd.coordinates(), self.myEllipse.majorAxisPositive())
73 self.assertPoints(self.myMajorAxis.startPoint(), self.myEllipse.majorAxisNegative())
74 self.assertPoints(self.myMajorAxis.endPoint(), self.myEllipse.majorAxisPositive())
75 self.assertPoints(self.myMinorStart.coordinates(), self.myEllipse.minorAxisNegative())
76 self.assertPoints(self.myMinorEnd.coordinates(), self.myEllipse.minorAxisPositive())
77 self.assertPoints(self.myMinorAxis.startPoint(), self.myEllipse.minorAxisNegative())
78 self.assertPoints(self.myMinorAxis.endPoint(), self.myEllipse.minorAxisPositive())
79 model.testNbSubFeatures(self.mySketch, "SketchPoint", 8)
80 model.testNbSubFeatures(self.mySketch, "SketchLine", 3)
81 model.testNbSubFeatures(self.mySketch, "SketchEllipse", 1)
82 model.testNbSubFeatures(self.mySketch, "SketchConstraintCoincidenceInternal", 11)
83 model.testNbSubFeatures(self.mySketch, "SketchConstraintDistance", 1)
87 self.assertEqual(model.dof(self.mySketch), self.myDOF)
89 def checkPointPointDistance(self, thePoint1, thePoint2):
90 self.mySketch.setDistance(thePoint1, thePoint2, self.myDistance)
93 if not self.myExpectFailure:
94 self.assertAlmostEqual(model.distancePointPoint(thePoint1, thePoint2), self.myDistance)
95 self.assertGreater(self.myEllipse.majorRadius().value(), 0.0)
96 self.assertGreater(self.myEllipse.minorRadius().value(), 0.0)
98 def checkPointLineDistance(self, thePoint, theLine):
99 self.mySketch.setDistance(thePoint, theLine.result(), self.myDistance)
102 self.assertAlmostEqual(model.distancePointLine(thePoint, theLine), self.myDistance)
103 self.assertGreater(self.myEllipse.majorRadius().value(), 0.0)
104 self.assertGreater(self.myEllipse.minorRadius().value(), 0.0)
106 def assertPoints(self, thePoint1, thePoint2):
107 self.assertAlmostEqual(thePoint1.x(), thePoint2.x())
108 self.assertAlmostEqual(thePoint1.y(), thePoint2.y())
111 def test_distance_center(self):
112 """ Test 1. Set distance to the Origin from the center of ellipse
114 self.checkPointPointDistance(self.myCenter.coordinates(), self.myOrigin.coordinates())
116 def test_distance_first_focus(self):
117 """ Test 2. Set distance to the Origin from the first focus of ellipse
119 self.checkPointPointDistance(self.myFocus1.coordinates(), self.myOrigin.coordinates())
121 def test_distance_second_focus(self):
122 """ Test 3. Set distance to the Origin from the second focus of ellipse
124 self.checkPointPointDistance(self.myFocus2.coordinates(), self.myOrigin.coordinates())
126 def test_distance_major_axis_start(self):
127 """ Test 4. Set distance to the Origin from the start point on the major axis of ellipse
129 self.checkPointPointDistance(self.myMajorStart.coordinates(), self.myOrigin.coordinates())
131 def test_distance_major_axis_end(self):
132 """ Test 5. Set distance to the Origin from the end point on the major axis of ellipse
134 self.checkPointPointDistance(self.myMajorEnd.coordinates(), self.myOrigin.coordinates())
136 def test_distance_minor_axis_start(self):
137 """ Test 6. Set distance to the Origin from the start point on the minor axis of ellipse
139 self.checkPointPointDistance(self.myMinorStart.coordinates(), self.myOrigin.coordinates())
141 def test_distance_minor_axis_end(self):
142 """ Test 7. Set distance to the Origin from the end point on the minor axis of ellipse
144 self.myExpectFailure = True
145 self.checkPointPointDistance(self.myMinorEnd.coordinates(), self.myOrigin.coordinates())
148 def test_distance_center_to_line(self):
149 """ Test 8. Set distance from theOX to the center of ellipse
151 self.checkPointLineDistance(self.myCenter.coordinates(), self.myOX)
153 def test_distance_first_focus_to_line(self):
154 """ Test 9. Set distance from theOX to the first focus of ellipse
156 self.checkPointLineDistance(self.myFocus1.coordinates(), self.myOX)
158 def test_distance_second_focus_to_line(self):
159 """ Test 10. Set distance from theOX to the second focus of ellipse
161 self.checkPointLineDistance(self.myFocus2.coordinates(), self.myOX)
163 def test_distance_major_axis_start_to_line(self):
164 """ Test 11. Set distance from theOX to the start point on the major axis of ellipse
166 self.checkPointLineDistance(self.myMajorStart.coordinates(), self.myOX)
168 def test_distance_major_axis_end_to_line(self):
169 """ Test 12. Set distance from theOX to the end point on the major axis of ellipse
171 self.checkPointLineDistance(self.myMajorEnd.coordinates(), self.myOX)
173 def test_distance_minor_axis_start_to_line(self):
174 """ Test 13. Set distance from theOX to the start point on the minor axis of ellipse
176 self.checkPointLineDistance(self.myMinorStart.coordinates(), self.myOX)
178 def test_distance_minor_axis_end_to_line(self):
179 """ Test 14. Set distance from theOX to the end point on the minor axis of ellipse
181 self.myDistance = 150
182 self.checkPointLineDistance(self.myMinorEnd.coordinates(), self.myOX)
185 def test_distance_origin_to_major_axis(self):
186 """ Test 15. Set distance from the Origin to the major axis of the ellipse
188 self.checkPointLineDistance(self.myOrigin.coordinates(), self.myMajorAxis)
190 def test_distance_origin_to_minor_axis(self):
191 """ Test 16. Set distance from the Origin to the minor axis of the ellipse
193 self.checkPointLineDistance(self.myOrigin.coordinates(), self.myMinorAxis)
196 if __name__ == "__main__":
197 test_program = unittest.main(exit=False)
198 assert test_program.result.wasSuccessful(), "Test failed"
199 assert model.checkPythonDump()