forked from Kitware/VeloView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vvPlayerControlsToolbar.cxx
387 lines (336 loc) · 13.3 KB
/
vvPlayerControlsToolbar.cxx
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/*=========================================================================
Program: ParaView
Module: pqVCRToolbar.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 "vvPlayerControlsToolbar.h"
#include "ui_vvPlayerControlsToolbar.h"
#include <limits>
#include <QLabel>
#include <QComboBox>
#include <QSlider>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QList>
#include <QPair>
#include <QString>
#include "pqActiveObjects.h"
#include "pqPVApplicationCore.h"
#include "pqUndoStack.h"
#include "pqAnimationManager.h"
#include <pqAnimationTimeWidget.h>
#include "vvPlayerControlsController.h"
#include "pqAnimationScene.h"
#include <vtkSMProxy.h>
#include <vtkSMProperty.h>
#include <vtkSMPropertyHelper.h>
#include <vtkSMTimeKeeperProxy.h>
#include <pqPropertyLinks.h>
class vvPlayerControlsToolbar::pqInternals : public Ui::vvPlayerControlsToolbar
{
public:
pqPropertyLinks Links;
QList<QPair<double, QString> > speedFactor;
QComboBox* speedComboBox;
QSlider* frameSlider;
QDoubleSpinBox* timeSpinBox;
QSpinBox* frameQSpinBox;
QLabel* frameLabel;
bool isPlaying;
bool ContinuePlaying;
};
namespace
{
/// Used to link the number of elements in a sm-property to the qt widget.
class vvPlayerControlsToolbarLinks : public pqPropertyLinksConnection
{
typedef pqPropertyLinksConnection Superclass;
public:
vvPlayerControlsToolbarLinks(
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 ~vvPlayerControlsToolbarLinks()
{
}
protected:
virtual QVariant currentServerManagerValue(bool use_unchecked) const
{
Q_ASSERT(use_unchecked == false);
Q_UNUSED(use_unchecked);
unsigned int count = vtkSMPropertyHelper(this->propertySM()).GetNumberOfElements();
return QVariant(static_cast<int>(count));
}
private:
Q_DISABLE_COPY(vvPlayerControlsToolbarLinks);
};
}
//-----------------------------------------------------------------------------
vvPlayerControlsToolbar::vvPlayerControlsToolbar(QWidget* parentObject)
: QToolBar(parentObject)
{
this->UI = new pqInternals();
Ui::vvPlayerControlsToolbar &ui = *this->UI;
ui.setupUi(this);
vvPlayerControlsController* controller = new vvPlayerControlsController(this);
this->Controller = controller;
this->connect(pqPVApplicationCore::instance()->animationManager(),
SIGNAL(activeSceneChanged(pqAnimationScene*)),
this, SLOT(setAnimationScene(pqAnimationScene*)));
this->connect(pqPVApplicationCore::instance()->animationManager(),
SIGNAL(activeSceneChanged(pqAnimationScene*)),
SLOT(setAnimationScene(pqAnimationScene*)));
//------------------------//
// Add the speed control
//------------------------//
// create the speed factor that will be display to the user
// we need to keep an order to display so we can't use hash table or set
// however the developper is reponsable for for the uniqueness of each element
this->UI->speedFactor.append(qMakePair(0., QString("All frames")));
this->UI->speedFactor.append(qMakePair(0.1, QString("x 0.1")));
this->UI->speedFactor.append(qMakePair(0.25, QString("x 0.25")));
this->UI->speedFactor.append(qMakePair(0.5, QString("x 0.5")));
this->UI->speedFactor.append(qMakePair(1., QString("x 1"))) ;
this->UI->speedFactor.append(qMakePair(2., QString("x 2")));
this->UI->speedFactor.append(qMakePair(3., QString("x 3")));
this->UI->speedFactor.append(qMakePair(5., QString("x 5")));
this->UI->speedFactor.append(qMakePair(10., QString("x 10")));
this->UI->speedFactor.append(qMakePair(20., QString("x 20")));
this->UI->speedFactor.append(qMakePair(100., QString("x100")));
// add the widget to the toolbar
this->addWidget(new QLabel("Speed:", this));
this->UI->speedComboBox = new QComboBox(this);
for (int i = 0; i < this->UI->speedFactor.size(); ++i)
{
this->UI->speedComboBox->addItem(this->UI->speedFactor[i].second);
if (this->UI->speedFactor[i].first == 1)
{
this->UI->speedComboBox->setCurrentIndex(i);
}
}
this->addWidget(this->UI->speedComboBox);
// create all connection
QObject::connect(this->UI->speedComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(onSpeedChanged()));
QObject::connect(this, SIGNAL(speedChange(double)),
controller, SLOT(onSpeedChange(double)));
// add a separator to visualy group the element together
this->addSeparator();
//------------------------//
// Add the Slider
//------------------------//
this->UI->frameSlider = new QSlider(Qt::Horizontal, this);
this->addWidget(this->UI->frameSlider);
// create connection
this->connect(this->UI->frameSlider, SIGNAL(sliderPressed()),
this, SLOT(PressSlider()));
this->connect(this->UI->frameSlider, SIGNAL(sliderReleased()),
this, SLOT(ReleaseSlider()));
this->connect(this->UI->frameSlider, SIGNAL(valueChanged(int)),
this, SLOT(setTimeStep(int)));
//------------------------//
// Add the Time DoubleSpinBox
//------------------------//
this->addWidget(new QLabel("Time", this));
this->UI->timeSpinBox = new QDoubleSpinBox(this);
this->addWidget(this->UI->timeSpinBox);
// create connection
this->connect(this->UI->timeSpinBox, SIGNAL(valueChanged(double)),
this, SLOT(setTimeValue(double)));
//------------------------//
// Add the Frame SpinBox
//------------------------//
this->addWidget(new QLabel("Frame", this));
this->UI->frameQSpinBox = new QSpinBox(this);
this->addWidget(this->UI->frameQSpinBox);
this->UI->frameLabel = new QLabel();
this->addWidget(this->UI->frameLabel);
// create connection
this->connect(this->UI->frameQSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(setTimeStep(int)));
// Ideally pqVCRController needs to be deprecated in lieu of a more
// action-reaction friendly implementation. But for now, I am simply reusing
// the old code.
QObject::connect(ui.actionPlay, SIGNAL(triggered()),
controller, SLOT(onPlay()));
QObject::connect(ui.actionFirstFrame, SIGNAL(triggered()),
controller, SLOT(onFirstFrame()));
QObject::connect(ui.actionPreviousFrame, SIGNAL(triggered()),
controller, SLOT(onPreviousFrame()));
QObject::connect(ui.actionNextFrame, SIGNAL(triggered()),
controller, SLOT(onNextFrame()));
QObject::connect(ui.actionLastFrame, SIGNAL(triggered()),
controller, SLOT(onLastFrame()));
QObject::connect(ui.actionLoop, SIGNAL(toggled(bool)),
controller, SLOT(onLoop(bool)));
QObject::connect(controller, SIGNAL(enabled(bool)),
ui.actionPlay, SLOT(setEnabled(bool)));
QObject::connect(controller, SIGNAL(enabled(bool)),
ui.actionFirstFrame, SLOT(setEnabled(bool)));
QObject::connect(controller, SIGNAL(enabled(bool)),
ui.actionPreviousFrame, SLOT(setEnabled(bool)));
QObject::connect(controller, SIGNAL(enabled(bool)),
ui.actionNextFrame, SLOT(setEnabled(bool)));
QObject::connect(controller, SIGNAL(enabled(bool)),
ui.actionLastFrame, SLOT(setEnabled(bool)));
QObject::connect(controller, SIGNAL(enabled(bool)),
ui.actionLoop, SLOT(setEnabled(bool)));
QObject::connect(controller, SIGNAL(loop(bool)),
ui.actionLoop, SLOT(setChecked(bool)));
QObject::connect(controller, SIGNAL(playing(bool)),
this, SLOT(onPlaying(bool)));
}
//-----------------------------------------------------------------------------
vvPlayerControlsToolbar::~vvPlayerControlsToolbar()
{
delete this->UI;
this->UI = 0;
}
//-----------------------------------------------------------------------------
void vvPlayerControlsToolbar::onPlaying(bool playing)
{
this->UI->isPlaying = playing;
if(playing)
{
disconnect(this->UI->actionPlay, SIGNAL(triggered()),
this->Controller, SLOT(onPlay()));
connect(this->UI->actionPlay, SIGNAL(triggered()),
this->Controller, SLOT(onPause()));
this->UI->actionPlay->setIcon(
QIcon(":/vvResources/Icons/media-playback-pause.png"));
this->UI->actionPlay->setText("Pa&use");
}
else
{
connect(this->UI->actionPlay, SIGNAL(triggered()),
this->Controller, SLOT(onPlay()));
disconnect(this->UI->actionPlay, SIGNAL(triggered()),
this->Controller, SLOT(onPause()));
this->UI->actionPlay->setIcon(
QIcon(":/vvResources/Icons/media-playback-start.png"));
this->UI->actionPlay->setText("&Play");
}
// this becomes a behavior.
// this->Implementation->Core->setSelectiveEn abledState(!playing);
}
//-----------------------------------------------------------------------------
void vvPlayerControlsToolbar::onSpeedChanged()
{
for (int i = 0; i < this->UI->speedFactor.size(); ++i)
{
if (this->UI->speedFactor[i].second == this->UI->speedComboBox->currentText())
{
emit speedChange(this->UI->speedFactor[i].first);
return;
}
}
}
//-----------------------------------------------------------------------------
void vvPlayerControlsToolbar::setAnimationScene(pqAnimationScene* scene)
{
this->UI->Links.clear();
this->Controller->setAnimationScene(scene);
this->UI->Links.addPropertyLink<vvPlayerControlsToolbarLinks>(
this, "timeStepCount", SIGNAL(dummySignal()),
this->timeKeeper(), this->timeKeeper()->GetProperty("TimestepValues"));
this->UI->Links.addPropertyLink(
this, "timeValue", SIGNAL(timeValueChanged()),
scene->getProxy(), scene->getProxy()->GetProperty("AnimationTime"));
}
//-----------------------------------------------------------------------------
void vvPlayerControlsToolbar::setTimeValue(double value)
{
this->UI->timeSpinBox->blockSignals(true);
this->UI->timeSpinBox->setValue(value);
this->UI->timeSpinBox->blockSignals(false);
int index = vtkSMTimeKeeperProxy::GetLowerBoundTimeStepIndex(this->timeKeeper(), value);
this->UI->frameQSpinBox->blockSignals(true);
this->UI->frameQSpinBox->setValue(index);
this->UI->frameQSpinBox->blockSignals(false);
this->UI->frameSlider->blockSignals(true);
this->UI->frameSlider->setValue(index);
this->UI->frameSlider->blockSignals(false);
emit timeValueChanged();
}
//-----------------------------------------------------------------------------
double vvPlayerControlsToolbar::timeValue() const
{
return this->UI->timeSpinBox->value();
}
//-----------------------------------------------------------------------------
void vvPlayerControlsToolbar::setTimeStepCount(int value)
{
this->setTimeValue(0);
this->UI->frameQSpinBox->setMaximum(value > 0? value -1 : 0);
this->UI->frameSlider->setMaximum(value > 0? value -1 : 0);
this->UI->frameLabel->setText(QString("of %1").arg(value));
this->UI->actionFirstFrame->setToolTip(
QString("First Frame (%1)").arg(0));
this->UI->actionLastFrame->setToolTip(
QString("Last Frame (%1)").arg(value));
double time = vtkSMTimeKeeperProxy::GetLowerBoundTimeStep(this->timeKeeper(), std::numeric_limits<double>::max());
this->UI->timeSpinBox->setMaximum(time);
}
//-----------------------------------------------------------------------------
int vvPlayerControlsToolbar::timeStepCount() const
{
return this->UI->frameQSpinBox->maximum();
}
//-----------------------------------------------------------------------------
void vvPlayerControlsToolbar::PressSlider()
{
if (this->UI->isPlaying)
{
this->UI->ContinuePlaying = true;
this->Controller->getAnimationScene()->pause();
}
else
{
this->UI->ContinuePlaying = false;
}
}
//-----------------------------------------------------------------------------
void vvPlayerControlsToolbar::ReleaseSlider()
{
if (this->UI->ContinuePlaying)
{
this->Controller->getAnimationScene()->play();
}
}
//-----------------------------------------------------------------------------
void vvPlayerControlsToolbar::setTimeStep(int value)
{
double time = this->Controller->getAnimationScene()->getTimeSteps()[value];
this->Controller->getAnimationScene()->setAnimationTime(time);
}
//-----------------------------------------------------------------------------
vtkSMProxy* vvPlayerControlsToolbar::timeKeeper() const
{
return vtkSMPropertyHelper(this->Controller->getAnimationScene()->getProxy(), "TimeKeeper").GetAsProxy();
}