]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/TestConstraintDistanceEllipse.py
Salome HOME
Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003)
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintDistanceEllipse.py
1 # Copyright (C) 2019  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 constraint "Distance" applied sub-elements of an ellipse
22 """
23
24 import unittest
25 import math
26
27 from salome.shaper import model
28
29 from GeomAPI import *
30 from SketchAPI import *
31
32 __updated__ = "2019-09-12"
33
34 class TestDistanceEllipse(unittest.TestCase):
35   def setUp(self):
36     axisStart = GeomAPI_Pnt2d(20., 60.)
37     axisEnd = GeomAPI_Pnt2d(80., 50.)
38     passedPoint = GeomAPI_Pnt2d(60., 70.)
39
40     model.begin()
41     self.myDocument = model.moduleDocument()
42     self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
43     macroEllipse = self.mySketch.addEllipse(axisStart, axisEnd, passedPoint, False)
44     self.myDOF = 5
45     self.myOrigin = self.mySketch.addPoint("Origin")
46     self.myOX = self.mySketch.addLine("OX")
47     model.do()
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
59     self.myDistance = 20
60
61   def tearDown(self):
62     model.end()
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"
65       model.undo()
66     else:
67       self.checkDOF()
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)
84
85
86   def checkDOF(self):
87     self.assertEqual(model.dof(self.mySketch), self.myDOF)
88
89   def checkPointPointDistance(self, thePoint1, thePoint2):
90     self.mySketch.setDistance(thePoint1, thePoint2, self.myDistance)
91     self.myDOF -= 1
92     model.do()
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)
97
98   def checkPointLineDistance(self, thePoint, theLine):
99     self.mySketch.setDistance(thePoint, theLine.result(), self.myDistance)
100     self.myDOF -= 1
101     model.do()
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)
105
106   def assertPoints(self, thePoint1, thePoint2):
107     self.assertAlmostEqual(thePoint1.x(), thePoint2.x())
108     self.assertAlmostEqual(thePoint1.y(), thePoint2.y())
109
110
111   def test_distance_center(self):
112     """ Test 1. Set distance to the Origin from the center of ellipse
113     """
114     self.checkPointPointDistance(self.myCenter.coordinates(), self.myOrigin.coordinates())
115
116   def test_distance_first_focus(self):
117     """ Test 2. Set distance to the Origin from the first focus of ellipse
118     """
119     self.checkPointPointDistance(self.myFocus1.coordinates(), self.myOrigin.coordinates())
120
121   def test_distance_second_focus(self):
122     """ Test 3. Set distance to the Origin from the second focus of ellipse
123     """
124     self.checkPointPointDistance(self.myFocus2.coordinates(), self.myOrigin.coordinates())
125
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
128     """
129     self.checkPointPointDistance(self.myMajorStart.coordinates(), self.myOrigin.coordinates())
130
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
133     """
134     self.checkPointPointDistance(self.myMajorEnd.coordinates(), self.myOrigin.coordinates())
135
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
138     """
139     self.checkPointPointDistance(self.myMinorStart.coordinates(), self.myOrigin.coordinates())
140
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
143     """
144     self.myExpectFailure = True
145     self.checkPointPointDistance(self.myMinorEnd.coordinates(), self.myOrigin.coordinates())
146
147
148   def test_distance_center_to_line(self):
149     """ Test 8. Set distance from theOX to the center of ellipse
150     """
151     self.checkPointLineDistance(self.myCenter.coordinates(), self.myOX)
152
153   def test_distance_first_focus_to_line(self):
154     """ Test 9. Set distance from theOX to the first focus of ellipse
155     """
156     self.checkPointLineDistance(self.myFocus1.coordinates(), self.myOX)
157
158   def test_distance_second_focus_to_line(self):
159     """ Test 10. Set distance from theOX to the second focus of ellipse
160     """
161     self.checkPointLineDistance(self.myFocus2.coordinates(), self.myOX)
162
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
165     """
166     self.checkPointLineDistance(self.myMajorStart.coordinates(), self.myOX)
167
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
170     """
171     self.checkPointLineDistance(self.myMajorEnd.coordinates(), self.myOX)
172
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
175     """
176     self.checkPointLineDistance(self.myMinorStart.coordinates(), self.myOX)
177
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
180     """
181     self.myDistance = 150
182     self.checkPointLineDistance(self.myMinorEnd.coordinates(), self.myOX)
183
184
185   def test_distance_origin_to_major_axis(self):
186     """ Test 15. Set distance from the Origin to the major axis of the ellipse
187     """
188     self.checkPointLineDistance(self.myOrigin.coordinates(), self.myMajorAxis)
189
190   def test_distance_origin_to_minor_axis(self):
191     """ Test 16. Set distance from the Origin to the minor axis of the ellipse
192     """
193     self.checkPointLineDistance(self.myOrigin.coordinates(), self.myMinorAxis)
194
195
196 if __name__ == "__main__":
197     test_program = unittest.main(exit=False)
198     assert test_program.result.wasSuccessful(), "Test failed"
199     assert model.checkPythonDump()