Salome HOME
updated copyright message
[modules/shaper.git] / src / ModelAPI / Test / TestFolder_Stability.py
1 # Copyright (C) 2014-2023  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 # Test checks stability of the foldering mechanism due to incorrect input parameters
22 #=========================================================================
23 from ModelAPI import *
24 from GeomDataAPI import *
25
26 __updated__ = "2017-11-23"
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 # Initialization of the model
44 #=========================================================================
45 aSession.startOperation()
46 aPart = aSession.moduleDocument().addFeature("Part")
47 aSession.finishOperation()
48
49 # add point and a folder before it
50 aPartDoc = aSession.activeDocument()
51 aPoint1 = newPoint(aPartDoc, 0., 0., 0.)
52
53 aSession.startOperation()
54 aFolder1 = aPartDoc.addFolder(aPoint1)
55 aSession.finishOperation()
56
57 NB_FEATURES_FULL = 2
58 NB_FEATURES_OUT  = 2
59
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
63 #=========================================================================
64 # Test 1. Check number of features out of folder
65 #         and absense of the crash while getting size of incorrect group
66 #=========================================================================
67 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
68 assert(aPartDoc.size("Construction", True) == 1), "Wrong size: {}".format(aPartDoc.size("Construction", True))
69
70 #=========================================================================
71 # Test 2. Add a feature to the folder and check number of features once again
72 #=========================================================================
73 toFolder = FeatureList()
74 toFolder.append(aPoint1)
75
76 aSession.startOperation()
77 aFolder2 = aPartDoc.addFolder(aPoint1)
78 aSession.finishOperation()
79
80 NB_FEATURES_FULL += 1
81 NB_FEATURES_OUT  += 1
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_OUT -= 1
91 assert(aPartDoc.size("Features", True) == NB_FEATURES_OUT), "Wrong number of features: {}, expected: {}".format(aPartDoc.size("Features", True), NB_FEATURES_OUT)
92 assert(aPartDoc.size("Construction", True) == 1), "Wrong size: {}".format(aPartDoc.size("Construction", True))