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