Salome HOME
Update copyrights
[modules/shaper.git] / src / SketchPlugin / Test / TestDistanceSignedVsUnsigned02.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 Point_1 = Sketch_1.addPoint(model.selection("VERTEX", "Origin"))
34 Sketch_1.setCoincident(SketchAPI_Line(Line_1).endPoint(), Point_1.result())
35 Sketch_1.setLength(SketchAPI_Line(Line_1).result(), "w")
36 Circle_1 = Sketch_1.addCircle(230, 40, 20)
37 Sketch_1.setSignedDistance(Circle_1.center(), SketchAPI_Line(Line_4).result(), "d")
38 Circle_2 = Sketch_1.addCircle(230, 80, 20)
39 Sketch_1.setUnsignedDistance(Circle_2.center(), 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 center1 = Circle_1.center()
44 center2 = Circle_2.center()
45 line = model.toSketchFeature(Line_4)
46 signedDist1 = model.signedDistancePointLine(center1, line)
47 signedDist2 = model.signedDistancePointLine(center2, line)
48
49 # change rectangle width and check distances
50 widthParam.setValue(2000)
51 model.do()
52 curDist = model.signedDistancePointLine(center1, line)
53 assert(math.fabs(signedDist1 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist1, curDist)
54 curDist = model.signedDistancePointLine(center2, 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(center1, line)
62 assert(math.fabs(signedDist1 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist1, curDist)
63 curDist = model.signedDistancePointLine(center2, 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()