Salome HOME
Merge remote-tracking branch 'origin/Toolbars_Management'
[modules/shaper.git] / src / SketchPlugin / Test / Test2390.py
1 ## Copyright (C) 2014-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 """
22     Test2390.py
23     Test case for issue #2390 "Revolution become invalid after changing parameter"
24 """
25
26
27 from SketchAPI import *
28
29 from salome.shaper import model
30
31 model.begin()
32 partSet = model.moduleDocument()
33 Part_1 = model.addPart(partSet)
34 Part_1_doc = Part_1.document()
35
36 Param_Width = model.addParameter(Part_1_doc, "Width", "64")
37 Param_Drill2Loc = model.addParameter(Part_1_doc, "Drill2_Loc", "6.5")
38 Param_Drill2Radius = model.addParameter(Part_1_doc, "Drill2_Radius", "1.4")
39 Param_Drill2InnerRadius = model.addParameter(Part_1_doc, "Drill2_InnerRadius", "0.5")
40 Param_Drill2DepthMin = model.addParameter(Part_1_doc, "Drill2_DepthMin", "6.5")
41 Param_Drill2DepthMax = model.addParameter(Part_1_doc, "Drill2_DepthMax", "7.5")
42
43 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
44 SketchLine_1 = Sketch_1.addLine(64, 0, 0, 0)
45 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
46 SketchPoint_1 = SketchProjection_1.createdFeature()
47 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchPoint_1.result())
48 SketchLine_2 = Sketch_1.addLine(0, 0, 0, 36)
49 SketchLine_3 = Sketch_1.addLine(0, 36, 64, 36)
50 SketchLine_4 = Sketch_1.addLine(64, 36, 64, 0)
51 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
52 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
53 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
54 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
55 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
56 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
57 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
58 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
59 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_3.startPoint(), SketchLine_3.endPoint(), "Width")
60 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_2.result(), 36)
61 SketchLine_5 = Sketch_1.addLine(22, 36, 22, 0)
62 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.startPoint(), SketchLine_3.result())
63 SketchLine_6 = Sketch_1.addLine(32, 36, 32, 0)
64 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_6.startPoint(), SketchLine_3.result())
65 SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_1.result())
66 SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_1.result())
67 SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_5.result())
68 SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_6.result())
69 SketchConstraintDistanceHorizontal_2 = Sketch_1.setHorizontalDistance(SketchLine_2.endPoint(), SketchLine_5.startPoint(), "Width/32*11")
70 SketchConstraintDistanceHorizontal_3 = Sketch_1.setHorizontalDistance(SketchLine_6.startPoint(), SketchLine_3.endPoint(), "Width/2")
71 model.do()
72
73 Sketch_4 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
74 SketchLine_52 = Sketch_4.addLine(28.5, -19, 28.5, 0)
75 SketchProjection_12 = Sketch_4.addProjection(model.selection("EDGE", "PartSet/OX"), False)
76 SketchLine_53 = SketchProjection_12.createdFeature()
77 SketchConstraintCoincidence_47 = Sketch_4.setCoincident(SketchLine_52.endPoint(), SketchLine_53.result())
78 SketchLine_54 = Sketch_4.addLine(28.5, 0, 29, 0)
79 SketchConstraintCoincidence_48 = Sketch_4.setCoincident(SketchLine_52.endPoint(), SketchLine_54.startPoint())
80 SketchConstraintCoincidence_49 = Sketch_4.setCoincident(SketchLine_54.endPoint(), SketchLine_53.result())
81 SketchLine_55 = Sketch_4.addLine(29, 0, 29, -11.5)
82 SketchConstraintCoincidence_50 = Sketch_4.setCoincident(SketchLine_54.endPoint(), SketchLine_55.startPoint())
83 SketchLine_56 = Sketch_4.addLine(28.5, -19, 29.9, -19)
84 SketchConstraintCoincidence_51 = Sketch_4.setCoincident(SketchLine_52.startPoint(), SketchLine_56.startPoint())
85 SketchLine_57 = Sketch_4.addLine(29.9, -19, 29.4, -18.5)
86 SketchConstraintCoincidence_52 = Sketch_4.setCoincident(SketchLine_56.endPoint(), SketchLine_57.startPoint())
87 SketchLine_58 = Sketch_4.addLine(29.4, -18.5, 29.4, -12.5)
88 SketchConstraintCoincidence_53 = Sketch_4.setCoincident(SketchLine_57.endPoint(), SketchLine_58.startPoint())
89 SketchArc_2 = Sketch_4.addArc(27.95, -12.5, 29.4, -12.5, 29, -11.5, False)
90 SketchConstraintCoincidence_54 = Sketch_4.setCoincident(SketchLine_58.endPoint(), SketchArc_2.startPoint())
91 SketchConstraintCoincidence_55 = Sketch_4.setCoincident(SketchLine_55.endPoint(), SketchArc_2.endPoint())
92 SketchConstraintVertical_15 = Sketch_4.setVertical(SketchLine_52.result())
93 SketchConstraintVertical_16 = Sketch_4.setVertical(SketchLine_55.result())
94 SketchConstraintVertical_17 = Sketch_4.setVertical(SketchLine_58.result())
95 SketchConstraintHorizontal_11 = Sketch_4.setHorizontal(SketchLine_56.result())
96 SketchProjection_13 = Sketch_4.addProjection(model.selection("VERTEX", "Sketch_1/SketchLine_5_EndVertex"), False)
97 SketchPoint_4 = SketchProjection_13.createdFeature()
98 SketchConstraintDistanceHorizontal_17 = Sketch_4.setHorizontalDistance(SketchAPI_Point(SketchPoint_4).coordinates(), SketchLine_52.endPoint(), "Drill2_Loc")
99 SketchConstraintLength_3 = Sketch_4.setLength(SketchLine_54.result(), "Drill2_InnerRadius")
100 SketchProjection_14 = Sketch_4.addProjection(model.selection("EDGE", "Sketch_1/SketchLine_3"), False)
101 SketchLine_59 = SketchProjection_14.createdFeature()
102 SketchConstraintAngle_6 = Sketch_4.setAngle(SketchLine_57.result(), SketchLine_56.result(), 45)
103 SketchConstraintLength_4 = Sketch_4.setLength(SketchLine_56.result(), "Drill2_Radius")
104 SketchConstraintMirror_2 = Sketch_4.addMirror(SketchLine_53.result(), [SketchLine_59.result()])
105 [SketchLine_60] = SketchConstraintMirror_2.mirrored()
106 SketchLine_60.setAuxiliary(True)
107 SketchConstraintCoincidence_56 = Sketch_4.setCoincident(SketchLine_56.startPoint(), SketchLine_60.result())
108 SketchConstraintDistance_12 = Sketch_4.setDistance(SketchArc_2.endPoint(), SketchLine_60.result(), "Drill2_DepthMax", True)
109 SketchConstraintDistance_13 = Sketch_4.setDistance(SketchLine_58.endPoint(), SketchLine_60.result(), "Drill2_DepthMin", True)
110 SketchConstraintDistance_14 = Sketch_4.setDistance(SketchLine_57.endPoint(), SketchLine_60.result(), 0.5, True)
111 SketchConstraintTangent_3 = Sketch_4.setTangent(SketchLine_58.result(), SketchArc_2.results()[1])
112 model.do()
113
114 Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_11f-SketchLine_12f-SketchLine_13f-SketchArc_1_2f-SketchLine_10r-SketchLine_9r-SketchLine_7r")], model.selection("EDGE", "Sketch_2/SketchLine_7"), 360, 0)
115 model.do()
116
117 from GeomAPI import GeomAPI_Shape
118
119 # Check Revolution_1 is correct
120 model.testNbResults(Revolution_1, 1)
121 model.testNbSubResults(Revolution_1, [0])
122 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.SOLID, [1])
123 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.FACE, [6])
124 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.EDGE, [18])
125 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.VERTEX, [36])
126 model.testResultsVolumes(Revolution_1, [41.691543241529835484016075497])
127
128 # Update Width parameter
129 Param_Width.setValue(100)
130 model.do()
131
132 # compare only 5 digits in the volume, due to small deviations
133 SIGNIFICANT_DIGITS = 5
134
135 # Check Revolution_1 is correct
136 model.testNbResults(Revolution_1, 1)
137 model.testNbSubResults(Revolution_1, [0])
138 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.SOLID, [1])
139 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.FACE, [6])
140 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.EDGE, [18])
141 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.VERTEX, [36])
142 model.testResultsVolumes(Revolution_1, [41.691543241529835484016075497], SIGNIFICANT_DIGITS)
143
144 # Update Width parameter once again
145 Param_Width.setValue(150)
146 model.do()
147
148 # Check Revolution_1 is correct
149 model.testNbResults(Revolution_1, 1)
150 model.testNbSubResults(Revolution_1, [0])
151 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.SOLID, [1])
152 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.FACE, [6])
153 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.EDGE, [18])
154 model.testNbSubShapes(Revolution_1, GeomAPI_Shape.VERTEX, [36])
155 model.testResultsVolumes(Revolution_1, [41.691543241529835484016075497], SIGNIFICANT_DIGITS)
156
157 model.end()
158
159 # TODO: uncomment following line when issue #2389 is fixed
160 #assert(model.checkPythonDump())