]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/TestMoveLine.py
Salome HOME
Task 2.4. Ability to modify the radius of circles and arcs of circle with the mouse
[modules/shaper.git] / src / SketchPlugin / Test / TestMoveLine.py
1 """
2     Test movement of the sketch line
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 TestMoveLine(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.myStart = [70., 50.]
17     self.myEnd = [100., 20.]
18     self.myLine = self.mySketch.addLine(self.myStart[0], self.myStart[1], self.myEnd[0], self.myEnd[1])
19     self.myDOF = 4
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 checkPointCoordinates(self, thePoint, theCoordinates):
32     self.assertAlmostEqual(thePoint.x(), theCoordinates[0])
33     self.assertAlmostEqual(thePoint.y(), theCoordinates[1])
34
35   def checkPointOnLine(self, theCoordinates):
36     self.assertAlmostEqual(model.distancePointLine(theCoordinates, self.myLine), 0.)
37
38   def test_move_start_of_free_line(self):
39     """ Test 1. Movement of start point of a free line
40     """
41     newPosition = [self.myStart[0] + 20., self.myStart[1] + 10.]
42     self.mySketch.move(self.myLine.startPoint(), newPosition[0], newPosition[1])
43     model.do()
44     self.checkPointCoordinates(self.myLine.startPoint(), newPosition)
45     self.checkPointCoordinates(self.myLine.endPoint(), self.myEnd)
46
47   def test_move_end_of_free_line(self):
48     """ Test 2. Movement of end point of a free line
49     """
50     newPosition = [self.myEnd[0] + 20., self.myEnd[1] + 10.]
51     self.mySketch.move(self.myLine.endPoint(), newPosition[0], newPosition[1])
52     model.do()
53     self.checkPointCoordinates(self.myLine.startPoint(), self.myStart)
54     self.checkPointCoordinates(self.myLine.endPoint(), newPosition)
55
56   def test_move_free_line(self):
57     """ Test 3. Movement of free line
58     """
59     diff = [self.myEnd[0] - self.myStart[0], self.myEnd[1] - self.myStart[1]]
60
61     newPosition = [100., 100.]
62     self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1])
63     model.do()
64     self.checkPointOnLine(newPosition)
65
66     # additionally check the line keeps geometry (relative positions of extremities)
67     startPoint = self.myLine.startPoint()
68     endPoint = [startPoint.x() + diff[0], startPoint.y() + diff[1]]
69     self.checkPointCoordinates(self.myLine.endPoint(), endPoint)
70
71   def test_move_line_start_fixed(self):
72     """ Test 4. Movement of a line, which start point is fixed
73     """
74     fixed = self.mySketch.setFixed(self.myLine.startPoint())
75     self.myDOF -= 2
76     model.do()
77     self.checkDOF()
78
79     newPosition = [100., 100.]
80     self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1])
81     model.do()
82     self.checkPointCoordinates(self.myLine.startPoint(), self.myStart)
83     self.assertNotEqual(self.myLine.endPoint().x(), self.myEnd[0])
84     self.assertNotEqual(self.myLine.endPoint().y(), self.myEnd[1])
85
86   def test_move_line_end_fixed(self):
87     """ Test 5. Movement of a line, which end point is fixed
88     """
89     fixed = self.mySketch.setFixed(self.myLine.endPoint())
90     self.myDOF -= 2
91     model.do()
92     self.checkDOF()
93
94     newPosition = [100., 100.]
95     self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1])
96     model.do()
97     self.assertNotEqual(self.myLine.startPoint().x(), self.myStart[0])
98     self.assertNotEqual(self.myLine.startPoint().y(), self.myStart[1])
99     self.checkPointCoordinates(self.myLine.endPoint(), self.myEnd)
100
101   def test_move_line_fully_fixed(self):
102     """ Test 6. Movement of fully fixed line (should not change its coordinates)
103     """
104     fixed = self.mySketch.setFixed(self.myLine.defaultResult())
105     self.myDOF -= 4
106     model.do()
107
108     newPosition = [100., 100.]
109     self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1])
110     model.do()
111     self.checkPointCoordinates(self.myLine.startPoint(), self.myStart)
112     self.checkPointCoordinates(self.myLine.endPoint(), self.myEnd)
113
114
115 if __name__ == '__main__':
116   unittest.main()