Salome HOME
Copyright update: 2016
[modules/paravis.git] / test / VisuPrs / Animation / G0.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/animation/G0 case
21 #%Create animation for Stream Lines for 'vitesse' field of the the given MED file and dumps picture files in JPEG format %
22
23 import sys
24 import os
25 from paravistest import *
26 from presentations import *
27 from pvsimple import *
28
29 # Directory for saving snapshots
30 picturedir = get_picture_dir("Animation/G0")
31
32 theFileName = datadir +  "TimeStamps.med"
33 print " --------------------------------- "
34 print "file ", theFileName
35 print " --------------------------------- "
36
37 OpenDataFile(theFileName)
38 aProxy = GetActiveSource()
39 if aProxy is None:
40         raise RuntimeError, "Error: can't import file."
41 else: print "OK"
42
43 print "Creating a Viewer.........................",
44 aView = GetRenderView()
45 time_value = get_time(aProxy, 0)
46 aView.ViewTime = time_value
47 UpdatePipeline(time=time_value, proxy=aProxy)
48 reset_view(aView)
49 Render(aView)
50
51 if aView is None : print "Error"
52 else : print "OK"
53
54 # Stream Lines creation
55 prs= StreamLinesOnField(aProxy,EntityType.NODE,'vitesse' , 1)
56 if prs is None:
57   # TODO: check why stream lines prs is empty
58   print "WARNING! StreamLines presentation wasn't created or is empty..."
59 else:
60   prs.Visibility=1
61 aView.ResetCamera()
62 print "Creating an Animation.....................",
63 my_format = "jpeg"
64 print "Current format to save snapshots: ",my_format
65 # Add path separator to the end of picture path if necessery
66 if not picturedir.endswith(os.sep):
67     picturedir += os.sep
68
69 # Select only the current field:
70 aProxy.AllArrays = ['TS0/dom/ComSup0/vitesse@@][@@P1']
71 time_value = get_time(aProxy, 0)
72 aView.ViewTime = time_value
73 UpdatePipeline(time=time_value, proxy=aProxy)
74
75 # Animation creation and saving into set of files into picturedir
76 scene = AnimateReader(aProxy,aView,picturedir+"G0_dom."+my_format)
77 nb_frames = len(scene.TimeKeeper.TimestepValues)
78
79 pics = os.listdir(picturedir)
80 if len(pics) != nb_frames:
81    print "FAILED!!! Number of made pictures is equal to ", len(pics), " instead of ", nb_frames
82
83 for pic in pics:
84     os.remove(picturedir+pic)
85
86 # Prepare animation  performance
87 scene.PlayMode = 1 #  set RealTime mode for animation performance
88 # set period
89 scene.Duration = 30 # correspond to set the speed of animation in VISU
90 scene.GoToFirst()
91 print "Animation.................................",
92 scene.Play()
93 scene.GoToFirst()