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