Skip to content

Commit

Permalink
Merge branch 'animation2' of https://github.com/vwaurich/OMEdit into …
Browse files Browse the repository at this point in the history
…animation2
  • Loading branch information
adeas31 committed Sep 16, 2016
2 parents 54c5148 + 4793ccf commit d2dfa3e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
38 changes: 33 additions & 5 deletions OMEdit/OMEditGUI/Animation/AnimationWindow.cpp
Expand Up @@ -71,6 +71,7 @@ AnimationWindow::AnimationWindow(PlotWindowContainer *pPlotWindowContainer)
QObject::connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(renderSlotFunction()));
mpUpdateTimer->start(100);
// actions and widgets for the toolbar
int toolbarIconSize = mpPlotWindowContainer->getMainWindow()->getOptionsDialog()->getGeneralSettingsPage()->getToolbarIconSizeSpinBox()->value();
mpAnimationChooseFileAction = new QAction(QIcon(":/Resources/icons/openFile.png"), Helper::animationChooseFile, this);
mpAnimationChooseFileAction->setStatusTip(Helper::animationChooseFileTip);
mpAnimationInitializeAction = new QAction(QIcon(":/Resources/icons/initialize.png"), Helper::animationInitialize, this);
Expand All @@ -85,10 +86,14 @@ AnimationWindow::AnimationWindow(PlotWindowContainer *pPlotWindowContainer)
mpAnimationSlider = new QSlider(Qt::Horizontal);
mpAnimationSlider->setMinimum(0);
mpAnimationSlider->setMaximum(100);
mpAnimationSlider->setSliderPosition(50);
mpAnimationSlider->setSliderPosition(0);
mpAnimationSlider->setEnabled(false);
mpAnimationTimeLabel = new QLabel();
mpAnimationTimeLabel->setText(QString(" Time [s]: ").append(QString::fromStdString("0.000")));
mpAnimationSpeedUpLabel = new QLabel();
mpAnimationSpeedUpLabel->setText(QString(" speedUp: "));
mpSpeedUpEdit = new QTextEdit("1.0",this);
mpSpeedUpEdit->setMaximumSize(QSize(toolbarIconSize*3,toolbarIconSize));
mpPerspectiveDropDownBox = new QComboBox(this);
mpPerspectiveDropDownBox->addItem(QIcon(":/Resources/icons/perspective0.png"), QString("to home position"));
mpPerspectiveDropDownBox->addItem(QIcon(":/Resources/icons/perspective2.png"),QString("normal to x-y plane"));
Expand All @@ -104,9 +109,13 @@ AnimationWindow::AnimationWindow(PlotWindowContainer *pPlotWindowContainer)
mpAnimationToolBar->addAction(mpAnimationPauseAction);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addWidget(mpAnimationSlider);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addWidget(mpAnimationTimeLabel);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addWidget(mpAnimationSpeedUpLabel);
mpAnimationToolBar->addWidget(mpSpeedUpEdit);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addWidget(mpPerspectiveDropDownBox);
int toolbarIconSize = mpPlotWindowContainer->getMainWindow()->getOptionsDialog()->getGeneralSettingsPage()->getToolbarIconSizeSpinBox()->value();
mpAnimationToolBar->setIconSize(QSize(toolbarIconSize, toolbarIconSize));
addToolBar(Qt::TopToolBarArea,mpAnimationToolBar);
setCentralWidget(mpViewerWidget);
Expand All @@ -117,6 +126,23 @@ AnimationWindow::AnimationWindow(PlotWindowContainer *pPlotWindowContainer)
connect(mpAnimationPauseAction, SIGNAL(triggered()),this, SLOT(pauseSlotFunction()));
connect(mpPerspectiveDropDownBox, SIGNAL(activated(int)), this, SLOT(setPerspective(int)));
connect(mpAnimationSlider, SIGNAL(sliderMoved(int)),this, SLOT(sliderSetTimeSlotFunction(int)));
connect(mpSpeedUpEdit, SIGNAL(textChanged()),this, SLOT(setSpeedUpSlotFunction()));
}


void AnimationWindow::setSpeedUpSlotFunction()
{
QString str = mpSpeedUpEdit->toPlainText();
bool isFloat = true;
double value = str.toFloat(&isFloat);
if (isFloat && value > 0.0)
{
mpVisualizer->getTimeManager()->setSpeedUp(value);
}
else
{
std::cout<<"The speedUp has to be a positive real value. "<<std::endl;
}
}

/*!
Expand Down Expand Up @@ -204,19 +230,19 @@ void AnimationWindow::loadVisualization()
*/
void AnimationWindow::chooseAnimationFileSlotFunction()
{
QString *dir = new QString("./");
std::string file = StringHandler::getOpenFileName(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseFile),
dir, Helper::matFileTypes, NULL).toStdString();
NULL, Helper::matFileTypes, NULL).toStdString();
if (file.compare("")) {
std::size_t pos = file.find_last_of("/\\");
mPathName = file.substr(0, pos + 1);
mFileName = file.substr(pos + 1, file.length());
std::cout<<"file "<<mFileName<<" path "<<mPathName<<std::endl;
//std::cout<<"file "<<mFileName<<" path "<<mPathName<<std::endl;
loadVisualization();
mpAnimationInitializeAction->setEnabled(true);
mpAnimationPlayAction->setEnabled(true);
mpAnimationPauseAction->setEnabled(true);
mpAnimationSlider->setEnabled(true);
mpSpeedUpEdit->setPlainText(QString("1.0"));
} else {
std::cout<<"No Visualization selected!"<<std::endl;
}
Expand Down Expand Up @@ -287,6 +313,8 @@ void AnimationWindow::updateSceneFunction()
// set time slider
int time = mpVisualizer->getTimeManager()->getTimeFraction();
mpAnimationSlider->setValue(time);
//set time label
mpAnimationTimeLabel->setText(QString(" Time [s]: ").append(QString::number(mpVisualizer->getTimeManager()->getVisTime())));
}
}

Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/Animation/AnimationWindow.h
Expand Up @@ -76,6 +76,7 @@ public slots:
void initSlotFunction();
void renderSlotFunction();
void chooseAnimationFileSlotFunction();
void setSpeedUpSlotFunction();
void updateSceneFunction();
void resetCamera();
void cameraPositionXY();
Expand All @@ -98,6 +99,8 @@ public slots:
QWidget* topWidget;
QSlider* mpAnimationSlider;
QLabel *mpAnimationTimeLabel;
QLabel *mpAnimationSpeedUpLabel;
QTextEdit * mpSpeedUpEdit;
QComboBox *mpPerspectiveDropDownBox;
//actions
QAction *mpAnimationChooseFileAction;
Expand Down
11 changes: 11 additions & 0 deletions OMEdit/OMEditGUI/Animation/TimeManager.cpp
Expand Up @@ -44,6 +44,7 @@ TimeManager::TimeManager(const double simTime, const double realTime, const doub
_startTime(startTime),
_endTime(endTime),
_pause(true),
mSpeedUp(1.0),
_visualTimer()
{
}
Expand Down Expand Up @@ -134,3 +135,13 @@ void TimeManager::setPause(const bool status)
{
_pause = status;
}
void TimeManager::setSpeedUp(double value)
{
mSpeedUp = value;
}

double TimeManager::getSpeedUp()
{
return mSpeedUp;
}

5 changes: 3 additions & 2 deletions OMEdit/OMEditGUI/Animation/TimeManager.h
Expand Up @@ -85,8 +85,9 @@ class TimeManager
bool isPaused() const;
/*! \brief Sets pause status to new value. */
void setPause(const bool status);

int getTimeFraction();
void setSpeedUp(double value);
double getSpeedUp();

private:
//! Time of the current simulation step.
Expand All @@ -105,7 +106,7 @@ class TimeManager
double _endTime;
//! This variable indicates if the simulation/visualization currently pauses.
bool _pause;

double mSpeedUp;
osg::Timer _visualTimer;

};
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Animation/Visualizer.cpp
Expand Up @@ -260,7 +260,7 @@ void VisualizerAbstract::sceneUpdate()
if (!_timeManager->isPaused())
{
updateScene(_timeManager->getVisTime());
_timeManager->setVisTime(_timeManager->getVisTime() + _timeManager->getHVisual());
_timeManager->setVisTime(_timeManager->getVisTime() + (_timeManager->getHVisual()*_timeManager->getSpeedUp()));
if (_timeManager->getVisTime() >= _timeManager->getEndTime() - 1.e-6)
{
_timeManager->setPause(true);
Expand Down

0 comments on commit d2dfa3e

Please sign in to comment.