]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/Test/TestFolder_Update.py
Salome HOME
Methods to remove features from folders (Task 2.3. Ability to put consecutive Feature...
[modules/shaper.git] / src / ModelAPI / Test / TestFolder_Update.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 # Initialization of the test
23 #=========================================================================
24 from ModelAPI import *
25
26 __updated__ = "2017-11-23"
27
28 aSession = ModelAPI_Session.get()
29
30
31 def newPoint(theDocument, theX, theY, theZ):
32     aSession.startOperation()
33     aPoint = theDocument.addFeature("Point")
34     aPointData = aPoint.data()
35     assert(aPointData is not None)
36     aPointData.real("x").setValue(theX)
37     aPointData.real("y").setValue(theY)
38     aPointData.real("z").setValue(theZ)
39     aPointData.string("creation_method").setValue("by_xyz")
40     aSession.finishOperation()
41     return aPoint
42
43
44 #=========================================================================
45 # Test 1. Add a point into a folder above
46 #=========================================================================
47 aSession.startOperation()
48 aPart = aSession.moduleDocument().addFeature("Part")
49 aSession.finishOperation()
50
51 # add point and a folder before it
52 aPartDoc = aSession.activeDocument()
53 aPoint1 = newPoint(aPartDoc, 0., 0., 0.)
54
55 aSession.startOperation()
56 aFolder1 = aPartDoc.addFolder(aPoint1)
57 aSession.finishOperation()
58
59 NB_FEATURES_FULL = 2
60 NB_FEATURES_OUT  = 2
61
62 assert(aPartDoc.size("Folders") == 1), "Wrong number of folders: {}".format(aPartDoc.size("Folders"))
63 assert(aPartDoc.size("Features") == 2), "Wrong number of features: {}".format(aPartDoc.size("Features"))
64 FOLDER_NAME_EXPECTED = "Folder_1"
65 assert(aFolder1.name() == FOLDER_NAME_EXPECTED), "Actual name '{}', expected '{}'".format(aFolder1.name(), FOLDER_NAME_EXPECTED)
66
67 toFolder = FeatureList()
68 toFolder.append(aPoint1)
69
70 # move point to the folder
71 aSession.startOperation()
72 aFolder = aPartDoc.findFolderAbove(toFolder)
73 assert(aFolder is not None)
74 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
75 aSession.finishOperation()
76 assert(isAdded)
77 NB_FEATURES_OUT -= 1
78 # full number of features
79 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
80 # number of features outside the folder
81 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
82
83 #=========================================================================
84 # Test 2. Add a point into a folder below
85 #=========================================================================
86 aPoint2 = newPoint(aPartDoc, 10., 0., 0.)
87 aPoint3 = newPoint(aPartDoc, 10., 10., 0.)
88
89 NB_FEATURES_FULL += 2
90 NB_FEATURES_OUT += 2
91
92 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
93 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
94
95 # add a folder
96 aSession.startOperation()
97 aFolder2 = aPartDoc.addFolder(aPoint3)
98 aSession.finishOperation()
99
100 NB_FEATURES_FULL += 1
101 NB_FEATURES_OUT += 1
102
103 assert(aPartDoc.size("Folders") == 2), "Wrong number of folders: {}".format(aPartDoc.size("Folders"))
104 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
105 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
106
107 toFolder = FeatureList()
108 toFolder.append(aPoint2)
109
110 # move point to the folder
111 aSession.startOperation()
112 aFolder = aPartDoc.findFolderBelow(toFolder)
113 assert(aFolder is not None)
114 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
115 aSession.finishOperation()
116 assert(isAdded)
117
118 NB_FEATURES_OUT -= 1
119
120 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
121 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
122
123 #=========================================================================
124 # Test 3. Add several points into a folder
125 #=========================================================================
126 aPoint4 = newPoint(aPartDoc, 0., 10., 0.)
127
128 NB_FEATURES_FULL += 1
129 NB_FEATURES_OUT += 1
130
131 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
132 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
133
134 # index without respect to foldering
135 assert(aPartDoc.index(aPoint4) == 5), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4))
136 # index according to folders
137 assert(aPartDoc.index(aPoint4, True) == 3), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
138
139 # add a folder
140 aSession.startOperation()
141 aFolder3 = aPartDoc.addFolder(aPoint3)
142 aSession.finishOperation()
143
144 NB_FEATURES_FULL += 1
145 NB_FEATURES_OUT += 1
146
147 assert(aPartDoc.size("Folders") == 3), "Wrong number of folders: {}".format(aPartDoc.size("Folders"))
148 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
149 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
150
151 # index without respect to foldering
152 assert(aPartDoc.index(aFolder3) == 4), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3))
153 assert(aPartDoc.index(aPoint4) == 6), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4))
154 # index according to folders
155 assert(aPartDoc.index(aFolder3, True) == 2), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
156 assert(aPartDoc.index(aPoint4, True) == 4), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
157
158 toFolder = FeatureList()
159 toFolder.append(aPoint3)
160 toFolder.append(aPoint4)
161
162 # move point to the folder
163 aSession.startOperation()
164 aFolder = aPartDoc.findFolderAbove(toFolder)
165 assert(aFolder is not None)
166 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
167 aSession.finishOperation()
168 assert(isAdded)
169
170 NB_FEATURES_OUT -= 2
171
172 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
173 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
174
175 # index without respect to foldering
176 assert(aPartDoc.index(aFolder3) == 4), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3))
177 assert(aPartDoc.index(aPoint3) == 5), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3))
178 assert(aPartDoc.index(aPoint4) == 6), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4))
179 # index according to folders
180 assert(aPartDoc.index(aFolder3, True) == 2), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
181 assert(aPartDoc.index(aPoint3, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True))
182 assert(aPartDoc.index(aPoint4, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
183
184
185 # add more points to the folder to move them out
186 aPoint5 = newPoint(aPartDoc, 0., 0., 10.)
187 aPoint6 = newPoint(aPartDoc, 10., 0., 10.)
188 aPoint7 = newPoint(aPartDoc, 10., 10., 10.)
189 aPoint8 = newPoint(aPartDoc, 0., 10., 10.)
190
191 toFolder = FeatureList()
192 toFolder.append(aPoint5)
193 toFolder.append(aPoint6)
194 toFolder.append(aPoint7)
195 toFolder.append(aPoint8)
196
197 # move point to the folder
198 aSession.startOperation()
199 aFolder = aPartDoc.findFolderAbove(toFolder)
200 assert(aFolder is not None)
201 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
202 aSession.finishOperation()
203 assert(isAdded)
204
205 NB_FEATURES_FULL += 4
206 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
207 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
208
209 assert(aPartDoc.index(aPoint5, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint5, True))
210 assert(aPartDoc.index(aPoint6, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint6, True))
211 assert(aPartDoc.index(aPoint7, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint7, True))
212 assert(aPartDoc.index(aPoint8, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint8, True))
213
214 assert(aFolder3.reference("first_feature").value() is not None)
215 assert(aFolder3.reference("last_feature").value() is not None)
216
217 #=========================================================================
218 # Test 4. Remove a point from a folder before it
219 #=========================================================================
220 fromFolder = FeatureList()
221 fromFolder.append(aPoint3)
222
223 aSession.startOperation()
224 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
225 aSession.finishOperation()
226 assert(isMovedOut)
227
228 NB_FEATURES_OUT += 1
229 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
230 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
231
232 assert(aPartDoc.index(aPoint3, True) == 2), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True))
233 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
234
235 assert(aFolder3.reference("first_feature").value() is not None)
236 assert(aFolder3.reference("last_feature").value() is not None)
237
238 #=========================================================================
239 # Test 5. Remove a point from a folder after it
240 #=========================================================================
241 fromFolder = FeatureList()
242 fromFolder.append(aPoint8)
243
244 aSession.startOperation()
245 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
246 aSession.finishOperation()
247 assert(isMovedOut)
248
249 NB_FEATURES_OUT += 1
250 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
251 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
252
253 assert(aPartDoc.index(aPoint8, True) == 4), "Wrong index of the point: {}".format(aPartDoc.index(aPoint8, True))
254 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
255
256 assert(aFolder3.reference("first_feature").value() is not None)
257 assert(aFolder3.reference("last_feature").value() is not None)
258
259 #=========================================================================
260 # Test 6. Try to remove several points which are not start nor end in a folder
261 #=========================================================================
262 fromFolder = FeatureList()
263 fromFolder.append(aPoint5)
264 fromFolder.append(aPoint6)
265
266 aSession.startOperation()
267 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
268 aSession.finishOperation()
269 assert(isMovedOut is False)
270
271 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
272 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
273
274 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
275 assert(aPartDoc.index(aPoint5, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint5, True))
276 assert(aPartDoc.index(aPoint6, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint6, True))
277 assert(aPartDoc.index(aPoint8, True) == 4), "Wrong index of the point: {}".format(aPartDoc.index(aPoint8, True))
278
279 assert(aFolder3.reference("first_feature").value() is not None)
280 assert(aFolder3.reference("last_feature").value() is not None)
281
282 #=========================================================================
283 # Test 7. Remove several points from a folder after it
284 #=========================================================================
285 fromFolder = FeatureList()
286 fromFolder.append(aPoint6)
287 fromFolder.append(aPoint7)
288
289 aSession.startOperation()
290 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
291 aSession.finishOperation()
292 assert(isMovedOut)
293
294 NB_FEATURES_OUT += 2
295 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
296 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
297
298 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
299 assert(aPartDoc.index(aPoint6, True) == 4), "Wrong index of the point: {}".format(aPartDoc.index(aPoint6, True))
300 assert(aPartDoc.index(aPoint7, True) == 5), "Wrong index of the point: {}".format(aPartDoc.index(aPoint7, True))
301 assert(aPartDoc.index(aPoint8, True) == 6), "Wrong index of the point: {}".format(aPartDoc.index(aPoint8, True))
302
303 assert(aFolder3.reference("first_feature").value() is not None)
304 assert(aFolder3.reference("last_feature").value() is not None)
305
306 #=========================================================================
307 # Test 8. Remove all remaining points from a folder after it
308 #=========================================================================
309 fromFolder = FeatureList()
310 fromFolder.append(aPoint4)
311 fromFolder.append(aPoint5)
312
313 aSession.startOperation()
314 isMovedOut = aPartDoc.removeFromFolder(fromFolder, False)
315 aSession.finishOperation()
316 assert(isMovedOut)
317
318 NB_FEATURES_OUT += 2
319 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
320 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
321
322 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
323 assert(aPartDoc.index(aPoint4, True) == 4), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
324 assert(aPartDoc.index(aPoint5, True) == 5), "Wrong index of the point: {}".format(aPartDoc.index(aPoint5, True))
325 assert(aPartDoc.index(aPoint6, True) == 6), "Wrong index of the point: {}".format(aPartDoc.index(aPoint6, True))
326 assert(aPartDoc.index(aPoint7, True) == 7), "Wrong index of the point: {}".format(aPartDoc.index(aPoint7, True))
327 assert(aPartDoc.index(aPoint8, True) == 8), "Wrong index of the point: {}".format(aPartDoc.index(aPoint8, True))
328
329 # folder is empty
330 assert(aFolder3.reference("first_feature").value() is None)
331 assert(aFolder3.reference("last_feature").value() is None)
332
333
334 from salome.shaper import model
335 assert(model.checkPythonDump())