1 # Copyright (C) 2014-2020 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #=========================================================================
21 # Initialization of the test
22 #=========================================================================
23 from ModelAPI import *
24 from GeomDataAPI import *
26 __updated__ = "2017-11-23"
28 aSession = ModelAPI_Session.get()
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 geomDataAPI_Point(aPointData.attribute("point3d")).setValue(theX, theY, theZ)
37 aPointData.string("creation_method").setValue("by_xyz")
38 aSession.finishOperation()
42 #=========================================================================
43 # Test 1. Add a point into a folder above
44 #=========================================================================
45 aSession.startOperation()
46 aPart = aSession.moduleDocument().addFeature("Part")
47 aSession.finishOperation()
49 # add point and a folder before it
50 aPartDoc = aSession.activeDocument()
51 aPoint1 = newPoint(aPartDoc, 0., 0., 0.)
53 aSession.startOperation()
54 aFolder1 = aPartDoc.addFolder(aPoint1)
55 aSession.finishOperation()
60 assert(aPartDoc.size("Folders") == 1), "Wrong number of folders: {}".format(aPartDoc.size("Folders"))
61 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}".format(aPartDoc.size("Features"))
62 FOLDER_NAME_EXPECTED = "Folder_1"
63 assert(aFolder1.name() == FOLDER_NAME_EXPECTED), "Actual name '{}', expected '{}'".format(aFolder1.name(), FOLDER_NAME_EXPECTED)
65 toFolder = FeatureList()
66 toFolder.append(aPoint1)
68 # move point to the folder
69 aSession.startOperation()
70 aFolder = aPartDoc.findFolderAbove(toFolder)
71 assert(aFolder is not None)
72 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
73 aSession.finishOperation()
76 # full number of features
77 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
78 # number of features outside the folder
79 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
81 # check the index of the point in the folder
82 aFound = aPartDoc.findContainingFolder(aPoint1)
83 assert(aFound[0].data().isEqual(aFolder1.data()))
84 assert(aFound[1] == 0)
86 #=========================================================================
87 # Test 2. Add a point, check it is added to a folder, then move it out
88 #=========================================================================
89 aPoint2 = newPoint(aPartDoc, 10., 0., 0.)
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)
95 fromFolder = FeatureList()
96 fromFolder.append(aPoint2)
98 aSession.startOperation()
99 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
100 aSession.finishOperation()
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)
107 #=========================================================================
108 # Test 3. Add a point into a folder below
109 #=========================================================================
110 aPoint3 = newPoint(aPartDoc, 10., 10., 0.)
112 NB_FEATURES_FULL += 1
116 aSession.startOperation()
117 aFolder2 = aPartDoc.addFolder(aPoint3)
118 aSession.finishOperation()
120 NB_FEATURES_FULL += 1
123 assert(aPartDoc.size("Folders") == 2), "Wrong number of folders: {}".format(aPartDoc.size("Folders"))
124 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
125 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
127 toFolder = FeatureList()
128 toFolder.append(aPoint2)
130 # move point to the folder
131 aSession.startOperation()
132 aFolder = aPartDoc.findFolderBelow(toFolder)
133 assert(aFolder is not None)
134 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
135 aSession.finishOperation()
140 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
141 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
143 # check the index of the point in the folder
144 aFound = aPartDoc.findContainingFolder(aPoint2)
145 assert(aFound[0].data().isEqual(aFolder2.data()))
146 assert(aFound[1] == 0)
147 aFound = aPartDoc.findContainingFolder(aPoint3)
150 #=========================================================================
151 # Test 4. Add several points into a folder
152 #=========================================================================
153 aPoint4 = newPoint(aPartDoc, 0., 10., 0.)
155 NB_FEATURES_FULL += 1
158 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
159 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
161 # index without respect to foldering
162 assert(aPartDoc.index(aPoint4) == 5), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4))
163 # index according to folders
164 assert(aPartDoc.index(aPoint4, True) == 3), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
167 aSession.startOperation()
168 aFolder3 = aPartDoc.addFolder(aPoint3)
169 aSession.finishOperation()
171 NB_FEATURES_FULL += 1
174 assert(aPartDoc.size("Folders") == 3), "Wrong number of folders: {}".format(aPartDoc.size("Folders"))
175 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
176 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
178 # index without respect to foldering
179 assert(aPartDoc.index(aFolder3) == 4), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3))
180 assert(aPartDoc.index(aPoint4) == 6), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4))
181 # index according to folders
182 assert(aPartDoc.index(aFolder3, True) == 2), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
183 assert(aPartDoc.index(aPoint4, True) == 4), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
185 toFolder = FeatureList()
186 toFolder.append(aPoint3)
187 toFolder.append(aPoint4)
189 # move point to the folder
190 aSession.startOperation()
191 aFolder = aPartDoc.findFolderAbove(toFolder)
192 assert(aFolder is not None)
193 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
194 aSession.finishOperation()
199 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
200 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
202 # index without respect to foldering
203 assert(aPartDoc.index(aFolder3) == 4), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3))
204 assert(aPartDoc.index(aPoint3) == 5), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3))
205 assert(aPartDoc.index(aPoint4) == 6), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4))
206 # index according to folders
207 assert(aPartDoc.index(aFolder3, True) == 2), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
208 assert(aPartDoc.index(aPoint3, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True))
209 assert(aPartDoc.index(aPoint4, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
211 # check the index of the point in the folder
212 aFound = aPartDoc.findContainingFolder(aPoint3)
213 assert(aFound[0].data().isEqual(aFolder3.data()))
214 assert(aFound[1] == 0)
215 aFound = aPartDoc.findContainingFolder(aPoint4)
216 assert(aFound[0].data().isEqual(aFolder3.data()))
217 assert(aFound[1] == 1)
219 aPoint5 = newPoint(aPartDoc, 0., 0., 10.)
220 fromFolder = FeatureList()
221 fromFolder.append(aPoint5)
223 aSession.startOperation()
224 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
225 aSession.finishOperation()
228 # add more points to the folder to move them out
229 aPoint6 = newPoint(aPartDoc, 10., 0., 10.)
230 aPoint7 = newPoint(aPartDoc, 10., 10., 10.)
231 aPoint8 = newPoint(aPartDoc, 0., 10., 10.)
233 toFolder = FeatureList()
234 toFolder.append(aPoint5)
235 toFolder.append(aPoint6)
236 toFolder.append(aPoint7)
237 toFolder.append(aPoint8)
239 # move point to the folder
240 aSession.startOperation()
241 aFolder = aPartDoc.findFolderAbove(toFolder)
242 assert(aFolder is not None)
243 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
244 aSession.finishOperation()
247 NB_FEATURES_FULL += 4
248 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
249 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
251 assert(aPartDoc.index(aPoint5, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint5, True))
252 assert(aPartDoc.index(aPoint6, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint6, True))
253 assert(aPartDoc.index(aPoint7, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint7, True))
254 assert(aPartDoc.index(aPoint8, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint8, True))
256 assert(aFolder3.reference("first_feature").value() is not None)
257 assert(aFolder3.reference("last_feature").value() is not None)
259 #=========================================================================
260 # Test 5. Remove a point from a folder before it
261 #=========================================================================
262 fromFolder = FeatureList()
263 fromFolder.append(aPoint3)
265 aSession.startOperation()
266 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
267 aSession.finishOperation()
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)
274 assert(aPartDoc.index(aPoint3, True) == 2), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True))
275 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
277 assert(aFolder3.reference("first_feature").value() is not None)
278 assert(aFolder3.reference("last_feature").value() is not None)
280 #=========================================================================
281 # Test 6. Remove a point from a folder after it
282 #=========================================================================
283 fromFolder = FeatureList()
284 fromFolder.append(aPoint8)
286 aSession.startOperation()
287 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
288 aSession.finishOperation()
292 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
293 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
295 assert(aPartDoc.index(aPoint8, True) == 4), "Wrong index of the point: {}".format(aPartDoc.index(aPoint8, True))
296 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
298 assert(aFolder3.reference("first_feature").value() is not None)
299 assert(aFolder3.reference("last_feature").value() is not None)
301 #=========================================================================
302 # Test 7. Try to remove several points which are not start nor end in a folder
303 #=========================================================================
304 fromFolder = FeatureList()
305 fromFolder.append(aPoint5)
306 fromFolder.append(aPoint6)
308 aSession.startOperation()
309 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
310 aSession.finishOperation()
311 assert(isMovedOut is False)
313 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
314 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
316 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
317 assert(aPartDoc.index(aPoint5, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint5, True))
318 assert(aPartDoc.index(aPoint6, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint6, True))
319 assert(aPartDoc.index(aPoint8, True) == 4), "Wrong index of the point: {}".format(aPartDoc.index(aPoint8, True))
321 assert(aFolder3.reference("first_feature").value() is not None)
322 assert(aFolder3.reference("last_feature").value() is not None)
324 #=========================================================================
325 # Test 8. Remove several points from a folder after it
326 #=========================================================================
327 fromFolder = FeatureList()
328 fromFolder.append(aPoint6)
329 fromFolder.append(aPoint7)
331 aSession.startOperation()
332 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
333 aSession.finishOperation()
337 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
338 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
340 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
341 assert(aPartDoc.index(aPoint6, True) == 4), "Wrong index of the point: {}".format(aPartDoc.index(aPoint6, True))
342 assert(aPartDoc.index(aPoint7, True) == 5), "Wrong index of the point: {}".format(aPartDoc.index(aPoint7, True))
343 assert(aPartDoc.index(aPoint8, True) == 6), "Wrong index of the point: {}".format(aPartDoc.index(aPoint8, True))
345 assert(aFolder3.reference("first_feature").value() is not None)
346 assert(aFolder3.reference("last_feature").value() is not None)
348 #=========================================================================
349 # Test 9. Remove all remaining points from a folder after it
350 #=========================================================================
351 fromFolder = FeatureList()
352 fromFolder.append(aPoint4)
353 fromFolder.append(aPoint5)
355 aSession.startOperation()
356 isMovedOut = aPartDoc.removeFromFolder(fromFolder, False)
357 aSession.finishOperation()
361 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
362 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
364 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
365 assert(aPartDoc.index(aPoint4, True) == 4), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
366 assert(aPartDoc.index(aPoint5, True) == 5), "Wrong index of the point: {}".format(aPartDoc.index(aPoint5, True))
367 assert(aPartDoc.index(aPoint6, True) == 6), "Wrong index of the point: {}".format(aPartDoc.index(aPoint6, True))
368 assert(aPartDoc.index(aPoint7, True) == 7), "Wrong index of the point: {}".format(aPartDoc.index(aPoint7, True))
369 assert(aPartDoc.index(aPoint8, True) == 8), "Wrong index of the point: {}".format(aPartDoc.index(aPoint8, True))
372 assert(aFolder3.reference("first_feature").value() is None)
373 assert(aFolder3.reference("last_feature").value() is None)
374 # remove empty folder
375 aSession.startOperation()
376 aPartDoc.removeFolder(aFolder3)
377 aSession.finishOperation()
379 from salome.shaper import model
380 assert(model.checkPythonDump())