Salome HOME
Revert "Synchronize adm files"
[modules/kernel.git] / doc / salome / examples / example20
1
2 batchmode_geompy.myBuilder._set_UndoLimit(20)
3
4 #--------------------------------------------------------------------------
5 #       create AttributeReal      
6 #===============================================
7 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, "AttributeReal")
8 if A == None :
9         raise  RuntimeError, "Can't create AttributeReal attribute"
10 A = A._narrow(SALOMEDS.AttributeReal)
11 A.SetValue(0.0001)
12 if A.Value() != 0.0001:
13         raise  RuntimeError, "Error : wrong value of  AttributeReal"
14
15 #      create AttributeStudyProperties
16 #================================================
17 A = batchmode_geompy.myStudy.GetProperties()
18 if A == None :
19         raise  RuntimeError, "Can't create AttributeStudyProperties attribute"
20 A = A._narrow(SALOMEDS.AttributeStudyProperties)
21
22 batchmode_geompy.myBuilder.NewCommand();
23 print "A.GetUserName()= ", A.GetUserName()
24 res,mm,hh,dd,mnth,yy=A.GetCreationDate()
25 print "A.GetCreationDate() = ", mm,hh,dd,mnth,yy
26 print "A.GetCreationMode() = ", A.GetCreationMode()
27 print "A.IsModified() = ", A.IsModified()
28 print "A.IsLocked() = ", A.IsLocked()
29 if A.IsLocked() == 0 :
30         A.SetUserName("tester"); print 'A.SetUserName("tester"), A.GetUserName() = ', A.GetUserName()
31         A.SetCreationDate(11,11,11,11,2002); print 'A.SetCreationDate(11,11,11,11,2002), A.GetCreationDate() =', A.GetCreationDate()
32         print "A.IsModified() = ", A.IsModified()
33 A.SetLocked(1)
34
35 #check the transaction result 
36 batchmode_geompy.myBuilder.CommitCommand()
37 if A.GetUserName() != "tester":
38         print 'Control after transaction close : A.GetUserName() = ', A.GetUserName()
39         raise RuntimeError, "Field 'UserName' was not modified but had to!"
40
41 # try to make some changes wrapped by transaction 
42 #================================================
43 batchmode_geompy.myBuilder.NewCommand()
44 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, "AttributeInteger")
45
46 if A == None :
47         raise  RuntimeError, "Can't create AttributeInteger attribute"
48 A = A._narrow(SALOMEDS.AttributeInteger)
49 A.SetValue(1000000)
50
51 exception_was = None
52 try : batchmode_geompy.myBuilder.CommitCommand()
53 except Exception: exception_was = 1
54
55 if exception_was is None:
56         raise RuntimeError, "Study was locked for changes but CommitCommand did not generate an exception !"
57
58 #      save / restore study      
59
60 #================================================
61 str= os.getenv("TmpDir")
62 if str == None:
63         str = "/tmp"
64 file = str+"/test.hdf"
65
66 print " -------  We will save to", file, "-----------"
67
68 batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
69
70
71 #--------------------------------------------------------------------------#
72 #--------------------------- Open file ------------------------------------# 
73 #--------------------------------------------------------------------------#
74
75 print" -------------- Open  " + file + "-------------- " 
76
77 openedStudy = batchmode_geompy.myStudyManager.Open(file)
78 if openedStudy == None:
79         raise  RuntimeError, "Can't open saved study!"
80
81 father = openedStudy.FindComponent("GEOM")
82 if father is None:
83          raise  RuntimeError, "Geom component is not found!  Wrong study is opened." 
84
85
86 #1.     find AttributeReal
87 #================================================
88
89 res,A=father.FindAttribute("AttributeReal")
90 if res == 0 or A == None:
91         raise  RuntimeError, "Error:  not found AttributeReal"
92
93 A = A._narrow(SALOMEDS.AttributeReal)
94 if A.Value() != 0.0001:
95         raise  RuntimeError, "Error : wrong value of  AttributeReal"
96  
97
98 #2.     find AttributeStudyProperties
99 #=================================================
100 A=openedStudy.GetProperties()
101 if res == 0 or A == None:
102         raise  RuntimeError, "Error:  not found AttributeStudyProperties"
103
104 A = A._narrow(SALOMEDS.AttributeStudyProperties)
105 if A.IsLocked() == 0 :
106         raise  RuntimeError, "Error : AttributeStudyProperties must have Locked flag but have no!"
107
108 #get the builder
109 myBuilder = openedStudy.NewBuilder()
110
111 #3. try to make some changes wrapped by transaction 
112 #==================================================
113 exception_was = None
114 try : 
115         myBuilder.NewCommand()
116         A = myBuilder.FindOrCreateAttribute(father, "AttributeInteger")
117
118         if A == None :
119                 raise  RuntimeError, "Can't create AttributeInteger attribute"
120         A = A._narrow(SALOMEDS.AttributeInteger)
121         A.SetValue(1000000)
122         myBuilder.CommitCommand()
123 except Exception: exception_was = 1
124
125 if exception_was is None:
126         raise RuntimeError, "Study was locked for changes but CommitCommand did not generate an exception !"
127
128
129 myBuilder.NewCommand()
130 A=openedStudy.GetProperties()
131 A = A._narrow(SALOMEDS.AttributeStudyProperties)
132 A.SetLocked(0)
133 myBuilder.CommitCommand()
134
135 #4.
136 myBuilder.NewCommand()
137 A.SetLocked(0);
138 print "A.GetUserName()= ", A.GetUserName()
139 print "A.GetCreationDate() = ", A.GetCreationDate()
140 print "A.GetCreationMode() = ", A.GetCreationMode()
141 print "A.IsModified() = ", A.IsModified()
142 myBuilder.CommitCommand()
143
144 #5.
145 myBuilder.NewCommand()
146 A.SetUserName("tester1")
147 myBuilder.CommitCommand()
148 print "A.GetUserName()= ", A.GetUserName()
149
150 #remove the document file
151 os.remove(file)
152