Salome HOME
Preparation of 3.1.0a2: version ID. compilation with new KERNEL
[modules/visu.git] / examples / VISU_Example_05.py
1 # Create a table and show it in Plot2d viewer
2
3 # This script is equivalent to script VISU_SWIG/visu_big_table.py
4
5 import salome
6 import math
7 import SALOMEDS
8 import VISU
9 #from visu_gui import *
10
11 # >>> Getting study builder ==================================================
12 myStudy = salome.myStudy
13 myBuilder = myStudy.NewBuilder()
14
15 # >>> Getting (loading) VISU component =======================================
16 myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
17 myComponent = myStudy.FindComponent("VISU")
18 myVisu.SetCurrentStudy(myStudy)
19 if not myComponent:
20    myComponent = myBuilder.NewComponent("VISU")
21    aName = myBuilder.FindOrCreateAttribute(myComponent, "AttributeName")
22    aName.SetValue( salome.sg.getComponentUserName("VISU") )
23    
24    A2 = myBuilder.FindOrCreateAttribute(myComponent, "AttributePixMap");
25    aPixmap = A2._narrow(SALOMEDS.AttributePixMap);
26    aPixmap.SetPixMap( "ICON_OBJBROWSER_Visu" );
27    
28    myBuilder.DefineComponentInstance(myComponent,myVisu)
29
30 # >>> Creating object with Table of real[ 200 * 20 ] =========================
31 myTRealObject = myBuilder.NewObject(myComponent)
32 AName = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeName")
33 AName.SetValue("Table Of Real")
34 ARealTable = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeTableOfReal")
35 myHorNb = 10
36 myVerNb = 200
37
38 k={}
39 for j in range(0,myHorNb):
40    k[j] = j*10+1
41 ARealTable.AddRow(k.values())
42 ARealTable.SetRowTitle(1, "Frequency")
43 ARealTable.SetRowUnit(1, "Hz")
44
45 for i in range(1,myVerNb+1):
46    for j in range(0,myHorNb):
47       if j % 2 == 1:
48          k[j] = math.log10(j*30*math.pi/180) * 20 + i * 15 + j*5
49       else:
50          k[j] = math.sin(j*30*math.pi/180) * 20 + i * 15 + j*5 
51    ARealTable.AddRow(k.values())
52    ARealTable.SetRowTitle(i+1, "Power " + str(i))
53    ARealTable.SetRowUnit(i+1, "Wt")
54
55 ARealTable.SetTitle("Very useful data")
56
57 # >>> Create Visu table ======================================================
58 myVisuTableReal = myVisu.CreateTable( myTRealObject.GetID() )
59
60 # >>> Create container and insert curves
61 myContainer = myVisu.CreateContainer()
62
63 # >>> Create curves ==========================================================
64 for i in range(1,myVerNb+1):
65    myCurve = myVisu.CreateCurve( myVisuTableReal, 1, i+1 )
66    myContainer.AddCurve(myCurve)
67
68 # >>> Updating Object Browser ================================================
69 salome.sg.updateObjBrowser(1)
70
71 # >>> Display curves in Plot2d viewer ========================================
72 myViewManager = myVisu.GetViewManager();
73 myView = myViewManager.CreateXYPlot();
74 myView.SetTitle("The viewer for Curves from the Table")
75 myView.Display(myContainer)
76
77 # ============================================================================