]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_SWIG/visu_table.py
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / VISU_SWIG / visu_table.py
1 #  VISU VISU_SWIG : binding of C++ implementation and Python
2 #
3 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5
6 #  This library is free software; you can redistribute it and/or 
7 #  modify it under the terms of the GNU Lesser General Public 
8 #  License as published by the Free Software Foundation; either 
9 #  version 2.1 of the License. 
10
11 #  This library is distributed in the hope that it will be useful, 
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 #  Lesser General Public License for more details. 
15
16 #  You should have received a copy of the GNU Lesser General Public 
17 #  License along with this library; if not, write to the Free Software 
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #  File   : visu_table.py
23 #  Author : Vadim SANDLER
24 #  Module : VISU
25 #  $Header$
26
27 import salome
28 import math
29 import SALOMEDS
30 import VISU
31
32 # >>> Getting study builder ==================================================
33 myStudy = salome.myStudy
34 myBuilder = myStudy.NewBuilder()
35
36 # >>> Getting (loading) VISU component =======================================
37 myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
38 myComponent = myStudy.FindComponent("VISU")
39 myVisu.SetCurrentStudy(myStudy)
40 if not myComponent:
41    myComponent = myBuilder.NewComponent("VISU")
42    aName = myBuilder.FindOrCreateAttribute(myComponent, "AttributeName")
43    #aName.SetValue("Visu")
44    aName.SetValue( salome.sg.getComponentUserName("VISU") )
45
46    A2 = myBuilder.FindOrCreateAttribute(myComponent, "AttributePixMap");
47    aPixmap = A2._narrow(SALOMEDS.AttributePixMap);
48    aPixmap.SetPixMap( "ICON_OBJBROWSER_Visu" );
49    
50    myBuilder.DefineComponentInstance(myComponent,myVisu)
51
52 # >>> Creating object with Table of integer ==================================
53 myTIntObject = myBuilder.NewObject(myComponent)
54 AName = myBuilder.FindOrCreateAttribute(myTIntObject, "AttributeName")
55 AName.SetValue("Table Of Integer")
56 AIntTable = myBuilder.FindOrCreateAttribute(myTIntObject, "AttributeTableOfInteger")
57
58 a=[1,2,3,4,5,6,7,8,9,10]
59 AIntTable.AddRow(a)
60 a=[110,120,130,140,150,160,170,180,190,200]
61 AIntTable.AddRow(a)
62 a=[-1,272,0,0,-642,10000,13,578,-578,99]
63 AIntTable.AddRow(a)
64 AIntTable.SetTitle("TEST table of integer")
65 AIntTable.SetRowTitle(1,"FR")
66 AIntTable.SetRowUnit(1,"m/h")
67 AIntTable.SetRowTitle(2,"SR")
68 AIntTable.SetRowUnit(2,"s")
69 AIntTable.SetRowTitle(3,"TR")
70 AIntTable.SetRowUnit(3,"$")
71 c=["C1","C2","C3","C4","C5","C6","C7","C8","C9","C10"]
72 AIntTable.SetColumnTitles(c)
73
74 # >>> Creating object with Table of real =====================================
75 myTRealObject = myBuilder.NewObject(myComponent)
76 AName = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeName")
77 AName.SetValue("Table Of Real")
78 ARealTable = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeTableOfReal")
79
80 k={}
81 l={}
82 for j in range(0,20):
83    k[j] = j*10+1
84    l[j] = "C"+str(j+1)
85 ARealTable.AddRow(k.values())
86 ARealTable.SetRowTitle(1, "Row 0")
87 ARealTable.SetRowUnit(1, "Hz")
88 ARealTable.SetColumnTitles(l.values())
89 for i in range(1,11):
90    for j in range(1,21):
91       if j % 2 == 1:
92          k[j] = math.log10(j*30*math.pi/180) * 20 + i * 15 + j*5
93       else:
94          k[j] = math.sin(j*30*math.pi/180) * 20 + i * 15 + j*5 
95    ARealTable.AddRow(k.values())
96    ARealTable.SetRowTitle(i+1, "Row " + str(i))
97    ARealTable.SetRowUnit(i+1, "Wt")
98 ARealTable.SetTitle("TEST table of real")
99
100 # >>> Creating object with integer attribute =================================
101 myIntObject = myBuilder.NewObject(myComponent)
102 AName = myBuilder.FindOrCreateAttribute(myIntObject, "AttributeName")
103 AName.SetValue("Integer")
104 AInt = myBuilder.FindOrCreateAttribute(myIntObject, "AttributeInteger")
105 AInt.SetValue(123)
106
107 # >>> Creating object with real attribute ====================================
108 myRealObject = myBuilder.NewObject(myComponent)
109 AName = myBuilder.FindOrCreateAttribute(myRealObject, "AttributeName")
110 AName.SetValue("Real")
111 AReal = myBuilder.FindOrCreateAttribute(myRealObject, "AttributeReal")
112 AReal.SetValue(-56.9634)
113
114 # >>> Creating object with comment attribute =================================
115 myCmtObject = myBuilder.NewObject(myComponent)
116 AName = myBuilder.FindOrCreateAttribute(myCmtObject, "AttributeName")
117 AName.SetValue("Comment")
118 ACmt = myBuilder.FindOrCreateAttribute(myCmtObject, "AttributeComment")
119 ACmt.SetValue("Just a comment")
120
121 # >>> Create VISU presentable objects ========================================
122 # >>> Create table of real
123 myVisuTableReal = myVisu.CreateTable( myTRealObject.GetID() )
124
125 # >>> Create curves
126 myCurve1 = myVisu.CreateCurve( myVisuTableReal, 1, 2 )
127 myCurve2 = myVisu.CreateCurve( myVisuTableReal, 1, 3 )
128 myCurve3 = myVisu.CreateCurve( myVisuTableReal, 1, 4 )
129 myCurve4 = myVisu.CreateCurve( myVisuTableReal, 1, 6 )
130 myCurve5 = myVisu.CreateCurve( myVisuTableReal, 1, 8 )
131 myCurve6 = myVisu.CreateCurve( myVisuTableReal, 1, 11 )
132
133 # >>> Set curve parameters
134 myCurve4.SetMarker( VISU.Curve.RECTANGLE )
135 myCurve4.SetLine( VISU.Curve.DASHLINE, 3 )
136 myCurve4.SetColor( SALOMEDS.Color(0, 0.7, 0.3) )
137 myCurve6.SetMarker( VISU.Curve.LTRIANGLE )
138 myCurve6.SetLine( VISU.Curve.DOTLINE, 2 )
139 myCurve6.SetColor( SALOMEDS.Color(0.2, 0.2, 0.9) )
140
141 # >>> Create container and insert curves
142 myContainer1 = myVisu.CreateContainer()
143 myContainer1.AddCurve(myCurve1)
144 myContainer1.AddCurve(myCurve2)
145 myContainer1.AddCurve(myCurve3)
146 myContainer1.AddCurve(myCurve4)
147 myContainer1.AddCurve(myCurve5)
148 myContainer1.AddCurve(myCurve6)
149
150 # >>> Create container and insert curves
151 myContainer2 = myVisu.CreateContainer()
152 myContainer2.AddCurve(myCurve4)
153
154 # >>> Create table of integer
155 myVisuTableInt = myVisu.CreateTable( myTIntObject.GetID() )
156
157 # >>> Create curves
158 myCurve101 = myVisu.CreateCurve( myVisuTableInt, 1, 1 )
159 myCurve102 = myVisu.CreateCurve( myVisuTableInt, 1, 3 )
160
161 # >>> Set curve parameters
162 myCurve101.SetMarker( VISU.Curve.RECTANGLE )
163 myCurve101.SetLine( VISU.Curve.DASHLINE, 3 )
164 myCurve101.SetColor( SALOMEDS.Color(0, 0.7, 0.3) )
165 myCurve101.SetTitle( "Very useful data" )
166
167 # >>> Create container and insert curves
168 myContainer3 = myVisu.CreateContainer()
169 myContainer3.AddCurve(myCurve101)
170 myContainer3.AddCurve(myCurve102)
171
172 # >>> Updating Object Browser ================================================
173 salome.sg.updateObjBrowser(1)
174
175 # ============================================================================
176
177
178