Back to index

salome-paravis  6.5.0
B6.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/B6 case
00021 # Create table of integer, create table of real, create curves
00022 
00023 from paravistest import tablesdir
00024 import paravis
00025 import pvsimple
00026 
00027 
00028 # Define script for table of integer creation
00029 script_ti = """
00030 def add_column(table, name, lst):
00031     col = vtk.vtkIntArray()
00032     col.SetName(name)
00033     for item in lst:
00034         col.InsertNextValue(item)
00035     table.AddColumn(col)
00036 
00037 # Get table output
00038 table = self.GetTableOutput()
00039 
00040 # Add columns
00041 lst = [1,2,3,4,5,6,7,8,9,10]
00042 add_column(table, 'FR', lst)
00043 
00044 lst = [110,120,130,140,150,160,170,180,190,200]
00045 add_column(table, 'SR', lst)
00046 
00047 lst = [-1,272,0,0,-642,10000,13,578,-578,99]
00048 add_column(table, 'TR', lst)
00049 """
00050 
00051 # Define script for table of real creation
00052 script_tr = """
00053 import math
00054 
00055 
00056 # Get table output
00057 table = self.GetTableOutput()
00058 
00059 # Create first column
00060 col1 = vtk.vtkDoubleArray()
00061 col1.SetName('Row 0')
00062 for i in xrange(0, 21):
00063     col1.InsertNextValue(i * 10 + 1)
00064 table.AddColumn(col1)
00065 
00066 # Create the rest columns
00067 for i in range(1, 11):
00068     col = vtk.vtkDoubleArray()
00069     col.SetName('Row ' + str(i))
00070 
00071     # Fill the next column
00072     col.InsertNextValue(1)
00073     for j in range(1, 21):
00074         if j % 2 == 1:
00075             col.InsertNextValue(math.log10(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
00076         else:
00077             col.InsertNextValue(math.sin(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
00078 
00079     table.AddColumn(col)
00080 """
00081 
00082 # Creating programmable source for the table of integer
00083 ps_ti = pvsimple.ProgrammableSource()
00084 ps_ti.OutputDataSetType = 'vtkTable'
00085 ps_ti.Script = script_ti
00086 pvsimple.RenameSource("TEST table of integer", ps_ti)
00087 ps_ti.UpdatePipeline()
00088 
00089 # Creating programmable source for the table of real
00090 ps_tr = pvsimple.ProgrammableSource()
00091 ps_tr.OutputDataSetType = 'vtkTable'
00092 ps_tr.Script = script_tr
00093 pvsimple.RenameSource("TEST table of real", ps_tr)
00094 ps_tr.UpdatePipeline()
00095 
00096 # Replace the current view with chart line one
00097 cur_view = pvsimple.GetRenderView()
00098 if cur_view:
00099     pvsimple.Delete(cur_view)
00100 
00101 xy_view1 = pvsimple.CreateXYPlotView()
00102 xy_view1.ChartTitle = 'TEST table of real'
00103 xy_view1.AxisTitle = ['[ Wt ]', 'Row 0 [ Hz ]']
00104 
00105 # Display curves for the table of real
00106 tr_rep = pvsimple.Show(ps_tr)
00107 tr_rep.AttributeType = 'Row Data'
00108 tr_rep.UseIndexForXAxis = 0
00109 tr_rep.XArrayName = 'Row 0'
00110 tr_rep.SeriesVisibility = ['Row 0', '0', 'Row 4', '0', \
00111 'Row 6', '0', 'Row 8', '0', 'Row 9', '0']
00112 
00113 # Set 'Square' marker style for 'Row 5' line
00114 tr_rep.SeriesMarkerStyle = ['Row 5', '3']
00115 # Set 'Dash' line style for 'Row 5' line
00116 tr_rep.SeriesLineStyle = ['Row 5', '2']
00117 # Set color for 'Row 5' line
00118 tr_rep.SeriesColor = ['Row 5', '0', '0.7', '0.3']
00119 # Set 'Diamond' marker style for 'Row 10' line
00120 tr_rep.SeriesMarkerStyle = ['Row 10', '5']
00121 # Set 'Dot' line style for 'Row 10' line
00122 tr_rep.SeriesLineStyle = ['Row 10', '3']
00123 # Set color for 'Row 10' line
00124 tr_rep.SeriesColor = ['Row 10', '0.2', '0.2', '0.9']
00125 
00126 # Create another chart line view
00127 xy_view2 = pvsimple.CreateXYPlotView()
00128 xy_view2.ChartTitle = 'TEST table of integer'
00129 xy_view2.AxisTitle = ['', 'FR [ m/h ]']
00130 
00131 # Display curves for the table of integer
00132 ti_rep = pvsimple.Show(ps_ti, xy_view2)
00133 ti_rep.AttributeType = 'Row Data'
00134 ti_rep.UseIndexForXAxis = 0
00135 ti_rep.XArrayName = 'FR'
00136 ti_rep.SeriesVisibility = ['SR', '0']
00137 
00138 # Change legend label for "FR" line
00139 ti_rep.SeriesLabel = ["FR", "FREQ"]
00140 
00141 # Set 'Square' marker style for 'FR' line
00142 ti_rep.SeriesMarkerStyle = ['FR', '3']
00143 # Set 'Dash' line style for 'FR' line
00144 ti_rep.SeriesLineStyle = ['FR', '2']
00145 # Set color for 'FR' line
00146 ti_rep.SeriesColor = ['FR', '0', '0.7', '0.3']
00147 
00148 
00149 # Update views
00150 pvsimple.Render(xy_view1)
00151 pvsimple.Render(xy_view2)