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