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