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