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