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