Salome HOME
05e2f0d128f1cd2a455ba1ef23921c4813a6ae71
[modules/shaper.git] / src / SketchPlugin / Test / TestDistanceSignedVsUnsigned01.py
1 # Copyright (C) 2017-2023  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 Sketch_1.setVertical(Line_4.result())
34 Origin = Sketch_1.addPoint(model.selection("VERTEX", "Origin"))
35 Sketch_1.setCoincident(SketchAPI_Line(Line_1).endPoint(), Origin.result())
36 Sketch_1.setLength(SketchAPI_Line(Line_1).result(), "w")
37 Point_1 = Sketch_1.addPoint(230, 40)
38 Sketch_1.setSignedDistance(Point_1.result(), SketchAPI_Line(Line_4).result(), "d")
39 Point_2 = Sketch_1.addPoint(230, 80)
40 Sketch_1.setUnsignedDistance(Point_2.result(), SketchAPI_Line(Line_4).result(), "d")
41 model.do()
42 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
43
44 line = model.toSketchFeature(Line_4)
45 signedDist1 = model.signedDistancePointLine(Point_1, line)
46 signedDist2 = model.signedDistancePointLine(Point_2, line)
47
48 # change rectangle width and check distances
49 widthParam.setValue(300)
50 model.do()
51 curDist = model.signedDistancePointLine(Point_1, line)
52 assert(math.fabs(signedDist1 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist1, curDist)
53 curDist = model.signedDistancePointLine(Point_2, line)
54 assert(math.fabs(math.fabs(signedDist2) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist2, -curDist)
55 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
56
57 # revert rectangle width and check distances again
58 widthParam.setValue(300)
59 model.do()
60 curDist = model.signedDistancePointLine(Point_1, line)
61 assert(math.fabs(signedDist1 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist1, curDist)
62 curDist = model.signedDistancePointLine(Point_2, line)
63 assert(math.fabs(math.fabs(signedDist2) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist2, -curDist)
64 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
65
66 model.end()
67