Salome HOME
This commit was generated by cvs2git to create tag 'V1_3_0'.
[modules/kernel.git] / doc / html / INPUT / exemple / Example3.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>#%AttributeSequenceOfReal interface(creations/saving/restoring)%\r
7 #% AttributeSequenceOfReal &nbsp;: ChangeValue, Add, &nbsp;Value, &nbsp;Remove, &nbsp;Length%\r
8 #% SALOMEDS methods : FindOrCreateAttribute, SaveAs, FindComponent, FindAttribute, Open%\r
9 \r
10 # &nbsp; &nbsp; &nbsp; create AttributeSequenceOfReal &nbsp; &nbsp; &nbsp;\r
11 #=================================\r
12 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, &quot;AttributeSequenceOfReal&quot;)\r
13 if A == None :\r
14  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeSequenceOfReal attribute&quot;\r
15 A = A._narrow(SALOMEDS.AttributeSequenceOfReal)\r
16 if A == None :\r
17  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;_narrow returns None instead of AttributeSequenceOfReal pointer&quot;\r
18 \r
19 A.Add(0.0293)\r
20 A.Add(625.1e+2)\r
21 A.Add(0.928e+100)\r
22 A.Add(83.287)\r
23 \r
24 print &quot;initial values &quot;,A.Value(1), A.Value(2), A.Value(3), A.Value(4)\r
25 A.Remove(3)\r
26 print &quot;after remove &quot;, A.Value(1), A.Value(2), A.Value(3)\r
27 A.ChangeValue(2,76.265)\r
28 print &quot;after second item change&quot;, A.Value(1), A.Value(2), A.Value(3)\r
29 \r
30 if A.Length() != 3:\r
31  &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Error : wrong length of SequenceOfReal&quot;\r
32 if A.Value(1) != 0.0293 or A.Value(2) != 76.265 or A.Value(3) != 83.287:\r
33  &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Error : wrong value of &nbsp;AttributeSequenceOfReal&quot;\r
34 \r
35 # &nbsp; &nbsp; &nbsp;save / restore study &nbsp; &nbsp; &nbsp;\r
36 #=================================\r
37 str= os.getenv(&quot;TmpDir&quot;)\r
38 if str == None:\r
39  &nbsp; &nbsp; &nbsp; &nbsp;str = &quot;/tmp&quot;\r
40 file = str+&quot;/test.hdf&quot;\r
41 \r
42 batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)\r
43 openedStudy=batchmode_geompy.myStudyManager.Open(file);\r
44 \r
45 if openedStudy == None:\r
46  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't open saved study!&quot;\r
47 \r
48 \r
49 father = openedStudy.FindComponent(&quot;GEOM&quot;)\r
50 if father is None:\r
51  &nbsp; &nbsp; &nbsp; &nbsp; raise &nbsp;RuntimeError, &quot;Geom component is not found! &nbsp;Wrong study is opened.&quot; \r
52 \r
53 \r
54 # &nbsp; &nbsp; find AttributeSequenceOfReal\r
55 #=================================\r
56 \r
57 res,A=father.FindAttribute(&quot;AttributeSequenceOfReal&quot;)\r
58 if res == 0 or A == None:\r
59  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Error: &nbsp;not found AttributeSequenceOfReal&quot;\r
60 \r
61 A = A._narrow(SALOMEDS.AttributeSequenceOfReal)\r
62 \r
63 if A.Length() != 3:\r
64  &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Error : wrong length of SequenceOfReal&quot;\r
65 if A.Value(1) != 0.0293 or A.Value(2) != 76.265 or A.Value(3) != 83.287:\r
66  &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Error : wrong value of &nbsp;AttributeSequenceOfReal&quot;\r
67 print &quot;after restoring &quot;, A.Value(1), A.Value(2), A.Value(3)\r
68 </PRE>