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