Salome HOME
Fix for the unit-tests that use not HighAPI pythion interface to create construction...
[modules/shaper.git] / src / ModelAPI / Test / TestFolder_Remove.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 from GeomDataAPI import *
26
27 __updated__ = "2017-11-24"
28
29 aSession = ModelAPI_Session.get()
30
31
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()
40     return aPoint
41
42
43 #=========================================================================
44 # Prepare some features and folders
45 #=========================================================================
46 aSession.startOperation()
47 aPart = aSession.moduleDocument().addFeature("Part")
48 aSession.finishOperation()
49
50 # add points
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.)
56
57 # add folders
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()
67
68 # place points into folders
69 toFolder = FeatureList()
70 toFolder.append(aPoint1)
71
72 aSession.startOperation()
73 aFolder = aPartDoc.findFolderBelow(toFolder)
74 assert(aFolder is not None)
75 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
76 aSession.finishOperation()
77 assert(isAdded)
78
79 toFolder = FeatureList()
80 toFolder.append(aPoint3)
81 toFolder.append(aPoint4)
82
83 aSession.startOperation()
84 aFolder = aPartDoc.findFolderAbove(toFolder)
85 assert(aFolder is not None)
86 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
87 aSession.finishOperation()
88 assert(isAdded)
89
90 NB_FEATURES_FULL = 7
91 NB_FEATURES_OUT  = 4
92
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)
95
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))
99
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))
104
105
106 #=========================================================================
107 # Test 1. Remove empty folder
108 #=========================================================================
109 aSession.startOperation()
110 aPartDoc.removeFolder(aFolder2)
111 aSession.finishOperation()
112
113 NB_FEATURES_FULL -= 1
114 NB_FEATURES_OUT  -= 1
115
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)
118
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))
122
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))
127
128
129 #=========================================================================
130 # Test 2. Remove non-empty folder
131 #=========================================================================
132 aSession.startOperation()
133 aPartDoc.removeFolder(aFolder3)
134 aSession.finishOperation()
135
136 NB_FEATURES_FULL -= 1
137 NB_FEATURES_OUT  += 1
138
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)
141
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))
145
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))
150
151
152 from salome.shaper import model
153 assert(model.checkPythonDump())