]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/Test/TestFolder_Remove.py
Salome HOME
Issue #19058: Error in sketch projection when changing parameter
[modules/shaper.git] / src / ModelAPI / Test / TestFolder_Remove.py
1 # Copyright (C) 2014-2020  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 email : webmaster.salome@opencascade.com
18 #
19
20 #=========================================================================
21 # Initialization of the test
22 #=========================================================================
23 from ModelAPI import *
24 from GeomDataAPI import *
25
26 __updated__ = "2017-11-24"
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     geomDataAPI_Point(aPointData.attribute("point3d")).setValue(theX, theY, theZ)
37     aPointData.string("creation_method").setValue("by_xyz")
38     aSession.finishOperation()
39     return aPoint
40
41
42 #=========================================================================
43 # Prepare some features and folders
44 #=========================================================================
45 aSession.startOperation()
46 aPart = aSession.moduleDocument().addFeature("Part")
47 aSession.finishOperation()
48
49 # add points
50 aPartDoc = aSession.activeDocument()
51 aPoint1 = newPoint(aPartDoc,  0.,  0., 0.)
52 aPoint2 = newPoint(aPartDoc, 10.,  0., 0.)
53 aPoint3 = newPoint(aPartDoc, 10., 10., 0.)
54 aPoint4 = newPoint(aPartDoc,  0., 10., 0.)
55
56 # add folders
57 aSession.startOperation()
58 aFolder1 = aPartDoc.addFolder(aPoint2)
59 aSession.finishOperation()
60 aSession.startOperation()
61 aFolder2 = aPartDoc.addFolder(aPoint2)
62 aSession.finishOperation()
63 aSession.startOperation()
64 aFolder3 = aPartDoc.addFolder(aPoint3)
65 aSession.finishOperation()
66
67 # place points into folders
68 toFolder = FeatureList()
69 toFolder.append(aPoint1)
70
71 aSession.startOperation()
72 aFolder = aPartDoc.findFolderBelow(toFolder)
73 assert(aFolder is not None)
74 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
75 aSession.finishOperation()
76 assert(isAdded)
77
78 toFolder = FeatureList()
79 toFolder.append(aPoint3)
80 toFolder.append(aPoint4)
81
82 aSession.startOperation()
83 aFolder = aPartDoc.findFolderAbove(toFolder)
84 assert(aFolder is not None)
85 isAdded = aPartDoc.moveToFolder(toFolder, aFolder)
86 aSession.finishOperation()
87 assert(isAdded)
88
89 NB_FEATURES_FULL = 7
90 NB_FEATURES_OUT  = 4
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 assert(aPartDoc.index(aFolder1, True) == 0), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder1, True))
96 assert(aPartDoc.index(aFolder2, True) == 1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2, True))
97 assert(aPartDoc.index(aFolder3, True) == 3), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
98
99 assert(aPartDoc.index(aPoint1, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint1, True))
100 assert(aPartDoc.index(aPoint2, True) ==  2), "Wrong index of the point: {}".format(aPartDoc.index(aPoint2, True))
101 assert(aPartDoc.index(aPoint3, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True))
102 assert(aPartDoc.index(aPoint4, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
103
104
105 #=========================================================================
106 # Test 1. Remove empty folder
107 #=========================================================================
108 aSession.startOperation()
109 aPartDoc.removeFolder(aFolder2)
110 aSession.finishOperation()
111
112 NB_FEATURES_FULL -= 1
113 NB_FEATURES_OUT  -= 1
114
115 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
116 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
117
118 assert(aPartDoc.index(aFolder1, True) == 0), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder1, True))
119 assert(aPartDoc.index(aFolder2, True) == -1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2, True))
120 assert(aPartDoc.index(aFolder3, True) == 2), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
121
122 assert(aPartDoc.index(aPoint1, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint1, True))
123 assert(aPartDoc.index(aPoint2, True) ==  1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint2, True))
124 assert(aPartDoc.index(aPoint3, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True))
125 assert(aPartDoc.index(aPoint4, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
126
127
128 #=========================================================================
129 # Test 2. Remove non-empty folder
130 #=========================================================================
131 aSession.startOperation()
132 aPartDoc.removeFolder(aFolder3)
133 aSession.finishOperation()
134
135 NB_FEATURES_FULL -= 1
136 NB_FEATURES_OUT  += 1
137
138 assert(aPartDoc.size("Features") == NB_FEATURES_FULL), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features"), NB_FEATURES_FULL)
139 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features outside a folder: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
140
141 assert(aPartDoc.index(aFolder1, True) == 0), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder1, True))
142 assert(aPartDoc.index(aFolder2, True) == -1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder2, True))
143 assert(aPartDoc.index(aFolder3, True) == -1), "Wrong index of the folder: {}".format(aPartDoc.index(aFolder3, True))
144
145 assert(aPartDoc.index(aPoint1, True) == -1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint1, True))
146 assert(aPartDoc.index(aPoint2, True) ==  1), "Wrong index of the point: {}".format(aPartDoc.index(aPoint2, True))
147 assert(aPartDoc.index(aPoint3, True) ==  2), "Wrong index of the point: {}".format(aPartDoc.index(aPoint3, True))
148 assert(aPartDoc.index(aPoint4, True) ==  3), "Wrong index of the point: {}".format(aPartDoc.index(aPoint4, True))
149
150
151 from salome.shaper import model
152 assert(model.checkPythonDump())