Salome HOME
Update copyrights
[modules/shaper.git] / test.API / SHAPER / Primitives / TestCylinder.py
1 # Copyright (C) 2014-2019  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 Test case for Primitive Cylinder feature.
22 Written on High API.
23 """
24 #from ModelAPI import *
25
26 from salome.shaper import model
27
28 model.begin()
29 partSet = model.moduleDocument()
30 Part_1 = model.addPart(partSet)
31 Part_1_doc = Part_1.document()
32
33 # Init
34 Point_1 = model.addPoint(Part_1_doc, 10, 10, 10).result()
35 Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Point_1")])
36
37 # Sketch
38 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
39 SketchLine_1 = Sketch_1.addLine(40.1917811348149, 87.63526969661267, 92.63493386188256, 31.1341153558487)
40 SketchLine_2 = Sketch_1.addLine(92.63493386188256, 31.1341153558487, 44.70109718071649, 32.40093347950982)
41 SketchLine_3 = Sketch_1.addLine(44.70109718071649, 32.40093347950982, 40.1917811348149, 87.63526969661267)
42 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
43 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
44 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_3.endPoint())
45 model.do()
46
47 # Extrusion
48 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_3r-SketchLine_2r-SketchLine_1r")], model.selection(), 100, 0)
49 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_1/Face-SketchLine_3r-SketchLine_2r-SketchLine_1r_wire")], model.selection(), 100, 0)
50
51 # Edge
52 Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_2")])
53 Edge_2 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_3")])
54
55 # Axis
56 Axis_1 = model.addAxis(Part_1_doc, 0, 10, 0)
57
58 # Parameters
59 model.addParameter(Part_1_doc, "r", "6")
60 model.addParameter(Part_1_doc, "h", "20")
61
62 model.addParameter(Part_1_doc, "r2", "6")
63 model.addParameter(Part_1_doc, "h2", "15")
64 model.addParameter(Part_1_doc, "angle", "270")
65
66 #Tests
67 Cylinder_1 = model.addCylinder(Part_1_doc, 5, 10)
68 Cylinder_2 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "Point_1"), model.selection("EDGE", "PartSet/OX"), 5, 10)
69 Cylinder_3 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "Point_1"), model.selection("EDGE", "Axis_1"), 7, 12)
70 Cylinder_4 = model.addCylinder(Part_1_doc, 0, 10)
71 Cylinder_5 = model.addCylinder(Part_1_doc, -5, 10)
72 Cylinder_6 = model.addCylinder(Part_1_doc, 5, 0)
73 Cylinder_7 = model.addCylinder(Part_1_doc, 5, -10)
74 Cylinder_8 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "InvalidName"), model.selection("EDGE", "PartSet/OX"), 5, 10)
75 Cylinder_9 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "InvalidName"), 5, 10)
76 Cylinder_10 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "Sketch_1/SketchLine_2_EndVertex"), model.selection("EDGE", "Sketch_1/SketchLine_3"), 50, 120)
77 Cylinder_11 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "Vertex_1_1"), model.selection("EDGE", "Edge_1_1"), 60, 100)
78 Cylinder_12 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1][Extrusion_1_1/To_Face]"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"), 5, 10)
79 Cylinder_13 = model.addCylinder(Part_1_doc, "r", "h")
80 Cylinder_14 = model.addCylinder(Part_1_doc, 5, 10, 45)
81 Cylinder_15 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "Point_1"), model.selection("EDGE", "PartSet/OX"), 5, 10, 90)
82 Cylinder_16 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "Point_1"), model.selection("EDGE", "Axis_1"), 7, 12, 120)
83 Cylinder_17 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "Point_1"), model.selection("EDGE", "PartSet/OY"), 5, 10, 360)
84 Cylinder_18 = model.addCylinder(Part_1_doc, 0, 10, 45)
85 Cylinder_19 = model.addCylinder(Part_1_doc, -5, 10, 45)
86 Cylinder_20 = model.addCylinder(Part_1_doc, 5, 0, 45)
87 Cylinder_21 = model.addCylinder(Part_1_doc, 5, -10, 45)
88 Cylinder_22 = model.addCylinder(Part_1_doc, 5, 10, 0)
89 Cylinder_23 = model.addCylinder(Part_1_doc, 5, 10, -45)
90 Cylinder_24 = model.addCylinder(Part_1_doc, 5, 10, 450)
91 Cylinder_25 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "InvalidName"), model.selection("EDGE", "PartSet/OX"), 5, 10, 90)
92 Cylinder_26 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "InvalidName"), 5, 10, 90)
93 Cylinder_27 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "Sketch_1/SketchLine_1_EndVertex"), model.selection("EDGE", "Sketch_1/SketchLine_3"), 50, 120, 90)
94 Cylinder_28 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "Vertex_1_1"), model.selection("EDGE", "Edge_2_1"), 60, 100, 180)
95 Cylinder_29 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_2_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_2_1/To_Face]"), model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_2_1/To_Face]"), 5, 10, 120)
96 Cylinder_30 = model.addCylinder(Part_1_doc, "r2", "h2", "angle")
97
98 model.do()
99 model.end()
100
101 # Checks
102 from GeomAPI import GeomAPI_Shape
103
104 model.testNbResults(Cylinder_1, 1)
105 model.testNbSubResults(Cylinder_1, [0])
106 model.testNbSubShapes(Cylinder_1, GeomAPI_Shape.SOLID, [1])
107 model.testNbSubShapes(Cylinder_1, GeomAPI_Shape.FACE, [3])
108 model.testHaveNamingFaces(Cylinder_1, model, Part_1_doc)
109
110 model.testNbResults(Cylinder_2, 1)
111 model.testNbSubResults(Cylinder_2, [0])
112 model.testNbSubShapes(Cylinder_2, GeomAPI_Shape.SOLID, [1])
113 model.testNbSubShapes(Cylinder_2, GeomAPI_Shape.FACE, [3])
114 model.testHaveNamingFaces(Cylinder_2, model, Part_1_doc)
115
116 model.testNbResults(Cylinder_3, 1)
117 model.testNbSubResults(Cylinder_3, [0])
118 model.testNbSubShapes(Cylinder_3, GeomAPI_Shape.SOLID, [1])
119 model.testNbSubShapes(Cylinder_3, GeomAPI_Shape.FACE, [3])
120 model.testHaveNamingFaces(Cylinder_3, model, Part_1_doc)
121
122 model.testNbResults(Cylinder_10, 1)
123 model.testNbSubResults(Cylinder_10, [0])
124 model.testNbSubShapes(Cylinder_10, GeomAPI_Shape.SOLID, [1])
125 model.testNbSubShapes(Cylinder_10, GeomAPI_Shape.FACE, [3])
126 model.testHaveNamingFaces(Cylinder_10, model, Part_1_doc)
127
128 model.testNbResults(Cylinder_11, 1)
129 model.testNbSubResults(Cylinder_11, [0])
130 model.testNbSubShapes(Cylinder_11, GeomAPI_Shape.SOLID, [1])
131 model.testNbSubShapes(Cylinder_11, GeomAPI_Shape.FACE, [3])
132 model.testHaveNamingFaces(Cylinder_11, model, Part_1_doc)
133
134 model.testNbResults(Cylinder_12, 1)
135 model.testNbSubResults(Cylinder_12, [0])
136 model.testNbSubShapes(Cylinder_12, GeomAPI_Shape.SOLID, [1])
137 model.testNbSubShapes(Cylinder_12, GeomAPI_Shape.FACE, [3])
138 model.testHaveNamingFaces(Cylinder_12, model, Part_1_doc)
139
140 model.testNbResults(Cylinder_13, 1)
141 model.testNbSubResults(Cylinder_13, [0])
142 model.testNbSubShapes(Cylinder_13, GeomAPI_Shape.SOLID, [1])
143 model.testNbSubShapes(Cylinder_13, GeomAPI_Shape.FACE, [3])
144 model.testHaveNamingFaces(Cylinder_13, model, Part_1_doc)
145
146 model.testNbResults(Cylinder_14, 1)
147 model.testNbSubResults(Cylinder_14, [0])
148 model.testNbSubShapes(Cylinder_14, GeomAPI_Shape.SOLID, [1])
149 model.testNbSubShapes(Cylinder_14, GeomAPI_Shape.FACE, [5])
150 model.testHaveNamingFaces(Cylinder_14, model, Part_1_doc)
151
152 model.testNbResults(Cylinder_15, 1)
153 model.testNbSubResults(Cylinder_15, [0])
154 model.testNbSubShapes(Cylinder_15, GeomAPI_Shape.SOLID, [1])
155 model.testNbSubShapes(Cylinder_15, GeomAPI_Shape.FACE, [5])
156 model.testHaveNamingFaces(Cylinder_15, model, Part_1_doc)
157
158 model.testNbResults(Cylinder_16, 1)
159 model.testNbSubResults(Cylinder_16, [0])
160 model.testNbSubShapes(Cylinder_16, GeomAPI_Shape.SOLID, [1])
161 model.testNbSubShapes(Cylinder_16, GeomAPI_Shape.FACE, [5])
162 model.testHaveNamingFaces(Cylinder_16, model, Part_1_doc)
163
164 model.testNbResults(Cylinder_17, 1)
165 model.testNbSubResults(Cylinder_17, [0])
166 model.testNbSubShapes(Cylinder_17, GeomAPI_Shape.SOLID, [1])
167 model.testNbSubShapes(Cylinder_17, GeomAPI_Shape.FACE, [3])
168 model.testHaveNamingFaces(Cylinder_17, model, Part_1_doc)
169
170 model.testNbResults(Cylinder_27, 1)
171 model.testNbSubResults(Cylinder_27, [0])
172 model.testNbSubShapes(Cylinder_27, GeomAPI_Shape.SOLID, [1])
173 model.testNbSubShapes(Cylinder_27, GeomAPI_Shape.FACE, [5])
174 model.testHaveNamingFaces(Cylinder_27, model, Part_1_doc)
175
176 model.testNbResults(Cylinder_28, 1)
177 model.testNbSubResults(Cylinder_28, [0])
178 model.testNbSubShapes(Cylinder_28, GeomAPI_Shape.SOLID, [1])
179 model.testNbSubShapes(Cylinder_28, GeomAPI_Shape.FACE, [5])
180 model.testHaveNamingFaces(Cylinder_28, model, Part_1_doc)
181
182 model.testNbResults(Cylinder_29, 1)
183 model.testNbSubResults(Cylinder_29, [0])
184 model.testNbSubShapes(Cylinder_29, GeomAPI_Shape.SOLID, [1])
185 model.testNbSubShapes(Cylinder_29, GeomAPI_Shape.FACE, [5])
186 model.testHaveNamingFaces(Cylinder_29, model, Part_1_doc)
187
188 model.testNbResults(Cylinder_30, 1)
189 model.testNbSubResults(Cylinder_30, [0])
190 model.testNbSubShapes(Cylinder_30, GeomAPI_Shape.SOLID, [1])
191 model.testNbSubShapes(Cylinder_30, GeomAPI_Shape.FACE, [5])
192 model.testHaveNamingFaces(Cylinder_30, model, Part_1_doc)
193
194 model.testNbResults(Cylinder_4, 0)
195 assert(Cylinder_4.feature().error() == "Cylinder builder :: radius is negative or null.")
196
197 model.testNbResults(Cylinder_5, 0)
198 assert(Cylinder_5.feature().error() == "Cylinder builder :: radius is negative or null.")
199
200 model.testNbResults(Cylinder_6, 0)
201 assert(Cylinder_6.feature().error() == "Cylinder builder :: height is negative or null.")
202
203 model.testNbResults(Cylinder_7, 0)
204 assert(Cylinder_7.feature().error() == "Cylinder builder :: height is negative or null.")
205
206 # To uncomment when #2044 will be performed.
207 #model.testNbResults(Cylinder_8, 0)
208 #assert(Cylinder_8.feature().error() == "Attribute \"base_point\" is not initialized")
209
210 # To uncomment when #2044 will be performed.
211 #model.testNbResults(Cylinder_9, 0)
212 #assert(Cylinder_9.feature().error() == "Attribute \"axis\" is not initialized")
213
214 model.testNbResults(Cylinder_18, 0)
215 assert(Cylinder_18.feature().error() == "Cylinder builder :: radius is negative or null.")
216
217 model.testNbResults(Cylinder_19, 0)
218 assert(Cylinder_19.feature().error() == "Cylinder builder :: radius is negative or null.")
219
220 model.testNbResults(Cylinder_20, 0)
221 assert(Cylinder_20.feature().error() == "Cylinder builder :: height is negative or null.")
222
223 model.testNbResults(Cylinder_21, 0)
224 assert(Cylinder_21.feature().error() == "Cylinder builder :: height is negative or null.")
225
226 model.testNbResults(Cylinder_22, 0)
227 assert(Cylinder_22.feature().error() == "Cylinder builder :: angle is negative or null.")
228
229 model.testNbResults(Cylinder_23, 0)
230 assert(Cylinder_23.feature().error() == "Cylinder builder :: angle is negative or null.")
231
232 model.testNbResults(Cylinder_24, 0)
233 assert(Cylinder_24.feature().error() == "Cylinder builder :: angle greater than 360 degrees.")
234
235 # To uncomment when #2044 will be performed.
236 #model.testNbResults(Cylinder_25, 0)
237 #assert(Cylinder_25.feature().error() == "Attribute \"base_point\" is not initialized")
238
239 # To uncomment when #2044 will be performed.
240 #model.testNbResults(Cylinder_26, 0)
241 #assert(Cylinder_26.feature().error() == "Attribute \"axis\" is not initialized")