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
|
/*=========================================================================
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 "vtkSMTimeKeeperProxy.h"
#include "vtkObjectFactory.h"
#include "vtkSMDoubleVectorProperty.h"
#include "vtkSMProxyProperty.h"
#include "vtkSMSourceProxy.h"
#include "vtkSMTimeKeeper.h"
#include "vtkSMTrace.h"
#include <algorithm>
vtkStandardNewMacro(vtkSMTimeKeeperProxy);
//----------------------------------------------------------------------------
vtkSMTimeKeeperProxy::vtkSMTimeKeeperProxy()
{
}
//----------------------------------------------------------------------------
vtkSMTimeKeeperProxy::~vtkSMTimeKeeperProxy()
{
}
//----------------------------------------------------------------------------
void vtkSMTimeKeeperProxy::CreateVTKObjects()
{
if (this->ObjectsCreated)
{
return;
}
this->Superclass::CreateVTKObjects();
if (this->ObjectsCreated)
{
vtkSMTimeKeeper* tk = vtkSMTimeKeeper::SafeDownCast(this->GetClientSideObject());
if (tk)
{
tk->SetTimestepValuesProperty(this->GetProperty("TimestepValues"));
tk->SetTimeRangeProperty(this->GetProperty("TimeRange"));
tk->SetTimeLabelProperty(this->GetProperty("TimeLabel"));
}
}
}
//----------------------------------------------------------------------------
bool vtkSMTimeKeeperProxy::AddTimeSource(vtkSMProxy* proxy, bool suppress_input)
{
vtkSMProxyProperty* pp = vtkSMProxyProperty::SafeDownCast(this->GetProperty("TimeSources"));
if (!proxy || pp->IsProxyAdded(proxy))
{
return false;
}
// Suppress produces for proxy
vtkSMProxyProperty* stspp =
vtkSMProxyProperty::SafeDownCast(this->GetProperty("SuppressedTimeSources"));
for (unsigned int cc = 0, max = proxy->GetNumberOfProducers(); suppress_input && cc < max; cc++)
{
vtkSMProxy* producer = proxy->GetProducerProxy(cc);
producer = producer ? producer->GetTrueParentProxy() : NULL;
if (producer && !stspp->IsProxyAdded(producer))
{
stspp->AddProxy(producer);
}
}
// add the requested proxy.
pp->AddProxy(proxy);
this->UpdateVTKObjects();
return true;
}
//----------------------------------------------------------------------------
bool vtkSMTimeKeeperProxy::RemoveTimeSource(vtkSMProxy* proxy, bool unsuppress_input)
{
vtkSMProxyProperty* pp = vtkSMProxyProperty::SafeDownCast(this->GetProperty("TimeSources"));
if (!proxy || !pp->IsProxyAdded(proxy))
{
return false;
}
// Remove producer suppressions.
vtkSMProxyProperty* stspp =
vtkSMProxyProperty::SafeDownCast(this->GetProperty("SuppressedTimeSources"));
for (unsigned int cc = 0, max = proxy->GetNumberOfProducers(); unsuppress_input && cc < max; cc++)
{
vtkSMProxy* producer = proxy->GetProducerProxy(cc);
producer = producer ? vtkSMSourceProxy::SafeDownCast(producer->GetTrueParentProxy()) : NULL;
if (producer)
{
stspp->RemoveProxy(producer);
}
}
// remove the requested proxy.
pp->RemoveProxy(proxy);
this->UpdateVTKObjects();
return true;
}
//----------------------------------------------------------------------------
bool vtkSMTimeKeeperProxy::IsTimeSourceTracked(vtkSMProxy* proxy)
{
vtkSMProxyProperty* pp = vtkSMProxyProperty::SafeDownCast(this->GetProperty("TimeSources"));
vtkSMProxyProperty* stspp =
vtkSMProxyProperty::SafeDownCast(this->GetProperty("SuppressedTimeSources"));
return (proxy && pp->IsProxyAdded(proxy) && !stspp->IsProxyAdded(proxy));
}
//----------------------------------------------------------------------------
bool vtkSMTimeKeeperProxy::SetSuppressTimeSource(vtkSMProxy* proxy, bool suppress)
{
if (proxy)
{
SM_SCOPED_TRACE(CallMethod)
.arg(this)
.arg("SetSuppressTimeSource")
.arg(proxy)
.arg(suppress)
.arg("comment", (suppress ? "ignore time" : "don't ignore time"));
vtkSMProxyProperty* pp =
vtkSMProxyProperty::SafeDownCast(this->GetProperty("SuppressedTimeSources"));
if (suppress && pp->IsProxyAdded(proxy) == false)
{
pp->AddProxy(proxy);
}
else if (!suppress && pp->IsProxyAdded(proxy))
{
pp->RemoveProxy(proxy);
}
this->UpdateVTKObjects();
return true;
}
return false;
}
//----------------------------------------------------------------------------
double vtkSMTimeKeeperProxy::GetLowerBoundTimeStep(double value)
{
vtkSMDoubleVectorProperty* dvp =
vtkSMDoubleVectorProperty::SafeDownCast(this->GetProperty("TimestepValues"));
if (dvp && dvp->GetNumberOfElements() > 0)
{
// we shirk the range so that if value > the last timestep, this simply
// returns the last timestep's time.
return *(std::lower_bound(
dvp->GetElements(), dvp->GetElements() + dvp->GetNumberOfElements() - 1, value));
}
return value;
}
//----------------------------------------------------------------------------
int vtkSMTimeKeeperProxy::GetLowerBoundTimeStepIndex(double value)
{
vtkSMDoubleVectorProperty* dvp =
vtkSMDoubleVectorProperty::SafeDownCast(this->GetProperty("TimestepValues"));
if (dvp && dvp->GetNumberOfElements() > 0)
{
// we shirk the range so that if value > the last timestep, this simply
// returns the last timestep's index.
const double* first = dvp->GetElements();
const double* last = dvp->GetElements() + dvp->GetNumberOfElements() - 1;
const double* iter = std::lower_bound(first, last, value);
return static_cast<int>(iter - first);
}
return 0;
}
//----------------------------------------------------------------------------
void vtkSMTimeKeeperProxy::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
|