Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / SketchPlugin / Test / TestMoveCircle.py
1 ## Copyright (C) 2017  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 """
22     Test movement of the sketch circle
23 """
24
25 import unittest
26 from GeomDataAPI import geomDataAPI_Point2D
27 from salome.shaper import model
28
29 __updated__ = "2017-05-11"
30
31 class TestMoveCircle(unittest.TestCase):
32   def setUp(self):
33     model.begin()
34     self.myDocument = model.moduleDocument()
35     self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
36     self.myCenter = [70., 50.]
37     self.myRadius = 20.
38     self.myCircle = self.mySketch.addCircle(self.myCenter[0], self.myCenter[1], self.myRadius)
39     self.myDOF = 3
40     model.do()
41     self.checkDOF()
42
43   def tearDown(self):
44     self.checkDOF()
45     model.end()
46     assert(model.checkPythonDump())
47
48   def checkDOF(self):
49     self.assertEqual(model.dof(self.mySketch), self.myDOF)
50
51   def checkPointCoordinates(self, thePoint, theCoordinates):
52     self.assertAlmostEqual(thePoint.x(), theCoordinates[0])
53     self.assertAlmostEqual(thePoint.y(), theCoordinates[1])
54
55   def checkPointOnCircle(self, theCoordinates):
56     self.assertAlmostEqual(model.distancePointPoint(self.myCircle.center(),  theCoordinates), self.myCircle.radius().value())
57
58   def fixCircleRadius(self):
59     self.mySketch.setRadius(self.myCircle.results()[1], self.myRadius)
60     self.myDOF -= 1
61     model.do()
62     self.checkDOF()
63
64   def fixCircleCenter(self):
65     self.mySketch.setFixed(self.myCircle.center())
66     self.myDOF -= 2
67     model.do()
68     self.checkDOF()
69
70
71   def test_move_center_free_circle(self):
72     """ Test 1. Movement of central point of a free circle
73     """
74     newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
75     self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1])
76     model.do()
77     self.checkPointCoordinates(self.myCircle.center(), newPosition)
78     self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
79
80   def test_move_free_circle(self):
81     """ Test 2. Movement of a free circle dragging the edge
82     """
83     newPosition = [120., 90.]
84     self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
85     model.do()
86     self.checkPointCoordinates(self.myCircle.center(), self.myCenter)
87     self.checkPointOnCircle(newPosition)
88     self.assertNotEqual(self.myCircle.radius().value(), self.myRadius)
89
90   def test_move_center_circle_fixed_radius(self):
91     """ Test 3. Movement of central point of a circle with fixed radius
92     """
93     self.fixCircleRadius()
94
95     newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
96     self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1])
97     model.do()
98     self.checkPointCoordinates(self.myCircle.center(), newPosition)
99     self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
100
101   def test_move_circle_fixed_radius(self):
102     """ Test 4. Movement of a circle with fixed radius
103     """
104     self.fixCircleRadius()
105
106     newPosition = [120., 90.]
107     self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
108     model.do()
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])
112
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)
115     """
116     self.fixCircleCenter()
117
118     newPosition = [self.myCenter[0] + 20., self.myCenter[1] + 10.]
119     self.mySketch.move(self.myCircle.center(), newPosition[0], newPosition[1])
120     model.do()
121     self.checkPointCoordinates(self.myCircle.center(), self.myCenter)
122     self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
123
124   def test_move_circle_fixed_center(self):
125     """ Test 6. Movement of a circle with fixed center
126     """
127     self.fixCircleCenter()
128
129     newPosition = [120., 90.]
130     self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
131     model.do()
132     self.checkPointOnCircle(newPosition)
133     self.assertNotEqual(self.myCircle.radius().value(), self.myRadius)
134
135   def test_move_fixed_circle(self):
136     """ Test 7. Trying to move fully fixed circle
137     """
138     self.fixCircleCenter()
139     self.fixCircleRadius()
140
141     newPosition = [120., 90.]
142     self.mySketch.move(self.myCircle.defaultResult(), newPosition[0], newPosition[1])
143     model.do()
144     self.checkPointCoordinates(self.myCircle.center(), self.myCenter)
145     self.assertAlmostEqual(self.myCircle.radius().value(), self.myRadius)
146
147
148 if __name__ == '__main__':
149   unittest.main()