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