Skip to content

Commit

Permalink
improvement Player
Browse files Browse the repository at this point in the history
  • Loading branch information
NickLaurenson committed Dec 13, 2018
1 parent 0797c5f commit 6c22228
Show file tree
Hide file tree
Showing 5 changed files with 349 additions and 37 deletions.
44 changes: 43 additions & 1 deletion vvPlayerControlsController.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkSMTrace.h"

// Qt includes.
#include <QPointer>
#include <QtDebug>
#include <QApplication>

Expand All @@ -48,8 +49,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqPipelineSource.h"
#include "pqSMAdaptor.h"
#include "pqUndoStack.h"
#include "vtkAnimationScene.h"

namespace {
void SetProperty(QPointer<pqAnimationScene> scene, const char* property, int value)
{
dynamic_cast<vtkSMIntVectorProperty*>
(scene->getProxy()->GetProperty(property))->SetElements1(value);
scene->getProxy()->UpdateProperty(property);
}
}

//-----------------------------------------------------------------------------
vvPlayerControlsController::vvPlayerControlsController(QObject* _parent/*=null*/) : QObject(_parent)
vvPlayerControlsController::vvPlayerControlsController(QObject* _parent/*=null*/)
: QObject(_parent),
speed(1),
duration(0)
{
}

Expand All @@ -58,6 +73,11 @@ vvPlayerControlsController::~vvPlayerControlsController()
{
}

//-----------------------------------------------------------------------------
pqAnimationScene *vvPlayerControlsController::getAnimationScene() {
return this->Scene.data();
}

//-----------------------------------------------------------------------------
void vvPlayerControlsController::setAnimationScene(pqAnimationScene* scene)
{
Expand Down Expand Up @@ -97,6 +117,7 @@ void vvPlayerControlsController::onTimeRangesChanged()
{
QPair<double, double> range = this->Scene->getClockTimeRange();
emit this->timeRanges(range.first, range.second);
this->duration = range.second - range.first;
}
}

Expand All @@ -115,6 +136,17 @@ void vvPlayerControlsController::onPlay()
.arg(this->Scene->getProxy())
.arg("Play");

if (speed != 0)
{
SetProperty(this->Scene, "Duration", this->duration / this->speed);
SetProperty(this->Scene, "PlayMode", vtkAnimationScene::PLAYMODE_REALTIME);
}
else
{
// there is no enum for mode 2...
SetProperty(this->Scene, "PlayMode", 2);
}

this->Scene->getProxy()->InvokeCommand("Play");

// NOTE: This is a blocking call, returns only after the
Expand Down Expand Up @@ -175,6 +207,7 @@ void vvPlayerControlsController::onPause()
return;
}
this->Scene->getProxy()->InvokeCommand("Stop");
SetProperty(this->Scene, "PlayMode", 2);
}

//-----------------------------------------------------------------------------
Expand All @@ -192,6 +225,7 @@ void vvPlayerControlsController::onFirstFrame()
void vvPlayerControlsController::onPreviousFrame()
{
emit this->beginNonUndoableChanges();
SetProperty(this->Scene, "Duration", this->duration);
this->Scene->getProxy()->InvokeCommand("GoToPrevious");
SM_SCOPED_TRACE(CallMethod)
.arg(this->Scene->getProxy())
Expand All @@ -203,6 +237,7 @@ void vvPlayerControlsController::onPreviousFrame()
void vvPlayerControlsController::onNextFrame()
{
emit this->beginNonUndoableChanges();
SetProperty(this->Scene, "Duration", this->duration);
this->Scene->getProxy()->InvokeCommand("GoToNext");
SM_SCOPED_TRACE(CallMethod)
.arg(this->Scene->getProxy())
Expand All @@ -221,3 +256,10 @@ void vvPlayerControlsController::onLastFrame()
emit this->endNonUndoableChanges();
}

//-----------------------------------------------------------------------------
void vvPlayerControlsController::onSpeedChange(double speed)
{
this->speed = speed;
this->onPause();
}

5 changes: 5 additions & 0 deletions vvPlayerControlsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class vvPlayerControlsController : public QObject
vvPlayerControlsController(QObject* parent = 0);
virtual ~vvPlayerControlsController();

pqAnimationScene* getAnimationScene();

signals:
void timestepChanged();

Expand Down Expand Up @@ -95,6 +97,7 @@ public slots:
void onPlay();
void onPause();
void onLoop(bool checked);
void onSpeedChange(double speed);

protected slots:
void onTick();
Expand All @@ -107,6 +110,8 @@ protected slots:
void operator=(const vvPlayerControlsController&); // Not implemented.

QPointer<pqAnimationScene> Scene;
double speed;
double duration;
};

#endif // VVPLAYERCONTROLSCONTROLLER_H
Loading

0 comments on commit 6c22228

Please sign in to comment.