Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / SALOME_SWIG / test_table.py
1 # Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either 
6 # version 2.1 of the License.
7 #
8 # This library is distributed in the hope that it will be useful 
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public  
14 # License along with this library; if not, write to the Free Software 
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 #  File   : test_table.py
20 #  Author : Vadim SANDLER
21 #  Module : SALOME
22 #  $Header$
23
24 import salome
25 import math
26 import SALOMEDS
27
28 # >>> Getting study builder ==================================================
29 myStudy = salome.myStudy
30 myBuilder = myStudy.NewBuilder()
31
32 # >>> Creating virtual component =============================================
33 myComponent = myStudy.FindComponent("VirtualComponent")
34 if not myComponent:
35    myComponent = myBuilder.NewComponent("VirtualComponent")
36    aName = myBuilder.FindOrCreateAttribute(myComponent, "AttributeName")
37    aName.SetValue("VirtualComponent")
38
39 # >>> Creating object with Table of integer ==================================
40 myTIntObject = myBuilder.NewObject(myComponent)
41 AName = myBuilder.FindOrCreateAttribute(myTIntObject, "AttributeName")
42 AName.SetValue("Table Of Integer")
43 AIntTable = myBuilder.FindOrCreateAttribute(myTIntObject, "AttributeTableOfInteger")
44
45 a=[1,2,3,4,5,6,7,8,9,10]
46 AIntTable.AddRow(a)
47 a=[110,120,130,140,150,160,170,180,190,200]
48 AIntTable.AddRow(a)
49 a=[-1,272,0,0,-642,10000,13,578,-578,99]
50 AIntTable.AddRow(a)
51 AIntTable.SetTitle("TEST table of integer")
52 AIntTable.SetRowTitle(1,"FR")
53 AIntTable.SetRowUnit(1,"m/h")
54 AIntTable.SetRowTitle(2,"SR")
55 AIntTable.SetRowUnit(2,"s")
56 AIntTable.SetRowTitle(3,"TR")
57 AIntTable.SetRowUnit(3,"$")
58 c=["C1","C2","C3","C4","C5","C6","C7","C8","C9","C10"]
59 AIntTable.SetColumnTitles(c)
60
61 # >>> Creating object with Table of real =====================================
62 myTRealObject = myBuilder.NewObject(myComponent)
63 AName = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeName")
64 AName.SetValue("Table Of Real")
65 ARealTable = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeTableOfReal")
66
67 k={}
68 l={}
69 for j in range(0,20):
70    k[j] = j*10+1
71    l[j] = "C"+str(j+1)
72 ARealTable.AddRow(k.values())
73 ARealTable.SetRowTitle(1, "Row 0")
74 ARealTable.SetRowUnit(1, "Hz")
75 ARealTable.SetColumnTitles(l.values())
76 for i in range(1,11):
77    for j in range(1,21):
78       if j % 2 == 1:
79          k[j] = math.log10(j*30*math.pi/180) * 20 + i * 15 + j*5
80       else:
81          k[j] = math.sin(j*30*math.pi/180) * 20 + i * 15 + j*5 
82    ARealTable.AddRow(k.values())
83    ARealTable.SetRowTitle(i+1, "Row " + str(i))
84    ARealTable.SetRowUnit(i+1, "Wt")
85 ARealTable.SetTitle("TEST table of real")
86
87 # >>> Creating object with integer attribute =================================
88 myIntObject = myBuilder.NewObject(myComponent)
89 AName = myBuilder.FindOrCreateAttribute(myIntObject, "AttributeName")
90 AName.SetValue("Integer")
91 AInt = myBuilder.FindOrCreateAttribute(myIntObject, "AttributeInteger")
92 AInt.SetValue(123)
93
94 # >>> Creating object with real attribute ====================================
95 myRealObject = myBuilder.NewObject(myComponent)
96 AName = myBuilder.FindOrCreateAttribute(myRealObject, "AttributeName")
97 AName.SetValue("Real")
98 AReal = myBuilder.FindOrCreateAttribute(myRealObject, "AttributeReal")
99 AReal.SetValue(-56.9634)
100
101 # >>> Creating object with comment attribute =================================
102 myCmtObject = myBuilder.NewObject(myComponent)
103 AName = myBuilder.FindOrCreateAttribute(myCmtObject, "AttributeName")
104 AName.SetValue("Comment")
105 ACmt = myBuilder.FindOrCreateAttribute(myCmtObject, "AttributeComment")
106 ACmt.SetValue("Just a comment")
107
108 # >>> Updating Object Browser ================================================
109 salome.sg.updateObjBrowser(1)
110
111 # ============================================================================
112
113
114