File: vtkSMAnimationSceneProxy.cxx

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (267 lines) | stat: -rw-r--r-- 9,437 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*=========================================================================

  Program:   ParaView
  Module:    $RCSfile$

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkSMAnimationSceneProxy.h"

#include "vtkCompositeAnimationPlayer.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPVXMLElement.h"
#include "vtkSMAnimationScene.h"
#include "vtkSMParaViewPipelineController.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMProxyIterator.h"
#include "vtkSMTimeKeeperProxy.h"
#include "vtkSMTrace.h"
#include "vtkVector.h"

namespace
{
  // This is a terrible way to address BUG #0015407. What's happening is that
  // when state is being loaded the timekeeper gets updated timesteps which are
  // then correctly propagated to the animation scene, which then, correctly (I
  // might add) updates the start and end times. However all this happends
  // before the "EndTime"/"StartTime" properties from the XML state are loaded.
  // Hence they get set and loose the values just updated by the application,
  // instead use the old values from the state files.
  // This function will prune the EndTime/StartTime XML elements from the state
  // being loaded if they should not be loaded.
  void PruneEndTimesIfNeeded(vtkPVXMLElement* element, vtkSMAnimationScene* self)
    {
    vtkPVXMLElement* startTimeElement = NULL;
    vtkPVXMLElement* endTimeElement = NULL;
    int playMode = self? self->GetPlayMode() : vtkCompositeAnimationPlayer::SEQUENCE ;
    int lockEndTime = self? (self->GetLockEndTime()? 1 : 0) : 0;
    int lockStartTime = self? (self->GetLockStartTime()? 1 : 0) : 0;
    for (unsigned int cc=0, max = element->GetNumberOfNestedElements(); cc < max; cc++)
      {
      vtkPVXMLElement* cur = element->GetNestedElement(cc);
      if (cur && cur->GetName() &&
        strcmp(cur->GetName(), "Property") == 0)
        {
        const char* name = cur->GetAttributeOrDefault("name", "");
        if (strcmp(name, "EndTime") == 0)
          {
          endTimeElement = cur;
          }
        else if (strcmp(name, "StartTime") == 0)
          {
          startTimeElement = cur;
          }
        else if (strcmp(name, "PlayMode") == 0)
          {
          if (vtkPVXMLElement* valueElem = cur->FindNestedElementByName("Element"))
            {
            valueElem->GetScalarAttribute("value", &playMode);
            }
          }
        else if (strcmp(name, "LockEndTime") == 0)
          {
          if (vtkPVXMLElement* valueElem = cur->FindNestedElementByName("Element"))
            {
            valueElem->GetScalarAttribute("value", &lockEndTime);
            }
          }
        else if (strcmp(name, "LockStartTime") == 0)
          {
          if (vtkPVXMLElement* valueElem = cur->FindNestedElementByName("Element"))
            {
            valueElem->GetScalarAttribute("value", &lockStartTime);
            }
          }
        }
      }
    if (playMode == vtkCompositeAnimationPlayer::SNAP_TO_TIMESTEPS)
      {
      if (lockStartTime != 1 && startTimeElement)
        {
        element->RemoveNestedElement(startTimeElement);
        }
      if (lockEndTime != 1 && endTimeElement)
        {
        element->RemoveNestedElement(endTimeElement);
        }
      }
    }
}

vtkStandardNewMacro(vtkSMAnimationSceneProxy);
//----------------------------------------------------------------------------
vtkSMAnimationSceneProxy::vtkSMAnimationSceneProxy()
{
}

//----------------------------------------------------------------------------
vtkSMAnimationSceneProxy::~vtkSMAnimationSceneProxy()
{
}

//----------------------------------------------------------------------------
void vtkSMAnimationSceneProxy::CreateVTKObjects()
{
  if (this->ObjectsCreated)
    {
    return;
    }
  this->Superclass::CreateVTKObjects();
  if (vtkObject* object = vtkObject::SafeDownCast(this->GetClientSideObject()))
    {
    object->AddObserver(vtkSMAnimationScene::UpdateStartEndTimesEvent,
      this, &vtkSMAnimationSceneProxy::OnUpdateStartEndTimesEvent);
    }
}

//----------------------------------------------------------------------------
void vtkSMAnimationSceneProxy::OnUpdateStartEndTimesEvent(
  vtkObject* object, unsigned long, void* calldata)
{
  const vtkVector2d &range = *(reinterpret_cast<vtkVector2d*>(calldata));
  vtkSMAnimationScene* caller = vtkSMAnimationScene::SafeDownCast(object);
  assert(caller == this->GetClientSideObject());

  vtkSMPropertyHelper startTime(this, "StartTime");
  vtkSMPropertyHelper endTime(this, "EndTime");
  vtkVector2d newRange(startTime.GetAsDouble(0), endTime.GetAsDouble(0));
  if (!caller->GetLockStartTime())
    {
    newRange.SetX(range.GetX());
    }
  if (!caller->GetLockEndTime())
    {
    newRange.SetY(range.GetY());
    }
  startTime.Set(newRange.GetX());
  endTime.Set(newRange.GetY());
  // XXX: What to do if the start or end time was locked and the suggested start
  // or end time would make the range invalid?
  this->UpdateVTKObjects();
}

//----------------------------------------------------------------------------
bool vtkSMAnimationSceneProxy::UpdateAnimationUsingDataTimeSteps()
{
  vtkSMProxy* timeKeeper = vtkSMPropertyHelper(this, "TimeKeeper").GetAsProxy();
  if (!timeKeeper)
    {
    vtkWarningMacro("Failed to locate TimeKeeper proxy.");
    return false;
    }

  SM_SCOPED_TRACE(CallMethodIfPropertiesModified)
    .arg("proxy", this)
    .arg("methodname", "UpdateAnimationUsingDataTimeSteps")
    .arg("comment", "update animation scene based on data timesteps");

  bool using_snap_to_timesteps_mode = false;
  vtkSMPropertyHelper timestepsHelper(timeKeeper, "TimestepValues");
  if (timestepsHelper.GetNumberOfElements() > 1)
    {
    vtkSMPropertyHelper(this, "PlayMode").Set(vtkCompositeAnimationPlayer::SNAP_TO_TIMESTEPS);
    using_snap_to_timesteps_mode = true;
    }
  else
    {
    vtkSMPropertyHelper playmodeHelper(this, "PlayMode");
    if (playmodeHelper.GetAsInt() == vtkCompositeAnimationPlayer::SNAP_TO_TIMESTEPS)
      {
      playmodeHelper.Set(vtkCompositeAnimationPlayer::SEQUENCE);
      }
    }

  this->UpdateVTKObjects();
  // This will internally adjust the Start and End times for the animation scene
  // based of the Locks for the times. We not simply need to copy the info
  // property values.

  /// If the animation time is not in the scene time range, set it to the min
  /// value.
  double minTime = vtkSMPropertyHelper(this, "StartTime").GetAsDouble();
  double maxTime = vtkSMPropertyHelper(this, "EndTime").GetAsDouble();
  double animationTime = vtkSMPropertyHelper(this, "AnimationTime").GetAsDouble();
  if (animationTime < minTime || animationTime > maxTime)
    {
    vtkSMPropertyHelper(this, "AnimationTime").Set(minTime);
    }
  else if (using_snap_to_timesteps_mode)
    {
    // BUG #15060. When using SNAP_TO_TIMESTEPS mode, ensure that the timestep
    // is "snapped".
    vtkSMPropertyHelper(this, "AnimationTime").Set(
      vtkSMTimeKeeperProxy::GetLowerBoundTimeStep(timeKeeper, animationTime));
    }
  this->UpdateVTKObjects();
  return true;
}

//----------------------------------------------------------------------------
vtkSMProxy* vtkSMAnimationSceneProxy::FindAnimationCue(
  vtkSMProxy* animatedProxy, const char* animatedPropertyName)
{
  if (!animatedProxy || !animatedPropertyName)
    {
    return NULL;
    }

  vtkSMPropertyHelper cuesHelper(this, "Cues");
  for (unsigned int cc=0, max = cuesHelper.GetNumberOfElements(); cc<max; ++cc)
    {
    vtkSMProxy* cueProxy = cuesHelper.GetAsProxy(cc);
    if (cueProxy)
      {
      vtkSMPropertyHelper proxyHelper(cueProxy, "AnimatedProxy");
      if (proxyHelper.GetAsProxy() == animatedProxy)
        {
        vtkSMPropertyHelper pnameHelper(cueProxy, "AnimatedPropertyName");
        if (pnameHelper.GetAsString() &&
          strcmp(animatedPropertyName, pnameHelper.GetAsString()) == 0)
          {
          return cueProxy;
          }
        }
      }
    }

  // Check if we're animating a helper proxy on the proxy.
  std::string groupname =
    vtkSMParaViewPipelineController::GetHelperProxyGroupName(animatedProxy);

  vtkNew<vtkSMProxyIterator> iter;
  iter->SetSessionProxyManager(animatedProxy->GetSessionProxyManager());
  iter->SetModeToOneGroup();
  for (iter->Begin(groupname.c_str()); !iter->IsAtEnd(); iter->Next())
    {
    vtkSMProxy* cue = this->FindAnimationCue(iter->GetProxy(), animatedPropertyName);
    if (cue)
      {
      return cue;
      }
    }
  return NULL;
}

//----------------------------------------------------------------------------
int vtkSMAnimationSceneProxy::LoadXMLState(
  vtkPVXMLElement* element, vtkSMProxyLocator* locator)
{
  PruneEndTimesIfNeeded(element,
    (this->ObjectsCreated?
     vtkSMAnimationScene::SafeDownCast(this->GetClientSideObject()): NULL));
  return this->Superclass::LoadXMLState(element, locator);;
}

//----------------------------------------------------------------------------
void vtkSMAnimationSceneProxy::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}