Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISU_SWIG / visu_table.py
1 #  VISU VISU_SWIG : binding of C++ implementation and Python
2 #
3 #  Copyright (C) 2003  CEA/DEN, EDF R&D
4 #
5 #
6 #
7 #  File   : visu_table.py
8 #  Author : Vadim SANDLER
9 #  Module : VISU
10 #  $Header$
11
12 import salome
13 import math
14 import SALOMEDS
15 import VISU
16
17 # >>> Getting study builder ==================================================
18 myStudy = salome.myStudy
19 myBuilder = myStudy.NewBuilder()
20
21 # >>> Getting (loading) VISU component =======================================
22 myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
23 myComponent = myStudy.FindComponent("VISU")
24 myVisu.SetCurrentStudy(myStudy)
25 if not myComponent:
26    myComponent = myBuilder.NewComponent("VISU")
27    aName = myBuilder.FindOrCreateAttribute(myComponent, "AttributeName")
28    #aName.SetValue("Visu")
29    aName.SetValue( salome.sg.getComponentUserName("VISU") )
30
31    A2 = myBuilder.FindOrCreateAttribute(myComponent, "AttributePixMap");
32    aPixmap = A2._narrow(SALOMEDS.AttributePixMap);
33    aPixmap.SetPixMap( "ICON_OBJBROWSER_Visu" );
34    
35    myBuilder.DefineComponentInstance(myComponent,myVisu)
36
37 # >>> Creating object with Table of integer ==================================
38 myTIntObject = myBuilder.NewObject(myComponent)
39 AName = myBuilder.FindOrCreateAttribute(myTIntObject, "AttributeName")
40 AName.SetValue("Table Of Integer")
41 AIntTable = myBuilder.FindOrCreateAttribute(myTIntObject, "AttributeTableOfInteger")
42
43 a=[1,2,3,4,5,6,7,8,9,10]
44 AIntTable.AddRow(a)
45 a=[110,120,130,140,150,160,170,180,190,200]
46 AIntTable.AddRow(a)
47 a=[-1,272,0,0,-642,10000,13,578,-578,99]
48 AIntTable.AddRow(a)
49 AIntTable.SetTitle("TEST table of integer")
50 AIntTable.SetRowTitle(1,"FR")
51 AIntTable.SetRowUnit(1,"m/h")
52 AIntTable.SetRowTitle(2,"SR")
53 AIntTable.SetRowUnit(2,"s")
54 AIntTable.SetRowTitle(3,"TR")
55 AIntTable.SetRowUnit(3,"$")
56 c=["C1","C2","C3","C4","C5","C6","C7","C8","C9","C10"]
57 AIntTable.SetColumnTitles(c)
58
59 # >>> Creating object with Table of real =====================================
60 myTRealObject = myBuilder.NewObject(myComponent)
61 AName = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeName")
62 AName.SetValue("Table Of Real")
63 ARealTable = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeTableOfReal")
64
65 k={}
66 l={}
67 for j in range(0,20):
68    k[j] = j*10+1
69    l[j] = "C"+str(j+1)
70 ARealTable.AddRow(k.values())
71 ARealTable.SetRowTitle(1, "Row 0")
72 ARealTable.SetRowUnit(1, "Hz")
73 ARealTable.SetColumnTitles(l.values())
74 for i in range(1,11):
75    for j in range(1,21):
76       if j % 2 == 1:
77          k[j] = math.log10(j*30*math.pi/180) * 20 + i * 15 + j*5
78       else:
79          k[j] = math.sin(j*30*math.pi/180) * 20 + i * 15 + j*5 
80    ARealTable.AddRow(k.values())
81    ARealTable.SetRowTitle(i+1, "Row " + str(i))
82    ARealTable.SetRowUnit(i+1, "Wt")
83 ARealTable.SetTitle("TEST table of real")
84
85 # >>> Creating object with integer attribute =================================
86 myIntObject = myBuilder.NewObject(myComponent)
87 AName = myBuilder.FindOrCreateAttribute(myIntObject, "AttributeName")
88 AName.SetValue("Integer")
89 AInt = myBuilder.FindOrCreateAttribute(myIntObject, "AttributeInteger")
90 AInt.SetValue(123)
91
92 # >>> Creating object with real attribute ====================================
93 myRealObject = myBuilder.NewObject(myComponent)
94 AName = myBuilder.FindOrCreateAttribute(myRealObject, "AttributeName")
95 AName.SetValue("Real")
96 AReal = myBuilder.FindOrCreateAttribute(myRealObject, "AttributeReal")
97 AReal.SetValue(-56.9634)
98
99 # >>> Creating object with comment attribute =================================
100 myCmtObject = myBuilder.NewObject(myComponent)
101 AName = myBuilder.FindOrCreateAttribute(myCmtObject, "AttributeName")
102 AName.SetValue("Comment")
103 ACmt = myBuilder.FindOrCreateAttribute(myCmtObject, "AttributeComment")
104 ACmt.SetValue("Just a comment")
105
106 # >>> Create VISU presentable objects ========================================
107 # >>> Create table of real
108 myVisuTableReal = myVisu.CreateTable( myTRealObject.GetID() )
109
110 # >>> Create curves
111 myCurve1 = myVisu.CreateCurve( myVisuTableReal, 1, 2 )
112 myCurve2 = myVisu.CreateCurve( myVisuTableReal, 1, 3 )
113 myCurve3 = myVisu.CreateCurve( myVisuTableReal, 1, 4 )
114 myCurve4 = myVisu.CreateCurve( myVisuTableReal, 1, 6 )
115 myCurve5 = myVisu.CreateCurve( myVisuTableReal, 1, 8 )
116 myCurve6 = myVisu.CreateCurve( myVisuTableReal, 1, 11 )
117
118 # >>> Set curve parameters
119 myCurve4.SetMarker( VISU.Curve.RECTANGLE )
120 myCurve4.SetLine( VISU.Curve.DASHLINE, 3 )
121 myCurve4.SetColor( SALOMEDS.Color(0, 0.7, 0.3) )
122 myCurve6.SetMarker( VISU.Curve.LTRIANGLE )
123 myCurve6.SetLine( VISU.Curve.DOTLINE, 2 )
124 myCurve6.SetColor( SALOMEDS.Color(0.2, 0.2, 0.9) )
125
126 # >>> Create container and insert curves
127 myContainer1 = myVisu.CreateContainer()
128 myContainer1.AddCurve(myCurve1)
129 myContainer1.AddCurve(myCurve2)
130 myContainer1.AddCurve(myCurve3)
131 myContainer1.AddCurve(myCurve4)
132 myContainer1.AddCurve(myCurve5)
133 myContainer1.AddCurve(myCurve6)
134
135 # >>> Create container and insert curves
136 myContainer2 = myVisu.CreateContainer()
137 myContainer2.AddCurve(myCurve4)
138
139 # >>> Create table of integer
140 myVisuTableInt = myVisu.CreateTable( myTIntObject.GetID() )
141
142 # >>> Create curves
143 myCurve101 = myVisu.CreateCurve( myVisuTableInt, 1, 1 )
144 myCurve102 = myVisu.CreateCurve( myVisuTableInt, 1, 3 )
145
146 # >>> Set curve parameters
147 myCurve101.SetMarker( VISU.Curve.RECTANGLE )
148 myCurve101.SetLine( VISU.Curve.DASHLINE, 3 )
149 myCurve101.SetColor( SALOMEDS.Color(0, 0.7, 0.3) )
150 myCurve101.SetTitle( "Very useful data" )
151
152 # >>> Create container and insert curves
153 myContainer3 = myVisu.CreateContainer()
154 myContainer3.AddCurve(myCurve101)
155 myContainer3.AddCurve(myCurve102)
156
157 # >>> Updating Object Browser ================================================
158 salome.sg.updateObjBrowser(1)
159
160 # ============================================================================
161
162
163