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