Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / VISU_SWIG / VISU_Example_05.py
1 #  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Create a table and show it in Plot2d viewer
21
22 # This script is equivalent to script VISU_SWIG/visu_big_table.py
23
24 import salome
25 import math
26 import SALOMEDS
27 import VISU
28 #from visu_gui import *
29
30 # >>> Getting study builder ==================================================
31 myStudy = salome.myStudy
32 myBuilder = myStudy.NewBuilder()
33
34 # >>> Getting (loading) VISU component =======================================
35 myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
36 myComponent = myStudy.FindComponent("VISU")
37 myVisu.SetCurrentStudy(myStudy)
38 if not myComponent:
39    myComponent = myBuilder.NewComponent("VISU")
40    aName = myBuilder.FindOrCreateAttribute(myComponent, "AttributeName")
41    aName.SetValue( salome.sg.getComponentUserName("VISU") )
42    
43    A2 = myBuilder.FindOrCreateAttribute(myComponent, "AttributePixMap");
44    aPixmap = A2._narrow(SALOMEDS.AttributePixMap);
45    aPixmap.SetPixMap( "ICON_OBJBROWSER_Visu" );
46    
47    myBuilder.DefineComponentInstance(myComponent,myVisu)
48
49 # >>> Creating object with Table of real[ 200 * 20 ] =========================
50 myTRealObject = myBuilder.NewObject(myComponent)
51 AName = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeName")
52 AName.SetValue("Table Of Real")
53 ARealTable = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeTableOfReal")
54 myHorNb = 10
55 myVerNb = 200
56
57 k={}
58 for j in range(0,myHorNb):
59    k[j] = j*10+1
60 ARealTable.AddRow(k.values())
61 ARealTable.SetRowTitle(1, "Frequency")
62 ARealTable.SetRowUnit(1, "Hz")
63
64 for i in range(1,myVerNb+1):
65    for j in range(0,myHorNb):
66       if j % 2 == 1:
67          k[j] = math.log10(j*30*math.pi/180) * 20 + i * 15 + j*5
68       else:
69          k[j] = math.sin(j*30*math.pi/180) * 20 + i * 15 + j*5 
70    ARealTable.AddRow(k.values())
71    ARealTable.SetRowTitle(i+1, "Power " + str(i))
72    ARealTable.SetRowUnit(i+1, "Wt")
73
74 ARealTable.SetTitle("Very useful data")
75
76 # >>> Create Visu table ======================================================
77 myVisuTableReal = myVisu.CreateTable( myTRealObject.GetID() )
78
79 # >>> Create container and insert curves
80 myContainer = myVisu.CreateContainer()
81
82 # >>> Create curves ==========================================================
83 for i in range(1,myVerNb+1):
84    myCurve = myVisu.CreateCurve( myVisuTableReal, 1, i+1 )
85    myContainer.AddCurve(myCurve)
86
87 # >>> Updating Object Browser ================================================
88 salome.sg.updateObjBrowser(1)
89
90 # >>> Display curves in Plot2d viewer ========================================
91 myViewManager = myVisu.GetViewManager();
92 myView = myViewManager.CreateXYPlot();
93 myView.SetTitle("The viewer for Curves from the Table")
94 myView.Display(myContainer)
95
96 # ============================================================================