Back to index

salome-paravis  6.5.0
B2.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/B2 case
00021 #%Create animation for Cut Planes for 'pression' field of the the given MED file and dumps picture files in JPEG 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/B2")
00035 
00036 theFileName = datadir +  "TimeStamps.med"
00037 print " --------------------------------- "
00038 print "file ", theFileName
00039 print " --------------------------------- "
00040 
00041 myParavis.ImportFile(theFileName)
00042 aProxy = GetActiveSource()
00043 if aProxy is None:
00044        raise RuntimeError, "Error: can't import file."
00045 else: print "OK"
00046 
00047 print "Creating a Viewer.........................",
00048 aView = GetRenderView()
00049 reset_view(aView)
00050 Render(aView)
00051 
00052 if aView is None : print "Error"
00053 else : print "OK"
00054 
00055 # Cut Planes creation
00056 prs= CutPlanesOnField(aProxy,EntityType.CELL,'pression' , 2)
00057 prs.Visibility=1
00058 aView.ResetCamera()
00059 print "Creating an Animation.....................",
00060 my_format = "jpeg"
00061 print "Current format to save snapshots: ",my_format
00062 # Add path separator to the end of picture path if necessery
00063 if not picturedir.endswith(os.sep):
00064     picturedir += os.sep
00065 
00066 # Select only the current field:
00067 aProxy.PointArrays.DeselectAll()
00068 aProxy.CellArrays.DeselectAll()
00069 aProxy.CellArrays = ['pression']
00070    
00071 # Animation creation and saving into set of files into picturedir
00072 scene = AnimateReader(aProxy,aView,picturedir+"B2_dom."+my_format)
00073 nb_frames = len(scene.TimeKeeper.TimestepValues)
00074 
00075 pics = os.listdir(picturedir) 
00076 if len(pics) != nb_frames:
00077    print "FAILED!!! Number of made pictures is equal to ", len(pics), " instead of ", nb_frames
00078     
00079 for pic in pics:
00080     os.remove(picturedir+pic)    
00081     
00082 # Prepare animation  performance    
00083 scene.PlayMode = 1 #  set RealTime mode for animation performance
00084 # set period
00085 scene.Duration = 30 # correspond to set the speed of animation in VISU 
00086 scene.GoToFirst()
00087 print "Animation.................................",
00088 scene.Play()
00089 scene.GoToFirst()