]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/TestMovePoint.py
Salome HOME
88a143a17a47162f82d5ce7e8dce49f88533fedb
[modules/shaper.git] / src / SketchPlugin / Test / TestMovePoint.py
1 """
2     Test movement of the sketch point
3 """
4
5 import unittest
6 from GeomDataAPI import geomDataAPI_Point2D
7 from salome.shaper import model
8
9 __updated__ = "2017-05-11"
10
11 class TestMovePoint(unittest.TestCase):
12   def setUp(self):
13     model.begin()
14     self.myDocument = model.moduleDocument()
15     self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
16     self.myOrigin = self.mySketch.addPoint(model.selection("VERTEX", "Origin"))
17     self.myPoint = self.mySketch.addPoint(70, 50)
18     self.myPointCoordinates = geomDataAPI_Point2D(self.myPoint.coordinates())
19     self.myDOF = 2
20     model.do()
21     self.checkDOF()
22
23   def tearDown(self):
24     self.checkDOF()
25     model.end()
26     assert(model.checkPythonDump())
27
28   def checkDOF(self):
29     self.assertEqual(model.dof(self.mySketch), self.myDOF)
30
31   def test_move_free_point(self):
32     """ Test 1. Movement of free point
33     """
34     newPosition = [100., 100.]
35     self.mySketch.move(self.myPoint, newPosition[0], newPosition[1])
36     model.do()
37     self.assertAlmostEqual(self.myPointCoordinates.x(), newPosition[0])
38     self.assertAlmostEqual(self.myPointCoordinates.y(), newPosition[1])
39
40   def test_move_fixed_x(self):
41     """ Test 2. Movement of partially fixed point (fixed x coordinate)
42     """
43     DISTANCE = 50.
44     horizDistance = self.mySketch.setHorizontalDistance(self.myOrigin.result(), self.myPoint.coordinates(), DISTANCE)
45     self.myDOF -= 1
46     model.do()
47     self.checkDOF()
48
49     newPosition = [100., 100.]
50     self.mySketch.move(self.myPoint, newPosition[0], newPosition[1])
51     model.do()
52     self.assertAlmostEqual(self.myPointCoordinates.x(), DISTANCE)
53     self.assertAlmostEqual(self.myPointCoordinates.y(), newPosition[1])
54
55   def test_move_fixed_y(self):
56     """ Test 3. Movement of partially fixed point (fixed y coordinate)
57     """
58     DISTANCE = 50.
59     vertDistance = self.mySketch.setVerticalDistance(self.myOrigin.result(), self.myPoint.coordinates(), DISTANCE)
60     self.myDOF -= 1
61     model.do()
62     self.checkDOF()
63
64     newPosition = [100., 100.]
65     self.mySketch.move(self.myPoint, newPosition[0], newPosition[1])
66     model.do()
67     self.assertAlmostEqual(self.myPointCoordinates.x(), newPosition[0])
68     self.assertAlmostEqual(self.myPointCoordinates.y(), DISTANCE)
69
70   def test_move_fully_fixed(self):
71     """ Test 4. Movement of fully fixed point (should not be changed)
72     """
73     coord = [self.myPointCoordinates.x(), self.myPointCoordinates.y()]
74
75     fixed = self.mySketch.setFixed(self.myPoint.result())
76     self.myDOF -= 2
77     model.do()
78     self.checkDOF()
79
80     newPosition = [100., 100.]
81     self.mySketch.move(self.myPoint, newPosition[0], newPosition[1])
82     model.do()
83     self.assertAlmostEqual(self.myPointCoordinates.x(), coord[0])
84     self.assertAlmostEqual(self.myPointCoordinates.y(), coord[1])
85
86
87 if __name__ == '__main__':
88   unittest.main()