]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_SWIG/VISU_Example_07.py
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / VISU_SWIG / VISU_Example_07.py
1 #  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Manage view parameters of presentations:
21 # Representation Mode, Shrink, Shading, Opacity, Line Width
22
23 import salome
24
25 import VISU
26 import visu_gui
27
28 import os
29 import time
30
31 datadir = os.getenv("DATA_DIR") + "/MedFiles/"
32
33 myVisu = visu_gui.myVisu
34 myVisu.SetCurrentStudy(salome.myStudy)
35 myViewManager = myVisu.GetViewManager()
36 myView = myViewManager.Create3DView()
37
38 sleep_delay = 1
39
40 def AfterSet(error_string, method_name, old_value, new_value):
41     print method_name, "(): old_value = ", old_value, "new_value  = ", new_value
42     if error_string == "":
43         time.sleep(sleep_delay)
44     else:
45         print method_name, "() error = ", error_string
46         pass
47     pass
48
49 def ChangeRepresentation(scalarmap,repres,shrink,shading,opacity,linew):
50     if scalarmap is None : print "Error"
51     else : print "OK"
52
53     myView.DisplayOnly(scalarmap)
54     myView.FitAll()
55
56     time.sleep(sleep_delay)
57
58     # enum PresentationType{ POINT, WIREFRAME, SHADED, INSIDEFRAME, SURFACEFRAME, SHRINK }
59     old_prs_type = myView.GetPresentationType(scalarmap)
60     if old_prs_type != repres:
61         err_str = myView.SetPresentationType(scalarmap, repres)
62         AfterSet(err_str, "SetPresentationType", old_prs_type, repres)
63         pass
64
65     old_is_shrinked = myView.IsShrinked(scalarmap)
66     if old_is_shrinked != shrink:
67         err_str = myView.SetShrinked(scalarmap, shrink) # 1 - shrinked, 0 - not shrinked
68         AfterSet(err_str, "SetShrinked", old_is_shrinked, shrink)
69         pass
70
71     old_is_shaded = myView.IsShaded(scalarmap)
72     if old_is_shaded != shading:
73         err_str = myView.SetShaded(scalarmap, shading) # 1 - shaded, 0 - not shaded
74         AfterSet(err_str, "SetShaded", old_is_shaded, shading)
75         pass
76
77     old_opacity = myView.GetOpacity(scalarmap)
78     if old_opacity != opacity:
79         err_str = myView.SetOpacity(scalarmap, opacity) # double value [0, 1]
80         AfterSet(err_str, "SetOpacity", old_opacity, opacity)
81         pass
82
83     old_linew = myView.GetLineWidth(scalarmap)
84     if old_linew != linew:
85         err_str = myView.SetLineWidth(scalarmap, linew) # double value, recommended round [1, 10]
86         AfterSet(err_str, "SetLineWidth", old_linew, linew)
87         pass
88
89     print ""
90     pass
91
92 # ResOK_0000.med
93
94 print 'Import "ResOK_0000.med"...............',
95 medFile = datadir + "ResOK_0000.med"
96 myMeshName = 'dom'
97 myFieldName = 'vitesse'
98
99 myResult = myVisu.ImportFile(medFile)
100 if myResult is None : print "Error"
101 else : print "OK"
102
103 print "Creating Scalar Map.......",
104 scmap = myVisu.ScalarMapOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
105 ChangeRepresentation(scmap, VISU.INSIDEFRAME, 1, 0, 0.3, 5)
106
107 print "Creating Stream Lines.......",
108 scmap = myVisu.StreamLinesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
109 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3)
110
111 print "Creating Vectors..........",
112 scmap = myVisu.VectorsOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
113 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.7, 2)
114
115 print "Creating Iso Surfaces.....",
116 scmap = myVisu.IsoSurfacesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
117 ChangeRepresentation(scmap, VISU.SHADED, 1, 0, 0.4, 8)
118
119 print "Creating Cut Planes.......",
120 scmap = myVisu.CutPlanesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
121 ChangeRepresentation(scmap, VISU.POINT, 0, 0, 0.6, 4)
122
123 # fra.med
124
125 print 'Import "fra.med"...............',
126 medFile = datadir + "fra.med"
127 myMeshName = 'LE VOLUME'
128 myFieldName = 'VITESSE'
129
130 myResult = myVisu.ImportFile(medFile)
131 if myResult is None : print "Error"
132 else : print "OK"
133
134 print "Creating Scalar Map.......",
135 scmap = myVisu.ScalarMapOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
136 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3)
137
138 print "Creating Iso Surfaces.....",
139 scmap = myVisu.IsoSurfacesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
140 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3)
141
142 print "Creating Cut Planes.......",
143 scmap = myVisu.CutPlanesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
144 ChangeRepresentation(scmap, VISU.SHADED, 1, 1, 0.5, 3)
145
146 print "Creating Scalar Map On Deformed Shape.......",
147 scmap = myVisu.ScalarMapOnDeformedShapeOnField(myResult,myMeshName,VISU.NODE,myFieldName,1);
148 ChangeRepresentation(scmap, VISU.SHADED, 1, 1, 0.5, 3)
149
150 print "Creating Deformed Shape.......",
151 scmap = myVisu.DeformedShapeOnField(myResult,myMeshName,VISU.NODE,myFieldName,1)
152 scmap.ShowColored(1)
153 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3)
154
155 print "Creating Cut Lines.......",
156 scmap = myVisu.CutLinesOnField(myResult,myMeshName,VISU.NODE,myFieldName,1)
157 ChangeRepresentation(scmap, VISU.WIREFRAME, 1, 1, 0.5, 3)
158
159 print "Creating Plot 3D.......",
160 scmap = myVisu.Plot3DOnField(myResult,myMeshName,VISU.NODE,myFieldName,1)
161 ChangeRepresentation(scmap, VISU.SHADED, 1, 1, 0.5, 3)