Salome HOME
This commit was generated by cvs2git to create tag 'V1_4_0b1'.
[modules/kernel.git] / doc / html / INPUT / exemple / Example16.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>\r
2 <HEAD>\r
3 <!-- hennerik CVSweb $Revision$ -->\r
4 <TITLE>Example</TITLE></HEAD>\r
5 <BODY BGCOLOR="#eeeeee">\r
6 <HR noshade><PRE>Methods : GetAvailableUndos, ChangeValue, FindOrCreateAttribute, SaveAs, GetAvailableRedos, Undo, FindComponent, Redo, FindAttribute, Open, CommitCommand, NewCommand\r
7 \r
8 \r
9 dir= os.getenv(&quot;TmpDir&quot;)\r
10 if dir == None:\r
11  &nbsp; &nbsp; &nbsp; &nbsp;dir = &quot;/tmp&quot;\r
12 \r
13 batchmode_geompy.myBuilder._set_UndoLimit(20)\r
14 \r
15 # 1st transaction -----------------------------------------\r
16 batchmode_geompy.myBuilder.NewCommand()\r
17 # &nbsp; &nbsp; &nbsp; create AttributeSequenceOfInteger &nbsp; &nbsp; &nbsp;\r
18 #=========================================================\r
19 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, &quot;AttributeSequenceOfInteger&quot;)\r
20 if A == None :\r
21  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeSequenceOfInteger attribute&quot;\r
22 A = A._narrow(SALOMEDS.AttributeSequenceOfInteger)\r
23 if A == None :\r
24  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeSequenceOfInteger attribute&quot;\r
25 \r
26 A.Add(100)\r
27 A.Add(300)\r
28 A.Add(500)\r
29 A.Add(400)\r
30 A.Add(700)\r
31 print &quot;First transaction goes on : &nbsp;HasOpenCommand() = &quot;, batchmode_geompy.myBuilder.HasOpenCommand()\r
32 batchmode_geompy.myBuilder.CommitCommand() #--------------\r
33 \r
34 # 2nd transaction ------------------------------------------\r
35 batchmode_geompy.myBuilder.NewCommand() \r
36 A.Remove(3)\r
37 A.ChangeValue(4,500)\r
38 batchmode_geompy.myBuilder.CommitCommand() #--------------\r
39 \r
40 if batchmode_geompy.myBuilder.GetAvailableUndos() == 0:\r
41  &nbsp; &nbsp; &nbsp; &nbsp;raise RuntimeError, &quot;GetAvailableUndos() = 0 but must not !&quot;\r
42 \r
43 if A.Length() != 4:\r
44  &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Wrong length of SequenceOfInteger&quot;\r
45 if A.Value(1) != 100 or A.Value(2) != 300 or A.Value(3) != 400 or A.Value(4) != 500:\r
46  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Wrong &nbsp;value of &nbsp;AttributeSequenceOfInteger&quot;\r
47 \r
48 file1 = dir + &quot;/test1.hdf&quot;\r
49 batchmode_geompy.myStudyManager.SaveAs(file1, batchmode_geompy.myStudy)\r
50 \r
51 # 1st Undo ---------------------------------------\r
52 batchmode_geompy.myBuilder.Undo()\r
53 res, A = batchmode_geompy.myBuilder.FindAttribute(batchmode_geompy.father, &quot;AttributeSequenceOfInteger&quot;)\r
54 if A is None:\r
55  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;After first 'undo' can't find AttributeSequenceOfInteger&quot;\r
56 if A.Length() != 5:\r
57  &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Wrong length of SequenceOfInteger&quot;\r
58 if A.Value(1) != 100 or A.Value(2) != 300 or A.Value(3) != 500 or A.Value(4) != 400 or &nbsp;A.Value(5) != 700:\r
59  &nbsp; &nbsp; &nbsp; &nbsp;print &nbsp;A.Value(1), A.Value(2), A.Value(3), A.Value(4), A.Value(5)\r
60  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Wrong &nbsp;value of &nbsp;AttributeSequenceOfInteger after the first 'undo'!&quot;\r
61 # save \r
62 file2 = dir + &quot;/test2.hdf&quot;\r
63 batchmode_geompy.myStudyManager.SaveAs(file2, batchmode_geompy.myStudy)\r
64 #-------------------------------------------------\r
65 # 2nd Undo ---------------------------------------\r
66 batchmode_geompy.myBuilder.Undo()\r
67 res, attr = batchmode_geompy.myBuilder.FindAttribute(batchmode_geompy.father, &quot;AttributeSequenceOfInteger&quot;)\r
68 if res !=0 or attr != None :\r
69  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;After the second 'undo' AttributeSequenceOfInteger exists but must not!&quot;\r
70 file3 = dir + &quot;/test3.hdf&quot;\r
71 batchmode_geompy.myStudyManager.SaveAs(file3, batchmode_geompy.myStudy)\r
72 #-------------------------------------------------\r
73 \r
74 #make redo twice ---------------------------------\r
75 if batchmode_geompy.myBuilder.GetAvailableRedos() == 0:\r
76  &nbsp; &nbsp; &nbsp; &nbsp;raise RuntimeError, &quot;GetAvailableRedos() = 0 but must not !&quot;\r
77 batchmode_geompy.myBuilder.Redo()\r
78 batchmode_geompy.myBuilder.Redo()\r
79 res, A = batchmode_geompy.myBuilder.FindAttribute(batchmode_geompy.father, &quot;AttributeSequenceOfInteger&quot;)\r
80 if res ==0 or A== None :\r
81  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;AttributeSequenceOfInteger is not found but must be!&quot;\r
82 if A.Length() != 4:\r
83  &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Wrong length of SequenceOfInteger&quot;\r
84 if A.Value(1) != 100 or A.Value(2) != 300 or A.Value(3) != 400 or A.Value(4) != 500:\r
85  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Wrong &nbsp;value of &nbsp;AttributeSequenceOfInteger&quot;\r
86 \r
87 \r
88 #----------------------------------------------------------------------\r
89 openedStudy=batchmode_geompy.myStudyManager.Open(file1);\r
90 \r
91 if openedStudy == None:\r
92  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't open saved study!&quot;\r
93 \r
94 \r
95 father = openedStudy.FindComponent(&quot;GEOM&quot;)\r
96 if father is None:\r
97  &nbsp; &nbsp; &nbsp; &nbsp; raise &nbsp;RuntimeError, &quot;Geom component is not found! &nbsp;Wrong study is opened.&quot; \r
98 \r
99 \r
100 # &nbsp; &nbsp; find AttributeSequenceOfInteger\r
101 #======================================\r
102 \r
103 res,A=father.FindAttribute(&quot;AttributeSequenceOfInteger&quot;)\r
104 if res == 0 or A == None:\r
105  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Error: &nbsp;not found AttributeSequenceOfInteger&quot;\r
106 \r
107 A = A._narrow(SALOMEDS.AttributeSequenceOfInteger)\r
108 \r
109 if A.Length() != 4:\r
110  &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Wrong length of SequenceOfInteger&quot;\r
111 if A.Value(1) != 100 or A.Value(2) != 300 or A.Value(3) != 400 or A.Value(4) != 500:\r
112  &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Wrong &nbsp;value of &nbsp;AttributeSequenceOfInteger&quot;\r
113 #----------------------------------------------------------------------\r
114 openedStudy=batchmode_geompy.myStudyManager.Open(file2);\r
115 \r
116 if openedStudy == None:\r
117  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't open saved study!&quot;\r
118 \r
119 \r
120 father = openedStudy.FindComponent(&quot;GEOM&quot;)\r
121 if father is None:\r
122  &nbsp; &nbsp; &nbsp; &nbsp; raise &nbsp;RuntimeError, &quot;Geom component is not found! &nbsp;Wrong study is opened.&quot; \r
123 \r
124 \r
125 # &nbsp; &nbsp; find AttributeSequenceOfInteger\r
126 #======================================\r
127 \r
128 res,A=father.FindAttribute(&quot;AttributeSequenceOfInteger&quot;)\r
129 if res == 0 or A == None:\r
130  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Error: &nbsp;not found AttributeSequenceOfInteger&quot;\r
131 \r
132 A = A._narrow(SALOMEDS.AttributeSequenceOfInteger)\r
133 \r
134 if A.Length() != 5:\r
135  &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Wrong length of SequenceOfInteger&quot;\r
136 if A.Value(1) != 100 or A.Value(2) != 300 or A.Value(3) != 500 or A.Value(4) != 400 or &nbsp;A.Value(5) != 700:\r
137  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Wrong &nbsp;value of &nbsp;AttributeSequenceOfInteger after the first 'undo'!&quot;\r
138 \r
139 #----------------------------------------------------------------------\r
140 openedStudy=batchmode_geompy.myStudyManager.Open(file3);\r
141 \r
142 if openedStudy == None:\r
143  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't open saved study!&quot;\r
144 \r
145 \r
146 father = openedStudy.FindComponent(&quot;GEOM&quot;)\r
147 if father is None:\r
148  &nbsp; &nbsp; &nbsp; &nbsp; raise &nbsp;RuntimeError, &quot;Geom component is not found! &nbsp;Wrong study is opened.&quot; \r
149 \r
150 \r
151 # &nbsp; &nbsp; find AttributeSequenceOfInteger\r
152 #======================================\r
153 \r
154 res,A=father.FindAttribute(&quot;AttributeSequenceOfInteger&quot;)\r
155 \r
156 if res!=0 or A != None:\r
157  &nbsp; &nbsp; &nbsp; &nbsp;raise RuntimeError, &quot; AttributeSequenceOfInteger is found but must not!&quot;\r
158 </PRE>