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