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