Salome HOME
Merge branch 'master' into cgt/devCEA
[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 # from GeomAlgoAPI import *
32
33 __updated__ = "2014-12-26"
34
35 #=========================================================================
36 # Creation and activation of documents
37 #=========================================================================
38 aSession = ModelAPI_Session.get()
39 # TODO: enable this assertion:
40 assert(aSession.moduleDocument())
41 assert(aSession.moduleDocument().id() == 0)
42 assert(aSession.moduleDocument().kind() == "PartSet")
43 assert(aSession.hasModuleDocument())
44 # Create a new document
45 aSession.startOperation()
46 aSession.moduleDocument().addFeature("Part")
47 aSession.finishOperation()
48
49 assert(aSession.activeDocument())
50 assert(aSession.activeDocument().id() == 1)
51 assert(aSession.activeDocument().kind() == "Part")
52 # Activate root doc
53 aRootDoc = aSession.document(0)
54 assert(aRootDoc)
55 aSession.startOperation()
56 aSession.setActiveDocument(aRootDoc, False)
57 aSession.finishOperation()
58 assert(aSession.activeDocument())
59 assert(aSession.activeDocument().id() == 0)
60 # check all opened docs
61 allDocsList = aSession.allOpenedDocuments()
62 assert(len(allDocsList) != 0)
63 # Activate Part_1 doc back for further testing
64 aSession.startOperation()
65 aSession.setActiveDocument(aSession.document(1), False)
66 aSession.finishOperation()
67 #=========================================================================
68 # Duplication of a document
69 #=========================================================================
70 aPart = aSession.activeDocument()
71 assert(aPart.size("Features") == 0)
72 # Create a point in the current document to check if it is duplicated
73 aSession.startOperation()
74 aFeature = aPart.addFeature("Point")
75 aFeatureData = aFeature.data()
76 assert(aFeatureData is not None)
77 aFeatureData.real("x").setValue(15.)
78 aFeatureData.real("y").setValue(10.)
79 aFeatureData.real("z").setValue(20.)
80 aSession.finishOperation()
81 assert(aPart.size("Features") == 1)
82 # Duplicate the document
83 assert(aSession.moduleDocument().size("Parts") == 1)
84 aSession.startOperation()
85 aPart.addFeature("Duplicate")
86 aSession.finishOperation()
87 assert(aSession.moduleDocument().size("Parts") == 2)
88 aCopyOfPart = aSession.activeDocument()
89 assert(aCopyOfPart.id() == 2)
90 assert(aCopyOfPart.kind() == "Part")
91 assert(aCopyOfPart.size("Features") == 1)
92 assert(aCopyOfPart != aPart)
93 #=========================================================================
94 # Remove document
95 #=========================================================================
96 assert(aSession.moduleDocument().size("Parts") == 2)
97 aSession.startOperation()
98 aPart.addFeature("Remove")
99 aSession.finishOperation()
100 # First part is deleted, but active is Part_2, so, it is still active
101 assert(aSession.moduleDocument().size("Parts") == 1)
102 assert(aSession.activeDocument().id() == aCopyOfPart.id())
103 # Remove another one document
104 aSession.startOperation()
105 aDoc2 = aSession.document(2)
106 aSession.setActiveDocument(aDoc2, False)
107 aDoc2.addFeature("Remove")
108 aSession.finishOperation()
109 assert(aSession.moduleDocument().size("Parts") == 0)
110 assert(aSession.activeDocument())
111
112 from salome.shaper import model
113 assert(model.checkPythonDump())