Salome HOME
Merge remote-tracking branch 'origin/CEA_2019'
[modules/shaper.git] / src / SketchPlugin / Test / TestDistanceSignedVsUnsigned01.py
1 # Copyright (C) 2017-2019  CEA/DEN, EDF R&D
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 from salome.shaper import model
21 from SketchAPI import *
22 import math
23
24 TOLERANCE = 1.e-5
25
26 model.begin()
27 partSet = model.moduleDocument()
28 widthParam = model.addParameter(partSet, "w", "200")
29 distParam = model.addParameter(partSet, "d", "30")
30 Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
31 Rectangle_1 = Sketch_1.addRectangle(0, 0, 200, 100)
32 [Line_1, Line_2, Line_3, Line_4] = Rectangle_1.lines()
33 Origin = Sketch_1.addPoint(model.selection("VERTEX", "Origin"))
34 Sketch_1.setCoincident(SketchAPI_Line(Line_1).endPoint(), Origin.result())
35 Sketch_1.setLength(SketchAPI_Line(Line_1).result(), "w")
36 Point_1 = Sketch_1.addPoint(230, 40)
37 Sketch_1.setSignedDistance(Point_1.result(), SketchAPI_Line(Line_4).result(), "d")
38 Point_2 = Sketch_1.addPoint(230, 80)
39 Sketch_1.setUnsignedDistance(Point_2.result(), SketchAPI_Line(Line_4).result(), "d")
40 model.do()
41 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
42
43 line = model.toSketchFeature(Line_4)
44 signedDist1 = model.signedDistancePointLine(Point_1, line)
45 signedDist2 = model.signedDistancePointLine(Point_2, line)
46
47 # change rectangle width and check distances
48 widthParam.setValue(2000)
49 model.do()
50 curDist = model.signedDistancePointLine(Point_1, line)
51 assert(math.fabs(signedDist1 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist1, curDist)
52 curDist = model.signedDistancePointLine(Point_2, line)
53 assert(math.fabs(math.fabs(signedDist2) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist2, -curDist)
54 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
55
56 # revert rectangle width and check distances again
57 widthParam.setValue(200)
58 model.do()
59 curDist = model.signedDistancePointLine(Point_1, line)
60 assert(math.fabs(signedDist1 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist1, curDist)
61 curDist = model.signedDistancePointLine(Point_2, line)
62 assert(math.fabs(math.fabs(signedDist2) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist2, -curDist)
63 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
64
65 model.end()