Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Allow setting the visualization on repeat #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ AbstractAnimationWindow::AbstractAnimationWindow(QWidget *pParent)
mpAnimationInitializeAction(nullptr),
mpAnimationPlayAction(nullptr),
mpAnimationPauseAction(nullptr),
mpAnimationRepeatAction(nullptr),
mpAnimationSlider(nullptr),
mpAnimationTimeLabel(nullptr),
mpTimeTextBox(nullptr),
Expand Down Expand Up @@ -116,6 +117,7 @@ void AbstractAnimationWindow::openAnimationFile(QString fileName, bool stashCame
mpAnimationInitializeAction->setEnabled(true);
mpAnimationPlayAction->setEnabled(true);
mpAnimationPauseAction->setEnabled(true);
mpAnimationRepeatAction->setEnabled(true);
mpAnimationSlider->setEnabled(true);
bool state = mpAnimationSlider->blockSignals(true);
mpAnimationSlider->setValue(0);
Expand Down Expand Up @@ -168,6 +170,12 @@ void AbstractAnimationWindow::createActions()
mpAnimationPauseAction->setStatusTip(Helper::animationPauseTip);
mpAnimationPauseAction->setEnabled(false);
connect(mpAnimationPauseAction, SIGNAL(triggered()),this, SLOT(pauseSlotFunction()));
// animation repeat action
mpAnimationRepeatAction = new QAction(QIcon(":/Resources/icons/refresh.svg"), Helper::animationRepeat, this);
mpAnimationRepeatAction->setStatusTip(Helper::animationRepeatTip);
mpAnimationRepeatAction->setEnabled(false);
mpAnimationRepeatAction->setCheckable(true);
connect(mpAnimationRepeatAction, SIGNAL(triggered(bool)),this, SLOT(repeatSlotFunciton(bool)));
// animation slide
mpAnimationSlider = new QSlider(Qt::Horizontal);
mpAnimationSlider->setMinimum(0);
Expand Down Expand Up @@ -603,6 +611,16 @@ void AbstractAnimationWindow::pauseSlotFunction()
mpVisualizer->getTimeManager()->setPause(true);
}

/*!
* \brief AbstractAnimationWindow::repeatSlotFunciton
* Slot function for the repeat button
* \param checked
*/
void AbstractAnimationWindow::repeatSlotFunciton(bool checked)
{
mpVisualizer->getTimeManager()->setRepeat(checked);
}

/*!
* \brief AbstractAnimationWindow::sliderSetTimeSlotFunction
* slot function for the time slider to jump to the adjusted point of time
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class AbstractAnimationWindow : public QMainWindow
QAction *mpAnimationPlayAction;
QAction *mpAnimationPauseAction;
QAction *mpInteractiveControlAction;
QAction *mpAnimationRepeatAction;
QSlider* mpAnimationSlider;
Label *mpAnimationTimeLabel;
QLineEdit *mpTimeTextBox;
Expand Down Expand Up @@ -121,6 +122,7 @@ public slots:
void initSlotFunction();
void playSlotFunction();
void pauseSlotFunction();
void repeatSlotFunciton(bool checked);
void sliderSetTimeSlotFunction(int value);
void jumpToTimeSlotFunction();
void setSpeedSlotFunction();
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Animation/AnimationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ void AnimationWindow::createActions()
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addAction(mpAnimationPauseAction);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addAction(mpAnimationRepeatAction);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addWidget(mpAnimationSlider);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addWidget(mpAnimationTimeLabel);
Expand Down
11 changes: 11 additions & 0 deletions OMEdit/OMEditGUI/Animation/TimeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ TimeManager::TimeManager(const double simTime, const double realTime, const doub
_startTime(startTime),
_endTime(endTime),
_pause(true),
_repeat(false),
mSpeedUp(1.0)
{
mpUpdateSceneTimer = new QTimer;
Expand Down Expand Up @@ -141,6 +142,16 @@ void TimeManager::setPause(const bool status)
}
}

bool TimeManager::canRepeat() const
{
return _repeat;
}

void TimeManager::setRepeat(const bool repeat)
{
_repeat = repeat;
}

void TimeManager::setSpeedUp(double value)
{
mSpeedUp = value;
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/Animation/TimeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class TimeManager
bool isPaused() const;
/*! \brief Sets pause status to new value. */
void setPause(const bool status);
bool canRepeat() const;
void setRepeat(const bool repeat);
int getTimeFraction();
void setSpeedUp(double value);
double getSpeedUp();
Expand All @@ -108,6 +110,8 @@ class TimeManager
double _endTime;
//! This variable indicates if the simulation/visualization currently pauses.
bool _pause;
//! This variable indicates if the simulation/visualization can repeat.
bool _repeat;
double mSpeedUp;
rtclock_t _visualTimer;
QTimer *mpUpdateSceneTimer;
Expand Down
8 changes: 6 additions & 2 deletions OMEdit/OMEditGUI/Animation/Visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ void VisualizerAbstract::modifyShape(std::string shapeName)
shape->setStateSetAction(stateSetAction::update);
}


void VisualizerAbstract::sceneUpdate()
{
//measure realtime
Expand All @@ -330,7 +329,12 @@ void VisualizerAbstract::sceneUpdate()
updateScene(mpTimeManager->getVisTime());
//finish animation with pause when endtime is reached
if (mpTimeManager->getVisTime() >= mpTimeManager->getEndTime()) {
mpTimeManager->setPause(true);
if (mpTimeManager->canRepeat()) {
initVisualization();
mpTimeManager->setPause(false);
} else {
mpTimeManager->setPause(true);
}
} else { // get the new visualization time
double newTime = mpTimeManager->getVisTime() + (mpTimeManager->getHVisual()*mpTimeManager->getSpeedUp());
if (newTime <= mpTimeManager->getEndTime()) {
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/Util/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ QString Helper::animationPlay;
QString Helper::animationPlayTip;
QString Helper::animationPause;
QString Helper::animationPauseTip;
QString Helper::animationRepeat;
QString Helper::animationRepeatTip;
QString Helper::simulationParams;
QString Helper::simulationParamsTip;
QString Helper::newModel;
Expand Down Expand Up @@ -641,6 +643,8 @@ void Helper::initHelperVariables()
Helper::animationInitializeTip = tr("Initialize the animation scene");
Helper::animationPlay = tr("Play");
Helper::animationPlayTip = tr("Play the animation");
Helper::animationRepeat = tr("Repeat");
Helper::animationRepeatTip = tr("Repeat the animation");
Helper::animationPause = tr("Pause");
Helper::animationPauseTip = tr("Pause the animation");
Helper::simulationParams = tr("Simulation Parameters");
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Util/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ class Helper : public QObject
static QString animationPlayTip;
static QString animationPause;
static QString animationPauseTip;
static QString animationRepeat;
static QString animationRepeatTip;
static QString simulationParams;
static QString simulationParamsTip;
static QString newModel;
Expand Down