Salome HOME
Initial version
[modules/gui.git] / doc / salome / tui / KERNEL / exemple / Example22.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>\r
2 <HEAD>\r
3 <!-- hennerik CVSweb $Revision$ -->\r
4 <TITLE>Exemple</TITLE></HEAD>\r
5 <BODY BGCOLOR="#eeeeee">\r
6 <HR noshade><PRE>\r
7 #^ SALOMEDS methods &nbsp;: FindOrCreateAttribute, SaveAs, FindComponent, FindAttribute, Open^\r
8 #^ Attribute methods : GetValue, GetNbColumns, AddColumn, SetRowTitles, PutValue, &nbsp;GetColumn, &nbsp;GetColumnTitles, GetTitle, SetRow, GetRowTitles, SetColumnTitles, &nbsp;SetColumn, &nbsp;GetRow, &nbsp;GetNbRows, SetColumnTitle, AddRow, SetTitle, SetRowTitle^\r
9 \r
10 # &nbsp; &nbsp; &nbsp; create AttributeReal &nbsp; &nbsp; &nbsp;\r
11 #===============================================\r
12 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, &quot;AttributeTableOfReal&quot;)\r
13 if A == None :\r
14  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeTableOfReal attribute&quot;\r
15 A = A._narrow(SALOMEDS.AttributeTableOfReal)\r
16 a=[1,2]\r
17 \r
18 b=[3,4]\r
19 \r
20 # &nbsp; &nbsp;2x2\r
21 # --- rows ---\r
22 A.AddRow(a)\r
23 A.AddRow(b)\r
24 a=[34,14]\r
25 A.SetRow(1,a)\r
26 \r
27 # &nbsp; &nbsp;3x3\r
28 #\r
29 b=[54,56]\r
30 A.AddRow(b)\r
31 \r
32 # --- columns ---\r
33 a=[76,25,12]\r
34 \r
35 A.AddColumn(a)\r
36 a=[836,3425,342]\r
37 A.SetColumn(3,a)\r
38 \r
39 # change attribute values\r
40 print &quot;A.GetValue(2,2) = &quot;, A.GetValue(2,2)\r
41 print &quot;A.PutValue(2,2,625323)&quot;\r
42 A.PutValue(625323,2,2)\r
43 print &quot;A.GetValue(2,2) = &quot;, A.GetValue(2,2)\r
44 \r
45 #set Titles\r
46 \r
47 A.SetTitle(&quot;TEST&quot;)\r
48 \r
49 A.SetRowTitle(1,&quot;FR&quot;)\r
50 A.SetRowTitle(2,&quot;SR&quot;)\r
51 A.SetRowTitle(3,&quot;TR&quot;)\r
52 \r
53 A.SetColumnTitle(1,&quot;FC&quot;)\r
54 A.SetColumnTitle(2,&quot;SC&quot;)\r
55 A.SetColumnTitle(3,&quot;TC&quot;)\r
56 \r
57 \r
58 #check the table\r
59 print &quot;Common title : &quot;,A.GetTitle()\r
60 print &quot;Rows titles : &quot;, &nbsp;A.GetRowTitles()\r
61 rnb = A.GetNbRows() + 1\r
62 for i in range(1, rnb):\r
63  &nbsp; &nbsp; &nbsp; &nbsp;b=A.GetRow(i)\r
64  &nbsp; &nbsp; &nbsp; &nbsp;print b\r
65 \r
66 cnb = A.GetNbColumns() + 1\r
67 print &quot;Columns title : &quot;, A.GetColumnTitles()\r
68 for i in range(1, cnb):\r
69  &nbsp; &nbsp; &nbsp; &nbsp;b=A.GetColumn(i)\r
70  &nbsp; &nbsp; &nbsp; &nbsp;print b\r
71 \r
72 # set titles\r
73 #titles=[&quot;11&quot;,&quot;12&quot;,&quot;13&quot;]\r
74 #A.SetRowTitles(titles)\r
75 #titles=[&quot;21&quot;,&quot;22&quot;,&quot;23&quot;]\r
76 #A.SetRowTitles(2,titles)\r
77 #titles=[&quot;31&quot;,&quot;32&quot;,&quot;33&quot;]\r
78 #A.SetRowTitles(3,titles)\r
79 \r
80 #--------------------------------------------------------------------------#\r
81 #------------------------ save the study ----------------------------------#\r
82 #--------------------------------------------------------------------------#\r
83 import os\r
84 str= os.getenv(&quot;TmpDir&quot;)\r
85 if str == None:\r
86  &nbsp; &nbsp; &nbsp; &nbsp;str = &quot;/tmp&quot;\r
87 file = str+&quot;/test.hdf&quot;\r
88 \r
89 print &quot; ------- &nbsp;We will save to&quot;, file, &quot;-----------&quot;\r
90 \r
91 batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)\r
92 \r
93 #--------------------------------------------------------------------------#\r
94 #---------------------------- Open file -----------------------------------# \r
95 #--------------------------------------------------------------------------#\r
96 \r
97 print&quot; -------------- Open &nbsp;&quot; + file + &quot;-------------- &quot; \r
98 \r
99 openedStudy = batchmode_geompy.myStudyManager.Open(file)\r
100 if openedStudy == None:\r
101  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't open saved study!&quot;\r
102 \r
103 father = openedStudy.FindComponent(&quot;GEOM&quot;)\r
104 if father is None:\r
105  &nbsp; &nbsp; &nbsp; &nbsp; raise &nbsp;RuntimeError, &quot;Geom component is not found! &nbsp;Wrong study is opened.&quot; \r
106 \r
107 # --- check attribute ---\r
108 \r
109 res,A=father.FindAttribute(&quot;AttributeTableOfReal&quot;)\r
110 if res == 0 or A == None:\r
111  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Error: &nbsp;not found AttributeTableOfReal&quot;\r
112 \r
113 A = A._narrow(SALOMEDS.AttributeTableOfReal)\r
114 \r
115 #check the table\r
116 print &quot;Common title : &quot;,A.GetTitle()\r
117 print &quot;Rows titles : &quot;, &nbsp;A.GetRowTitles()\r
118 rnb = A.GetNbRows() + 1\r
119 for i in range(1, rnb):\r
120  &nbsp; &nbsp; &nbsp; &nbsp;b=A.GetRow(i)\r
121  &nbsp; &nbsp; &nbsp; &nbsp;print b\r
122 \r
123 cnb = A.GetNbColumns() + 1\r
124 print &quot;Columns title : &quot;, A.GetColumnTitles()\r
125 for i in range(1, cnb):\r
126  &nbsp; &nbsp; &nbsp; &nbsp;b=A.GetColumn(i)\r
127  &nbsp; &nbsp; &nbsp; &nbsp;print b\r
128 \r
129 titles=[&quot;ff&quot;,&quot;ss&quot;,&quot;tt&quot;]\r
130 A.SetRowTitles(titles)\r
131 print &quot;Rows titles : &quot;, &nbsp;A.GetRowTitles()\r
132 \r
133 titles=[&quot;ww&quot;,&quot;zz&quot;,&quot;cc&quot;]\r
134 A.SetColumnTitles(titles)\r
135 print &quot;Column titles : &quot;, &nbsp;A.GetColumnTitles()\r
136 \r
137 </PRE>