1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
\r
3 <!-- hennerik CVSweb $Revision$ -->
\r
4 <TITLE>Exemple</TITLE></HEAD>
\r
5 <BODY BGCOLOR="#eeeeee">
\r
7 #^SALOMEDS methods : FindOrCreateAttribute, SaveAs, FindComponent, FindAttribute, NewCommand, GetProperties, Open, CommitCommand, NewBuilder^
\r
8 #^Attribute methods : SetLocked, IsLocked, GetCreationMode, SetCreationDate, IsModified, GetUserName, Value, SetUserName, SetValue, GetCreationDate^
\r
10 batchmode_geompy.myBuilder._set_UndoLimit(20)
\r
12 #--------------------------------------------------------------------------
\r
13 # create AttributeReal
\r
14 #===============================================
\r
15 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, "AttributeReal")
\r
17 raise RuntimeError, "Can't create AttributeReal attribute"
\r
18 A = A._narrow(SALOMEDS.AttributeReal)
\r
20 if A.Value() != 0.0001:
\r
21 raise RuntimeError, "Error : wrong value of AttributeReal"
\r
23 # create AttributeStudyProperties
\r
24 #================================================
\r
25 A = batchmode_geompy.myStudy.GetProperties()
\r
27 raise RuntimeError, "Can't create AttributeStudyProperties attribute"
\r
28 A = A._narrow(SALOMEDS.AttributeStudyProperties)
\r
30 batchmode_geompy.myBuilder.NewCommand();
\r
31 print "A.GetUserName()= ", A.GetUserName()
\r
32 res,mm,hh,dd,mnth,yy=A.GetCreationDate()
\r
33 print "A.GetCreationDate() = ", mm,hh,dd,mnth,yy
\r
34 print "A.GetCreationMode() = ", A.GetCreationMode()
\r
35 print "A.IsModified() = ", A.IsModified()
\r
36 print "A.IsLocked() = ", A.IsLocked()
\r
37 if A.IsLocked() == 0 :
\r
38 A.SetUserName("tester"); print 'A.SetUserName("tester"), A.GetUserName() = ', A.GetUserName()
\r
39 A.SetCreationDate(11,11,11,11,2002); print 'A.SetCreationDate(11,11,11,11,2002), A.GetCreationDate() =', A.GetCreationDate()
\r
40 print "A.IsModified() = ", A.IsModified()
\r
43 #check the transaction result
\r
44 batchmode_geompy.myBuilder.CommitCommand()
\r
45 if A.GetUserName() != "tester":
\r
46 print 'Control after transaction close : A.GetUserName() = ', A.GetUserName()
\r
47 raise RuntimeError, "Field 'UserName' was not modified but had to!"
\r
49 # try to make some changes wrapped by transaction
\r
50 #================================================
\r
51 batchmode_geompy.myBuilder.NewCommand()
\r
52 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, "AttributeInteger")
\r
55 raise RuntimeError, "Can't create AttributeInteger attribute"
\r
56 A = A._narrow(SALOMEDS.AttributeInteger)
\r
59 exception_was = None
\r
60 try : batchmode_geompy.myBuilder.CommitCommand()
\r
61 except Exception: exception_was = 1
\r
63 if exception_was is None:
\r
64 raise RuntimeError, "Study was locked for changes but CommitCommand did not generate an exception !"
\r
66 # save / restore study
\r
68 #================================================
\r
69 str= os.getenv("TmpDir")
\r
71 str = "/tmp"
\r
72 file = str+"/test.hdf"
\r
74 print " ------- We will save to", file, "-----------"
\r
76 batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
\r
79 #--------------------------------------------------------------------------#
\r
80 #--------------------------- Open file ------------------------------------#
\r
81 #--------------------------------------------------------------------------#
\r
83 print" -------------- Open " + file + "-------------- "
\r
85 openedStudy = batchmode_geompy.myStudyManager.Open(file)
\r
86 if openedStudy == None:
\r
87 raise RuntimeError, "Can't open saved study!"
\r
89 father = openedStudy.FindComponent("GEOM")
\r
91 raise RuntimeError, "Geom component is not found! Wrong study is opened."
\r
94 #1. find AttributeReal
\r
95 #================================================
\r
97 res,A=father.FindAttribute("AttributeReal")
\r
98 if res == 0 or A == None:
\r
99 raise RuntimeError, "Error: not found AttributeReal"
\r
101 A = A._narrow(SALOMEDS.AttributeReal)
\r
102 if A.Value() != 0.0001:
\r
103 raise RuntimeError, "Error : wrong value of AttributeReal"
\r
106 #2. find AttributeStudyProperties
\r
107 #=================================================
\r
108 A=openedStudy.GetProperties()
\r
109 if res == 0 or A == None:
\r
110 raise RuntimeError, "Error: not found AttributeStudyProperties"
\r
112 A = A._narrow(SALOMEDS.AttributeStudyProperties)
\r
113 if A.IsLocked() == 0 :
\r
114 raise RuntimeError, "Error : AttributeStudyProperties must have Locked flag but have no!"
\r
117 myBuilder = openedStudy.NewBuilder()
\r
119 #3. try to make some changes wrapped by transaction
\r
120 #==================================================
\r
121 exception_was = None
\r
123 myBuilder.NewCommand()
\r
124 A = myBuilder.FindOrCreateAttribute(father, "AttributeInteger")
\r
126 if A == None :
\r
127 raise RuntimeError, "Can't create AttributeInteger attribute"
\r
128 A = A._narrow(SALOMEDS.AttributeInteger)
\r
129 A.SetValue(1000000)
\r
130 myBuilder.CommitCommand()
\r
131 except Exception: exception_was = 1
\r
133 if exception_was is None:
\r
134 raise RuntimeError, "Study was locked for changes but CommitCommand did not generate an exception !"
\r
137 myBuilder.NewCommand()
\r
138 A=openedStudy.GetProperties()
\r
139 A = A._narrow(SALOMEDS.AttributeStudyProperties)
\r
141 myBuilder.CommitCommand()
\r
144 myBuilder.NewCommand()
\r
146 print "A.GetUserName()= ", A.GetUserName()
\r
147 print "A.GetCreationDate() = ", A.GetCreationDate()
\r
148 print "A.GetCreationMode() = ", A.GetCreationMode()
\r
149 print "A.IsModified() = ", A.IsModified()
\r
150 myBuilder.CommitCommand()
\r
153 myBuilder.NewCommand()
\r
154 A.SetUserName("tester1")
\r
155 myBuilder.CommitCommand()
\r
156 print "A.GetUserName()= ", A.GetUserName()
\r
158 #remove the document file
\r