Salome HOME
Merge commit 'refs/tags/V9_2_0^{}'
[modules/shaper.git] / test.API / SHAPER / Transformations / TestMultiTranslation.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 MultiTranslation 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 # Create 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
43 # Create Sketches
44 # Sketch contenant un contour ferme de 3 lignes
45 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
46 SketchLine_1 = Sketch_1.addLine(20.57127738485033, 88.55774147773481, -110.037034305799, -25.45393392073257)
47 SketchLine_2 = Sketch_1.addLine(-110.037034305799, -25.45393392073257, 49.43499267560162, -77.40862144408482)
48 SketchLine_3 = Sketch_1.addLine(49.43499267560162, -77.40862144408482, 68.1964076145899, 55.3644688933709)
49 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
50 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
51
52 # Sketch creer sur la face de la box confondue avec le plan XOZ contenant un cercle inclus dans la face de la box
53 Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_9_1/Left"))
54 SketchCircle_1 = Sketch_2.addCircle(3.420516499282639, 6.702654232424678, 2.660489383382409)
55 model.do()
56
57 # Create Wire & Extrusion
58 Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchLine_2"), model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_3")])
59 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection("EDGE", "PartSet/OZ"), 50, 0)
60
61 # Revolution of the circle
62 Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("WIRE", "Sketch_2/Face-SketchCircle_1_2r_wire")], model.selection("EDGE", "PartSet/OZ"), 360, 0)
63
64 # Create MultiTranslations
65 MultiTranslation_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 15, 5)
66 MultiTranslation_2 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_2_1")], model.selection("EDGE", "PartSet/OX"), -15, 5)
67 MultiTranslation_3 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OX"), 15, -2)
68 MultiTranslation_4 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_4_1")], model.selection("EDGE", "InvalidName"), 15, -2)
69 MultiTranslation_5 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_5_1")], model.selection("EDGE", "PartSet/OX"), 10, 5, model.selection("EDGE", "PartSet/OY"), 10, 5)
70 MultiTranslation_6 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_6_1")], model.selection("EDGE", "PartSet/OX"), 10, 5, model.selection("EDGE", "PartSet/OY"), -10, 5)
71 MultiTranslation_7 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_7_1")], model.selection("EDGE", "PartSet/OX"), 10, 5, model.selection("EDGE", "PartSet/OY"), 10, -2)
72 MultiTranslation_8 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_8_1")], model.selection("EDGE", "PartSet/OX"), 10, 5, model.selection("EDGE", "InvalidName"), 10, 5)
73 MultiTranslation_9 = model.addMultiTranslation(Part_1_doc, [model.selection("SHELL", "Extrusion_1_1")], model.selection("EDGE", "PartSet/OZ"), 50, 10)
74 MultiTranslation_10 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Revolution_1_1"), model.selection("SOLID", "Box_9_1")], model.selection("EDGE", "PartSet/OY"), 20, 3)
75
76 model.do()
77 model.end()
78
79
80
81 # Checks
82 from GeomAPI import GeomAPI_Shape, GeomAPI_ShapeExplorer
83 from GeomAlgoAPI import *
84
85 model.testNbResults(MultiTranslation_1, 1)
86 model.testNbSubResults(MultiTranslation_1, [5])
87 model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.COMPOUND, [1])
88 model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.SOLID, [5])
89 model.testNbSubShapes(MultiTranslation_1, GeomAPI_Shape.FACE, [30])
90 model.testHaveNamingFaces(MultiTranslation_1, model, Part_1_doc)
91
92 model.testNbResults(MultiTranslation_2, 1)
93 model.testNbSubResults(MultiTranslation_2, [5])
94 model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.COMPOUND, [1])
95 model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.SOLID, [5])
96 model.testNbSubShapes(MultiTranslation_2, GeomAPI_Shape.FACE, [30])
97 model.testHaveNamingFaces(MultiTranslation_2, model, Part_1_doc)
98
99 model.testNbResults(MultiTranslation_5, 1)
100 model.testNbSubResults(MultiTranslation_5, [25])
101 model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.COMPOUND, [1])
102 model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.SOLID, [25])
103 model.testNbSubShapes(MultiTranslation_5, GeomAPI_Shape.FACE, [150])
104 model.testHaveNamingFaces(MultiTranslation_5, model, Part_1_doc)
105
106 model.testNbResults(MultiTranslation_6, 1)
107 model.testNbSubResults(MultiTranslation_6, [25])
108 model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.COMPOUND, [1])
109 model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.SOLID, [25])
110 model.testNbSubShapes(MultiTranslation_6, GeomAPI_Shape.FACE, [150])
111 model.testHaveNamingFaces(MultiTranslation_6, model, Part_1_doc)
112
113 ####################################################################################################
114 # Test of MultiTranslation 10
115 model.testNbResults(MultiTranslation_10, 2)
116 model.testNbSubResults(MultiTranslation_10, [3, 3])
117
118 def testSubResult(theFeature, theModel, thePartDoc, resultIndex, nbSolidsExpected, nbFacesExpected):
119     result = theFeature.results()[resultIndex].resultSubShapePair()[0]
120     shape = result.shape()
121     shapeExplorer = GeomAPI_ShapeExplorer(shape, GeomAPI_Shape.SOLID)
122     nbSolids = 0
123     while shapeExplorer.more():
124         nbSolids += 1
125         shapeExplorer.next()
126     assert(nbSolids == nbSolidsExpected)
127
128     shapeExplorer = GeomAPI_ShapeExplorer(shape, GeomAPI_Shape.FACE)
129     nbFaces = 0
130     selectionList = []
131     while shapeExplorer.more():
132         nbFaces += 1
133         selection = theModel.selection(result, shapeExplorer.current()) # First argument should be result/sub-result, second is sub-shape on this result/sub-result
134         selectionList.append(selection)
135         shapeExplorer.next()
136     assert(nbFaces == nbFacesExpected)
137     # Create group with this selection list
138     Group_1 = theModel.addGroup(thePartDoc, selectionList)
139     theModel.do()
140     theModel.end()
141
142     # Now you can check that all selected shapes in group have right shape type and name.
143     groupFeature = Group_1.feature()
144     groupSelectionList = groupFeature.selectionList("group_list")
145     theModel.end()
146     assert(groupSelectionList.size() == len(selectionList))
147     for index in range(0, groupSelectionList.size()):
148         attrSelection = groupSelectionList.value(index)
149         shape = attrSelection.value()
150         name = attrSelection.namingName()
151         assert(shape.isFace())
152         assert(name != ""), "String empty"
153
154 testSubResult(MultiTranslation_10, model, Part_1_doc, 0, 3, 3)
155 testSubResult(MultiTranslation_10, model, Part_1_doc, 1, 3, 18)
156 ####################################################################################################
157
158 model.testNbResults(MultiTranslation_3, 0)
159 assert(MultiTranslation_3.feature().error() == 'Multitranslation builder :: the number of copies for the first direction is null or negative.')
160
161 model.testNbResults(MultiTranslation_4, 0)
162 assert(MultiTranslation_4.feature().error() == 'Attribute "axis_first_dir" is not initialized.')
163
164 model.testNbResults(MultiTranslation_7, 0)
165 assert(MultiTranslation_7.feature().error() == 'Multitranslation builder :: the number of copies for the second direction is null or negative.')
166
167 model.testNbResults(MultiTranslation_8, 0)
168 assert(MultiTranslation_8.feature().error() == 'Attribute "axis_second_dir" is not initialized.')
169
170
171 # Multitranslation en erreur
172 #model.testNbResults(MultiTranslation_9, 1)
173 #model.testNbSubResults(MultiTranslation_9, [10])
174 #model.testNbSubShapes(MultiTranslation_9, GeomAPI_Shape.COMPOUND, [1])
175 #model.testNbSubShapes(MultiTranslation_9, GeomAPI_Shape.SOLID, [0])
176 #model.testNbSubShapes(MultiTranslation_9, GeomAPI_Shape.SHELL, [10])
177 #model.testNbSubShapes(MultiTranslation_9, GeomAPI_Shape.FACE, [30])
178 #model.testHaveNamingFaces(MultiTranslation_9, model, Part_1_doc)