Salome HOME
Merge from V6_main 13/12/2012
[modules/paravis.git] / src / Macro / modes.py
1 # Copyright (C) 2010-2012  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.
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   sys.exit(0)
63
64 ScaleVector1.ScaleFactor = 0
65 ScaleVector1.UpdatePipeline()
66 bounds = info.DataInformation.GetBounds()
67 side = [bounds[1] - bounds[0], bounds[3] - bounds[2], bounds[5] - bounds[4]]
68 length = side[0]
69 if side[1] > length : length = side[1] 
70 if side[2] > length : length = side[2] 
71
72 scale = length / 20
73 if vectorname != None :
74   arrayrange = arrayinfo.GetComponentRange(-1)
75   if arrayrange[1] > 0 :
76     scale = scale / arrayrange[1]
77
78 WarpByVector1.ScaleFactor = scale
79
80 AnimationScene1 = GetAnimationScene()
81
82 TimeAnimationCue1 = GetTimeTrack()
83 TimeAnimationCue1.Enabled = 0
84
85 KeyFrameAnimationCue1 = GetAnimationTrack( ScaleVector1.GetProperty('ScaleFactor'))
86 KeyFrame0 = CompositeKeyFrame( KeyValues=[1.0], Interpolation='Sinusoid' )
87 KeyFrame1 = CompositeKeyFrame( KeyTime=1.000000001, KeyValues=[1.0] )
88
89 KeyFrameAnimationCue1.KeyFrames = [ KeyFrame0, KeyFrame1 ]
90
91 AnimationScene1.Cues.append(KeyFrameAnimationCue1)
92 AnimationScene1.Loop = 1
93 AnimationScene1.PlayMode = 'Sequence'
94 AnimationScene1.NumberOfFrames = 21
95
96 WarpByVectorDataRepresentation = Show(WarpByVector1)
97 if rootname != None :
98   pvLookupTable = GetLookupTableForArray( rootname, 3, VectorMode='Magnitude' )
99   WarpByVectorDataRepresentation.ColorArrayName = rootname
100   WarpByVectorDataRepresentation.LookupTable = pvLookupTable
101
102 AnimationScene1.Play()