1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
23 Unit test for Model_Document/ModelAPI_Document class
26 #=========================================================================
27 # Initialization of the test
28 #=========================================================================
29 from ModelAPI import *
30 from GeomDataAPI import *
32 __updated__ = "2014-12-26"
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()
47 assert(aSession.activeDocument())
48 assert(aSession.activeDocument().id() == 1)
49 assert(aSession.activeDocument().kind() == "Part")
51 aRootDoc = aSession.document(0)
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 #=========================================================================
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())
108 from salome.shaper import model
109 assert(model.checkPythonDump())