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