1 # Copyright (C) 2017-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 movement of the sketch circle
25 from GeomDataAPI import geomDataAPI_Point2D
26 from salome.shaper import model
28 __updated__ = "2017-05-11"
30 class TestMoveCircle(unittest.TestCase):
33 self.myDocument = model.moduleDocument()
34 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
35 self.myCenter = [70., 50.]
37 self.myCircle = self.mySketch.addCircle(self.myCenter[0], self.myCenter[1], self.myRadius)
45 assert(model.checkPythonDump())
48 self.assertEqual(model.dof(self.mySketch), self.myDOF)
50 def checkPointCoordinates(self, thePoint, theCoordinates):
51 self.assertAlmostEqual(thePoint.x(), theCoordinates[0])
52 self.assertAlmostEqual(thePoint.y(), theCoordinates[1])
54 def checkPointOnCircle(self, theCoordinates):
55 self.assertAlmostEqual(model.distancePointPoint(self.myCircle.center(), theCoordinates), self.myCircle.radius().value())
57 def fixCircleRadius(self):
58 self.mySketch.setRadius(self.myCircle.results()[1], self.myRadius)
63 def fixCircleCenter(self):
64 self.mySketch.setFixed(self.myCircle.center())
70 def test_move_center_free_circle(self):
71 """ Test 1. Movement of central point of a free circle
73 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
74 self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1])
76 self.checkPointCoordinates(self.myCircle.center(), newPosition)
77 self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
79 def test_move_free_circle(self):
80 """ Test 2. Movement of a free circle dragging the edge
82 newPosition = [120., 90.]
83 self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
85 self.checkPointCoordinates(self.myCircle.center(), self.myCenter)
86 self.checkPointOnCircle(newPosition)
87 self.assertNotEqual(self.myCircle.radius().value(), self.myRadius)
89 def test_move_center_circle_fixed_radius(self):
90 """ Test 3. Movement of central point of a circle with fixed radius
92 self.fixCircleRadius()
94 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
95 self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1])
97 self.checkPointCoordinates(self.myCircle.center(), newPosition)
98 self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
100 def test_move_circle_fixed_radius(self):
101 """ Test 4. Movement of a circle with fixed radius
103 self.fixCircleRadius()
105 newPosition = [120., 90.]
106 self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
108 self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
109 self.assertNotEqual(self.myCircle.center().x(), self.myCenter[0])
110 self.assertNotEqual(self.myCircle.center().y(), self.myCenter[1])
112 def test_move_center_circle_fixed_center(self):
113 """ Test 5. Movement of central point of a circle with fixed center (nothing should be changed)
115 self.fixCircleCenter()
117 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
118 self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1])
120 self.checkPointCoordinates(self.myCircle.center(), self.myCenter)
121 self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
123 def test_move_circle_fixed_center(self):
124 """ Test 6. Movement of a circle with fixed center
126 self.fixCircleCenter()
128 newPosition = [120., 90.]
129 self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
131 self.checkPointOnCircle(newPosition)
132 self.assertNotEqual(self.myCircle.radius().value(), self.myRadius)
134 def test_move_fixed_circle(self):
135 """ Test 7. Trying to move fully fixed circle
137 self.fixCircleCenter()
138 self.fixCircleRadius()
140 newPosition = [120., 90.]
141 self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
143 self.checkPointCoordinates(self.myCircle.center(), self.myCenter)
144 self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
147 if __name__ == "__main__":
148 test_program = unittest.main(exit=False)
149 assert test_program.result.wasSuccessful(), "Test failed"