Salome HOME
Merge branch 'Dev_2.8.0'
[modules/shaper.git] / src / SketchPlugin / Test / TestMovePoint.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 point
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 TestMovePoint(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.myOrigin = self.mySketch.addPoint(model.selection("VERTEX", "Origin"))
37     self.myPoint = self.mySketch.addPoint(70, 50)
38     self.myPointCoordinates = geomDataAPI_Point2D(self.myPoint.coordinates())
39     self.myDOF = 2
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 test_move_free_point(self):
52     """ Test 1. Movement of free point
53     """
54     newPosition = [100., 100.]
55     self.mySketch.move(self.myPoint, newPosition[0], newPosition[1])
56     model.do()
57     self.assertAlmostEqual(self.myPointCoordinates.x(), newPosition[0])
58     self.assertAlmostEqual(self.myPointCoordinates.y(), newPosition[1])
59
60   def test_move_fixed_x(self):
61     """ Test 2. Movement of partially fixed point (fixed x coordinate)
62     """
63     DISTANCE = 50.
64     horizDistance = self.mySketch.setHorizontalDistance(self.myOrigin.result(), self.myPoint.coordinates(), DISTANCE)
65     self.myDOF -= 1
66     model.do()
67     self.checkDOF()
68
69     newPosition = [100., 100.]
70     self.mySketch.move(self.myPoint, newPosition[0], newPosition[1])
71     model.do()
72     self.assertAlmostEqual(self.myPointCoordinates.x(), DISTANCE)
73     self.assertAlmostEqual(self.myPointCoordinates.y(), newPosition[1])
74
75   def test_move_fixed_y(self):
76     """ Test 3. Movement of partially fixed point (fixed y coordinate)
77     """
78     DISTANCE = 50.
79     vertDistance = self.mySketch.setVerticalDistance(self.myOrigin.result(), self.myPoint.coordinates(), DISTANCE)
80     self.myDOF -= 1
81     model.do()
82     self.checkDOF()
83
84     newPosition = [100., 100.]
85     self.mySketch.move(self.myPoint, newPosition[0], newPosition[1])
86     model.do()
87     self.assertAlmostEqual(self.myPointCoordinates.x(), newPosition[0])
88     self.assertAlmostEqual(self.myPointCoordinates.y(), DISTANCE)
89
90   def test_move_fully_fixed(self):
91     """ Test 4. Movement of fully fixed point (should not be changed)
92     """
93     coord = [self.myPointCoordinates.x(), self.myPointCoordinates.y()]
94
95     fixed = self.mySketch.setFixed(self.myPoint.result())
96     self.myDOF -= 2
97     model.do()
98     self.checkDOF()
99
100     newPosition = [100., 100.]
101     self.mySketch.move(self.myPoint, newPosition[0], newPosition[1])
102     model.do()
103     self.assertAlmostEqual(self.myPointCoordinates.x(), coord[0])
104     self.assertAlmostEqual(self.myPointCoordinates.y(), coord[1])
105
106
107 if __name__ == '__main__':
108   unittest.main()