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 *
25 from GeomDataAPI import *
27 __updated__ = "2017-11-24"
29 aSession = ModelAPI_Session.get()
32 def newPoint(theDocument, theX, theY, theZ):
33 aSession.startOperation()
34 aPoint = theDocument.addFeature("Point")
35 aPointData = aPoint.data()
36 assert(aPointData is not None)
37 geomDataAPI_Point(aPointData.attribute("point3d")).setValue(theX, theY, theZ)
38 aPointData.string("creation_method").setValue("by_xyz")
39 aSession.finishOperation()
43 #=========================================================================
44 # Prepare some features and folders
45 #=========================================================================
46 aSession.startOperation()
47 aPart = aSession.moduleDocument().addFeature("Part")
48 aSession.finishOperation()
51 aPartDoc = aSession.activeDocument()
52 aPoint1 = newPoint(aPartDoc, 0., 0., 0.)
53 aPoint2 = newPoint(aPartDoc, 10., 0., 0.)
54 aPoint3 = newPoint(aPartDoc, 10., 10., 0.)
55 aPoint4 = newPoint(aPartDoc, 0., 10., 0.)
58 aSession.startOperation()
59 aFolder1 = aPartDoc.addFolder(aPoint2)
60 aSession.finishOperation()
61 aSession.startOperation()
62 aFolder2 = aPartDoc.addFolder(aPoint2)
63 aSession.finishOperation()
64 aSession.startOperation()
65 aFolder3 = aPartDoc.addFolder(aPoint3)
66 aSession.finishOperation()
68 # place points into folders
69 toFolder = FeatureList()
70 toFolder.append(aPoint1)
72 aSession.startOperation()
73 aFolder = aPartDoc.findFolderBelow(toFolder)
74 assert(aFolder is not None)
75 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
76 aSession.finishOperation()
79 toFolder = FeatureList()
80 toFolder.append(aPoint3)
81 toFolder.append(aPoint4)
83 aSession.startOperation()
84 aFolder = aPartDoc.findFolderAbove(toFolder)
85 assert(aFolder is not None)
86 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
87 aSession.finishOperation()
93 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
94 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 assert(aPartDoc.index(aFolder1, True) == 0), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder1, True))
97 assert(aPartDoc.index(aFolder2, True) == 1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2, True))
98 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
100 assert(aPartDoc.index(aPoint1, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint1, True))
101 assert(aPartDoc.index(aPoint2, True) == 2), "Wrong index of the point: {}".format(aPartDoc.index(aPoint2, True))
102 assert(aPartDoc.index(aPoint3, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True))
103 assert(aPartDoc.index(aPoint4, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
106 #=========================================================================
107 # Test 1. Remove empty folder
108 #=========================================================================
109 aSession.startOperation()
110 aPartDoc.removeFolder(aFolder2)
111 aSession.finishOperation()
113 NB_FEATURES_FULL -= 1
116 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
117 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
119 assert(aPartDoc.index(aFolder1, True) == 0), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder1, True))
120 assert(aPartDoc.index(aFolder2, True) == -1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2, True))
121 assert(aPartDoc.index(aFolder3, True) == 2), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
123 assert(aPartDoc.index(aPoint1, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint1, True))
124 assert(aPartDoc.index(aPoint2, True) == 1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint2, True))
125 assert(aPartDoc.index(aPoint3, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True))
126 assert(aPartDoc.index(aPoint4, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
129 #=========================================================================
130 # Test 2. Remove non-empty folder
131 #=========================================================================
132 aSession.startOperation()
133 aPartDoc.removeFolder(aFolder3)
134 aSession.finishOperation()
136 NB_FEATURES_FULL -= 1
139 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
140 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
142 assert(aPartDoc.index(aFolder1, True) == 0), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder1, True))
143 assert(aPartDoc.index(aFolder2, True) == -1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2, True))
144 assert(aPartDoc.index(aFolder3, True) == -1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
146 assert(aPartDoc.index(aPoint1, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint1, True))
147 assert(aPartDoc.index(aPoint2, True) == 1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint2, True))
148 assert(aPartDoc.index(aPoint3, True) == 2), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True))
149 assert(aPartDoc.index(aPoint4, True) == 3), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
152 from salome.shaper import model
153 assert(model.checkPythonDump())