Back to index

salome-paravis  6.5.0
C3.py
Go to the documentation of this file.
00001 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 #
00003 # This library is free software; you can redistribute it and/or
00004 # modify it under the terms of the GNU Lesser General Public
00005 # License as published by the Free Software Foundation; either
00006 # version 2.1 of the License.
00007 #
00008 # This library is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 # Lesser General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU Lesser General Public
00014 # License along with this library; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 #
00017 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 #
00019 
00020 # This case corresponds to: /visu/SWIG_scripts/C3 case
00021 # Create table and display curves
00022 
00023 import paraview.simple as pv
00024 import paraview.servermanager as sm
00025 
00026 
00027 # Define script for table creation
00028 script = """
00029 import math
00030 
00031 
00032 # Get table output
00033 table = self.GetTableOutput()
00034 
00035 nb_rows = 10
00036 nb_cols = 200
00037 
00038 # Create first column
00039 col1 = vtk.vtkDoubleArray()
00040 col1.SetName('Frequency')
00041 for i in xrange(0, nb_rows):
00042     col1.InsertNextValue(i * 10 + 1)
00043 table.AddColumn(col1)
00044 
00045 # Create the rest columns
00046 for i in xrange(1, nb_cols + 1):
00047    col = vtk.vtkDoubleArray()
00048    col.SetName('Power ' + str(i))
00049 
00050    # Fill the next column
00051    for j in xrange(0, nb_rows):
00052       if j % 2 == 1:
00053          col.InsertNextValue(math.log10(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
00054       else:
00055          col.InsertNextValue(math.sin(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
00056 
00057    table.AddColumn(col)
00058 """
00059 
00060 # Creating programmable source (table)
00061 ps = pv.ProgrammableSource()
00062 ps.OutputDataSetType = 'vtkTable'
00063 ps.Script = script
00064 pv.RenameSource("Very useful data", ps)
00065 ps.UpdatePipeline()
00066 
00067 # Display table
00068 # TODO: no possibility to create spreadsheet view
00069 
00070 # Display curves
00071 xy_view = pv.CreateXYPlotView()
00072 xy_view.ChartTitle = 'Very useful data'
00073 xy_view.AxisTitle = ['[ Wt ]', 'Frequency [ Hz ]']
00074 
00075 xy_rep = pv.Show(ps)
00076 xy_rep.AttributeType = 'Row Data'
00077 xy_rep.UseIndexForXAxis = 0
00078 xy_rep.XArrayName = 'Frequency'
00079 xy_rep.SeriesVisibility = ['Frequency', '0']
00080 pv.Render(xy_view)
00081 
00082 # Hide legend
00083 xy_view.ShowLegend = 0
00084 pv.Render(xy_view)
00085 
00086 # Set logarithmic scaling for X axis
00087 xy_view.AxisLogScale[1] = 1
00088 pv.Render(xy_view)
00089 
00090 # Set linear scaling for X axis
00091 xy_view.AxisLogScale[1] = 0
00092 pv.Render(xy_view)
00093 
00094 # Set logarithmic scaling for X axis
00095 xy_view.AxisLogScale[0] = 1
00096 pv.Render(xy_view)
00097 
00098 # Show legend
00099 xy_view.ShowLegend = 1
00100 pv.Render(xy_view)