Salome HOME
enable make test
[modules/paravis.git] / test / VisuPrs / SWIG_scripts / B6.py
1 # Copyright (C) 2010-2015  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # This case corresponds to: /visu/SWIG_scripts/B6 case
21 # Create table of integer, create table of real, create curves
22
23 from paravistest import tablesdir
24 import pvsimple
25
26 # Define script for table of integer creation
27 script_ti = """
28 def add_column(table, name, lst):
29     col = vtk.vtkIntArray()
30     col.SetName(name)
31     for item in lst:
32         col.InsertNextValue(item)
33     table.AddColumn(col)
34
35 # Get table output
36 table = self.GetTableOutput()
37
38 # Add columns
39 lst = [1,2,3,4,5,6,7,8,9,10]
40 add_column(table, 'FR', lst)
41
42 lst = [110,120,130,140,150,160,170,180,190,200]
43 add_column(table, 'SR', lst)
44
45 lst = [-1,272,0,0,-642,10000,13,578,-578,99]
46 add_column(table, 'TR', lst)
47 """
48
49 # Define script for table of real creation
50 script_tr = """
51 import math
52
53
54 # Get table output
55 table = self.GetTableOutput()
56
57 # Create first column
58 col1 = vtk.vtkDoubleArray()
59 col1.SetName('Row 0')
60 for i in xrange(0, 21):
61     col1.InsertNextValue(i * 10 + 1)
62 table.AddColumn(col1)
63
64 # Create the rest columns
65 for i in range(1, 11):
66     col = vtk.vtkDoubleArray()
67     col.SetName('Row ' + str(i))
68
69     # Fill the next column
70     col.InsertNextValue(1)
71     for j in range(1, 21):
72         if j % 2 == 1:
73             col.InsertNextValue(math.log10(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
74         else:
75             col.InsertNextValue(math.sin(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
76
77     table.AddColumn(col)
78 """
79
80 # Creating programmable source for the table of integer
81 ps_ti = pvsimple.ProgrammableSource()
82 ps_ti.OutputDataSetType = 'vtkTable'
83 ps_ti.Script = script_ti
84 pvsimple.RenameSource("TEST table of integer", ps_ti)
85 ps_ti.UpdatePipeline()
86
87 # Creating programmable source for the table of real
88 ps_tr = pvsimple.ProgrammableSource()
89 ps_tr.OutputDataSetType = 'vtkTable'
90 ps_tr.Script = script_tr
91 pvsimple.RenameSource("TEST table of real", ps_tr)
92 ps_tr.UpdatePipeline()
93
94 # Replace the current view with chart line one
95 cur_view = pvsimple.GetRenderView()
96 if cur_view:
97     pvsimple.Delete(cur_view)
98
99 xy_view1 = pvsimple.CreateXYPlotView()
100 xy_view1.ChartTitle = 'TEST table of real'
101 xy_view1.AxisTitle = ['[ Wt ]', 'Row 0 [ Hz ]']
102
103 # Display curves for the table of real
104 tr_rep = pvsimple.Show(ps_tr)
105 tr_rep.AttributeType = 'Row Data'
106 tr_rep.UseIndexForXAxis = 0
107 tr_rep.XArrayName = 'Row 0'
108 tr_rep.SeriesVisibility = ['Row 0', '0', 'Row 4', '0', \
109 'Row 6', '0', 'Row 8', '0', 'Row 9', '0']
110
111 # Set 'Square' marker style for 'Row 5' line
112 tr_rep.SeriesMarkerStyle = ['Row 5', '3']
113 # Set 'Dash' line style for 'Row 5' line
114 tr_rep.SeriesLineStyle = ['Row 5', '2']
115 # Set color for 'Row 5' line
116 tr_rep.SeriesColor = ['Row 5', '0', '0.7', '0.3']
117 # Set 'Diamond' marker style for 'Row 10' line
118 tr_rep.SeriesMarkerStyle = ['Row 10', '5']
119 # Set 'Dot' line style for 'Row 10' line
120 tr_rep.SeriesLineStyle = ['Row 10', '3']
121 # Set color for 'Row 10' line
122 tr_rep.SeriesColor = ['Row 10', '0.2', '0.2', '0.9']
123
124 # Create another chart line view
125 xy_view2 = pvsimple.CreateXYPlotView()
126 xy_view2.ChartTitle = 'TEST table of integer'
127 xy_view2.AxisTitle = ['', 'FR [ m/h ]']
128
129 # Display curves for the table of integer
130 ti_rep = pvsimple.Show(ps_ti, xy_view2)
131 ti_rep.AttributeType = 'Row Data'
132 ti_rep.UseIndexForXAxis = 0
133 ti_rep.XArrayName = 'FR'
134 ti_rep.SeriesVisibility = ['SR', '0']
135
136 # Change legend label for "FR" line
137 ti_rep.SeriesLabel = ["FR", "FREQ"]
138
139 # Set 'Square' marker style for 'FR' line
140 ti_rep.SeriesMarkerStyle = ['FR', '3']
141 # Set 'Dash' line style for 'FR' line
142 ti_rep.SeriesLineStyle = ['FR', '2']
143 # Set color for 'FR' line
144 ti_rep.SeriesColor = ['FR', '0', '0.7', '0.3']
145
146
147 # Update views
148 pvsimple.Render(xy_view1)
149 pvsimple.Render(xy_view2)