Salome HOME
05501b849532515b5146921d821c5b3ff62b932c
[modules/shaper.git] / test.API / SHAPER / Transformations / TestRotation.py
1 # Copyright (C) 2014-2021  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 email : webmaster.salome@opencascade.com
18 #
19
20 """
21 Test case for Rotation 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
48 # Create Points
49 Point_1 = model.addPoint(Part_1_doc, 20, 0, 0)
50 Point_2 = model.addPoint(Part_1_doc, 20, 20, 0)
51 Point_3 = model.addPoint(Part_1_doc, -10, 0, 0)
52
53 # Create Parts
54 Part_2 = model.addPart(partSet)
55 Part_2_doc = Part_2.document()
56 Box_16 = model.addBox(Part_2_doc, 10, 10, 10)
57 Cylinder_1 = model.addCylinder(Part_2_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
58
59 Part_3 = model.addPart(partSet)
60 Part_3_doc = Part_3.document()
61 Box_17 = model.addBox(Part_3_doc, 10, 10, 10)
62 Cylinder_1 = model.addCylinder(Part_3_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
63 Point_4 = model.addPoint(partSet, -10, 0, 0)
64 Point_5 = model.addPoint(partSet, 20, 20, 0)
65
66 model.do()
67
68 # Create Rotations
69 Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OZ"), 45)
70 Rotation_2 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_2_1")], model.selection("EDGE", "PartSet/OZ"), 0)
71 Rotation_3 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OZ"), 360)
72 Rotation_4 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_4_1")], model.selection("EDGE", "PartSet/OZ"), -360)
73 Rotation_5 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_5_1")], model.selection("EDGE", "PartSet/OZ"), 450)
74 Rotation_6 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_6_1")], model.selection("EDGE", "PartSet/OZ"), -450)
75 Rotation_7 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_7_1")], model.selection("EDGE", "InvalidName"), 180)
76
77 Rotation_9 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_8_1")], model.selection("VERTEX", "PartSet/Origin"), model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_2"))
78 Rotation_10 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_9_1")], model.selection("VERTEX", "Point_3"), model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_2"))
79 Rotation_11 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_10_1")], model.selection("VERTEX", "Point_3"), model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_1"))
80 Rotation_12 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_11_1")], model.selection("VERTEX", "Point_3"), model.selection("VERTEX", "Point_3"), model.selection("VERTEX", "Point_1"))
81 Rotation_13 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_12_1")], model.selection("VERTEX", "Point_3"), model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_3"))
82 Rotation_14 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_13_1")], model.selection("VERTEX", "PartSet/Origin"), model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "InvalidName"))
83 Rotation_15 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_14_1")], model.selection("VERTEX", "InvalidName"), model.selection("VERTEX", "Point_3"), model.selection("VERTEX", "Point_2"))
84 Rotation_16 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Box_15_1")], model.selection("VERTEX", "PartSet/Origin"), model.selection("VERTEX", "InvalidName"), model.selection("VERTEX", "Point_1"))
85
86 Rotation_18 = model.addRotation(partSet, [model.selection("COMPOUND", "Part_2/")], model.selection("EDGE", "OY"), 90)
87 Rotation_19 = model.addRotation(partSet, [model.selection("COMPOUND", "Part_3/")], model.selection("VERTEX", "Origin"), model.selection("VERTEX", "Point_2"), model.selection("VERTEX", "Point_3"))
88
89 model.do()
90 model.end()
91
92 # Checks
93 from GeomAPI import GeomAPI_Shape
94
95 model.testNbResults(Rotation_1, 1)
96 model.testNbSubResults(Rotation_1, [0])
97 model.testNbSubShapes(Rotation_1, GeomAPI_Shape.SOLID, [1])
98 model.testNbSubShapes(Rotation_1, GeomAPI_Shape.FACE, [6])
99 model.testHaveNamingFaces(Rotation_1, model, Part_1_doc)
100
101 model.testNbResults(Rotation_2, 1)
102 model.testNbSubResults(Rotation_2, [0])
103 model.testNbSubShapes(Rotation_2, GeomAPI_Shape.SOLID, [1])
104 model.testNbSubShapes(Rotation_2, GeomAPI_Shape.FACE, [6])
105 model.testHaveNamingFaces(Rotation_2, model, Part_1_doc)
106
107 model.testNbResults(Rotation_3, 1)
108 model.testNbSubResults(Rotation_3, [0])
109 model.testNbSubShapes(Rotation_3, GeomAPI_Shape.SOLID, [1])
110 model.testNbSubShapes(Rotation_3, GeomAPI_Shape.FACE, [6])
111 model.testHaveNamingFaces(Rotation_3, model, Part_1_doc)
112
113 model.testNbResults(Rotation_4, 1)
114 model.testNbSubResults(Rotation_4, [0])
115 model.testNbSubShapes(Rotation_4, GeomAPI_Shape.SOLID, [1])
116 model.testNbSubShapes(Rotation_4, GeomAPI_Shape.FACE, [6])
117 model.testHaveNamingFaces(Rotation_4, model, Part_1_doc)
118
119 model.testNbResults(Rotation_5, 1)
120 model.testNbSubResults(Rotation_5, [0])
121 model.testNbSubShapes(Rotation_5, GeomAPI_Shape.SOLID, [1])
122 model.testNbSubShapes(Rotation_5, GeomAPI_Shape.FACE, [6])
123 model.testHaveNamingFaces(Rotation_5, model, Part_1_doc)
124
125 model.testNbResults(Rotation_6, 1)
126 model.testNbSubResults(Rotation_6, [0])
127 model.testNbSubShapes(Rotation_6, GeomAPI_Shape.SOLID, [1])
128 model.testNbSubShapes(Rotation_6, GeomAPI_Shape.FACE, [6])
129 model.testHaveNamingFaces(Rotation_6, model, Part_1_doc)
130
131 model.testNbResults(Rotation_9, 1)
132 model.testNbSubResults(Rotation_9, [0])
133 model.testNbSubShapes(Rotation_9, GeomAPI_Shape.SOLID, [1])
134 model.testNbSubShapes(Rotation_9, GeomAPI_Shape.FACE, [6])
135 model.testHaveNamingFaces(Rotation_9, model, Part_1_doc)
136
137 model.testNbResults(Rotation_10, 1)
138 model.testNbSubResults(Rotation_10, [0])
139 model.testNbSubShapes(Rotation_10, GeomAPI_Shape.SOLID, [1])
140 model.testNbSubShapes(Rotation_10, GeomAPI_Shape.FACE, [6])
141 model.testHaveNamingFaces(Rotation_10, model, Part_1_doc)
142
143 model.testNbResults(Rotation_18, 1)
144 model.testNbSubResults(Rotation_18, [0])
145
146 model.testNbResults(Rotation_19, 1)
147 model.testNbSubResults(Rotation_19, [0])
148
149
150 # This test is OK because we accept angles greater than 360
151 #model.testNbResults(Rotation_5, 0)
152 #assert(Rotation_5.feature().error() == 'Rotation builder :: angle greater than 360 degrees.')
153
154 # This test is OK because we accept angles smaller than 360
155 #model.testNbResults(Rotation_6, 0)
156 #assert(Rotation_6.feature().error() == 'Rotation builder :: angle smaller than -360 degrees.')
157
158 model.testNbResults(Rotation_7, 0)
159 assert(Rotation_7.feature().error() == 'Attribute "axis_object" is not initialized.')
160
161 model.testNbResults(Rotation_11, 0)
162 assert(Rotation_11.feature().error() == "The feature uses equal shapes.")
163
164 model.testNbResults(Rotation_12, 0)
165 assert(Rotation_12.feature().error() == "The feature uses equal shapes.")
166
167 model.testNbResults(Rotation_13, 0)
168 assert(Rotation_13.feature().error() == "The feature uses equal shapes.")
169
170 model.testNbResults(Rotation_14, 0)
171 assert(Rotation_14.feature().error() == 'Attribute "end_point" is not initialized.')
172
173 model.testNbResults(Rotation_15, 0)
174 assert(Rotation_15.feature().error() == 'Attribute "center_point" is not initialized.')
175
176 model.testNbResults(Rotation_16, 0)
177 assert(Rotation_16.feature().error() == 'Attribute "start_point" is not initialized.')
178
179
180
181
182 #Rotation_8 = model.addRotation(Part_1_doc, [model.selection("SOLID", "InvalidName")], model.selection("EDGE", "PartSet/OZ"), 180)
183 #Rotation_17 = model.addRotation(Part_1_doc, [model.selection("SOLID", "InvalidName")], model.selection("VERTEX", "PartSet/Origin"), model.selection("VERTEX", "Point_3"), model.selection("VERTEX", "Point_2"))
184
185 #model.testNbResults(Rotation_8, 0)
186 #assert(Rotation_8.feature().error() == 'Attribute "main_object" is not initialized.')
187
188 #model.testNbResults(Rotation_17, 0)
189 #assert(Rotation_17.feature().error() == 'Attribute "main_object" is not initialized.')