Salome HOME
Merge akl/tests_update: update tests
[modules/paravis.git] / src / Macro / modes.py
1 # Copyright (C) 2010-2014  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 try: paraview.simple
21 except: from paraview.simple import *
22 paraview.simple._DisableFirstRenderCameraReset()
23
24 import sys
25
26 source = GetActiveSource()
27 representation = GetDisplayProperties(source)
28 representation.Visibility = 0
29
30 oldmode = None
31
32 if source.SMProxy.GetVTKClassName() == 'vtkMedReader' :
33   oldmode = source.AnimationMode
34   source.AnimationMode = 'Modes'
35
36 ExtractSurface1 = ExtractSurface()
37 ScaleVector1 = ScaleVector()
38 WarpByVector1 = WarpByVector()
39
40 # first, find the first point-centered vector array.
41 ExtractSurface1.UpdatePipeline()
42 info = ExtractSurface1.GetDataInformation()
43 pinfo = info.DataInformation.GetPointDataInformation()
44 arrayinfo = None
45 vectorname = None
46 rootname = None
47 for arrayid in range(0, pinfo.GetNumberOfArrays()) :
48   arrayinfo = pinfo.GetArrayInformation(arrayid)
49   if arrayinfo.GetNumberOfComponents() == 3 : 
50     vectorname = arrayinfo.GetName()
51     rootpos = vectorname.rfind("[")
52     if rootpos == -1 :     
53       rootname = vectorname
54     else :
55       rootname = vectorname[0:rootpos-1]
56     ScaleVector1.VectorField = ['POINTS', vectorname]
57     WarpByVector1.Vectors = ['POINTS', rootname]
58     break
59
60 if vectorname == None :
61   source.AnimationMode = oldmode
62 else :
63   ScaleVector1.ScaleFactor = 0
64   ScaleVector1.UpdatePipeline()
65   bounds = info.DataInformation.GetBounds()
66   side = [bounds[1] - bounds[0], bounds[3] - bounds[2], bounds[5] - bounds[4]]
67   length = side[0]
68   if side[1] > length : length = side[1] 
69   if side[2] > length : length = side[2] 
70
71   scale = length / 20
72   if vectorname != None :
73     arrayrange = arrayinfo.GetComponentRange(-1)
74     if arrayrange[1] > 0 :
75       scale = scale / arrayrange[1]
76   
77   WarpByVector1.ScaleFactor = scale
78   
79   AnimationScene1 = GetAnimationScene()
80
81   TimeAnimationCue1 = GetTimeTrack()
82   TimeAnimationCue1.Enabled = 0
83
84   KeyFrameAnimationCue1 = GetAnimationTrack( ScaleVector1.GetProperty('ScaleFactor'))
85   KeyFrame0 = CompositeKeyFrame( KeyValues=[1.0], Interpolation='Sinusoid' )
86   KeyFrame1 = CompositeKeyFrame( KeyTime=1.000000001, KeyValues=[1.0] )
87
88   KeyFrameAnimationCue1.KeyFrames = [ KeyFrame0, KeyFrame1 ]
89
90   AnimationScene1.Cues.append(KeyFrameAnimationCue1)
91   AnimationScene1.Loop = 1
92   AnimationScene1.PlayMode = 'Sequence'
93   AnimationScene1.NumberOfFrames = 21
94   
95   WarpByVectorDataRepresentation = Show(WarpByVector1)
96   if rootname != None :
97     pvLookupTable = GetLookupTableForArray( rootname, 3, VectorMode='Magnitude' )
98     WarpByVectorDataRepresentation.ColorArrayName = rootname
99     WarpByVectorDataRepresentation.LookupTable = pvLookupTable
100   
101   AnimationScene1.Play()