Back to index

salome-paravis  6.5.0
G3.py
Go to the documentation of this file.
00001 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 #
00003 # This library is free software; you can redistribute it and/or
00004 # modify it under the terms of the GNU Lesser General Public
00005 # License as published by the Free Software Foundation; either
00006 # version 2.1 of the License.
00007 #
00008 # This library is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 # Lesser General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU Lesser General Public
00014 # License along with this library; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 #
00017 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 #
00019 
00020 #This case corresponds to: /visu/animation/G3 case
00021 #%Create animation for Stream Lines for 'vitesse' field of the the given MED file and dumps picture files in PNG format %
00022 
00023 import sys
00024 import os
00025 from paravistest import * 
00026 from presentations import *
00027 from pvsimple import *
00028 import paravis
00029 
00030 #import file
00031 myParavis = paravis.myParavis
00032 
00033 # Directory for saving snapshots
00034 picturedir = get_picture_dir(sys.argv[1], "Animation/G3")
00035 
00036 theFileName = datadir +  "TimeStamps.med"
00037 print " --------------------------------- "
00038 print "file ", theFileName
00039 print " --------------------------------- "
00040 
00041 myParavis.ImportFile(theFileName)
00042 
00043 aProxy = GetActiveSource()
00044 if aProxy is None:
00045        raise RuntimeError, "Error: can't import file."
00046 else: print "OK"
00047 
00048 print "Creating a Viewer.........................",
00049 aView = GetRenderView()
00050 reset_view(aView)
00051 Render(aView)
00052 
00053 if aView is None : print "Error"
00054 else : print "OK"
00055 
00056 # Stream Lines creation
00057 prs= StreamLinesOnField(aProxy,EntityType.NODE,'vitesse' , 1)
00058 prs.Visibility=1
00059 aView.ResetCamera()
00060 print "Creating an Animation.....................",
00061 my_format = "png"
00062 print "Current format to save snapshots: ",my_format
00063 # Add path separator to the end of picture path if necessery
00064 if not picturedir.endswith(os.sep):
00065     picturedir += os.sep
00066 
00067 # Select only the current field:
00068 aProxy.CellArrays.DeselectAll()
00069 aProxy.PointArrays.DeselectAll()
00070 aProxy.PointArrays = ['vitesse']
00071    
00072 # Animation creation and saving into set of files into picturedir
00073 scene = AnimateReader(aProxy,aView,picturedir+"G3_dom."+my_format)
00074 nb_frames = len(scene.TimeKeeper.TimestepValues)
00075 
00076 pics = os.listdir(picturedir) 
00077 if len(pics) != nb_frames:
00078    print "FAILED!!! Number of made pictures is equal to ", len(pics), " instead of ", nb_frames
00079     
00080 for pic in pics:
00081     os.remove(picturedir+pic)    
00082     
00083 # Prepare animation  performance    
00084 scene.PlayMode = 1 #  set RealTime mode for animation performance
00085 # set period
00086 scene.Duration = 30 # correspond to set the speed of animation in VISU 
00087 scene.GoToFirst()
00088 print "Animation.................................",
00089 scene.Play()
00090 scene.GoToFirst()