Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / test.API / SHAPER / Transformations / TestScale.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 Scale 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 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
52 # Create Sketches
53 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
54 SketchLine_1 = Sketch_1.addLine(11.50379459310504, -12.39258082761096, 58.75227313132206, 54.23988890577205)
55
56 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
57 SketchLine_2 = Sketch_2.addLine(41.58300156386008, 83.65088639460937, -69.84532559339473, 11.87498196448581)
58 SketchLine_3 = Sketch_2.addLine(-69.84532559339473, 11.87498196448581, -47.25850252097817, -30.78901717230093)
59 SketchLine_4 = Sketch_2.addLine(-47.25850252097817, -30.78901717230093, 108.3396119778911, -36.812169991612)
60 SketchLine_5 = Sketch_2.addLine(108.3396119778911, -36.812169991612, 35.05791934293975, 16.39234657896911)
61 SketchLine_6 = Sketch_2.addLine(35.05791934293975, 16.39234657896911, 41.58300156386008, 83.65088639460937)
62 SketchConstraintCoincidence_1 = Sketch_2.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
63 SketchConstraintCoincidence_2 = Sketch_2.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
64 SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
65 SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
66 SketchConstraintCoincidence_5 = Sketch_2.setCoincident(SketchLine_2.startPoint(), SketchLine_6.endPoint())
67 model.do()
68
69 # Create Points
70 Point_1 = model.addPoint(Part_1_doc, -10, -10, -10)
71
72 # Create Vertexes
73 Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Sketch_1/Vertex-SketchLine_1e")])
74
75 # Create Wire & Extrusion
76 Wire_1 = model.addWire(Part_1_doc, [model.selection("WIRE", "Sketch_2/Wire-SketchLine_2f-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f")])
77 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection(), 50, 0)
78
79 # Create Scales
80 Scale_1 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_1_1")] , model.selection("VERTEX", "PartSet/Origin"), 2)
81 Scale_2 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_2_1")] , model.selection("VERTEX", "Point_1"), 2)
82 Scale_3 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_3_1")] , model.selection("VERTEX", "Box_3_1/Back&Box_3_1/Left&Box_3_1/Top"), 2)
83 Scale_4 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_4_1")] , model.selection("VERTEX", "Sketch_1/Vertex-SketchLine_1e"), 2)
84 Scale_5 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_5_1")] , model.selection("VERTEX", "Vertex_1_1"), 2)
85 Scale_6 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_6_1")] , model.selection("VERTEX", "PartSet/Origin"), 0)
86 Scale_7 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_7_1")] , model.selection("VERTEX", "PartSet/Origin"), -3)
87 Scale_8 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_8_1")] , model.selection("VERTEX", "InvalidName"), 2)
88 Scale_9 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_9_1")] , model.selection("VERTEX", "PartSet/Origin"), 2 , 3, 1)
89 Scale_10 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_10_1")] , model.selection("VERTEX", "Point_1"), 2 , 3, 1)
90 Scale_11 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_11_1")] , model.selection("VERTEX", "Box_11_1/Back&Box_11_1/Right&Box_11_1/Top"), 2 , 3, 1)
91 Scale_12 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_12_1")] , model.selection("VERTEX", "Sketch_1/Vertex-SketchLine_1e"), 2 , 3, 1)
92 Scale_13 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_13_1")] , model.selection("VERTEX", "Vertex_1_1"), 2 , 3, 1)
93 Scale_14 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_14_1")] , model.selection("VERTEX", "PartSet/Origin"), 0 , 3, 1)
94 Scale_15 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_15_1")] , model.selection("VERTEX", "PartSet/Origin"), 2 , 0, 1)
95 Scale_16 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_16_1")] , model.selection("VERTEX", "PartSet/Origin"), 2 , 3, 0)
96 Scale_17 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_17_1")] , model.selection("VERTEX", "PartSet/Origin"), -2 , -3, -0.5)
97 Scale_18 = model.addScale(Part_1_doc, [model.selection("SOLID", "Box_18_1")] , model.selection("VERTEX", "InvalidName"), 2 , 3, 1)
98 Scale_19 = model.addScale(Part_1_doc, [model.selection("SHELL", "Extrusion_1_1")] , model.selection("VERTEX", "PartSet/Origin"), 5)
99
100 model.do()
101 model.end()
102
103
104 # Checks
105 from GeomAPI import GeomAPI_Shape
106
107 model.testNbResults(Scale_1, 1)
108 model.testNbSubResults(Scale_1, [0])
109 model.testNbSubShapes(Scale_1, GeomAPI_Shape.SOLID, [1])
110 model.testNbSubShapes(Scale_1, GeomAPI_Shape.FACE, [6])
111 model.testHaveNamingFaces(Scale_1, model, Part_1_doc)
112
113 model.testNbResults(Scale_2, 1)
114 model.testNbSubResults(Scale_2, [0])
115 model.testNbSubShapes(Scale_2, GeomAPI_Shape.SOLID, [1])
116 model.testNbSubShapes(Scale_2, GeomAPI_Shape.FACE, [6])
117 model.testHaveNamingFaces(Scale_2, model, Part_1_doc)
118
119 model.testNbResults(Scale_3, 1)
120 model.testNbSubResults(Scale_3, [0])
121 model.testNbSubShapes(Scale_3, GeomAPI_Shape.SOLID, [1])
122 model.testNbSubShapes(Scale_3, GeomAPI_Shape.FACE, [6])
123 model.testHaveNamingFaces(Scale_3, model, Part_1_doc)
124
125 model.testNbResults(Scale_4, 1)
126 model.testNbSubResults(Scale_4, [0])
127 model.testNbSubShapes(Scale_4, GeomAPI_Shape.SOLID, [1])
128 model.testNbSubShapes(Scale_4, GeomAPI_Shape.FACE, [6])
129 model.testHaveNamingFaces(Scale_4, model, Part_1_doc)
130
131 model.testNbResults(Scale_5, 1)
132 model.testNbSubResults(Scale_5, [0])
133 model.testNbSubShapes(Scale_5, GeomAPI_Shape.SOLID, [1])
134 model.testNbSubShapes(Scale_5, GeomAPI_Shape.FACE, [6])
135 model.testHaveNamingFaces(Scale_5, model, Part_1_doc)
136
137 model.testNbResults(Scale_7, 1)
138 model.testNbSubResults(Scale_7, [0])
139 model.testNbSubShapes(Scale_7, GeomAPI_Shape.SOLID, [1])
140 model.testNbSubShapes(Scale_7, GeomAPI_Shape.FACE, [6])
141 model.testHaveNamingFaces(Scale_7, model, Part_1_doc)
142
143 model.testNbResults(Scale_9, 1)
144 model.testNbSubResults(Scale_9, [0])
145 model.testNbSubShapes(Scale_9, GeomAPI_Shape.SOLID, [1])
146 model.testNbSubShapes(Scale_9, GeomAPI_Shape.FACE, [6])
147 model.testHaveNamingFaces(Scale_9, model, Part_1_doc)
148
149 model.testNbResults(Scale_10, 1)
150 model.testNbSubResults(Scale_10, [0])
151 model.testNbSubShapes(Scale_10, GeomAPI_Shape.SOLID, [1])
152 model.testNbSubShapes(Scale_10, GeomAPI_Shape.FACE, [6])
153 model.testHaveNamingFaces(Scale_10, model, Part_1_doc)
154
155 model.testNbResults(Scale_11, 1)
156 model.testNbSubResults(Scale_11, [0])
157 model.testNbSubShapes(Scale_11, GeomAPI_Shape.SOLID, [1])
158 model.testNbSubShapes(Scale_11, GeomAPI_Shape.FACE, [6])
159 model.testHaveNamingFaces(Scale_11, model, Part_1_doc)
160
161 model.testNbResults(Scale_12, 1)
162 model.testNbSubResults(Scale_12, [0])
163 model.testNbSubShapes(Scale_12, GeomAPI_Shape.SOLID, [1])
164 model.testNbSubShapes(Scale_12, GeomAPI_Shape.FACE, [6])
165 model.testHaveNamingFaces(Scale_12, model, Part_1_doc)
166
167 model.testNbResults(Scale_13, 1)
168 model.testNbSubResults(Scale_13, [0])
169 model.testNbSubShapes(Scale_13, GeomAPI_Shape.SOLID, [1])
170 model.testNbSubShapes(Scale_13, GeomAPI_Shape.FACE, [6])
171 model.testHaveNamingFaces(Scale_13, model, Part_1_doc)
172
173 model.testNbResults(Scale_17, 1)
174 model.testNbSubResults(Scale_17, [0])
175 model.testNbSubShapes(Scale_17, GeomAPI_Shape.SOLID, [1])
176 model.testNbSubShapes(Scale_17, GeomAPI_Shape.FACE, [6])
177 model.testHaveNamingFaces(Scale_17, model, Part_1_doc)
178
179
180 model.testNbResults(Scale_6, 0)
181 assert(Scale_6.feature().error() == 'Scale builder :: the scale factor is null.')
182
183 model.testNbResults(Scale_8, 0)
184 assert(Scale_8.feature().error() == 'Attribute "center_point" is not initialized.')
185
186 model.testNbResults(Scale_14, 0)
187 assert(Scale_14.feature().error() == 'Scale builder :: the scale factor in X is null.')
188
189 model.testNbResults(Scale_15, 0)
190 assert(Scale_15.feature().error() == 'Scale builder :: the scale factor in Y is null.')
191
192 model.testNbResults(Scale_16, 0)
193 assert(Scale_16.feature().error() == 'Scale builder :: the scale factor in Z is null.')
194
195 model.testNbResults(Scale_18, 0)
196 assert(Scale_18.feature().error() == 'Attribute "center_point" is not initialized.')
197
198 # To uncomment when #2046 will be performed
199 #model.testNbResults(Scale_19, 1)
200 #model.testNbSubResults(Scale_19, [0])
201 #model.testNbSubShapes(Scale_19, GeomAPI_Shape.SHELL, [1])
202 #model.testNbSubShapes(Scale_19, GeomAPI_Shape.SOLID, [0])
203 #model.testNbSubShapes(Scale_19, GeomAPI_Shape.FACE, [5])
204 #model.testHaveNamingFaces(Scale_19, model, Part_1_doc)