Salome HOME
This commit was generated by cvs2git to create tag 'V1_4_0b2'.
[modules/kernel.git] / doc / html / INPUT / exemple / Example21.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 : FindOrCreateAttribute, SaveAs, FindComponent, FindAttribute, Open^\r
8 #^Attribute methods: GetValue, GetNbColumns, AddColumn, SetRowTitles, PutValue, GetColumn, GetColumnTitles, GetTitle, SetRow, GetRowTitles, SetColumnTitles, SetColumn, GetRow, 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;AttributeTableOfInteger&quot;)\r
13 if A == None :\r
14  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeTableOfInteger attribute&quot;\r
15 A = A._narrow(SALOMEDS.AttributeTableOfInteger)\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()\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()\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 str= os.getenv(&quot;TmpDir&quot;)\r
84 if str == None:\r
85  &nbsp; &nbsp; &nbsp; &nbsp;str = &quot;/tmp&quot;\r
86 file = str+&quot;/test.hdf&quot;\r
87 \r
88 print &quot; ------- &nbsp;We will save to&quot;, file, &quot;-----------&quot;\r
89 \r
90 batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)\r
91 \r
92 #--------------------------------------------------------------------------#\r
93 #---------------------------- Open file -----------------------------------# \r
94 #--------------------------------------------------------------------------#\r
95 \r
96 print&quot; -------------- Open &nbsp;&quot; + file + &quot;-------------- &quot; \r
97 \r
98 openedStudy=batchmode_geompy.myStudyManager.Open(file)\r
99 if openedStudy == None:\r
100  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't open saved study!&quot;\r
101 \r
102 father = openedStudy.FindComponent(&quot;GEOM&quot;)\r
103 if father is None:\r
104  &nbsp; &nbsp; &nbsp; &nbsp; raise &nbsp;RuntimeError, &quot;Geom component is not found! &nbsp;Wrong study is opened.&quot; \r
105 \r
106 # --- check attribute ---\r
107 \r
108 res,A=father.FindAttribute(&quot;AttributeTableOfInteger&quot;)\r
109 if res == 0 or A == None:\r
110  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Error: &nbsp;not found AttributeTableOfInteger&quot;\r
111 \r
112 A = A._narrow(SALOMEDS.AttributeTableOfInteger)\r
113 \r
114 #check the table\r
115 print &quot;Common title : &quot;,A.GetTitle()\r
116 print &quot;Rows titles : &quot;, &nbsp;A.GetRowTitles()\r
117 rnb = A.GetNbRows()\r
118 for i in range(1, rnb):\r
119  &nbsp; &nbsp; &nbsp; &nbsp;b=A.GetRow(i)\r
120  &nbsp; &nbsp; &nbsp; &nbsp;print b\r
121 \r
122 cnb = A.GetNbColumns()\r
123 print &quot;Columns title : &quot;, A.GetColumnTitles()\r
124 for i in range(1, cnb):\r
125  &nbsp; &nbsp; &nbsp; &nbsp;b=A.GetColumn(i)\r
126  &nbsp; &nbsp; &nbsp; &nbsp;print b\r
127 \r
128 titles=[&quot;ff&quot;,&quot;ss&quot;,&quot;tt&quot;]\r
129 A.SetRowTitles(titles)\r
130 print &quot;Rows titles : &quot;, &nbsp;A.GetRowTitles()\r
131 \r
132 titles=[&quot;ww&quot;,&quot;zz&quot;,&quot;cc&quot;]\r
133 A.SetColumnTitles(titles)\r
134 print &quot;Column titles : &quot;, &nbsp;A.GetColumnTitles()\r
135 \r
136 </PRE>