1 # Copyright (C) 2017-2019 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from salome.shaper import model
21 from SketchAPI import *
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 Line_5 = Sketch_1.addLine(260, 0, 260, 100)
41 Sketch_1.setSignedDistance(Point_1.result(), Line_5.result(), "d")
42 Sketch_1.setUnsignedDistance(Point_2.result(), Line_5.result(), "d")
44 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
46 line4 = model.toSketchFeature(Line_4)
47 line5 = model.toSketchFeature(Line_5)
48 signedDist14 = model.signedDistancePointLine(Point_1, line4)
49 signedDist15 = model.signedDistancePointLine(Point_1, line5)
50 signedDist24 = model.signedDistancePointLine(Point_2, line4)
51 signedDist25 = model.signedDistancePointLine(Point_2, line5)
53 # change rectangle width and check distances
54 widthParam.setValue(2000)
56 curDist = model.signedDistancePointLine(Point_1, line4)
57 assert(math.fabs(signedDist14 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist14, curDist)
58 curDist = model.signedDistancePointLine(Point_2, line4)
59 assert(math.fabs(math.fabs(signedDist24) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist24, -curDist)
60 curDist = model.signedDistancePointLine(Point_1, line5)
61 assert(math.fabs(signedDist15 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist15, curDist)
62 curDist = model.signedDistancePointLine(Point_2, line5)
63 assert(math.fabs(math.fabs(signedDist25) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist25, -curDist)
64 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"
66 # revert rectangle width and check distances again
67 widthParam.setValue(200)
69 curDist = model.signedDistancePointLine(Point_1, line4)
70 assert(math.fabs(signedDist14 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist14, curDist)
71 curDist = model.signedDistancePointLine(Point_2, line4)
72 assert(math.fabs(math.fabs(signedDist24) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist24, -curDist)
73 curDist = model.signedDistancePointLine(Point_1, line5)
74 assert(math.fabs(signedDist15 - curDist) < TOLERANCE), "Expected {}, actual {}".format(signedDist15, curDist)
75 curDist = model.signedDistancePointLine(Point_2, line5)
76 assert(math.fabs(math.fabs(signedDist25) - math.fabs(curDist)) < TOLERANCE), "Expected {}, actual {}".format(signedDist25, -curDist)
77 assert Sketch_1.solverError().value() == "", "FAILED: Sketch should NOT report over-constrained situation"