Salome HOME
bbd01c2080c7a763eb02c94b3803ea27c04ed156
[modules/paravis.git] / test / VisuPrs / SWIG_scripts / C3.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/C3 case
21 # Create table and display curves
22
23 # Do not use pv as a short name.
24 # It is a name of function from numpy and may be redefined implicitly by 'from numpy import *' call.
25 # import paraview.simple as pv
26 import paraview.simple as pvs
27 import paraview.servermanager as sm
28
29
30 # Define script for table creation
31 script = """
32 import math
33
34
35 # Get table output
36 table = self.GetTableOutput()
37
38 nb_rows = 10
39 nb_cols = 200
40
41 # Create first column
42 col1 = vtk.vtkDoubleArray()
43 col1.SetName('Frequency')
44 for i in xrange(0, nb_rows):
45     col1.InsertNextValue(i * 10 + 1)
46 table.AddColumn(col1)
47
48 # Create the rest columns
49 for i in xrange(1, nb_cols + 1):
50    col = vtk.vtkDoubleArray()
51    col.SetName('Power ' + str(i))
52
53    # Fill the next column
54    for j in xrange(0, nb_rows):
55       if j % 2 == 1:
56          col.InsertNextValue(math.log10(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
57       else:
58          col.InsertNextValue(math.sin(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
59
60    table.AddColumn(col)
61 """
62
63 # Creating programmable source (table)
64 ps = pvs.ProgrammableSource()
65 ps.OutputDataSetType = 'vtkTable'
66 ps.Script = script
67 pvs.RenameSource("Very useful data", ps)
68 ps.UpdatePipeline()
69
70 # Display table
71 # TODO: no possibility to create spreadsheet view
72
73 # Display curves
74 xy_view = pvs.CreateXYPlotView()
75 xy_view.ChartTitle = 'Very useful data'
76 xy_view.AxisTitle = ['[ Wt ]', 'Frequency [ Hz ]']
77
78 xy_rep = pvs.Show(ps)
79 xy_rep.AttributeType = 'Row Data'
80 xy_rep.UseIndexForXAxis = 0
81 xy_rep.XArrayName = 'Frequency'
82 xy_rep.SeriesVisibility = ['Frequency', '0']
83 pvs.Render(xy_view)
84
85 # Hide legend
86 xy_view.ShowLegend = 0
87 pvs.Render(xy_view)
88
89 # Set logarithmic scaling for X axis
90 xy_view.AxisLogScale[1] = 1
91 pvs.Render(xy_view)
92
93 # Set linear scaling for X axis
94 xy_view.AxisLogScale[1] = 0
95 pvs.Render(xy_view)
96
97 # Set logarithmic scaling for X axis
98 xy_view.AxisLogScale[0] = 1
99 pvs.Render(xy_view)
100
101 # Show legend
102 xy_view.ShowLegend = 1
103 pvs.Render(xy_view)