1 # Copyright (C) 2014-2020 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 email : webmaster.salome@opencascade.com
22 Unit test for Model_Document/ModelAPI_Document class
25 #=========================================================================
26 # Initialization of the test
27 #=========================================================================
28 from ModelAPI import *
29 from GeomDataAPI import *
31 __updated__ = "2014-12-26"
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()
46 assert(aSession.activeDocument())
47 assert(aSession.activeDocument().id() == 1)
48 assert(aSession.activeDocument().kind() == "Part")
50 aRootDoc = aSession.document(0)
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 geomDataAPI_Point(aFeatureData.attribute("point3d")).setValue(15., 10., 20.)
75 aSession.finishOperation()
76 assert(aPart.size("Features") == 1)
77 # Duplicate the document
78 assert(aSession.moduleDocument().size("Parts") == 1)
79 aSession.startOperation()
80 aPart.addFeature("Duplicate")
81 aSession.finishOperation()
82 assert(aSession.moduleDocument().size("Parts") == 2)
83 aCopyOfPart = aSession.activeDocument()
84 assert(aCopyOfPart.id() == 2)
85 assert(aCopyOfPart.kind() == "Part")
86 assert(aCopyOfPart.size("Features") == 1)
87 assert(aCopyOfPart != aPart)
88 #=========================================================================
90 #=========================================================================
91 assert(aSession.moduleDocument().size("Parts") == 2)
92 aSession.startOperation()
93 aPart.addFeature("Remove")
94 aSession.finishOperation()
95 # First part is deleted, but active is Part_2, so, it is still active
96 assert(aSession.moduleDocument().size("Parts") == 1)
97 assert(aSession.activeDocument().id() == aCopyOfPart.id())
98 # Remove another one document
99 aSession.startOperation()
100 aDoc2 = aSession.document(2)
101 aSession.setActiveDocument(aDoc2, False)
102 aDoc2.addFeature("Remove")
103 aSession.finishOperation()
104 assert(aSession.moduleDocument().size("Parts") == 0)
105 assert(aSession.activeDocument())
107 from salome.shaper import model
108 assert(model.checkPythonDump())