1 ## Copyright (C) 2017 CEA/DEN, EDF R&D
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.
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.
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
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
22 Test movement of the sketch line
26 from GeomDataAPI import geomDataAPI_Point2D
27 from salome.shaper import model
29 __updated__ = "2017-05-11"
31 class TestMoveLine(unittest.TestCase):
34 self.myDocument = model.moduleDocument()
35 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
36 self.myStart = [70., 50.]
37 self.myEnd = [100., 20.]
38 self.myLine = self.mySketch.addLine(self.myStart[0], self.myStart[1], self.myEnd[0], self.myEnd[1])
46 assert(model.checkPythonDump())
49 self.assertEqual(model.dof(self.mySketch), self.myDOF)
51 def checkPointCoordinates(self, thePoint, theCoordinates):
52 self.assertAlmostEqual(thePoint.x(), theCoordinates[0])
53 self.assertAlmostEqual(thePoint.y(), theCoordinates[1])
55 def checkPointOnLine(self, theCoordinates):
56 self.assertAlmostEqual(model.distancePointLine(theCoordinates, self.myLine), 0.)
58 def test_move_start_of_free_line(self):
59 """ Test 1. Movement of start point of a free line
61 newPosition = [self.myStart[0] + 20., self.myStart[1] + 10.]
62 self.mySketch.move(self.myLine.startPoint(), newPosition[0], newPosition[1])
64 self.checkPointCoordinates(self.myLine.startPoint(), newPosition)
65 self.checkPointCoordinates(self.myLine.endPoint(), self.myEnd)
67 def test_move_end_of_free_line(self):
68 """ Test 2. Movement of end point of a free line
70 newPosition = [self.myEnd[0] + 20., self.myEnd[1] + 10.]
71 self.mySketch.move(self.myLine.endPoint(), newPosition[0], newPosition[1])
73 self.checkPointCoordinates(self.myLine.startPoint(), self.myStart)
74 self.checkPointCoordinates(self.myLine.endPoint(), newPosition)
76 def test_move_free_line(self):
77 """ Test 3. Movement of free line
79 diff = [self.myEnd[0] - self.myStart[0], self.myEnd[1] - self.myStart[1]]
81 newPosition = [100., 100.]
82 self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1])
84 self.checkPointOnLine(newPosition)
86 # additionally check the line keeps geometry (relative positions of extremities)
87 startPoint = self.myLine.startPoint()
88 endPoint = [startPoint.x() + diff[0], startPoint.y() + diff[1]]
89 self.checkPointCoordinates(self.myLine.endPoint(), endPoint)
91 def test_move_line_start_fixed(self):
92 """ Test 4. Movement of a line, which start point is fixed
94 fixed = self.mySketch.setFixed(self.myLine.startPoint())
99 newPosition = [100., 100.]
100 self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1])
102 self.checkPointCoordinates(self.myLine.startPoint(), self.myStart)
103 self.assertNotEqual(self.myLine.endPoint().x(), self.myEnd[0])
104 self.assertNotEqual(self.myLine.endPoint().y(), self.myEnd[1])
106 def test_move_line_end_fixed(self):
107 """ Test 5. Movement of a line, which end point is fixed
109 fixed = self.mySketch.setFixed(self.myLine.endPoint())
114 newPosition = [100., 100.]
115 self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1])
117 self.assertNotEqual(self.myLine.startPoint().x(), self.myStart[0])
118 self.assertNotEqual(self.myLine.startPoint().y(), self.myStart[1])
119 self.checkPointCoordinates(self.myLine.endPoint(), self.myEnd)
121 def test_move_line_fully_fixed(self):
122 """ Test 6. Movement of fully fixed line (should not change its coordinates)
124 fixed = self.mySketch.setFixed(self.myLine.defaultResult())
128 newPosition = [100., 100.]
129 self.mySketch.move(self.myLine.defaultResult(), newPosition[0], newPosition[1])
131 self.checkPointCoordinates(self.myLine.startPoint(), self.myStart)
132 self.checkPointCoordinates(self.myLine.endPoint(), self.myEnd)
135 if __name__ == "__main__":
136 test_program = unittest.main(exit=False)
137 assert test_program.result.wasSuccessful(), "Test failed"