Commit 1b7668eb authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

add `interval` to LiveSource hint.

Adding ability to provide refresh interval to a live source.
parent 6cccdcfd
......@@ -46,25 +46,65 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkSMViewProxy.h"
#include <QPointer>
#include <algorithm>
#include <limits>
#include <utility>
#include <vector>
//-----------------------------------------------------------------------------
class pqLiveSourceBehavior::pqInternals
{
void updateSources()
{
const auto old_size = this->LiveSources.size();
auto iter = this->LiveSources.begin();
while (iter != this->LiveSources.end())
{
if (iter->first == nullptr)
{
iter = this->LiveSources.erase(iter);
}
else
{
++iter;
}
}
if (old_size != this->LiveSources.size())
{
// update interval
int interval = std::numeric_limits<int>::max();
for (const auto& pair : this->LiveSources)
{
interval = std::min(interval, pair.second);
}
this->Timer.setInterval(interval);
}
}
static const int DEFAULT_INTERVAL = 100;
public:
pqTimer Timer;
QList<QPointer<pqPipelineSource> > LiveSources;
std::vector<std::pair<QPointer<pqPipelineSource>, int> > LiveSources;
pqInternals()
{
this->Timer.setInterval(100);
this->Timer.setInterval(DEFAULT_INTERVAL);
this->Timer.setSingleShot(true);
}
void addSource(pqPipelineSource* src, vtkPVXMLElement* liveHints)
{
Q_ASSERT(liveHints != nullptr);
Q_UNUSED(liveHints);
this->LiveSources.push_back(src);
int interval = 0;
if (!liveHints->GetScalarAttribute("interval", &interval) || interval <= 0)
{
interval = DEFAULT_INTERVAL;
}
this->LiveSources.push_back(std::make_pair(QPointer<pqPipelineSource>(src), interval));
this->Timer.setInterval(std::min(this->Timer.interval(), interval));
this->Timer.start();
}
......@@ -72,7 +112,7 @@ public:
void resume()
{
this->LiveSources.removeAll(nullptr);
this->updateSources();
if (this->LiveSources.size() > 0)
{
this->Timer.start();
......@@ -82,7 +122,7 @@ public:
void update()
{
this->Timer.stop();
this->LiveSources.removeAll(nullptr);
this->updateSources();
if (this->LiveSources.size() == 0)
{
return;
......@@ -95,8 +135,9 @@ public:
}
// iterate over all sources and update those that need updating.
for (pqPipelineSource* src : this->LiveSources)
for (const auto& pair : this->LiveSources)
{
pqPipelineSource* src = pair.first;
auto proxy = vtkSMSourceProxy::SafeDownCast(src->getProxy());
auto session = proxy->GetSession();
......
......@@ -240,9 +240,12 @@ For that, one simply adds a hint to the proxy as follows:
<SourceProxy ...>
...
<Hints>
<LiveSource />
<LiveSource interval="100" />
</Hints>
</SourceProxy>
The algorithm subclass must have `bool GetNeedsUpdate()` method that returns
true if the algorithm needs update.
The `interval` attribute is optional (defaults to 100) and can be used to
provide a refresh rate in milliseconds.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment