2 batchmode_geompy.myBuilder._set_UndoLimit(20)
4 #--------------------------------------------------------------------------
6 #===============================================
7 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, "AttributeReal")
9 raise RuntimeError, "Can't create AttributeReal attribute"
10 A = A._narrow(SALOMEDS.AttributeReal)
12 if A.Value() != 0.0001:
13 raise RuntimeError, "Error : wrong value of AttributeReal"
15 # create AttributeStudyProperties
16 #================================================
17 A = batchmode_geompy.myStudy.GetProperties()
19 raise RuntimeError, "Can't create AttributeStudyProperties attribute"
20 A = A._narrow(SALOMEDS.AttributeStudyProperties)
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())
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!"
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")
47 raise RuntimeError, "Can't create AttributeInteger attribute"
48 A = A._narrow(SALOMEDS.AttributeInteger)
52 try : batchmode_geompy.myBuilder.CommitCommand()
53 except Exception: exception_was = 1
55 if exception_was is None:
56 raise RuntimeError, "Study was locked for changes but CommitCommand did not generate an exception !"
58 # save / restore study
60 #================================================
61 str= os.getenv("TmpDir")
64 file = str+"/test.hdf"
66 print(" ------- We will save to", file, "-----------")
68 batchmode_geompy.myStudy.SaveAs(file)
71 #--------------------------------------------------------------------------#
72 #--------------------------- Open file ------------------------------------#
73 #--------------------------------------------------------------------------#
75 print" -------------- Open " + file + "-------------- "
77 openedStudy = batchmode_geompy.myStudy.Open(file)
78 if openedStudy == None:
79 raise RuntimeError, "Can't open saved study!"
81 father = openedStudy.FindComponent("GEOM")
83 raise RuntimeError, "Geom component is not found! Wrong study is opened."
86 #1. find AttributeReal
87 #================================================
89 res,A=father.FindAttribute("AttributeReal")
90 if res == 0 or A == None:
91 raise RuntimeError, "Error: not found AttributeReal"
93 A = A._narrow(SALOMEDS.AttributeReal)
94 if A.Value() != 0.0001:
95 raise RuntimeError, "Error : wrong value of AttributeReal"
98 #2. find AttributeStudyProperties
99 #=================================================
100 A=openedStudy.GetProperties()
101 if res == 0 or A == None:
102 raise RuntimeError, "Error: not found AttributeStudyProperties"
104 A = A._narrow(SALOMEDS.AttributeStudyProperties)
105 if A.IsLocked() == 0 :
106 raise RuntimeError, "Error : AttributeStudyProperties must have Locked flag but have no!"
109 myBuilder = openedStudy.NewBuilder()
111 #3. try to make some changes wrapped by transaction
112 #==================================================
115 myBuilder.NewCommand()
116 A = myBuilder.FindOrCreateAttribute(father, "AttributeInteger")
119 raise RuntimeError, "Can't create AttributeInteger attribute"
120 A = A._narrow(SALOMEDS.AttributeInteger)
122 myBuilder.CommitCommand()
123 except Exception: exception_was = 1
125 if exception_was is None:
126 raise RuntimeError, "Study was locked for changes but CommitCommand did not generate an exception !"
129 myBuilder.NewCommand()
130 A=openedStudy.GetProperties()
131 A = A._narrow(SALOMEDS.AttributeStudyProperties)
133 myBuilder.CommitCommand()
136 myBuilder.NewCommand()
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()
145 myBuilder.NewCommand()
146 A.SetUserName("tester1")
147 myBuilder.CommitCommand()
148 print("A.GetUserName()= ", A.GetUserName())
150 #remove the document file