Salome HOME
Copyright update: 2016
[modules/paravis.git] / test / VisuPrs / dump_study / B4.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/dump_study/B4 case
21
22 import paravistest
23 from presentations import *
24 from pvsimple import *
25
26 # 1. Table creation
27 title = "My Table"
28 errors = 0
29
30 table_title = "My Table"
31
32 # define script for table creation
33 table_script = """
34 import math
35
36
37 # Get table output
38 table = self.GetTableOutput()
39
40 # Create first column
41 col1 = vtk.vtkIntArray()
42 col1.SetName('First Column')
43 col1.InsertNextValue(1)
44 col1.InsertNextValue(4)
45 table.AddColumn(col1)
46
47 # Create second column
48 col2 = vtk.vtkDoubleArray()
49 col2.SetName('Second Column')
50 col2.InsertNextValue(2)
51 col2.InsertNextValue(5)
52 table.AddColumn(col2)
53
54 # Create third column
55 col3 = vtk.vtkDoubleArray()
56 col3.SetName('Third Column')
57 col3.InsertNextValue(3)
58 col3.InsertNextValue(6)
59 table.AddColumn(col3)
60 """
61
62 # creating programmable source for the table
63 table = ProgrammableSource()
64 table.OutputDataSetType = 'vtkTable'
65 table.Script = table_script
66 RenameSource(title, table)
67 table.UpdatePipeline()
68
69 orig_script = table.Script
70
71 # 2. Dump Study
72 path_to_save = os.path.join(os.getenv("HOME"), "table.py")
73 SaveTrace(path_to_save)
74
75 # 3. Delete the table
76 Delete(table)
77
78 # 4. Execution of the created script
79 execfile(path_to_save)
80
81 # 5. Check the restored table
82 table = FindSource(title)
83 if table is None:
84     raise RuntimeError, "There is no table in the study (must be created by executed python script)!!!"
85
86 if table.Script != orig_script:
87     print "ERROR!!! The script value is incorrect:"
88     print table.Script
89     errors += 1
90
91 if errors > 0:
92     raise RuntimeError, "There is(are) some error(s) was(were) found... For more info see ERRORs above..."