Salome HOME
Fix the problem of the sketch plane update
[modules/shaper.git] / src / SketchPlugin / Test / TestDistanceSignedVsUnsigned05.py
1 ## Copyright (C) 2017  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 from salome.shaper import model
22 from SketchAPI import *
23 import math
24
25 TOLERANCE = 1.e-5
26
27 model.begin()
28 partSet = model.moduleDocument()
29 widthParam = model.addParameter(partSet, "w", "200")
30 distParam = model.addParameter(partSet, "d", "30")
31 Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
32 Rectangle_1 = Sketch_1.addRectangle(0, 0, 200, 100)
33 [Line_1, Line_2, Line_3, Line_4] = Rectangle_1.lines()
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 Line_5 = Sketch_1.addLine(260, 0, 260, 100)
42 Sketch_1.setSignedDistance(Point_1.result(), Line_5.result(), "d")
43 Sketch_1.setUnsignedDistance(Point_2.result(), Line_5.result(), "d")
44 model.do()
45 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
46
47 line4 = model.toSketchFeature(Line_4)
48 line5 = model.toSketchFeature(Line_5)
49 signedDist14 = model.signedDistancePointLine(Point_1, line4)
50 signedDist15 = model.signedDistancePointLine(Point_1, line5)
51 signedDist24 = model.signedDistancePointLine(Point_2, line4)
52 signedDist25 = model.signedDistancePointLine(Point_2, line5)
53
54 # change rectangle width and check distances
55 widthParam.setValue(2000)
56 model.do()
57 curDist = model.signedDistancePointLine(Point_1, line4)
58 assert(math.fabs(signedDist14 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist14, curDist)
59 curDist = model.signedDistancePointLine(Point_2, line4)
60 assert(math.fabs(math.fabs(signedDist24) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist24, -curDist)
61 curDist = model.signedDistancePointLine(Point_1, line5)
62 assert(math.fabs(signedDist15 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist15, curDist)
63 curDist = model.signedDistancePointLine(Point_2, line5)
64 assert(math.fabs(math.fabs(signedDist25) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist25, -curDist)
65 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
66
67 # revert rectangle width and check distances again
68 widthParam.setValue(200)
69 model.do()
70 curDist = model.signedDistancePointLine(Point_1, line4)
71 assert(math.fabs(signedDist14 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist14, curDist)
72 curDist = model.signedDistancePointLine(Point_2, line4)
73 assert(math.fabs(math.fabs(signedDist24) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist24, -curDist)
74 curDist = model.signedDistancePointLine(Point_1, line5)
75 assert(math.fabs(signedDist15 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist15, curDist)
76 curDist = model.signedDistancePointLine(Point_2, line5)
77 assert(math.fabs(math.fabs(signedDist25) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist25, -curDist)
78 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
79
80 model.end()