1 # Copyright (C) 2019 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 email : webmaster.salome@opencascade.com
21 Test the zero value of the constraint "DistanceHorizontal"
27 from salome.shaper import model
28 from SketchAPI import *
30 __updated__ = "2019-10-22"
33 class TestZeroDistanceHorizontal(unittest.TestCase):
36 self.myDocument = model.moduleDocument()
37 self.mySketch = model.addSketch(self.myDocument, model.defaultPlane("XOY"))
38 self.myLine1 = self.mySketch.addLine(10, 10, 45, 27.5)
39 self.myLine2 = self.mySketch.addLine(20, 15, 30, 40)
40 self.myLine3 = self.mySketch.addLine(10, 0, 10, 10)
46 model.checkSketch(self.mySketch, self.myDOF)
48 def assertDistanceHorizontal(self, theObject1, theObject2, theDistance):
49 dist = theObject2.x() - theObject1.x()
50 self.assertTrue(math.fabs(dist - theDistance) < TOLERANCE, "Current distance = {}, reference = {}".format(dist, theDistance))
51 model.checkSketch(self.mySketch, self.myDOF)
54 def test_distance_positive_nzznz(self):
55 """ Test 1. Change distance from non-zero to zero and back to non-zero
57 dist = self.mySketch.setHorizontalDistance(self.myLine1.startPoint(), self.myLine2.startPoint(), 10)
60 self.assertDistanceHorizontal(self.myLine1.startPoint(), self.myLine2.startPoint(), 10)
62 SketchAPI_Constraint(dist).setValue(0)
64 self.assertDistanceHorizontal(self.myLine1.startPoint(), self.myLine2.startPoint(), 0)
66 SketchAPI_Constraint(dist).setValue(10)
68 self.assertDistanceHorizontal(self.myLine1.startPoint(), self.myLine2.startPoint(), 10)
70 def test_distance_negative_nzznz(self):
71 """ Test 2. Change distance from non-zero to zero and back to non-zero
73 dist = self.mySketch.setHorizontalDistance(self.myLine1.endPoint(), self.myLine2.endPoint(), 15)
76 self.assertDistanceHorizontal(self.myLine1.endPoint(), self.myLine2.endPoint(), -15)
78 SketchAPI_Constraint(dist).setValue(0)
80 self.assertDistanceHorizontal(self.myLine1.endPoint(), self.myLine2.endPoint(), 0)
82 SketchAPI_Constraint(dist).setValue(10)
84 self.assertDistanceHorizontal(self.myLine1.endPoint(), self.myLine2.endPoint(), -10)
86 def test_distance_equal_znzz(self):
87 """ Test 3. Change distance from zero to non-zero and back to zero
89 dist = self.mySketch.setHorizontalDistance(self.myLine1.startPoint(), self.myLine3.endPoint(), 0)
92 self.assertDistanceHorizontal(self.myLine1.startPoint(), self.myLine3.endPoint(), 0)
94 SketchAPI_Constraint(dist).setValue(10)
96 self.assertDistanceHorizontal(self.myLine1.startPoint(), self.myLine3.endPoint(), 10)
98 SketchAPI_Constraint(dist).setValue(0)
100 self.assertDistanceHorizontal(self.myLine1.startPoint(), self.myLine3.endPoint(), 0)
102 def test_distance_notequal_znzz(self):
103 """ Test 4. Change distance from zero to non-zero and back to zero
105 dist = self.mySketch.setHorizontalDistance(self.myLine1.startPoint(), self.myLine3.startPoint(), 0)
108 self.assertDistanceHorizontal(self.myLine1.startPoint(), self.myLine3.startPoint(), 0)
110 SketchAPI_Constraint(dist).setValue(10)
112 self.assertDistanceHorizontal(self.myLine1.startPoint(), self.myLine3.startPoint(), 10)
114 SketchAPI_Constraint(dist).setValue(0)
116 self.assertDistanceHorizontal(self.myLine1.startPoint(), self.myLine3.startPoint(), 0)
119 if __name__ == "__main__":
120 test_program = unittest.main(exit=False)
121 assert test_program.result.wasSuccessful(), "Test failed"
122 assert model.checkPythonDump()