Salome HOME
NRI : Merge from V1_2.
[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    myBuilder.DefineComponentInstance(myComponent,myVisu)
30
31 # >>> Creating object with Table of integer ==================================
32 myTIntObject = myBuilder.NewObject(myComponent)
33 AName = myBuilder.FindOrCreateAttribute(myTIntObject, "AttributeName")
34 AName.SetValue("Table Of Integer")
35 AIntTable = myBuilder.FindOrCreateAttribute(myTIntObject, "AttributeTableOfInteger")
36
37 a=[1,2,3,4,5,6,7,8,9,10]
38 AIntTable.AddRow(a)
39 a=[110,120,130,140,150,160,170,180,190,200]
40 AIntTable.AddRow(a)
41 a=[-1,272,0,0,-642,10000,13,578,-578,99]
42 AIntTable.AddRow(a)
43 AIntTable.SetTitle("TEST table of integer")
44 AIntTable.SetRowTitle(1,"FR")
45 AIntTable.SetRowUnit(1,"m/h")
46 AIntTable.SetRowTitle(2,"SR")
47 AIntTable.SetRowUnit(2,"s")
48 AIntTable.SetRowTitle(3,"TR")
49 AIntTable.SetRowUnit(3,"$")
50 c=["C1","C2","C3","C4","C5","C6","C7","C8","C9","C10"]
51 AIntTable.SetColumnTitles(c)
52
53 # >>> Creating object with Table of real =====================================
54 myTRealObject = myBuilder.NewObject(myComponent)
55 AName = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeName")
56 AName.SetValue("Table Of Real")
57 ARealTable = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeTableOfReal")
58
59 k={}
60 l={}
61 for j in range(0,20):
62    k[j] = j*10+1
63    l[j] = "C"+str(j+1)
64 ARealTable.AddRow(k.values())
65 ARealTable.SetRowTitle(1, "Row 0")
66 ARealTable.SetRowUnit(1, "Hz")
67 ARealTable.SetColumnTitles(l.values())
68 for i in range(1,11):
69    for j in range(1,21):
70       if j % 2 == 1:
71          k[j] = math.log10(j*30*math.pi/180) * 20 + i * 15 + j*5
72       else:
73          k[j] = math.sin(j*30*math.pi/180) * 20 + i * 15 + j*5 
74    ARealTable.AddRow(k.values())
75    ARealTable.SetRowTitle(i+1, "Row " + str(i))
76    ARealTable.SetRowUnit(i+1, "Wt")
77 ARealTable.SetTitle("TEST table of real")
78
79 # >>> Creating object with integer attribute =================================
80 myIntObject = myBuilder.NewObject(myComponent)
81 AName = myBuilder.FindOrCreateAttribute(myIntObject, "AttributeName")
82 AName.SetValue("Integer")
83 AInt = myBuilder.FindOrCreateAttribute(myIntObject, "AttributeInteger")
84 AInt.SetValue(123)
85
86 # >>> Creating object with real attribute ====================================
87 myRealObject = myBuilder.NewObject(myComponent)
88 AName = myBuilder.FindOrCreateAttribute(myRealObject, "AttributeName")
89 AName.SetValue("Real")
90 AReal = myBuilder.FindOrCreateAttribute(myRealObject, "AttributeReal")
91 AReal.SetValue(-56.9634)
92
93 # >>> Creating object with comment attribute =================================
94 myCmtObject = myBuilder.NewObject(myComponent)
95 AName = myBuilder.FindOrCreateAttribute(myCmtObject, "AttributeName")
96 AName.SetValue("Comment")
97 ACmt = myBuilder.FindOrCreateAttribute(myCmtObject, "AttributeComment")
98 ACmt.SetValue("Just a comment")
99
100 # >>> Create VISU presentable objects ========================================
101 # >>> Create table of real
102 myVisuTableReal = myVisu.CreateTable( myTRealObject.GetID() )
103
104 # >>> Create curves
105 myCurve1 = myVisu.CreateCurve( myVisuTableReal, 1, 2 )
106 myCurve2 = myVisu.CreateCurve( myVisuTableReal, 1, 3 )
107 myCurve3 = myVisu.CreateCurve( myVisuTableReal, 1, 4 )
108 myCurve4 = myVisu.CreateCurve( myVisuTableReal, 1, 6 )
109 myCurve5 = myVisu.CreateCurve( myVisuTableReal, 1, 8 )
110 myCurve6 = myVisu.CreateCurve( myVisuTableReal, 1, 11 )
111
112 # >>> Set curve parameters
113 myCurve4.SetMarker( VISU.Curve.RECTANGLE )
114 myCurve4.SetLine( VISU.Curve.DASHLINE, 3 )
115 myCurve4.SetColor( SALOMEDS.Color(0, 0.7, 0.3) )
116 myCurve6.SetMarker( VISU.Curve.LTRIANGLE )
117 myCurve6.SetLine( VISU.Curve.DOTLINE, 2 )
118 myCurve6.SetColor( SALOMEDS.Color(0.2, 0.2, 0.9) )
119
120 # >>> Create container and insert curves
121 myContainer1 = myVisu.CreateContainer()
122 myContainer1.AddCurve(myCurve1)
123 myContainer1.AddCurve(myCurve2)
124 myContainer1.AddCurve(myCurve3)
125 myContainer1.AddCurve(myCurve4)
126 myContainer1.AddCurve(myCurve5)
127 myContainer1.AddCurve(myCurve6)
128
129 # >>> Create container and insert curves
130 myContainer2 = myVisu.CreateContainer()
131 myContainer2.AddCurve(myCurve4)
132
133 # >>> Create table of integer
134 myVisuTableInt = myVisu.CreateTable( myTIntObject.GetID() )
135
136 # >>> Create curves
137 myCurve101 = myVisu.CreateCurve( myVisuTableInt, 1, 1 )
138 myCurve102 = myVisu.CreateCurve( myVisuTableInt, 1, 3 )
139
140 # >>> Set curve parameters
141 myCurve101.SetMarker( VISU.Curve.RECTANGLE )
142 myCurve101.SetLine( VISU.Curve.DASHLINE, 3 )
143 myCurve101.SetColor( SALOMEDS.Color(0, 0.7, 0.3) )
144 myCurve101.SetTitle( "Very useful data" )
145
146 # >>> Create container and insert curves
147 myContainer3 = myVisu.CreateContainer()
148 myContainer3.AddCurve(myCurve101)
149 myContainer3.AddCurve(myCurve102)
150
151 # >>> Updating Object Browser ================================================
152 salome.sg.updateObjBrowser(1)
153
154 # ============================================================================
155
156
157