Skip to content

Commit

Permalink
Use different timers for updating scene and rendering frame.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 10, 2016
1 parent f793884 commit 153b56c
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 195 deletions.
18 changes: 10 additions & 8 deletions OMEdit/OMEditGUI/Animation/AnimationWindow.cpp
Expand Up @@ -51,7 +51,6 @@ AnimationWindow::AnimationWindow(PlotWindowContainer *pPlotWindowContainer)
mpSceneView(new osgViewer::View()),
mpVisualizer(nullptr),
mpViewerWidget(nullptr),
mpUpdateTimer(new QTimer()),
mpAnimationToolBar(new QToolBar(QString("Animation Toolbar"),this)),
mpFMUSettingsDialog(nullptr),
mpAnimationChooseFileAction(nullptr),
Expand All @@ -63,14 +62,16 @@ AnimationWindow::AnimationWindow(PlotWindowContainer *pPlotWindowContainer)
this->setObjectName(QString("animationWidget"));
// the osg threading model
setThreadingModel(osgViewer::CompositeViewer::SingleThreaded);
// disable the default setting of viewer.done() by pressing Escape.
setKeyEventSetsDone(0);
//the viewer widget
mpViewerWidget = setupViewWidget();
// we need to set the minimum height so that visualization window is still shown when we cascade windows.
mpViewerWidget->setMinimumHeight(100);
// let timer do a scene update at every tick
QObject::connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(updateSceneFunction()));
QObject::connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(renderSlotFunction()));
mpUpdateTimer->start(100);
// let render timer do a render frame at every tick
mRenderFrameTimer.setInterval(100);
QObject::connect(&mRenderFrameTimer, SIGNAL(timeout()), this, SLOT(renderFrame()));
mRenderFrameTimer.start();
// actions and widgets for the toolbar
int toolbarIconSize = mpPlotWindowContainer->getMainWindow()->getOptionsDialog()->getGeneralSettingsPage()->getToolbarIconSizeSpinBox()->value();
mpAnimationChooseFileAction = new QAction(QIcon(":/Resources/icons/open.svg"), Helper::animationChooseFile, this);
Expand Down Expand Up @@ -284,6 +285,7 @@ void AnimationWindow::loadVisualization()
mpPlotWindowContainer->getMainWindow()->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, msg,
Helper::scriptingKind, Helper::errorLevel));
} else {
connect(mpVisualizer->getTimeManager()->getUpdateSceneTimer(), SIGNAL(timeout()), SLOT(updateScene()));
mpVisualizer->initData();
mpVisualizer->setUpScene();
mpVisualizer->initVisualization();
Expand Down Expand Up @@ -375,7 +377,7 @@ void AnimationWindow::initSlotFunction()
* \brief AnimationWindow::updateSceneFunction
* updates the visualization objects
*/
void AnimationWindow::updateSceneFunction()
void AnimationWindow::updateScene()
{
if (!(mpVisualizer == NULL)) {
//set time label
Expand All @@ -395,10 +397,10 @@ void AnimationWindow::updateSceneFunction()
}

/*!
* \brief AnimationWindow::renderSlotFunction
* \brief AnimationWindow::renderFrame
* renders the osg viewer
*/
void AnimationWindow::renderSlotFunction()
void AnimationWindow::renderFrame()
{
frame();
}
Expand Down
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/Animation/AnimationWindow.h
Expand Up @@ -81,11 +81,11 @@ public slots:
void playSlotFunction();
void pauseSlotFunction();
void initSlotFunction();
void renderSlotFunction();
void updateScene();
void renderFrame();
void chooseAnimationFileSlotFunction();
void setSpeedSlotFunction();
void jumpToTimeSlotFunction();
void updateSceneFunction();
void resetCamera();
void cameraPositionXY();
void cameraPositionXZ();
Expand All @@ -103,7 +103,7 @@ public slots:
VisualizerAbstract* mpVisualizer;
//widgets
QWidget* mpViewerWidget;
QTimer* mpUpdateTimer;
QTimer mRenderFrameTimer;
QToolBar* mpAnimationToolBar;
QSlider* mpAnimationSlider;
QLabel *mpAnimationTimeLabel;
Expand Down
34 changes: 20 additions & 14 deletions OMEdit/OMEditGUI/Animation/TimeManager.cpp
Expand Up @@ -35,18 +35,20 @@
#include "TimeManager.h"

TimeManager::TimeManager(const double simTime, const double realTime, const double realTimeFactor, const double visTime,
const double hVisual, const double startTime, const double endTime)
: _simTime(simTime),
_realTime(realTime),
_realTimeFactor(realTimeFactor),
_visTime(visTime),
_hVisual(hVisual),
_startTime(startTime),
_endTime(endTime),
_pause(true),
mSpeedUp(1.0),
_visualTimer()
{
const double hVisual, const double startTime, const double endTime)
: _simTime(simTime),
_realTime(realTime),
_realTimeFactor(realTimeFactor),
_visTime(visTime),
_hVisual(hVisual),
_startTime(startTime),
_endTime(endTime),
_pause(true),
mSpeedUp(1.0),
_visualTimer()
{
mpUpdateSceneTimer = new QTimer;
mpUpdateSceneTimer->setInterval(100);
}

void TimeManager::updateTick()
Expand Down Expand Up @@ -110,7 +112,6 @@ void TimeManager::setHVisual(const double hVis)
_hVisual = hVis;
}


double TimeManager::getRealTime() const
{
return _realTime;
Expand All @@ -134,7 +135,13 @@ bool TimeManager::isPaused() const
void TimeManager::setPause(const bool status)
{
_pause = status;
if (status) {
mpUpdateSceneTimer->stop();
} else {
mpUpdateSceneTimer->start();
}
}

void TimeManager::setSpeedUp(double value)
{
mSpeedUp = value;
Expand All @@ -144,4 +151,3 @@ double TimeManager::getSpeedUp()
{
return mSpeedUp;
}

4 changes: 3 additions & 1 deletion OMEdit/OMEditGUI/Animation/TimeManager.h
Expand Up @@ -39,6 +39,7 @@

#include <osg/Timer>

#include <QTimer>

class TimeManager
{
Expand Down Expand Up @@ -88,6 +89,7 @@ class TimeManager
int getTimeFraction();
void setSpeedUp(double value);
double getSpeedUp();
QTimer* getUpdateSceneTimer() {return mpUpdateSceneTimer;}

private:
//! Time of the current simulation step.
Expand All @@ -108,7 +110,7 @@ class TimeManager
bool _pause;
double mSpeedUp;
osg::Timer _visualTimer;

QTimer *mpUpdateSceneTimer;
};


Expand Down

0 comments on commit 153b56c

Please sign in to comment.