Salome HOME
Task 2.3. Ability to put consecutive Features in a folder
[modules/shaper.git] / src / ModelAPI / Test / TestFolder_Create.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
26 __updated__ = "2017-11-22"
27
28 #=========================================================================
29 # Test 1. Check the Folder is created in PartSet
30 #=========================================================================
31 aSession = ModelAPI_Session.get()
32 aPartSetDoc = aSession.activeDocument()
33
34 aSession.startOperation()
35 aPoint0 = aPartSetDoc.addFeature("Point")
36 aPoint0Data = aPoint0.data()
37 assert(aPoint0Data is not None)
38 aPoint0Data.real("x").setValue(0.)
39 aPoint0Data.real("y").setValue(0.)
40 aPoint0Data.real("z").setValue(0.)
41 aPoint0Data.string("creation_method").setValue("by_xyz")
42 aSession.finishOperation()
43
44 aSession.startOperation()
45 aPoint1 = aPartSetDoc.addFeature("Point")
46 aPoint1Data = aPoint1.data()
47 assert(aPoint1Data is not None)
48 aPoint1Data.real("x").setValue(0.)
49 aPoint1Data.real("y").setValue(0.)
50 aPoint1Data.real("z").setValue(0.)
51 aPoint1Data.string("creation_method").setValue("by_xyz")
52 aSession.finishOperation()
53
54 # Folder before the feature
55 aSession.startOperation()
56 aFolder1 = aPartSetDoc.addFolder(aPoint1)
57 aSession.finishOperation()
58
59 assert(aPartSetDoc.size("Folders") == 1)
60 assert(aFolder1.name() == "Folder_1")
61
62 ## Folder at the end of features list
63 #aSession.startOperation()
64 #aPartSetDoc.addFolder()
65 #aSession.finishOperation()
66 #assert(aPartSetDoc.size("Folders") == 2)
67
68 #=========================================================================
69 # Test 2. Check the Folder is created in a Part
70 #=========================================================================
71 aSession.startOperation()
72 aPart = aSession.moduleDocument().addFeature("Part")
73 aSession.finishOperation()
74
75 # check part is a last feature
76 aFeaturesList = aSession.moduleDocument().allObjects()
77 aLast = aFeaturesList[len(aFeaturesList)-1]
78 assert(aLast.data().isEqual(aPart.data())), "Part is not a last object in the list"
79
80 # add point and a folder before it
81 aPartDoc = aSession.activeDocument()
82 aSession.startOperation()
83 aPoint2 = aPartDoc.addFeature("Point")
84 aPoint2Data = aPoint2.data()
85 assert(aPoint2Data is not None)
86 aPoint2Data.real("x").setValue(0.)
87 aPoint2Data.real("y").setValue(0.)
88 aPoint2Data.real("z").setValue(0.)
89 aPoint2Data.string("creation_method").setValue("by_xyz")
90 aSession.finishOperation()
91
92 aSession.startOperation()
93 aFolder2 = aPartDoc.addFolder(aPoint2)
94 aSession.finishOperation()
95
96 assert(aPartDoc.size("Folders") == 1)
97 assert(aFolder2.data().name() == "Folder_1")
98
99 from salome.shaper import model
100 assert(model.checkPythonDump())