Commit c8c4e805 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Add ability to pause a live source

Adding pqPauseLiveSourcePropertyWidget which can be used to add UI
button to pause/resume live source updates.

The `LiveProgrammableSource` adds this widget to its properties to allow
users to pause (and also act as an example of how to use this widget).
parent 1b7668eb
......@@ -553,6 +553,12 @@ annotation text.
outside of ParaView.
</Documentation>
</StringVectorProperty>
<Property name="PauseLiveSource" panel_widget="pause_livesource">
<Documentation>
Pause live source.
</Documentation>
</Property>
<Hints>
<LiveSource />
</Hints>
......
......@@ -240,6 +240,8 @@ set (Module_SRCS
pqParaViewBehaviors.h
pqParaViewMenuBuilders.cxx
pqParaViewMenuBuilders.h
pqPauseLiveSourcePropertyWidget.cxx
pqPauseLiveSourcePropertyWidget.h
pqPersistentMainWindowStateBehavior.cxx
pqPersistentMainWindowStateBehavior.h
pqPipelineContextMenuBehavior.cxx
......@@ -464,6 +466,7 @@ set (Module_MOC_HDRS
pqPVAnimationWidget.h
pqPVApplicationCore.h
pqParaViewBehaviors.h
pqPauseLiveSourcePropertyWidget.h
pqPersistentMainWindowStateBehavior.h
pqPipelineContextMenuBehavior.h
pqPluginActionGroupBehavior.h
......
......@@ -51,6 +51,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <utility>
#include <vector>
bool pqLiveSourceBehavior::PauseLiveUpdates = false;
//-----------------------------------------------------------------------------
class pqLiveSourceBehavior::pqInternals
{
......@@ -135,24 +137,27 @@ public:
}
// iterate over all sources and update those that need updating.
for (const auto& pair : this->LiveSources)
if (!pqLiveSourceBehavior::isPaused())
{
pqPipelineSource* src = pair.first;
auto proxy = vtkSMSourceProxy::SafeDownCast(src->getProxy());
auto session = proxy->GetSession();
vtkClientServerStream stream;
stream << vtkClientServerStream::Invoke << VTKOBJECT(proxy) << "GetNeedsUpdate"
<< vtkClientServerStream::End;
session->ExecuteStream(vtkPVSession::DATA_SERVER_ROOT, stream, /*ignore errors*/ true);
vtkClientServerStream result = session->GetLastResult(vtkPVSession::DATA_SERVER_ROOT);
bool needs_update = false;
if (result.GetNumberOfMessages() == 1 && result.GetNumberOfArguments(0) == 1 &&
result.GetArgument(0, 0, &needs_update) && needs_update)
for (const auto& pair : this->LiveSources)
{
proxy->MarkModified(proxy);
src->renderAllViews();
pqPipelineSource* src = pair.first;
auto proxy = vtkSMSourceProxy::SafeDownCast(src->getProxy());
auto session = proxy->GetSession();
vtkClientServerStream stream;
stream << vtkClientServerStream::Invoke << VTKOBJECT(proxy) << "GetNeedsUpdate"
<< vtkClientServerStream::End;
session->ExecuteStream(vtkPVSession::DATA_SERVER_ROOT, stream, /*ignore errors*/ true);
vtkClientServerStream result = session->GetLastResult(vtkPVSession::DATA_SERVER_ROOT);
bool needs_update = false;
if (result.GetNumberOfMessages() == 1 && result.GetNumberOfArguments(0) == 1 &&
result.GetArgument(0, 0, &needs_update) && needs_update)
{
proxy->MarkModified(proxy);
src->renderAllViews();
}
}
}
......@@ -203,6 +208,18 @@ pqLiveSourceBehavior::~pqLiveSourceBehavior()
{
}
//-----------------------------------------------------------------------------
void pqLiveSourceBehavior::pause()
{
pqLiveSourceBehavior::PauseLiveUpdates = true;
}
//-----------------------------------------------------------------------------
void pqLiveSourceBehavior::resume()
{
pqLiveSourceBehavior::PauseLiveUpdates = false;
}
//-----------------------------------------------------------------------------
void pqLiveSourceBehavior::viewAdded(pqView* view)
{
......
......@@ -59,6 +59,21 @@ public:
pqLiveSourceBehavior(QObject* parent = 0);
~pqLiveSourceBehavior() override;
/**
* Pause live updates.
*/
static void pause();
/**
* Resume live updates.
*/
static void resume();
/**
* Returns true if live updates are paused.
*/
static bool isPaused() { return pqLiveSourceBehavior::PauseLiveUpdates; }
protected slots:
void viewAdded(pqView*);
void sourceAdded(pqPipelineSource*);
......@@ -71,6 +86,8 @@ private:
class pqInternals;
QScopedPointer<pqInternals> Internals;
static bool PauseLiveUpdates;
};
#endif
/*=========================================================================
Program: ParaView
Module: pqPauseLiveSourcePropertyWidget.cxx
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#include "pqPauseLiveSourcePropertyWidget.h"
#include "pqLiveSourceBehavior.h"
#include <QPushButton>
#include <QVBoxLayout>
//-----------------------------------------------------------------------------
pqPauseLiveSourcePropertyWidget::pqPauseLiveSourcePropertyWidget(
vtkSMProxy* smproxy, vtkSMProperty* smproperty, QWidget* parentObject)
: Superclass(smproxy, parentObject)
{
auto l = new QVBoxLayout(this);
l->setSpacing(0);
l->setMargin(0);
auto button = new QPushButton(smproperty->GetXMLLabel());
button->setCheckable(true);
l->addWidget(button);
this->setShowLabel(false);
QObject::connect(button, &QPushButton::clicked, [button](bool checked) {
if (checked)
{
pqLiveSourceBehavior::pause();
}
else
{
pqLiveSourceBehavior::resume();
}
button->setChecked(pqLiveSourceBehavior::isPaused());
});
PV_DEBUG_PANELS() << "pqPauseLiveSourcePropertyWidget for a property with "
<< "the panel_widget=\"pause_livesource\" attribute";
}
//-----------------------------------------------------------------------------
pqPauseLiveSourcePropertyWidget::~pqPauseLiveSourcePropertyWidget()
{
}
/*=========================================================================
Program: ParaView
Module: pqPauseLiveSourcePropertyWidget.h
Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
========================================================================*/
#ifndef pqPauseLiveSourcePropertyWidget_h
#define pqPauseLiveSourcePropertyWidget_h
#include "pqApplicationComponentsModule.h" // needed for exports
#include "pqPropertyWidget.h"
/**
* @class pqPauseLiveSourcePropertyWidget
* @brief widget to pause all live sources
*
* pqPauseLiveSourcePropertyWidget can be added to a property on any source that
* is a "live source" i.e. has the `<LiveSource>` XML hint. This will add a
* button to the UI that allows the user to pause all live sources.
*/
class PQAPPLICATIONCOMPONENTS_EXPORT pqPauseLiveSourcePropertyWidget : public pqPropertyWidget
{
Q_OBJECT
typedef pqPropertyWidget Superclass;
public:
pqPauseLiveSourcePropertyWidget(
vtkSMProxy* proxy, vtkSMProperty* smproperty, QWidget* parent = 0);
~pqPauseLiveSourcePropertyWidget() override;
private:
Q_DISABLE_COPY(pqPauseLiveSourcePropertyWidget)
};
#endif
......@@ -66,6 +66,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqListPropertyWidget.h"
#include "pqMultiComponentsDecorator.h"
#include "pqOSPRayHidingDecorator.h"
#include "pqPauseLiveSourcePropertyWidget.h"
#include "pqPropertyGroupButton.h"
#include "pqProxyEditorPropertyWidget.h"
#include "pqSeriesEditorPropertyWidget.h"
......@@ -199,6 +200,10 @@ pqPropertyWidget* pqStandardPropertyWidgetInterface::createWidgetForProperty(
{
return new pqViewResolutionPropertyWidget(smProxy, smProperty, parentWidget);
}
else if (name == "pause_livesource")
{
return new pqPauseLiveSourcePropertyWidget(smProxy, smProperty, parentWidget);
}
// *** NOTE: When adding new types, please update the header documentation ***
return NULL;
......
......@@ -75,6 +75,7 @@ public:
* \li \c transfer_function_editor : pqTransferFunctionWidgetPropertyWidget
* \li \c viewtype_selector: pqViewTypePropertyWidget
* \li \c view_resolution: pqViewResolutionPropertyWidget
* \li \c pause_livesource: pqPauseLiveSourcePropertyWidget
*/
pqPropertyWidget* createWidgetForProperty(
vtkSMProxy* proxy, vtkSMProperty* property, QWidget* parentWidget) override;
......
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