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