Salome HOME
Merge Python 3 porting.
[modules/kernel.git] / doc / salome / examples / example21
1
2 #       create AttributeReal      
3 #=======================================================================================================
4 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, "AttributeTableOfInteger")
5 if A == None :
6         raise  RuntimeError, "Can't create AttributeTableOfInteger attribute"
7 A = A._narrow(SALOMEDS.AttributeTableOfInteger)
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()
54 for i in range(1, rnb):
55         b=A.GetRow(i)
56         print(b)
57
58 cnb = A.GetNbColumns()
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 str= os.getenv("TmpDir")
76 if str == None:
77         str = "/tmp"
78 file = str+"/test.hdf"
79
80 print(" -------  We will save to", file, "-----------")
81
82 batchmode_geompy.myStudy.SaveAs(file)
83
84 #--------------------------------------------------------------------------#
85 #---------------------------- Open file -----------------------------------# 
86 #--------------------------------------------------------------------------#
87
88 print" -------------- Open  " + file + "-------------- " 
89
90 openedStudy=batchmode_geompy.myStudy.Open(file)
91 if openedStudy == None:
92         raise  RuntimeError, "Can't open saved study!"
93
94 father = openedStudy.FindComponent("GEOM")
95 if father is None:
96          raise  RuntimeError, "Geom component is not found!  Wrong study is opened." 
97
98 # --- check attribute ---
99
100 res,A=father.FindAttribute("AttributeTableOfInteger")
101 if res == 0 or A == None:
102         raise  RuntimeError, "Error:  not found AttributeTableOfInteger"
103
104 A = A._narrow(SALOMEDS.AttributeTableOfInteger)
105
106 #check the table
107 print("Common title : ",A.GetTitle())
108 print("Rows titles : ",  A.GetRowTitles())
109 rnb = A.GetNbRows()
110 for i in range(1, rnb):
111         b=A.GetRow(i)
112         print(b)
113
114 cnb = A.GetNbColumns()
115 print("Columns title : ", A.GetColumnTitles())
116 for i in range(1, cnb):
117         b=A.GetColumn(i)
118         print(b)
119
120 titles=["ff","ss","tt"]
121 A.SetRowTitles(titles)
122 print("Rows titles : ",  A.GetRowTitles())
123
124 titles=["ww","zz","cc"]
125 A.SetColumnTitles(titles)
126 print("Column titles : ",  A.GetColumnTitles())
127