1 ## Copyright (C) 2017 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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
22 Test movement of the sketch circle
26 from GeomDataAPI import geomDataAPI_Point2D
27 from salome.shaper import model
29 __updated__ = "2017-05-11"
31 class TestMoveCircle(unittest.TestCase):
34 self.myDocument = model.moduleDocument()
35 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
36 self.myCenter = [70., 50.]
38 self.myCircle = self.mySketch.addCircle(self.myCenter[0], self.myCenter[1], self.myRadius)
46 assert(model.checkPythonDump())
49 self.assertEqual(model.dof(self.mySketch), self.myDOF)
51 def checkPointCoordinates(self, thePoint, theCoordinates):
52 self.assertAlmostEqual(thePoint.x(), theCoordinates[0])
53 self.assertAlmostEqual(thePoint.y(), theCoordinates[1])
55 def checkPointOnCircle(self, theCoordinates):
56 self.assertAlmostEqual(model.distancePointPoint(self.myCircle.center(), theCoordinates), self.myCircle.radius().value())
58 def fixCircleRadius(self):
59 self.mySketch.setRadius(self.myCircle.results()[1], self.myRadius)
64 def fixCircleCenter(self):
65 self.mySketch.setFixed(self.myCircle.center())
71 def test_move_center_free_circle(self):
72 """ Test 1. Movement of central point of a free circle
74 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
75 self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1])
77 self.checkPointCoordinates(self.myCircle.center(), newPosition)
78 self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
80 def test_move_free_circle(self):
81 """ Test 2. Movement of a free circle dragging the edge
83 newPosition = [120., 90.]
84 self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
86 self.checkPointCoordinates(self.myCircle.center(), self.myCenter)
87 self.checkPointOnCircle(newPosition)
88 self.assertNotEqual(self.myCircle.radius().value(), self.myRadius)
90 def test_move_center_circle_fixed_radius(self):
91 """ Test 3. Movement of central point of a circle with fixed radius
93 self.fixCircleRadius()
95 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
96 self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1])
98 self.checkPointCoordinates(self.myCircle.center(), newPosition)
99 self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
101 def test_move_circle_fixed_radius(self):
102 """ Test 4. Movement of a circle with fixed radius
104 self.fixCircleRadius()
106 newPosition = [120., 90.]
107 self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
109 self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
110 self.assertNotEqual(self.myCircle.center().x(), self.myCenter[0])
111 self.assertNotEqual(self.myCircle.center().y(), self.myCenter[1])
113 def test_move_center_circle_fixed_center(self):
114 """ Test 5. Movement of central point of a circle with fixed center (nothing should be changed)
116 self.fixCircleCenter()
118 newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
119 self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1])
121 self.checkPointCoordinates(self.myCircle.center(), self.myCenter)
122 self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
124 def test_move_circle_fixed_center(self):
125 """ Test 6. Movement of a circle with fixed center
127 self.fixCircleCenter()
129 newPosition = [120., 90.]
130 self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
132 self.checkPointOnCircle(newPosition)
133 self.assertNotEqual(self.myCircle.radius().value(), self.myRadius)
135 def test_move_fixed_circle(self):
136 """ Test 7. Trying to move fully fixed circle
138 self.fixCircleCenter()
139 self.fixCircleRadius()
141 newPosition = [120., 90.]
142 self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
144 self.checkPointCoordinates(self.myCircle.center(), self.myCenter)
145 self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
148 if __name__ == "__main__":
149 test_program = unittest.main(exit=False)
150 assert test_program.result.wasSuccessful(), "Test failed"