1 ## Copyright (C) 2014-2017 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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #=========================================================================
22 # Initialization of the test
23 #=========================================================================
24 from ModelAPI 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 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()
44 #=========================================================================
45 # Test 1. Add a point into a folder above
46 #=========================================================================
47 aSession.startOperation()
48 aPart = aSession.moduleDocument().addFeature("Part")
49 aSession.finishOperation()
51 # add point and a folder before it
52 aPartDoc = aSession.activeDocument()
53 aPoint1 = newPoint(aPartDoc, 0., 0., 0.)
55 aSession.startOperation()
56 aFolder1 = aPartDoc.addFolder(aPoint1)
57 aSession.finishOperation()
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)
67 toFolder = FeatureList()
68 toFolder.append(aPoint1)
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()
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)
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.)
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)
96 aSession.startOperation()
97 aFolder2 = aPartDoc.addFolder(aPoint3)
98 aSession.finishOperation()
100 NB_FEATURES_FULL += 1
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)
107 toFolder = FeatureList()
108 toFolder.append(aPoint2)
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()
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)
123 #=========================================================================
124 # Test 3. Add several points into a folder
125 #=========================================================================
126 aPoint4 = newPoint(aPartDoc, 0., 10., 0.)
128 NB_FEATURES_FULL += 1
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)
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))
140 aSession.startOperation()
141 aFolder3 = aPartDoc.addFolder(aPoint3)
142 aSession.finishOperation()
144 NB_FEATURES_FULL += 1
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)
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))
158 toFolder = FeatureList()
159 toFolder.append(aPoint3)
160 toFolder.append(aPoint4)
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()
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)
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))
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.)
191 toFolder = FeatureList()
192 toFolder.append(aPoint5)
193 toFolder.append(aPoint6)
194 toFolder.append(aPoint7)
195 toFolder.append(aPoint8)
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()
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)
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))
214 assert(aFolder3.reference("first_feature").value() is not None)
215 assert(aFolder3.reference("last_feature").value() is not None)
217 #=========================================================================
218 # Test 4. Remove a point from a folder before it
219 #=========================================================================
220 fromFolder = FeatureList()
221 fromFolder.append(aPoint3)
223 aSession.startOperation()
224 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
225 aSession.finishOperation()
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)
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))
235 assert(aFolder3.reference("first_feature").value() is not None)
236 assert(aFolder3.reference("last_feature").value() is not None)
238 #=========================================================================
239 # Test 5. Remove a point from a folder after it
240 #=========================================================================
241 fromFolder = FeatureList()
242 fromFolder.append(aPoint8)
244 aSession.startOperation()
245 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
246 aSession.finishOperation()
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)
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))
256 assert(aFolder3.reference("first_feature").value() is not None)
257 assert(aFolder3.reference("last_feature").value() is not None)
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)
266 aSession.startOperation()
267 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
268 aSession.finishOperation()
269 assert(isMovedOut is False)
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(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))
279 assert(aFolder3.reference("first_feature").value() is not None)
280 assert(aFolder3.reference("last_feature").value() is not None)
282 #=========================================================================
283 # Test 7. Remove several points from a folder after it
284 #=========================================================================
285 fromFolder = FeatureList()
286 fromFolder.append(aPoint6)
287 fromFolder.append(aPoint7)
289 aSession.startOperation()
290 isMovedOut = aPartDoc.removeFromFolder(fromFolder)
291 aSession.finishOperation()
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)
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))
303 assert(aFolder3.reference("first_feature").value() is not None)
304 assert(aFolder3.reference("last_feature").value() is not None)
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)
313 aSession.startOperation()
314 isMovedOut = aPartDoc.removeFromFolder(fromFolder, False)
315 aSession.finishOperation()
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)
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))
330 assert(aFolder3.reference("first_feature").value() is None)
331 assert(aFolder3.reference("last_feature").value() is None)
334 from salome.shaper import model
335 assert(model.checkPythonDump())