Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / ModelAPI / Test / TestDocument.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       TestDocument.py
23       Unit test for Model_Document/ModelAPI_Document class
24
25 """
26 #=========================================================================
27 # Initialization of the test
28 #=========================================================================
29 from ModelAPI import *
30 from GeomDataAPI import *
31
32 __updated__ = "2014-12-26"
33
34 #=========================================================================
35 # Creation and activation of documents
36 #=========================================================================
37 aSession = ModelAPI_Session.get()
38 assert(aSession.moduleDocument())
39 assert(aSession.moduleDocument().id() == 0)
40 assert(aSession.moduleDocument().kind() == "PartSet")
41 assert(aSession.hasModuleDocument())
42 # Create a new document
43 aSession.startOperation()
44 aSession.moduleDocument().addFeature("Part")
45 aSession.finishOperation()
46
47 assert(aSession.activeDocument())
48 assert(aSession.activeDocument().id() == 1)
49 assert(aSession.activeDocument().kind() == "Part")
50 # Activate root doc
51 aRootDoc = aSession.document(0)
52 assert(aRootDoc)
53 aSession.startOperation()
54 aSession.setActiveDocument(aRootDoc, False)
55 aSession.finishOperation()
56 assert(aSession.activeDocument())
57 assert(aSession.activeDocument().id() == 0)
58 # check all opened docs
59 allDocsList = aSession.allOpenedDocuments()
60 assert(len(allDocsList) != 0)
61 # Activate Part_1 doc back for further testing
62 aSession.startOperation()
63 aSession.setActiveDocument(aSession.document(1), False)
64 aSession.finishOperation()
65 #=========================================================================
66 # Duplication of a document
67 #=========================================================================
68 aPart = aSession.activeDocument()
69 assert(aPart.size("Features") == 0)
70 # Create a point in the current document to check if it is duplicated
71 aSession.startOperation()
72 aFeature = aPart.addFeature("Point")
73 aFeatureData = aFeature.data()
74 assert(aFeatureData is not None)
75 geomDataAPI_Point(aFeatureData.attribute("point3d")).setValue(15., 10., 20.)
76 aSession.finishOperation()
77 assert(aPart.size("Features") == 1)
78 # Duplicate the document
79 assert(aSession.moduleDocument().size("Parts") == 1)
80 aSession.startOperation()
81 aPart.addFeature("Duplicate")
82 aSession.finishOperation()
83 assert(aSession.moduleDocument().size("Parts") == 2)
84 aCopyOfPart = aSession.activeDocument()
85 assert(aCopyOfPart.id() == 2)
86 assert(aCopyOfPart.kind() == "Part")
87 assert(aCopyOfPart.size("Features") == 1)
88 assert(aCopyOfPart != aPart)
89 #=========================================================================
90 # Remove document
91 #=========================================================================
92 assert(aSession.moduleDocument().size("Parts") == 2)
93 aSession.startOperation()
94 aPart.addFeature("Remove")
95 aSession.finishOperation()
96 # First part is deleted, but active is Part_2, so, it is still active
97 assert(aSession.moduleDocument().size("Parts") == 1)
98 assert(aSession.activeDocument().id() == aCopyOfPart.id())
99 # Remove another one document
100 aSession.startOperation()
101 aDoc2 = aSession.document(2)
102 aSession.setActiveDocument(aDoc2, False)
103 aDoc2.addFeature("Remove")
104 aSession.finishOperation()
105 assert(aSession.moduleDocument().size("Parts") == 0)
106 assert(aSession.activeDocument())
107
108 from salome.shaper import model
109 assert(model.checkPythonDump())