Salome HOME
58a8da9e2742fb1e76c9f03bd27ec12fa482c454
[modules/paravis.git] / test / VisuPrs / SWIG_scripts / C7.py
1 # Copyright (C) 2010-2013  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.
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/C7 case
21 # Import a table in Post-Pro specific format from file;
22 # create 3D representation of the table and show it in 3D viewer
23
24 import sys
25
26 from paravistest import tablesdir, get_picture_dir, pictureext
27 from presentations import *
28 import paravis
29 import pvsimple
30
31
32 # Import table from file
33 print 'Import file with tables....',
34 file_path = tablesdir + "table_test.xls"
35 table_reader = pvsimple.TableReader(FileName=file_path)
36 if table_reader is None:
37     print "FAILED"
38 else:
39     print "OK"
40
41 # Get default settings of the reader
42 available_tables = table_reader.GetPropertyValue("AvailableTables")
43 is_detect_num = table_reader.DetectNumericColumns
44 first_str_as_title = table_reader.FirstStringAsTitles
45 delimiter = table_reader.ValueDelimiter
46 table_nb = table_reader.TableNumber
47
48 print "Default reader settings:"
49 print "Available tables: ", available_tables
50 print "Detect Numeric Columns: ", is_detect_num
51 print "Interpret First String As Column Titles: ", first_str_as_title
52 print "Value Delimiter: '%s'" % delimiter
53 print "Table Number: ", table_nb
54
55
56 # Create 3D representation of the table with the
57 # help of "Table To 3D" filter,
58 # in Post-Pro this representation is known as "Pointmap3d"
59 table_to_3d = pvsimple.TableTo3D(table_reader)
60
61 print 'Create "Table To 3D" filter....',
62 if table_to_3d is None:
63     print "FAILED"
64 else:
65     print "OK"
66
67 print "Default 'Table To 3D' filter settings:"
68 print "Scale Factor: ", table_to_3d.ScaleFactor
69 print "Use Optimus Scale: ", table_to_3d.UseOptimusScale
70 print "Presentation Type: ", table_to_3d.PresentationType
71 print "Number Of Contours: ", table_to_3d.NumberOfContours
72
73
74 # Show table 3D representation
75
76 # Get 3D view
77 print 'Get 3D view...................',
78 view = pvsimple.GetRenderView()
79 if view is None:
80     print "FAILED"
81 else:
82     reset_view(view)
83     print "OK"
84
85 pointmap3d = pvsimple.GetRepresentation(table_to_3d)
86
87 table_name = available_tables
88 if type(available_tables) == list:
89   table_name = available_tables[table_nb]
90
91 vector_mode = 'Magnitude'
92 nb_components = 1
93 entity = EntityType.NODE
94
95 # Get lookup table
96 lookup_table = get_lookup_table(table_name, nb_components, vector_mode)
97 lookup_table.LockScalarRange = 0
98
99 # Set properties
100 pointmap3d.ColorAttributeType = EntityType.get_pvtype(entity)
101 pointmap3d.ColorArrayName = table_name
102 pointmap3d.LookupTable = lookup_table
103
104 # Add scalar bar
105 add_scalar_bar(table_name, nb_components, vector_mode,
106                lookup_table, "")
107
108 # Reset view
109 reset_view(view=view)
110
111
112 # Write image
113
114 # Directory for saving snapshots
115 picturedir = get_picture_dir("SWIG_scripts/C7")
116 if not picturedir.endswith(os.sep):
117     picturedir += os.sep
118
119 file_name = picturedir + "pointmap3d." + pictureext
120 pvsimple.WriteImage(file_name, view=view, Magnification=1)