From 4d458c7959a81a4aa5d545a5ff69a85a7ddd17f4 Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Sat, 9 Feb 2019 14:55:11 +0100 Subject: [PATCH] Allow setting the visualization on repeat --- .../Animation/AbstractAnimationWindow.cpp | 18 ++++++++++++++++++ .../Animation/AbstractAnimationWindow.h | 2 ++ OMEdit/OMEditGUI/Animation/AnimationWindow.cpp | 2 ++ OMEdit/OMEditGUI/Animation/TimeManager.cpp | 11 +++++++++++ OMEdit/OMEditGUI/Animation/TimeManager.h | 4 ++++ OMEdit/OMEditGUI/Animation/Visualizer.cpp | 8 ++++++-- OMEdit/OMEditGUI/Util/Helper.cpp | 4 ++++ OMEdit/OMEditGUI/Util/Helper.h | 2 ++ 8 files changed, 49 insertions(+), 2 deletions(-) diff --git a/OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.cpp b/OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.cpp index c0b00dc09..c998a98b1 100644 --- a/OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.cpp +++ b/OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.cpp @@ -66,6 +66,7 @@ AbstractAnimationWindow::AbstractAnimationWindow(QWidget *pParent) mpAnimationInitializeAction(nullptr), mpAnimationPlayAction(nullptr), mpAnimationPauseAction(nullptr), + mpAnimationRepeatAction(nullptr), mpAnimationSlider(nullptr), mpAnimationTimeLabel(nullptr), mpTimeTextBox(nullptr), @@ -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); @@ -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); @@ -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 diff --git a/OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.h b/OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.h index 23ee6503f..201428cab 100644 --- a/OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.h +++ b/OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.h @@ -93,6 +93,7 @@ class AbstractAnimationWindow : public QMainWindow QAction *mpAnimationPlayAction; QAction *mpAnimationPauseAction; QAction *mpInteractiveControlAction; + QAction *mpAnimationRepeatAction; QSlider* mpAnimationSlider; Label *mpAnimationTimeLabel; QLineEdit *mpTimeTextBox; @@ -121,6 +122,7 @@ public slots: void initSlotFunction(); void playSlotFunction(); void pauseSlotFunction(); + void repeatSlotFunciton(bool checked); void sliderSetTimeSlotFunction(int value); void jumpToTimeSlotFunction(); void setSpeedSlotFunction(); diff --git a/OMEdit/OMEditGUI/Animation/AnimationWindow.cpp b/OMEdit/OMEditGUI/Animation/AnimationWindow.cpp index 4dfd6dfa9..f10c3cfe2 100644 --- a/OMEdit/OMEditGUI/Animation/AnimationWindow.cpp +++ b/OMEdit/OMEditGUI/Animation/AnimationWindow.cpp @@ -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); diff --git a/OMEdit/OMEditGUI/Animation/TimeManager.cpp b/OMEdit/OMEditGUI/Animation/TimeManager.cpp index e2b08eb3a..56b6d44a2 100644 --- a/OMEdit/OMEditGUI/Animation/TimeManager.cpp +++ b/OMEdit/OMEditGUI/Animation/TimeManager.cpp @@ -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; @@ -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; diff --git a/OMEdit/OMEditGUI/Animation/TimeManager.h b/OMEdit/OMEditGUI/Animation/TimeManager.h index c4561349e..c8931b011 100644 --- a/OMEdit/OMEditGUI/Animation/TimeManager.h +++ b/OMEdit/OMEditGUI/Animation/TimeManager.h @@ -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(); @@ -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; diff --git a/OMEdit/OMEditGUI/Animation/Visualizer.cpp b/OMEdit/OMEditGUI/Animation/Visualizer.cpp index c63903af3..354efa8ad 100644 --- a/OMEdit/OMEditGUI/Animation/Visualizer.cpp +++ b/OMEdit/OMEditGUI/Animation/Visualizer.cpp @@ -320,7 +320,6 @@ void VisualizerAbstract::modifyShape(std::string shapeName) shape->setStateSetAction(stateSetAction::update); } - void VisualizerAbstract::sceneUpdate() { //measure realtime @@ -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()) { diff --git a/OMEdit/OMEditGUI/Util/Helper.cpp b/OMEdit/OMEditGUI/Util/Helper.cpp index 814d11c70..c4fd88dc3 100644 --- a/OMEdit/OMEditGUI/Util/Helper.cpp +++ b/OMEdit/OMEditGUI/Util/Helper.cpp @@ -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; @@ -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"); diff --git a/OMEdit/OMEditGUI/Util/Helper.h b/OMEdit/OMEditGUI/Util/Helper.h index d8c4bdcab..26c33a40e 100644 --- a/OMEdit/OMEditGUI/Util/Helper.h +++ b/OMEdit/OMEditGUI/Util/Helper.h @@ -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;