Skip to content

Commit

Permalink
- make an animation toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich committed Aug 26, 2016
1 parent e5a6e45 commit 8707392
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 33 deletions.
38 changes: 22 additions & 16 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.cpp
Expand Up @@ -51,7 +51,7 @@ AnimationWindowContainer::AnimationWindowContainer(MainWindow *pParent)
_pathName(""),
_fileName(""),
_sceneView(new osgViewer::View()),
_visualizer(),
_visualizer(nullptr),
_viewerWidget(nullptr),
_topWidget(nullptr),
_visFileButton(nullptr),
Expand Down Expand Up @@ -90,8 +90,8 @@ QWidget* AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootN
traits->x = 0;
traits->y = 0;

traits->width = this->parentWidget()->width();
traits->height = this->parentWidget()->height();
traits->width = 1000;
traits->height = 600;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
Expand Down Expand Up @@ -198,13 +198,12 @@ void AnimationWindowContainer::loadVisualization(){
_visualizer->setUpScene();
_visualizer->initVisualization();

//add
//add scene for the chosen visualization
_sceneView->setSceneData(_visualizer->getOMVisScene()->getScene().getRootNode());

std::cout<<"start timer"<<std::endl;
_updateTimer = new QTimer();
// do a scene update at every tick
QObject::connect(_updateTimer, SIGNAL(timeout()), this, SLOT(updateSceneFunction()));
QObject::connect(_updateTimer, SIGNAL(timeout()), this, SLOT(moveTimeSliderSlotFunction()));
QObject::connect(_updateTimer, SIGNAL(timeout()), parentWidget(), SLOT(doSomething()));

_updateTimer->start(100);
}
Expand Down Expand Up @@ -239,14 +238,11 @@ void AnimationWindowContainer::showWidgets(){
show();
}


/*!
* \brief AnimationWindowContainer::moveTiemSliderSlotFunction
* slot function to move the time slider
*/
void AnimationWindowContainer::moveTimeSliderSlotFunction(){
//std::cout<<"moveTimeSliderSlotFunction "<<_visualizer->getTimeManager()->getSliderPosition()<<std::endl;
_timeSlider->setSliderPosition(_visualizer->getTimeManager()->getSliderPosition());
double AnimationWindowContainer::getTimeFraction(){
if (_visualizer==NULL)
return 0.0;
else
return _visualizer->getTimeManager()->getTimeFraction();
}

/*!
Expand All @@ -257,7 +253,7 @@ void AnimationWindowContainer::sliderSetTimeSlotFunction(int value){
int time = (_visualizer->getTimeManager()->getEndTime()
- _visualizer->getTimeManager()->getStartTime())
* (float) (value / 100.0);
std::cout<<"moveSliderSlotFunction "<<time<<std::endl;
std::cout<<"moveSliderSlotFunction "<<value<<" : "<<time<<std::endl;
_visualizer->getTimeManager()->setVisTime(time);
_visualizer->sceneUpdate();
}
Expand Down Expand Up @@ -308,6 +304,16 @@ void AnimationWindowContainer::renderSlotFunction()
frame();
}

/*!
* \brief AnimationWindowContainer::getVisTime
* returns the current visualization time
*/
double AnimationWindowContainer::getVisTime(){
if (_visualizer==NULL)
return -1.0;
else
return _visualizer->getTimeManager()->getVisTime();
}



Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEditGUI/Animation/AnimationWindowContainer.h
Expand Up @@ -66,9 +66,11 @@ class AnimationWindowContainer : public QWidget, public osgViewer::CompositeView
QWidget* setupViewWidget(osg::ref_ptr<osg::Node> rootNode);
void showWidgets();
void loadVisualization();
double getTimeFraction();
double getVisTime();

public slots:
void sliderSetTimeSlotFunction(int value);
void moveTimeSliderSlotFunction();
void playSlotFunction();
void pauseSlotFunction();
void initSlotFunction();
Expand Down
12 changes: 3 additions & 9 deletions OMEdit/OMEditGUI/Animation/TimeManager.cpp
Expand Up @@ -44,8 +44,7 @@ TimeManager::TimeManager(const double simTime, const double realTime, const doub
_startTime(startTime),
_endTime(endTime),
_pause(true),
_visualTimer(),
_sliderRange(0)
_visualTimer()
{
}

Expand All @@ -55,14 +54,9 @@ void TimeManager::updateTick()
_realTime = _visualTimer.time_m() / 1000.0;
}

int TimeManager::getSliderPosition() const
double TimeManager::getTimeFraction()
{
return std::round(_visTime * _sliderRange / (_endTime - _startTime));
}

void TimeManager::setSliderRange(const int min, const int max)
{
_sliderRange = max - min;
return _visTime / (_endTime - _startTime);
}

double TimeManager::getEndTime() const
Expand Down
6 changes: 2 additions & 4 deletions OMEdit/OMEditGUI/Animation/TimeManager.h
Expand Up @@ -48,8 +48,6 @@ class TimeManager
const double hVisual, const double startTime, const double endTime);
~TimeManager() = default;
void updateTick();
int getSliderPosition() const;
void setSliderRange(const int min, const int max);
/*! \brief Returns the end time of the simulation. */
double getEndTime() const;
/*! \brief Sets the end time of the simulation to the given value. */
Expand Down Expand Up @@ -88,6 +86,8 @@ class TimeManager
/*! \brief Sets pause status to new value. */
void setPause(const bool status);

double getTimeFraction();

private:
//! Time of the current simulation step.
double _simTime;
Expand All @@ -108,8 +108,6 @@ class TimeManager

osg::Timer _visualTimer;

//! Range of the slider widget.
int _sliderRange;
};


Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Animation/Visualizer.cpp
Expand Up @@ -216,9 +216,9 @@ VisualizerAbstract::VisualizerAbstract()
: _visType(VisType::NONE),
_baseData(nullptr),
_viewerStuff(nullptr),
_nodeUpdater(nullptr),
_timeManager(nullptr)
_nodeUpdater(nullptr)
{
_timeManager = new TimeManager(0.0, 0.0, 1.0, 0.0, 0.1, 0.0, 1.0);
}

VisualizerAbstract::VisualizerAbstract(const std::string& modelFile, const std::string& path, const VisType visType)
Expand Down
30 changes: 29 additions & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -238,8 +238,16 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, bool debug, QWidget *parent
mpAnimationWindowContainer = new AnimationWindowContainer(this);
renderTimer = new QTimer();
QObject::connect(renderTimer, SIGNAL(timeout()), mpAnimationWindowContainer, SLOT(renderSlotFunction()));
QObject::connect(renderTimer, SIGNAL(timeout()), this, SLOT(updateAnimationTimeContent()));
renderTimer->start(10);

// some widgets for the animation toolbar
mpAnimationSlider = new QSlider(Qt::Horizontal,this);
mpAnimationSlider->setFixedWidth(100);
mpAnimationSlider->setMinimum(0);
mpAnimationSlider->setMaximum(100);
mpAnimationSlider->setSliderPosition(50);
mpAnimationTimeLabel = new QLabel(this);
mpAnimationTimeLabel->setText(QString("Time [s]: ").append(QString::fromStdString("0.000")));
// Create an object of PlotWindowContainer
mpPlotWindowContainer = new PlotWindowContainer(this);
// create an object of VariablesWidget
Expand Down Expand Up @@ -3317,6 +3325,10 @@ void MainWindow::createToolbars()
mpAnimationToolBar->addAction(mpAnimationPlayAction);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addAction(mpAnimationPauseAction);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addWidget(mpAnimationSlider);
mpAnimationToolBar->addWidget(mpAnimationTimeLabel);
connect(mpAnimationSlider, SIGNAL(sliderMoved(int)),mpAnimationWindowContainer, SLOT(sliderSetTimeSlotFunction(int)));
}


Expand Down Expand Up @@ -3522,3 +3534,19 @@ void AboutOMEditWidget::keyPressEvent(QKeyEvent *pEvent)
}
QWidget::keyPressEvent(pEvent);
}


/*!
* \brief MainWindow::updateAnimationTimeContent
* Displays the animation in mpAnimationTimeLabel and moves mpAnimationSlider
* Hides the widget when ESC key is pressed.
* \param pEvent
*/
void MainWindow::updateAnimationTimeContent(){
double time = mpAnimationWindowContainer->getVisTime();
double timeFrac = mpAnimationWindowContainer->getTimeFraction();
double sliderPos = timeFrac*(mpAnimationSlider->maximum() - mpAnimationSlider->minimum());
//std::cout<<"time "<<time<<" timeFrac "<<timeFrac<<" sliderPos "<<sliderPos<<std::endl;
mpAnimationTimeLabel->setText(QString("Time [s]: ").append(QString::number(time)));
mpAnimationSlider->setSliderPosition(sliderPos);
}
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -372,6 +372,8 @@ class MainWindow : public QMainWindow
QToolBar *mpAnimationToolBar;
QHash<QString, TransformationsWidget*> mTransformationsWidgetHash;
QTimer *renderTimer;
QSlider *mpAnimationSlider;
QLabel * mpAnimationTimeLabel;
public slots:
void createNewModelicaClass();
void openModelicaFile();
Expand Down Expand Up @@ -437,6 +439,7 @@ public slots:
void updateModelSwitcherMenu(QMdiSubWindow *pSubWindow);
void toggleAutoSave();
void readInterfaceData(LibraryTreeItem *pLibraryTreeItem);
void updateAnimationTimeContent();
private slots:
void perspectiveTabChanged(int tabIndex);
void documentationDockWidgetVisibilityChanged(bool visible);
Expand Down

0 comments on commit 8707392

Please sign in to comment.