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