Salome HOME
d81298acc02ea3280196416a777a2e5cb93d3a33
[modules/shaper.git] / test.API / SHAPER / Transformations / TestSymmetry.py
1 # Copyright (C) 2014-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 """
21 Test case for Symmetry feature.
22 Written on High API.
23 """
24 from salome.shaper import model
25
26 model.begin()
27 partSet = model.moduleDocument()
28 Part_1 = model.addPart(partSet)
29 Part_1_doc = Part_1.document()
30
31 # Boxes
32 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
33 Box_2 = model.addBox(Part_1_doc, 10, 10, 10)
34 Box_3 = model.addBox(Part_1_doc, 10, 10, 10)
35 Box_4 = model.addBox(Part_1_doc, 10, 10, 10)
36 Box_5 = model.addBox(Part_1_doc, 10, 10, 10)
37 Box_6 = model.addBox(Part_1_doc, 10, 10, 10)
38 Box_7 = model.addBox(Part_1_doc, 10, 10, 10)
39 Box_8 = model.addBox(Part_1_doc, 10, 10, 10)
40 Box_9 = model.addBox(Part_1_doc, 10, 10, 10)
41 Box_10 = model.addBox(Part_1_doc, 10, 10, 10)
42 Box_11 = model.addBox(Part_1_doc, 10, 10, 10)
43 Box_12 = model.addBox(Part_1_doc, 10, 10, 10)
44 Box_13 = model.addBox(Part_1_doc, 10, 10, 10)
45 Box_14 = model.addBox(Part_1_doc, 10, 10, 10)
46 Box_15 = model.addBox(Part_1_doc, 10, 10, 10)
47 Box_16 = model.addBox(Part_1_doc, 10, 10, 10)
48 Box_17 = model.addBox(Part_1_doc, 10, 10, 10)
49 Box_18 = model.addBox(Part_1_doc, 10, 10, 10)
50 Box_19 = model.addBox(Part_1_doc, 10, 10, 10)
51 Box_20 = model.addBox(Part_1_doc, 10, 10, 10)
52
53 # Points
54 Point_1 = model.addPoint(Part_1_doc, -10, -10, -10)
55
56 # Axes
57 Axis_1 = model.addAxis(Part_1_doc, 10, 10, 20)
58
59 # Sketches
60 # Sketch comportant une ligne n'ayant dont les extremites ne coincident pas avec l'origine
61 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
62 SketchLine_1 = Sketch_1.addLine(-60.61265429508839, -83.21124437581197, 133.0036727560886, 114.0582209216138)
63
64 # Sketch comportant une contour ferme de 4 lignes
65 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
66 SketchLine_2 = Sketch_2.addLine(82.71019756173548, 167.8442841418389, -114.8596207554555, -2.66979472427181)
67 SketchLine_3 = Sketch_2.addLine(-114.8596207554555, -2.66979472427181, 102.2154980962352, -58.03968011252918)
68 SketchLine_4 = Sketch_2.addLine(102.2154980962352, -58.03968011252918, 240.6402115668787, 65.28415552495312)
69 SketchLine_5 = Sketch_2.addLine(240.6402115668787, 65.28415552495312, 82.71019756173548, 167.8442841418389)
70 SketchConstraintCoincidence_1 = Sketch_2.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
71 SketchConstraintCoincidence_2 = Sketch_2.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
72 SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
73 SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_2.startPoint(), SketchLine_5.endPoint())
74
75 # Sketch comportant un contour ferme de 5 lignes
76 Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
77 SketchLine_6 = Sketch_3.addLine(26.85462764597397, 67.26291526312015, -53.39765785606262, 39.86755675840885)
78 SketchLine_7 = Sketch_3.addLine(-53.39765785606262, 39.86755675840885, -33.73745939974039, -8.799491879372397)
79 SketchLine_8 = Sketch_3.addLine(-33.73745939974039, -8.799491879372397, 33.30059435296487, -32.6495686952387)
80 SketchLine_9 = Sketch_3.addLine(33.30059435296487, -32.6495686952387, 19.44176593293446, 18.5958666253389)
81 SketchLine_10 = Sketch_3.addLine(19.44176593293446, 18.5958666253389, 26.85462764597397, 67.26291526312015)
82 SketchConstraintCoincidence_1 = Sketch_3.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
83 SketchConstraintCoincidence_2 = Sketch_3.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
84 SketchConstraintCoincidence_3 = Sketch_3.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint())
85 SketchConstraintCoincidence_4 = Sketch_3.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint())
86 SketchConstraintCoincidence_5 = Sketch_3.setCoincident(SketchLine_6.startPoint(), SketchLine_10.endPoint())
87
88 model.do()
89
90 # Vertexes
91 Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/SketchLine_1_EndVertex")])
92
93 # Edges
94 Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_1")])
95
96 # Wire & Extrusion
97 Wire_1 = model.addWire(Part_1_doc, [model.selection("WIRE", "Sketch_3/Face-SketchLine_6r-SketchLine_7f-SketchLine_8f-SketchLine_9f-SketchLine_10f_wire")])
98 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection(), 50, 0)
99
100 # Planes
101 Plane_1 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_14_1/Top"), 10, False)
102 Plane_2 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOZ"), 40, False)
103
104 # Faces
105 Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_2/Face-SketchLine_2r-SketchLine_3f-SketchLine_4f-SketchLine_5f_wire")])
106
107
108 # Symmetries
109 Symmetry_1 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("VERTEX", "PartSet/Origin"))
110 Symmetry_2 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_2_1")], model.selection("VERTEX", "Point_1"))
111 Symmetry_3 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("VERTEX", "[Box_3_1/Front][Box_3_1/Right][Box_3_1/Top]"))
112 Symmetry_4 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_4_1")], model.selection("VERTEX", "Sketch_1/SketchLine_1_EndVertex"))
113 Symmetry_5 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_5_1")], model.selection("VERTEX", "Vertex_1_1"))
114 Symmetry_6 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_6_1")], model.selection("VERTEX", "InvalidName"))
115 Symmetry_7 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_7_1")], model.selection("VERTEX", "PartSet/Origin"), False)
116
117 Symmetry_8 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_8_1")], model.selection("EDGE", "PartSet/OZ"))
118 Symmetry_9 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_9_1")], model.selection("EDGE", "Axis_1"))
119 Symmetry_10 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_10_1")], model.selection("EDGE", "[Box_9_1/Front][Box_9_1/Top]"))
120 Symmetry_11 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_11_1")], model.selection("EDGE", "Sketch_1/SketchLine_1"))
121 Symmetry_12 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_12_1")], model.selection("EDGE", "Edge_1_1"))
122 Symmetry_13 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_13_1")], model.selection("EDGE", "InvalidName"))
123 Symmetry_14 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_14_1")], model.selection("EDGE", "PartSet/OZ"), False)
124
125 Symmetry_15 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_15_1")], model.selection("FACE", "PartSet/XOY"))
126 Symmetry_16 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_16_1")], model.selection("FACE", "Plane_1"))
127 Symmetry_17 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_17_1")], model.selection("FACE", "Box_15_1/Front"))
128 Symmetry_18 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_18_1")], model.selection("FACE", "Face_1_1"))
129 Symmetry_19 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_19_1")], model.selection("FACE", "InvalidName"))
130 Symmetry_20 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_20_1")], model.selection("FACE", "PartSet/XOY"), False)
131 Symmetry_21 = model.addSymmetry(Part_1_doc, [model.selection("SHELL", "Extrusion_1_1")], model.selection("FACE", "Plane_2"))
132
133 model.do()
134 model.end()
135
136 # Checks
137 from GeomAPI import GeomAPI_Shape
138
139 model.testNbResults(Symmetry_1, 1)
140 model.testNbSubResults(Symmetry_1, [2])
141 model.testNbSubShapes(Symmetry_1, GeomAPI_Shape.SOLID, [2])
142 model.testNbSubShapes(Symmetry_1, GeomAPI_Shape.FACE, [12])
143 model.testHaveNamingFaces(Symmetry_1, model, Part_1_doc)
144
145 model.testNbResults(Symmetry_2, 1)
146 model.testNbSubResults(Symmetry_2, [2])
147 model.testNbSubShapes(Symmetry_2, GeomAPI_Shape.SOLID, [2])
148 model.testNbSubShapes(Symmetry_2, GeomAPI_Shape.FACE, [12])
149 model.testHaveNamingFaces(Symmetry_2, model, Part_1_doc)
150
151 model.testNbResults(Symmetry_3, 1)
152 model.testNbSubResults(Symmetry_3, [2])
153 model.testNbSubShapes(Symmetry_3, GeomAPI_Shape.SOLID, [2])
154 model.testNbSubShapes(Symmetry_3, GeomAPI_Shape.FACE, [12])
155 model.testHaveNamingFaces(Symmetry_3, model, Part_1_doc)
156
157 model.testNbResults(Symmetry_4, 1)
158 model.testNbSubResults(Symmetry_4, [2])
159 model.testNbSubShapes(Symmetry_4, GeomAPI_Shape.SOLID, [2])
160 model.testNbSubShapes(Symmetry_4, GeomAPI_Shape.FACE, [12])
161 model.testHaveNamingFaces(Symmetry_4, model, Part_1_doc)
162
163 model.testNbResults(Symmetry_5, 1)
164 model.testNbSubResults(Symmetry_5, [2])
165 model.testNbSubShapes(Symmetry_5, GeomAPI_Shape.SOLID, [2])
166 model.testNbSubShapes(Symmetry_5, GeomAPI_Shape.FACE, [12])
167 model.testHaveNamingFaces(Symmetry_5, model, Part_1_doc)
168
169 model.testNbResults(Symmetry_7, 1)
170 model.testNbSubResults(Symmetry_7, [0])
171 model.testNbSubShapes(Symmetry_7, GeomAPI_Shape.SOLID, [1])
172 model.testNbSubShapes(Symmetry_7, GeomAPI_Shape.FACE, [6])
173 model.testHaveNamingFaces(Symmetry_7, model, Part_1_doc)
174
175 model.testNbResults(Symmetry_8, 1)
176 model.testNbSubResults(Symmetry_8, [2])
177 model.testNbSubShapes(Symmetry_8, GeomAPI_Shape.SOLID, [2])
178 model.testNbSubShapes(Symmetry_8, GeomAPI_Shape.FACE, [12])
179 model.testHaveNamingFaces(Symmetry_8, model, Part_1_doc)
180
181 model.testNbResults(Symmetry_9, 1)
182 model.testNbSubResults(Symmetry_9, [2])
183 model.testNbSubShapes(Symmetry_9, GeomAPI_Shape.SOLID, [2])
184 model.testNbSubShapes(Symmetry_9, GeomAPI_Shape.FACE, [12])
185 model.testHaveNamingFaces(Symmetry_9, model, Part_1_doc)
186
187 model.testNbResults(Symmetry_10, 1)
188 model.testNbSubResults(Symmetry_10, [2])
189 model.testNbSubShapes(Symmetry_10, GeomAPI_Shape.SOLID, [2])
190 model.testNbSubShapes(Symmetry_10, GeomAPI_Shape.FACE, [12])
191 model.testHaveNamingFaces(Symmetry_10, model, Part_1_doc)
192
193 model.testNbResults(Symmetry_11, 1)
194 model.testNbSubResults(Symmetry_11, [2])
195 model.testNbSubShapes(Symmetry_11, GeomAPI_Shape.SOLID, [2])
196 model.testNbSubShapes(Symmetry_11, GeomAPI_Shape.FACE, [12])
197 model.testHaveNamingFaces(Symmetry_11, model, Part_1_doc)
198
199 model.testNbResults(Symmetry_12, 1)
200 model.testNbSubResults(Symmetry_12, [2])
201 model.testNbSubShapes(Symmetry_12, GeomAPI_Shape.SOLID, [2])
202 model.testNbSubShapes(Symmetry_12, GeomAPI_Shape.FACE, [12])
203 model.testHaveNamingFaces(Symmetry_12, model, Part_1_doc)
204
205 model.testNbResults(Symmetry_14, 1)
206 model.testNbSubResults(Symmetry_14, [0])
207 model.testNbSubShapes(Symmetry_14, GeomAPI_Shape.SOLID, [1])
208 model.testNbSubShapes(Symmetry_14, GeomAPI_Shape.FACE, [6])
209 model.testHaveNamingFaces(Symmetry_14, model, Part_1_doc)
210
211 model.testNbResults(Symmetry_15, 1)
212 model.testNbSubResults(Symmetry_15, [2])
213 model.testNbSubShapes(Symmetry_15, GeomAPI_Shape.SOLID, [2])
214 model.testNbSubShapes(Symmetry_15, GeomAPI_Shape.FACE, [12])
215 model.testHaveNamingFaces(Symmetry_15, model, Part_1_doc)
216
217 model.testNbResults(Symmetry_16, 1)
218 model.testNbSubResults(Symmetry_16, [2])
219 model.testNbSubShapes(Symmetry_16, GeomAPI_Shape.SOLID, [2])
220 model.testNbSubShapes(Symmetry_16, GeomAPI_Shape.FACE, [12])
221 model.testHaveNamingFaces(Symmetry_16, model, Part_1_doc)
222
223 model.testNbResults(Symmetry_17, 1)
224 model.testNbSubResults(Symmetry_17, [2])
225 model.testNbSubShapes(Symmetry_17, GeomAPI_Shape.SOLID, [2])
226 model.testNbSubShapes(Symmetry_17, GeomAPI_Shape.FACE, [12])
227 model.testHaveNamingFaces(Symmetry_17, model, Part_1_doc)
228
229 model.testNbResults(Symmetry_18, 1)
230 model.testNbSubResults(Symmetry_18, [2])
231 model.testNbSubShapes(Symmetry_18, GeomAPI_Shape.SOLID, [2])
232 model.testNbSubShapes(Symmetry_18, GeomAPI_Shape.FACE, [12])
233 model.testHaveNamingFaces(Symmetry_18, model, Part_1_doc)
234
235 model.testNbResults(Symmetry_20, 1)
236 model.testNbSubResults(Symmetry_20, [0])
237 model.testNbSubShapes(Symmetry_20, GeomAPI_Shape.SOLID, [1])
238 model.testNbSubShapes(Symmetry_20, GeomAPI_Shape.FACE, [6])
239 model.testHaveNamingFaces(Symmetry_20, model, Part_1_doc)
240
241 model.testNbResults(Symmetry_6, 0)
242 assert(Symmetry_6.feature().error() == 'Attribute "point_object" is not initialized.')
243
244 model.testNbResults(Symmetry_13, 0)
245 assert(Symmetry_13.feature().error() == 'Attribute "axis_object" is not initialized.')
246
247 model.testNbResults(Symmetry_19, 0)
248 assert(Symmetry_19.feature().error() == 'Attribute "plane_object" is not initialized.')
249
250 model.testNbResults(Symmetry_21, 1)
251 model.testNbSubResults(Symmetry_21, [2])
252 model.testNbSubShapes(Symmetry_21, GeomAPI_Shape.SOLID, [0])
253 model.testNbSubShapes(Symmetry_21, GeomAPI_Shape.SHELL, [2])
254 model.testNbSubShapes(Symmetry_21, GeomAPI_Shape.FACE, [10])
255 model.testHaveNamingFaces(Symmetry_21, model, Part_1_doc)