Salome HOME
77c49338ee1f961587e534814aa23bfa38849c16
[modules/shaper.git] / src / SketchPlugin / Test / TestChangeSketchPlane3.py
1 # Copyright (C) 2019-2023  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 SketchAPI import *
21 from salome.shaper import model
22 import math
23
24 def checkSketchLine(theLine, theX1, theY1, theX2, theY2, theTolerance = 1.e-7):
25     assert(math.fabs(theLine.startPoint().x() - theX1) < theTolerance)
26     assert(math.fabs(theLine.startPoint().y() - theY1) < theTolerance)
27     assert(math.fabs(theLine.endPoint().x() - theX2) < theTolerance)
28     assert(math.fabs(theLine.endPoint().y() - theY2) < theTolerance)
29
30 model.begin()
31 partSet = model.moduleDocument()
32 Part_1 = model.addPart(partSet)
33 Part_1_doc = Part_1.document()
34 ParamD1 = model.addParameter(Part_1_doc, "D1", "80")
35 ParamD2 = model.addParameter(Part_1_doc, "D2", "30")
36 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
37 SketchLine_1 = Sketch_1.addLine(0, 80, 30, 0)
38 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
39 SketchLine_2 = SketchProjection_1.createdFeature()
40 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_2.result())
41 SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False)
42 SketchLine_3 = SketchProjection_2.createdFeature()
43 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_3.result())
44 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_1.startPoint(), SketchAPI_Line(SketchLine_2).startPoint(), "D1", True)
45 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchLine_1.endPoint(), SketchAPI_Line(SketchLine_2).startPoint(), "D2", True)
46 model.do()
47 model.end()
48 model.checkSketch(Sketch_1, 0)
49 checkSketchLine(SketchLine_1, 0, ParamD1.value(), ParamD2.value(), 0)
50
51 model.begin()
52 Sketch_1.setPlane(model.selection("FACE", "PartSet/YOZ"))
53 model.end()
54 model.checkSketch(Sketch_1, 0)
55 checkSketchLine(SketchLine_1, 0, ParamD1.value(), ParamD2.value(), 0)
56
57 model.begin()
58 Sketch_1.setPlane(model.selection("FACE", "PartSet/XOZ"))
59 model.end()
60 model.checkSketch(Sketch_1, 0)
61 checkSketchLine(SketchLine_1, 0, ParamD1.value(), ParamD2.value(), 0)
62
63 assert(model.checkPythonDump())