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 Part_1 = model.addPart(partSet)
29 Part_1_doc = Part_1.document()
30 DistanceParam = model.addParameter(Part_1_doc, "distance", "10.")
31 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
32 SketchRectangle_1 = Sketch_1.addRectangle(20., 20., 70., 50.)
33 [SketchLine_1, SketchLine_2, SketchLine_3, SketchLine_4] = SketchRectangle_1.lines()
34 firstPoint = SketchAPI_Line(SketchLine_2).startPoint()
35 secondPoint = SketchAPI_Line(SketchLine_3).endPoint()
38 # =============================================================================
40 # =============================================================================
41 # horizontal distance constraint
42 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(firstPoint, secondPoint, 10)
43 SketchConstraintDistanceHorizontal_1.feature().real("ConstraintValue").setText(DistanceParam.name().value())
46 # changing the parameter
47 for param in range(-30, 31, 2):
50 DistanceParam.setValue(param)
52 dist = secondPoint.x() - firstPoint.x()
53 assert math.fabs(dist - param) < TOLERANCE, "Incorrect horizontal distance {}, expected {}".format(dist, param)
55 model.testNbSubFeatures(Sketch_1, "SketchLine", 4)
56 model.testNbSubFeatures(Sketch_1, "SketchConstraintDistanceHorizontal", 1)
58 # remove horizontal distance constraint
59 Part_1_doc.removeFeature(SketchConstraintDistanceHorizontal_1.feature())
62 # =============================================================================
64 # =============================================================================
65 # Vertical distance constraint
66 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(firstPoint, secondPoint, 10)
67 SketchConstraintDistanceVertical_1.feature().real("ConstraintValue").setText(DistanceParam.name().value())
70 # changing the parameter
71 for param in range(-30, 31, 2):
74 DistanceParam.setValue(param)
76 dist = secondPoint.y() - firstPoint.y()
77 assert math.fabs(dist - param) < TOLERANCE, "Incorrect vertical distance {}, expected {}".format(dist, param)
79 model.testNbSubFeatures(Sketch_1, "SketchLine", 4)
80 model.testNbSubFeatures(Sketch_1, "SketchConstraintDistanceVertical", 1)
82 # remove verticel distance constraint
83 Part_1_doc.removeFeature(SketchConstraintDistanceVertical_1.feature())
86 # =============================================================================
88 # =============================================================================
90 SketchConstraintDistance_1 = Sketch_1.setDistance(firstPoint, secondPoint, "distance")
93 # changing the parameter
94 for param in range(-30, 31, 2):
95 DistanceParam.setValue(param)
98 assert SketchConstraintDistance_1.feature().error() != '', "ERROR: Sketch should not be valid due to negative distance value"
100 dist = model.distancePointPoint(firstPoint, secondPoint)
101 assert math.fabs(dist - math.fabs(param)) < TOLERANCE, "Incorrect distance {}, expected {}".format(dist, math.fabs(param))
103 model.testNbSubFeatures(Sketch_1, "SketchLine", 4)
104 model.testNbSubFeatures(Sketch_1, "SketchConstraintDistance", 1)
105 # leave distance constraint alive