Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / ModelAPI / Test / TestDocument.py
1 """
2       TestDocument.py
3       Unit test for Model_Document/ModelAPI_Document class
4       
5 """
6 #=========================================================================
7 # Initialization of the test
8 #=========================================================================
9 from ModelAPI import *
10 # from GeomDataAPI import *
11 # from GeomAlgoAPI import *
12
13 __updated__ = "2014-12-26"
14
15 #=========================================================================
16 # Creation and activation of documents
17 #=========================================================================
18 aSession = ModelAPI_Session.get()
19 # TODO: enable this assertion:
20 assert(aSession.moduleDocument())
21 assert(aSession.moduleDocument().id() == "root")
22 assert(aSession.moduleDocument().kind() == "PartSet")
23 assert(aSession.hasModuleDocument())
24 # Create a new document
25 aSession.startOperation()
26 aSession.moduleDocument().addFeature("Part")
27 aSession.finishOperation()
28
29 assert(aSession.activeDocument())
30 assert(aSession.activeDocument().id() == "Part_1")
31 assert(aSession.activeDocument().kind() == "Part")
32 # Activate root doc
33 aRootDoc = aSession.document("root")
34 assert(aRootDoc)
35 aSession.startOperation()
36 aSession.setActiveDocument(aRootDoc, False)
37 aSession.finishOperation()
38 assert(aSession.activeDocument())
39 assert(aSession.activeDocument().id() == "root")
40 # check all opened docs
41 allDocsList = aSession.allOpenedDocuments()
42 assert(len(allDocsList) != 0)
43 # Activate Part_1 doc back for further testing
44 aSession.startOperation()
45 aSession.setActiveDocument(aSession.document("Part_1"), False)
46 aSession.finishOperation()
47 #=========================================================================
48 # Duplication of a document
49 #=========================================================================
50 aPart = aSession.activeDocument()
51 assert(aPart.size("Features") == 0)
52 # Create a point in the current document to check if it is duplicated
53 aSession.startOperation()
54 aFeature = aPart.addFeature("Point")
55 aFeatureData = aFeature.data()
56 assert(aFeatureData is not None)
57 aFeatureData.real("x").setValue(15.)
58 aFeatureData.real("y").setValue(10.)
59 aFeatureData.real("z").setValue(20.)
60 aSession.finishOperation()
61 assert(aPart.size("Features") == 1)
62 # Duplicate the document
63 assert(aSession.moduleDocument().size("Parts") == 1)
64 aSession.startOperation()
65 aPart.addFeature("Duplicate")
66 aSession.finishOperation()
67 assert(aSession.moduleDocument().size("Parts") == 2)
68 aCopyOfPart = aSession.activeDocument()
69 assert(aCopyOfPart.id() == "Part_2")
70 assert(aCopyOfPart.kind() == "Part")
71 assert(aCopyOfPart.size("Features") == 1)
72 assert(aCopyOfPart != aPart)
73 #=========================================================================
74 # Remove document
75 #=========================================================================
76 assert(aSession.moduleDocument().size("Parts") == 2)
77 aSession.startOperation()
78 aPart.addFeature("Remove")
79 aSession.finishOperation()
80 assert(aSession.moduleDocument().size("Parts") == 1)
81 assert(aSession.activeDocument().id() == aSession.moduleDocument().id())
82 # Remove another one document
83 aSession.startOperation()
84 aDoc1 = aSession.document("Part_1")
85 aSession.setActiveDocument(aDoc1, False)
86 aDoc1.addFeature("Remove")
87 aSession.finishOperation()
88 assert(aSession.moduleDocument().size("Parts") == 0)
89 assert(aSession.activeDocument())