Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / test.API / SHAPER / Transformations / TestTranslation_2.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 Translation 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 Box_21 = model.addBox(Part_1_doc, 10, 10, 10)
54 Box_22 = model.addBox(Part_1_doc, 10, 10, 10)
55 Box_23 = model.addBox(Part_1_doc, 10, 10, 10)
56 Box_24 = model.addBox(Part_1_doc, 10, 10, 10)
57 Box_25 = model.addBox(Part_1_doc, 10, 10, 10)
58 Box_26 = model.addBox(Part_1_doc, 10, 10, 10)
59 Box_27 = model.addBox(Part_1_doc, 10, 10, 10)
60 Box_28 = model.addBox(Part_1_doc, 10, 10, 10)
61 Box_29 = model.addBox(Part_1_doc, 10, 10, 10)
62 Box_30 = model.addBox(Part_1_doc, 10, 10, 10)
63 Box_31 = model.addBox(Part_1_doc, 10, 10, 10)
64 Box_32 = model.addBox(Part_1_doc, 10, 10, 10)
65 Box_33 = model.addBox(Part_1_doc, 10, 10, 10)
66 Box_34 = model.addBox(Part_1_doc, 10, 10, 10)
67 Box_35 = model.addBox(Part_1_doc, 10, 10, 10)
68 Box_36 = model.addBox(Part_1_doc, 10, 10, 10)
69
70 ####################
71 # Sketches
72 # Sketch contenant un triangle
73 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
74 SketchLine_1 = Sketch_1.addLine(105.8795836373178, 106.9780351893485, -55.30451701345322, -118.6797057217308)
75 SketchLine_2 = Sketch_1.addLine(-55.30451701345322, -118.6797057217308, -134.9484255703047, 86.11891628160174)
76 SketchLine_3 = Sketch_1.addLine(-134.9484255703047, 86.11891628160174, 105.8795836373178, 106.9780351893485)
77 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
78 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
79 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_3.endPoint())
80
81 model.do()
82
83 # Edges
84 Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/Edge-SketchLine_2")])
85
86 # Axis
87 Axis_1 = model.addAxis(Part_1_doc, 10, 10, 10)
88
89 # Parameters
90 model.addParameter(Part_1_doc, "d", "15")
91
92 # Translation 27
93 Translation_27_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 5)
94 Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_2_1")], [model.selection("SOLID", "Translation_1_1")])
95 Translation_27 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_1_1")], model.selection("EDGE", "PartSet/OX"), 15)
96
97 # Translation 28
98 Translation_28_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OX"), 5)
99 Intersection_2 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_4_1")], [model.selection("SOLID", "Translation_3_1")])
100 Translation_28 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_2_1")], model.selection("EDGE", "PartSet/OX"), 0)
101
102 # Translation 29
103 Translation_29_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_5_1")], model.selection("EDGE", "PartSet/OX"), 5)
104 Intersection_3 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_6_1")], [model.selection("SOLID", "Translation_5_1")])
105 Translation_29 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_3_1")], model.selection("EDGE", "PartSet/OX"), -15)
106
107 # Translation 30
108 Translation_30_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_7_1")], model.selection("EDGE", "PartSet/OX"), 5)
109 Intersection_4 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_8_1")], [model.selection("SOLID", "Translation_7_1")])
110 Translation_30 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_4_1")], model.selection("EDGE", "InvalidName"), -15)
111
112 # Translation 31
113 Translation_31_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_9_1")], model.selection("EDGE", "PartSet/OX"), 5)
114 Intersection_5 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_10_1")], [model.selection("SOLID", "Translation_9_1")])
115 Translation_31 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_5_1")], model.selection("EDGE", "PartSet/OY"), "d")
116
117 # Translation 32
118 Translation_32_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_11_1")], model.selection("EDGE", "PartSet/OX"), 5)
119 Intersection_6 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_12_1")], [model.selection("SOLID", "Translation_11_1")])
120 Translation_32 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_6_1")], model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"), 15)
121
122 # Translation 33
123 Translation_33_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_13_1")], model.selection("EDGE", "PartSet/OX"), 5)
124 Intersection_7 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_14_1")], [model.selection("SOLID", "Translation_13_1")])
125 Translation_33 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_7_1")], model.selection("EDGE", "Edge_1_1"), 15)
126
127 # Translation 34
128 Translation_34_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_15_1")], model.selection("EDGE", "PartSet/OX"), 5)
129 Intersection_8 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_16_1")], [model.selection("SOLID", "Translation_15_1")])
130 Translation_34 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_8_1")], model.selection("EDGE", "Intersection_8_1_6"), 15)
131
132 # Translation 35
133 Translation_35_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_17_1")], model.selection("EDGE", "PartSet/OX"), 5)
134 Intersection_9 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_18_1")], [model.selection("SOLID", "Translation_17_1")])
135 Translation_35 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_9_1")], model.selection("EDGE", "Axis_1"), 15)
136
137 #Translation 36
138 Translation_36_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_19_1")], model.selection("EDGE", "PartSet/OX"), 5)
139 Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_20_1"), model.selection("SOLID", "Translation_19_1")])
140 Translation_36 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1")], model.selection("EDGE", "PartSet/OX"), 15)
141
142 ## Translation 37
143 Translation_37_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_21_1")], model.selection("EDGE", "PartSet/OX"), 5)
144 Partition_2 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_22_1"), model.selection("SOLID", "Translation_21_1")])
145 Translation_37 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_2_1")], model.selection("EDGE", "PartSet/OX"), 0)
146
147 ## Translation 38
148 Translation_38_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_23_1")], model.selection("EDGE", "PartSet/OX"), 5)
149 Partition_3 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_24_1"), model.selection("SOLID", "Translation_23_1")])
150 Translation_38 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_3_1")], model.selection("EDGE", "PartSet/OX"), 0)
151
152 ## Translation 39
153 Translation_39_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_25_1")], model.selection("EDGE", "PartSet/OX"), 5)
154 Partition_4 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_26_1"), model.selection("SOLID", "Translation_25_1")])
155 Translation_39 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_4_1")], model.selection("EDGE", "InvalidName"), 0)
156
157 ## Translation 40
158 Translation_40_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_27_1")], model.selection("EDGE", "PartSet/OX"), 5)
159 Partition_5 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_28_1"), model.selection("SOLID", "Translation_27_1")])
160 Translation_40 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_5_1")], model.selection("EDGE", "PartSet/OX"), "d")
161
162 # Translation 41
163 Translation_41_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_29_1")], model.selection("EDGE", "PartSet/OX"), 5)
164 Partition_6 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_30_1"), model.selection("SOLID", "Translation_29_1")])
165 Translation_41 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_6_1")], model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"), 15)
166
167 # Translateion 42
168 Translation_42_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_31_1")], model.selection("EDGE", "PartSet/OX"), 5)
169 Partition_7 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_32_1"), model.selection("SOLID", "Translation_31_1")])
170 Translation_42 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_7_1")], model.selection("EDGE", "Edge_1_1"), 15)
171
172 # Translation 43
173 Translation_43_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_33_1")], model.selection("EDGE", "PartSet/OX"), 5)
174 Partition_8 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_34_1"), model.selection("SOLID", "Translation_33_1")])
175 Translation_43 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_8_1")], model.selection("EDGE", "Partition_8_1/Modified_Face_1_1_1&Partition_8_1/Modified_Face_1_9_1"), 15)
176
177 # Translation 44
178 Translation_44_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_35_1")], model.selection("EDGE", "PartSet/OX"), 5)
179 Partition_9 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_36_1"), model.selection("SOLID", "Translation_35_1")])
180 Translation_44 = model.addTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_9_1")], model.selection("EDGE", "Axis_1"), 15)
181 model.do()
182 model.end()
183
184
185 # Checks
186 from GeomAPI import GeomAPI_Shape
187 from GeomAPI import GeomAPI_ShapeExplorer
188
189 def testHaveNamingEdges(theFeature, theModel, thePartDoc) :
190   """ Tests if all faces of result have a name
191   :param theFeature: feature to test.
192   """
193   # Get feature result/sub-result
194   aResult = theFeature.results()[0].resultSubShapePair()[0]
195   # Get result/sub-result shape
196   shape = aResult.shape()
197   # Create shape explorer with desired shape type
198   shapeExplorer = GeomAPI_ShapeExplorer(shape, GeomAPI_Shape.EDGE)
199   # Create list, and store selections in it
200   selectionList = []
201   while shapeExplorer.more():
202     selection = theModel.selection(aResult, shapeExplorer.current()) # First argument should be result/sub-result, second is sub-shape on this result/sub-result
203     selectionList.append(selection)
204     shapeExplorer.next()
205   # Create group with this selection list
206   Group_1 = theModel.addGroup(thePartDoc, selectionList)
207   theModel.do()
208   theModel.end()
209
210   # Now you can check that all selected shapes in group have right shape type and name.
211   groupFeature = Group_1.feature()
212   groupSelectionList = groupFeature.selectionList("group_list")
213   theModel.end()
214   assert(groupSelectionList.size() == len(selectionList))
215   for index in range(0, groupSelectionList.size()):
216     attrSelection = groupSelectionList.value(index)
217     shape = attrSelection.value()
218     name = attrSelection.namingName()
219     assert(shape.isEdge())
220     assert(name != ""), "String empty"
221
222 # Translation 27
223 model.testNbResults(Translation_27, 1)
224 model.testNbSubResults(Translation_27, [12])
225 model.testNbSubShapes(Translation_27, GeomAPI_Shape.SOLID, [0])
226 model.testNbSubShapes(Translation_27, GeomAPI_Shape.EDGE, [12])
227 testHaveNamingEdges(Translation_27, model, Part_1_doc)
228
229 # Translation 28
230 model.testNbResults(Translation_28, 1)
231 model.testNbSubResults(Translation_28, [12])
232 model.testNbSubShapes(Translation_28, GeomAPI_Shape.SOLID, [0])
233 model.testNbSubShapes(Translation_28, GeomAPI_Shape.EDGE, [12])
234 testHaveNamingEdges(Translation_28, model, Part_1_doc)
235
236 # Translation 29
237 model.testNbResults(Translation_29, 1)
238 model.testNbSubResults(Translation_29, [12])
239 model.testNbSubShapes(Translation_29, GeomAPI_Shape.SOLID, [0])
240 model.testNbSubShapes(Translation_29, GeomAPI_Shape.EDGE, [12])
241 testHaveNamingEdges(Translation_29, model, Part_1_doc)
242
243 # Translation 31
244 model.testNbResults(Translation_31, 1)
245 model.testNbSubResults(Translation_31, [12])
246 model.testNbSubShapes(Translation_31, GeomAPI_Shape.SOLID, [0])
247 model.testNbSubShapes(Translation_31, GeomAPI_Shape.EDGE, [12])
248 testHaveNamingEdges(Translation_31, model, Part_1_doc)
249
250 # Translation 32
251 model.testNbResults(Translation_32, 1)
252 model.testNbSubResults(Translation_32, [12])
253 model.testNbSubShapes(Translation_32, GeomAPI_Shape.SOLID, [0])
254 model.testNbSubShapes(Translation_32, GeomAPI_Shape.EDGE, [12])
255 testHaveNamingEdges(Translation_32, model, Part_1_doc)
256
257 # Translation 33
258 model.testNbResults(Translation_33, 1)
259 model.testNbSubResults(Translation_33, [12])
260 model.testNbSubShapes(Translation_33, GeomAPI_Shape.SOLID, [0])
261 model.testNbSubShapes(Translation_33, GeomAPI_Shape.EDGE, [12])
262 testHaveNamingEdges(Translation_33, model, Part_1_doc)
263
264 # Translation 34
265 model.testNbResults(Translation_34, 1)
266 model.testNbSubResults(Translation_34, [12])
267 model.testNbSubShapes(Translation_34, GeomAPI_Shape.SOLID, [0])
268 model.testNbSubShapes(Translation_34, GeomAPI_Shape.EDGE, [12])
269 testHaveNamingEdges(Translation_34, model, Part_1_doc)
270
271 # Translation 35
272 model.testNbResults(Translation_35, 1)
273 model.testNbSubResults(Translation_35, [12])
274 model.testNbSubShapes(Translation_35, GeomAPI_Shape.SOLID, [0])
275 model.testNbSubShapes(Translation_35, GeomAPI_Shape.EDGE, [12])
276 testHaveNamingEdges(Translation_35, model, Part_1_doc)
277
278 # Translation 36
279 model.testNbResults(Translation_36, 1)
280 model.testNbSubResults(Translation_36, [3])
281 model.testNbSubShapes(Translation_36, GeomAPI_Shape.COMPSOLID, [1])
282 model.testNbSubShapes(Translation_36, GeomAPI_Shape.SOLID, [3])
283 model.testNbSubShapes(Translation_36, GeomAPI_Shape.FACE, [18])
284 model.testHaveNamingFaces(Translation_36, model, Part_1_doc)
285
286 # Translation 37
287 model.testNbResults(Translation_37, 1)
288 model.testNbSubResults(Translation_37, [3])
289 model.testNbSubShapes(Translation_37, GeomAPI_Shape.COMPSOLID, [1])
290 model.testNbSubShapes(Translation_37, GeomAPI_Shape.SOLID, [3])
291 model.testNbSubShapes(Translation_37, GeomAPI_Shape.FACE, [18])
292 model.testHaveNamingFaces(Translation_37, model, Part_1_doc)
293
294 # Translation 38
295 model.testNbResults(Translation_38, 1)
296 model.testNbSubResults(Translation_38, [3])
297 model.testNbSubShapes(Translation_38, GeomAPI_Shape.COMPSOLID, [1])
298 model.testNbSubShapes(Translation_38, GeomAPI_Shape.SOLID, [3])
299 model.testNbSubShapes(Translation_38, GeomAPI_Shape.FACE, [18])
300 model.testHaveNamingFaces(Translation_38, model, Part_1_doc)
301
302 # Translation 40
303 model.testNbResults(Translation_40, 1)
304 model.testNbSubResults(Translation_40, [3])
305 model.testNbSubShapes(Translation_40, GeomAPI_Shape.COMPSOLID, [1])
306 model.testNbSubShapes(Translation_40, GeomAPI_Shape.SOLID, [3])
307 model.testNbSubShapes(Translation_40, GeomAPI_Shape.FACE, [18])
308 model.testHaveNamingFaces(Translation_40, model, Part_1_doc)
309
310 # Translation 41
311 model.testNbResults(Translation_41, 1)
312 model.testNbSubResults(Translation_41, [3])
313 model.testNbSubShapes(Translation_41, GeomAPI_Shape.COMPSOLID, [1])
314 model.testNbSubShapes(Translation_41, GeomAPI_Shape.SOLID, [3])
315 model.testNbSubShapes(Translation_41, GeomAPI_Shape.FACE, [18])
316 model.testHaveNamingFaces(Translation_41, model, Part_1_doc)
317
318 # Translation 42
319 model.testNbResults(Translation_42, 1)
320 model.testNbSubResults(Translation_42, [3])
321 model.testNbSubShapes(Translation_42, GeomAPI_Shape.COMPSOLID, [1])
322 model.testNbSubShapes(Translation_42, GeomAPI_Shape.SOLID, [3])
323 model.testNbSubShapes(Translation_42, GeomAPI_Shape.FACE, [18])
324 model.testHaveNamingFaces(Translation_42, model, Part_1_doc)
325
326 # Translation 43
327 model.testNbResults(Translation_43, 1)
328 model.testNbSubResults(Translation_43, [3])
329 model.testNbSubShapes(Translation_43, GeomAPI_Shape.COMPSOLID, [1])
330 model.testNbSubShapes(Translation_43, GeomAPI_Shape.SOLID, [3])
331 model.testNbSubShapes(Translation_43, GeomAPI_Shape.FACE, [18])
332 model.testHaveNamingFaces(Translation_43, model, Part_1_doc)
333
334 # Translation 44
335 model.testNbResults(Translation_44, 1)
336 model.testNbSubResults(Translation_44, [3])
337 model.testNbSubShapes(Translation_44, GeomAPI_Shape.COMPSOLID, [1])
338 model.testNbSubShapes(Translation_44, GeomAPI_Shape.SOLID, [3])
339 model.testNbSubShapes(Translation_44, GeomAPI_Shape.FACE, [18])
340 model.testHaveNamingFaces(Translation_44, model, Part_1_doc)
341
342 # Translation 30
343 model.testNbResults(Translation_30, 0)
344 assert(Translation_30.feature().error() == 'Attribute "axis_object" is not initialized.')
345
346 # Translation 39
347 model.testNbResults(Translation_39, 0)
348 assert(Translation_39.feature().error() == 'Attribute "axis_object" is not initialized.')