Salome HOME
Porting to PV5.0.1
[modules/paravis.git] / test / VisuPrs / SWIG_scripts / A5.py
1 # Copyright (C) 2010-2016  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/A5 case
21 # Create table and display it as curves
22
23 from paravistest import tablesdir
24 import pvsimple
25
26 # Define script for table creation
27 script = """
28 import math
29
30
31 # Get table output
32 table = self.GetTableOutput()
33
34 nb_rows = 10
35 nb_cols = 200
36
37 # Create first column
38 col1 = vtk.vtkDoubleArray()
39 col1.SetName('Frequency')
40 for i in xrange(0, nb_rows):
41     col1.InsertNextValue(i * 10 + 1)
42 table.AddColumn(col1)
43
44 # Create the rest columns
45 for i in xrange(1, nb_cols + 1):
46    col = vtk.vtkDoubleArray()
47    col.SetName('Power ' + str(i))
48
49    # Fill the next column
50    for j in xrange(0, nb_rows):
51       if j % 2 == 1:
52          col.InsertNextValue(math.log10(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
53       else:
54          col.InsertNextValue(math.sin(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
55
56    table.AddColumn(col)
57 """
58
59 # Creating programmable source (table)
60 ps = pvsimple.ProgrammableSource()
61 ps.OutputDataSetType = 'vtkTable'
62 ps.Script = script
63 pvsimple.RenameSource("Very useful data", ps)
64 ps.UpdatePipeline()
65
66 # Display curves
67 cur_view = pvsimple.GetRenderView()
68 if cur_view:
69     pvsimple.Delete(cur_view)
70 xy_view = pvsimple.CreateXYPlotView()
71 xy_view.ChartTitle = 'Very useful data'
72 xy_view.AxisTitle = ['[ Wt ]', 'Frequency [ Hz ]']
73
74 xy_rep = pvsimple.Show(ps)
75 xy_rep.AttributeType = 'Row Data'
76 xy_rep.UseIndexForXAxis = 0
77 xy_rep.XArrayName = 'Frequency'
78 xy_rep.SeriesVisibility = ['Frequency', '0']
79
80 pvsimple.Render()