Commit e41a5dc9 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Added new pqAnimationTimeWidget.

Added a new pqAnimationTimeWidget that will eventually replace
pqCurrentTimeToolbar. This widget uses pqPropertyLinks to make it easier
to link SM properties and the Qt widget.

Change-Id: I73d5de94062fe5739a0ea003e46b584234d04124
parent c5a7e65c
......@@ -156,6 +156,22 @@ double vtkSMTimeKeeperProxy::GetLowerBoundTimeStep(double value)
return value;
}
//----------------------------------------------------------------------------
int vtkSMTimeKeeperProxy::GetLowerBoundTimeStepIndex(double value)
{
vtkSMDoubleVectorProperty* dvp = vtkSMDoubleVectorProperty::SafeDownCast(
this->GetProperty("TimestepValues"));
if (dvp && dvp->GetNumberOfElements() > 0)
{
const double* first = dvp->GetElements();
const double* last = dvp->GetElements() + dvp->GetNumberOfElements() - 1; // note: this is "last"
const double* iter = std::lower_bound(first, last, value);
return static_cast<int>(iter - first);
}
return 0;
}
//----------------------------------------------------------------------------
void vtkSMTimeKeeperProxy::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -81,6 +81,15 @@ public:
return self? self->GetLowerBoundTimeStep(value) : value;
}
// Description:
// Returns the index for the lower bound of the time specified in current
// timestep values, if possible. If there are no timestep values, returns 0.
virtual int GetLowerBoundTimeStepIndex(double value);
static int GetLowerBoundTimeStepIndex(vtkSMProxy* timeKeeper, double value)
{
vtkSMTimeKeeperProxy* self = vtkSMTimeKeeperProxy::SafeDownCast(timeKeeper);
return self? self->GetLowerBoundTimeStepIndex(value) : 0;
}
//BTX
......
......@@ -35,6 +35,8 @@ set (Module_SRCS
pqAlwaysConnectedBehavior.h
pqAnimationTimeToolbar.cxx
pqAnimationTimeToolbar.h
pqAnimationTimeWidget.cxx
pqAnimationTimeWidget.h
pqApplicationSettingsReaction.cxx
pqApplicationSettingsReaction.h
pqApplyBehavior.cxx
......@@ -268,6 +270,7 @@ set (Module_MOC_HDRS
pqAboutDialogReaction.h
pqAlwaysConnectedBehavior.h
pqAnimationTimeToolbar.h
pqAnimationTimeWidget.h
pqApplicationSettingsReaction.h
pqApplyBehavior.h
pqAutoApplyReaction.h
......@@ -398,6 +401,7 @@ if (PARAVIEW_ENABLE_PYTHON)
endif()
set (Module_UI_FILES
Resources/UI/pqAnimationTimeWidget.ui
Resources/UI/pqAxesToolbar.ui
Resources/UI/pqBackgroundEditorWidget.ui
Resources/UI/pqCameraManipulatorWidget.ui
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AnimationTimeWidget</class>
<widget class="QWidget" name="AnimationTimeWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>344</width>
<height>27</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,1,0,0,0">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="timeLabel">
<property name="text">
<string>Time:</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonValue">
<property name="text">
<string/>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="pqLineEdit" name="timeValue">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>0</string>
</property>
<property name="resetCursorPositionOnEditingFinished" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonStep">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="pqSpinBox" name="timestepValue">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="timestepCountLabel">
<property name="text">
<string>of (TDB)</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>pqSpinBox</class>
<extends>QSpinBox</extends>
<header>pqSpinBox.h</header>
</customwidget>
<customwidget>
<class>pqLineEdit</class>
<extends>QLineEdit</extends>
<header>pqLineEdit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>radioButtonStep</sender>
<signal>toggled(bool)</signal>
<receiver>timestepValue</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>209</x>
<y>13</y>
</hint>
<hint type="destinationlabel">
<x>257</x>
<y>13</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioButtonValue</sender>
<signal>toggled(bool)</signal>
<receiver>timeValue</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>33</x>
<y>12</y>
</hint>
<hint type="destinationlabel">
<x>133</x>
<y>13</y>
</hint>
</hints>
</connection>
</connections>
</ui>
/*=========================================================================
Program: ParaView
Module: pqAnimationTimeWidget.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 "pqAnimationTimeWidget.h"
#include "ui_pqAnimationTimeWidget.h"
#include "pqPropertyLinksConnection.h"
#include "pqPropertyLinks.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMTimeKeeperProxy.h"
#include "vtkWeakPointer.h"
#include <QDoubleValidator>
class pqAnimationTimeWidget::pqInternals
{
public:
Ui::AnimationTimeWidget Ui;
vtkWeakPointer<vtkSMProxy> AnimationScene;
void* AnimationSceneVoidPtr;
pqPropertyLinks Links;
int CachedTimestepCount;
pqInternals(pqAnimationTimeWidget* self) :
AnimationSceneVoidPtr(NULL),
CachedTimestepCount(-1)
{
this->Ui.setupUi(self);
this->Ui.timeValue->setValidator(new QDoubleValidator(self));
}
};
namespace
{
/// Used to link the number of elements in a sm-property to the qt widget.
class pqAnimationTimeWidgetLinks : public pqPropertyLinksConnection
{
typedef pqPropertyLinksConnection Superclass;
public:
pqAnimationTimeWidgetLinks(
QObject* qobject, const char* qproperty, const char* qsignal,
vtkSMProxy* smproxy, vtkSMProperty* smproperty, int smindex,
bool use_unchecked_modified_event,
QObject* parentObject=0)
: Superclass(qobject, qproperty, qsignal,
smproxy, smproperty, smindex,
use_unchecked_modified_event, parentObject)
{
}
virtual ~pqAnimationTimeWidgetLinks()
{
}
protected:
virtual QVariant currentServerManagerValue(bool use_unchecked) const
{
Q_ASSERT(use_unchecked == false);
unsigned int count = vtkSMPropertyHelper(this->propertySM()).GetNumberOfElements();
return QVariant(static_cast<int>(count));
}
private:
Q_DISABLE_COPY(pqAnimationTimeWidgetLinks);
};
}
//-----------------------------------------------------------------------------
pqAnimationTimeWidget::pqAnimationTimeWidget(QWidget* parentObject)
: Superclass(parentObject),
Internals(new pqAnimationTimeWidget::pqInternals(this))
{
this->setEnabled(false);
Ui::AnimationTimeWidget &ui = this->Internals->Ui;
this->connect(ui.timeValue, SIGNAL(textChangedAndEditingFinished()), SIGNAL(timeValueChanged()));
this->connect(ui.radioButtonValue, SIGNAL(toggled(bool)), SIGNAL(playModeChanged()));
this->connect(ui.radioButtonValue, SIGNAL(toggled(bool)), SLOT(updateTimestepCountLabelVisibility()));
this->connect(ui.timestepValue, SIGNAL(editingFinished()),
SLOT(timestepValueChanged()));
}
//-----------------------------------------------------------------------------
pqAnimationTimeWidget::~pqAnimationTimeWidget()
{
}
//-----------------------------------------------------------------------------
void pqAnimationTimeWidget::setAnimationScene(vtkSMProxy* animationScene)
{
pqInternals& internals = *this->Internals;
if (internals.AnimationSceneVoidPtr == animationScene)
{
return;
}
internals.Links.clear();
internals.AnimationScene = animationScene;
internals.AnimationSceneVoidPtr = animationScene;
this->setEnabled(animationScene != NULL);
if (!animationScene)
{
return;
}
internals.Links.addPropertyLink(
this, "timeValue", SIGNAL(timeValueChanged()),
animationScene, animationScene->GetProperty("AnimationTime"));
internals.Links.addPropertyLink(this, "playMode", SIGNAL(playModeChanged()),
animationScene, animationScene->GetProperty("PlayMode"));
// In a ParaView application, it's safe to assume that the timekeeper an
// animation scene is using doesn't change in the life span of the scene.
vtkSMProxy* timeKeeper = vtkSMPropertyHelper(animationScene, "TimeKeeper").GetAsProxy();
Q_ASSERT(timeKeeper != NULL);
internals.Links.addPropertyLink<pqAnimationTimeWidgetLinks>(
this, "timeStepCount", SIGNAL(dummySignal()),
timeKeeper, timeKeeper->GetProperty("TimestepValues"));
}
//-----------------------------------------------------------------------------
vtkSMProxy* pqAnimationTimeWidget::animationScene() const
{
pqInternals& internals = *this->Internals;
return internals.AnimationScene;
}
//-----------------------------------------------------------------------------
vtkSMProxy* pqAnimationTimeWidget::timeKeeper() const
{
pqInternals& internals = *this->Internals;
return internals.AnimationScene?
vtkSMPropertyHelper(internals.AnimationScene, "TimeKeeper").GetAsProxy() : NULL;
}
//-----------------------------------------------------------------------------
void pqAnimationTimeWidget::setTimeValue(double time)
{
Ui::AnimationTimeWidget &ui = this->Internals->Ui;
ui.timeValue->setTextAndResetCursor(QString::number(time));
bool prev = ui.timestepValue->blockSignals(true);
ui.timestepValue->setValue(
vtkSMTimeKeeperProxy::GetLowerBoundTimeStepIndex(this->timeKeeper(), time));
ui.timestepValue->blockSignals(prev);
}
//-----------------------------------------------------------------------------
double pqAnimationTimeWidget::timeValue() const
{
Ui::AnimationTimeWidget &ui = this->Internals->Ui;
return ui.timeValue->text().toDouble();
}
//-----------------------------------------------------------------------------
void pqAnimationTimeWidget::setTimeStepCount(int value)
{
pqInternals& internals = *this->Internals;
internals.CachedTimestepCount = value;
Ui::AnimationTimeWidget &ui = this->Internals->Ui;
ui.timestepValue->setMaximum(value > 0? value -1 : 0);
ui.timestepCountLabel->setText(QString("of %1").arg(value));
ui.timestepCountLabel->setVisible(
(value > 0) && (this->playMode() == "Snap To TimeSteps"));
bool prev = ui.timestepValue->blockSignals(true);
ui.timestepValue->setValue(
vtkSMTimeKeeperProxy::GetLowerBoundTimeStepIndex(this->timeKeeper(), this->timeValue()));
ui.timestepValue->blockSignals(prev);
this->updateTimestepCountLabelVisibility();
}
//-----------------------------------------------------------------------------
int pqAnimationTimeWidget::timeStepCount() const
{
pqInternals& internals = *this->Internals;
return internals.CachedTimestepCount;
}
//-----------------------------------------------------------------------------
void pqAnimationTimeWidget::setPlayMode(const QString& value)
{
Ui::AnimationTimeWidget &ui = this->Internals->Ui;
if (value == "Sequence" || value == "Real Time")
{
ui.radioButtonValue->setChecked(true);
}
else if (value == "Snap To TimeSteps")
{
ui.radioButtonStep->setChecked(true);
}
this->updateTimestepCountLabelVisibility();
}
//-----------------------------------------------------------------------------
QString pqAnimationTimeWidget::playMode() const
{
Ui::AnimationTimeWidget &ui = this->Internals->Ui;
return ui.radioButtonValue->isChecked()? "Sequence" : "Snap To TimeSteps";
}
//-----------------------------------------------------------------------------
void pqAnimationTimeWidget::updateTimestepCountLabelVisibility()
{
Ui::AnimationTimeWidget &ui = this->Internals->Ui;
ui.timestepCountLabel->setVisible(
(this->timeStepCount() > 0) && (this->playMode() == "Snap To TimeSteps"));
}
//-----------------------------------------------------------------------------
void pqAnimationTimeWidget::timestepValueChanged()
{
Ui::AnimationTimeWidget &ui = this->Internals->Ui;
int index = ui.timestepValue->value();
vtkSMPropertyHelper helper(this->timeKeeper(), "TimestepValues");
if (index >=0 && static_cast<unsigned int>(index) < helper.GetNumberOfElements())
{
this->setTimeValue(helper.GetAsDouble(index));
emit this->timeValueChanged();
}
}
//-----------------------------------------------------------------------------
void pqAnimationTimeWidget::setPlayModeReadOnly(bool val)
{
Ui::AnimationTimeWidget &ui = this->Internals->Ui;
ui.radioButtonValue->setVisible(!val);
ui.radioButtonStep->setVisible(!val);
}
//-----------------------------------------------------------------------------
bool pqAnimationTimeWidget::playModeReadOnly() const
{
Ui::AnimationTimeWidget &ui = this->Internals->Ui;
return !ui.radioButtonStep->isVisible();
}
/*=========================================================================
Program: ParaView
Module: pqAnimationTimeWidget.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 __pqAnimationTimeWidget_h
#define __pqAnimationTimeWidget_h
#include "pqApplicationComponentsModule.h"
#include <QWidget>
#include <QScopedPointer>
#include <vector>
class vtkSMProxy;
/// pqAnimationTimeWidget is a widget that can be used to show/set the current
/// animation time.
/// The widget allow the user to do the following:
/// \li View and/or change the current time value (in seq/realtime modes), or
/// current time step value (in snap-to-timesteps mode).
/// \li View and/or change the play mode (from seq to snap-to-timesteps). While
/// the widget behaves acceptably if the application externally changes the
/// animation play mode to realtime, the widget itself doesn't allow the
/// user to do that. This mode is optional. You can disabling allowing the
/// user to change the play mode by setting playModeReadOnly to true
/// (default is false).
class PQAPPLICATIONCOMPONENTS_EXPORT pqAnimationTimeWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(double timeValue READ timeValue WRITE setTimeValue NOTIFY timeValueChanged)
Q_PROPERTY(int timeStepCount READ timeStepCount WRITE setTimeStepCount)
Q_PROPERTY(QString playMode READ playMode WRITE setPlayMode)
Q_PROPERTY(bool playModeReadOnly READ playModeReadOnly WRITE setPlayModeReadOnly)
typedef QWidget Superclass;
public:
pqAnimationTimeWidget(QWidget* parent=0);
virtual ~pqAnimationTimeWidget();
/// Provides access to the animation scene proxy currently
/// controlled/reflected by this widget.
vtkSMProxy* animationScene() const;
/// Get/set the current time value.
void setTimeValue(double time);
double timeValue() const;
/// Get/set the number of timesteps.
void setTimeStepCount(int count);
int timeStepCount() const;
/// Get/set the playmode.
void setPlayMode(const QString& mode);
QString playMode() const;
/// Get/set whether the user should be able to change the animation
/// play mode using this widget.
void setPlayModeReadOnly(bool val);
bool playModeReadOnly() const;
signals:
void timeValueChanged();
void playModeChanged();
void dummySignal();
public slots:
/// Set the animation scene proxy which is reflected/controlled by this
/// widget.
void setAnimationScene(vtkSMProxy* animationScene);
private slots:
void updateTimestepCountLabelVisibility();
/// called when the user changes the timestepValue spinbox manually
/// to change the current timestep. We will update the current time and
/// result in triggering timeValueChanged() if time indeed changed.
void timestepValueChanged();
private:
Q_DISABLE_COPY(pqAnimationTimeWidget);
// Returns the current timekeeper.
vtkSMProxy* timeKeeper() const;
class pqInternals;
QScopedPointer<pqInternals> Internals;
};
#endif
......@@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkSMProperty.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMProxy.h"
#include "vtkSMTimeKeeperProxy.h"
#include <QList>
#include <QtDebug>
......@@ -106,22 +107,7 @@ double pqTimeKeeper::getTimeStepValue(int index) const
//-----------------------------------------------------------------------------
int pqTimeKeeper::getTimeStepValueIndex(double time) const
{
int num_values = this->getNumberOfTimeStepValues();
double *values = new double[num_values+1];
vtkSMPropertyHelper(this->getProxy(), "TimestepValues").Get(values,
num_values);
int cc=1;
for (cc=1; cc < num_values; cc++)
{
if (values[cc] > time)
{
delete[] values;
return (cc-1);
}
}
delete[] values;
return (cc-1);
return vtkSMTimeKeeperProxy::GetLowerBoundTimeStepIndex(this->getProxy(), time);
}
//-----------------------------------------------------------------------------
......
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