Skip to content

Commit

Permalink
- add an animation toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich authored and adeas31 committed Sep 30, 2016
1 parent 527c264 commit 535913b
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 3 deletions.
27 changes: 27 additions & 0 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.cpp
Expand Up @@ -158,6 +158,7 @@ QWidget* AnimationWindowContainer::setupAnimationWidgets()

// Connect the buttons to the corresponding slot functions.
QObject::connect(_visFileButton, SIGNAL(clicked()), this, SLOT(chooseAnimationFileSlotFunction()));
QObject::connect(_timeSlider, SIGNAL(sliderMoved(int)), this, SLOT(sliderSetTimeSlotFunction(int)));
QObject::connect(_playButton, SIGNAL(clicked()), this, SLOT(playSlotFunction()));
QObject::connect(_pauseButton, SIGNAL(clicked()), this, SLOT(pauseSlotFunction()));
QObject::connect(_initButton, SIGNAL(clicked()), this, SLOT(initSlotFunction()));
Expand Down Expand Up @@ -203,6 +204,8 @@ void AnimationWindowContainer::loadVisualization(){
std::cout<<"start timer"<<std::endl;
_updateTimer = new QTimer();
QObject::connect(_updateTimer, SIGNAL(timeout()), this, SLOT(updateSceneFunction()));
QObject::connect(_updateTimer, SIGNAL(timeout()), this, SLOT(moveTimeSliderSlotFunction()));

_updateTimer->start(100);
}

Expand Down Expand Up @@ -236,6 +239,30 @@ 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());
}

/*!
* \brief AnimationWindowContainer::sliderSetTimeSlotFunction
* slot function for the time slider
*/
void AnimationWindowContainer::sliderSetTimeSlotFunction(int value){
int time = (_visualizer->getTimeManager()->getEndTime()
- _visualizer->getTimeManager()->getStartTime())
* (float) (value / 100.0);
std::cout<<"moveSliderSlotFunction "<<time<<std::endl;
_visualizer->getTimeManager()->setVisTime(time);
_visualizer->sceneUpdate();
}


/*!
* \brief AnimationWindowContainer::playSlotFunction
* slot function for the play button
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.h
Expand Up @@ -67,6 +67,8 @@ class AnimationWindowContainer : public QWidget, public osgViewer::CompositeView
void showWidgets();
void loadVisualization();
public slots:
void sliderSetTimeSlotFunction(int value);
void moveTimeSliderSlotFunction();
void playSlotFunction();
void pauseSlotFunction();
void initSlotFunction();
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Animation/Visualizer.cpp
Expand Up @@ -437,7 +437,7 @@ void VisualizerMAT::updateVisAttributes(const double time)
shape._T[6].exp, shape._T[7].exp, shape._T[8].exp),
osg::Vec3f(shape._lDir[0].exp, shape._lDir[1].exp, shape._lDir[2].exp),
osg::Vec3f(shape._wDir[0].exp, shape._wDir[1].exp, shape._wDir[2].exp),
shape._length.exp, shape._width.exp, shape._height.exp, shape._type);
shape._length.exp,/* shape._width.exp, shape._height.exp,*/ shape._type);

assemblePokeMatrix(shape._mat, rT._T, rT._r);
// Update the shapes.
Expand Down Expand Up @@ -796,7 +796,7 @@ void assemblePokeMatrix(osg::Matrix& M, const osg::Matrix3& T, const osg::Vec3f&
}


rAndT rotateModelica2OSG(osg::Vec3f r, osg::Vec3f r_shape, osg::Matrix3 T, osg::Vec3f lDirIn, osg::Vec3f wDirIn, float length, float width, float height, std::string type)
rAndT rotateModelica2OSG(osg::Vec3f r, osg::Vec3f r_shape, osg::Matrix3 T, osg::Vec3f lDirIn, osg::Vec3f wDirIn, float length,/* float width, float height,*/ std::string type)
{
rAndT res;

Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Animation/Visualizer.h
Expand Up @@ -209,7 +209,7 @@ osg::Vec3f normalize(osg::Vec3f vec);
osg::Vec3f cross(osg::Vec3f vec1, osg::Vec3f vec2);
Directions fixDirections(osg::Vec3f lDir, osg::Vec3f wDir);
void assemblePokeMatrix(osg::Matrix& M, const osg::Matrix3& T, const osg::Vec3f& r);
rAndT rotateModelica2OSG(osg::Vec3f r, osg::Vec3f r_shape, osg::Matrix3 T, osg::Vec3f lDirIn, osg::Vec3f wDirIn, float length, float width, float height, std::string type);
rAndT rotateModelica2OSG(osg::Vec3f r, osg::Vec3f r_shape, osg::Matrix3 T, osg::Vec3f lDirIn, osg::Vec3f wDirIn, float length,/* float width, float height,*/ std::string type);


#endif
42 changes: 42 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -2706,6 +2706,23 @@ void MainWindow::createActions()
mpTLMCoSimulationAction->setStatusTip(Helper::tlmCoSimulationSetupTip);
mpTLMCoSimulationAction->setEnabled(false);
connect(mpTLMCoSimulationAction, SIGNAL(triggered()), SLOT(TLMSimulate()));
// animation action
mpAnimationChooseFileAction = new QAction(QIcon(":/Resources/icons/tlm-simulate.svg"), Helper::animationChooseFile, this);
mpAnimationChooseFileAction->setStatusTip(Helper::animationChooseFileTip);
mpAnimationChooseFileAction->setEnabled(true);
mpAnimationInitializeAction = new QAction(QIcon(":/Resources/icons/tlm-simulate.svg"), Helper::animationInitialize, this);
mpAnimationInitializeAction->setStatusTip(Helper::animationInitializeTip);
mpAnimationInitializeAction->setEnabled(true);
mpAnimationPlayAction = new QAction(QIcon(":/Resources/icons/tlm-simulate.svg"), Helper::animationPlay, this);
mpAnimationPlayAction->setStatusTip(Helper::animationPlayTip);
mpAnimationPlayAction->setEnabled(true);
mpAnimationPauseAction = new QAction(QIcon(":/Resources/icons/tlm-simulate.svg"), Helper::animationPause, this);
mpAnimationPauseAction->setStatusTip(Helper::animationPauseTip);
mpAnimationPauseAction->setEnabled(true);
connect(mpAnimationChooseFileAction, SIGNAL(triggered()),mpAnimationWindowContainer, SLOT(chooseAnimationFileSlotFunction()));
connect(mpAnimationInitializeAction, SIGNAL(triggered()),mpAnimationWindowContainer, SLOT(initSlotFunction()));
connect(mpAnimationPlayAction, SIGNAL(triggered()),mpAnimationWindowContainer, SLOT(playSlotFunction()));
connect(mpAnimationPauseAction, SIGNAL(triggered()),mpAnimationWindowContainer, SLOT(pauseSlotFunction()));
}

//! Creates the menus
Expand Down Expand Up @@ -2967,6 +2984,8 @@ void MainWindow::switchToWelcomePerspective()
mpTargetOutputDockWidget->hide();
mpGDBLoggerDockWidget->hide();
mpPlotToolBar->setEnabled(false);
mpAnimationToolBar->setEnabled(false);

}

/*!
Expand All @@ -2981,6 +3000,8 @@ void MainWindow::switchToModelingPerspective()
mpModelWidgetContainer->currentModelWidgetChanged(mpModelWidgetContainer->getCurrentMdiSubWindow());
mpVariablesDockWidget->hide();
mpPlotToolBar->setEnabled(false);
mpAnimationToolBar->setEnabled(false);

// In case user has tabbed the dock widgets then make LibraryWidget active.
QList<QDockWidget*> tabifiedDockWidgetsList = tabifiedDockWidgets(mpLibraryDockWidget);
if (tabifiedDockWidgetsList.size() > 0) {
Expand Down Expand Up @@ -3025,6 +3046,7 @@ void MainWindow::switchToPlottingPerspective()
mpModelWidgetContainer->currentModelWidgetChanged(0);
mpUndoAction->setEnabled(false);
mpRedoAction->setEnabled(false);
mpAnimationToolBar->setEnabled(false);
mpModelSwitcherToolButton->setEnabled(false);
// if not plotwindow is opened then open one for user
if (mpPlotWindowContainer->subWindowList().size() == 0) {
Expand Down Expand Up @@ -3057,6 +3079,7 @@ void MainWindow::switchToAlgorithmicDebuggingPerspective()
mpModelWidgetContainer->currentModelWidgetChanged(mpModelWidgetContainer->getCurrentMdiSubWindow());
mpVariablesDockWidget->hide();
mpPlotToolBar->setEnabled(false);
mpAnimationToolBar->setEnabled(false);
// In case user has tabbed the dock widgets then make LibraryWidget active.
QList<QDockWidget*> tabifiedDockWidgetsList = tabifiedDockWidgets(mpLibraryDockWidget);
if (tabifiedDockWidgetsList.size() > 0) {
Expand All @@ -3079,6 +3102,12 @@ void MainWindow::switchToAnimationPerspective()
storePlotWindowsStateAndGeometry();
mpCentralStackedWidget->setCurrentWidget(mpAnimationWindowContainer);
mpAnimationWindowContainer->showWidgets();
mpAnimationToolBar->setEnabled(true);

mpPlotToolBar->setEnabled(false);
mpUndoAction->setEnabled(false);
mpRedoAction->setEnabled(false);
mpModelSwitcherToolButton->setEnabled(false);
mpVariablesDockWidget->hide();
mpStackFramesDockWidget->hide();
mpBreakpointsDockWidget->hide();
Expand Down Expand Up @@ -3260,8 +3289,21 @@ void MainWindow::createToolbars()
mpTLMSimulationToolbar->addAction(mpAlignInterfacesAction);
mpTLMSimulationToolbar->addSeparator();
mpTLMSimulationToolbar->addAction(mpTLMCoSimulationAction);
// Animation Toolbar
mpAnimationToolBar = addToolBar(tr("Animation Toolbar"));
mpAnimationToolBar->setObjectName("Animation Toolbar");
mpAnimationToolBar->setAllowedAreas(Qt::TopToolBarArea);
// add actions to TLM Simulation Toolbar
mpAnimationToolBar->addAction(mpAnimationChooseFileAction);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addAction(mpAnimationInitializeAction);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addAction(mpAnimationPlayAction);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addAction(mpAnimationPauseAction);
}


//! when the dragged object enters the main window
//! @param event contains information of the drag operation.
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
Expand Down
6 changes: 6 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -349,6 +349,11 @@ class MainWindow : public QMainWindow
QAction *mpFetchInterfaceDataAction;
QAction *mpAlignInterfacesAction;
QAction *mpTLMCoSimulationAction;
// Animation Action
QAction* mpAnimationChooseFileAction;
QAction* mpAnimationInitializeAction;
QAction* mpAnimationPlayAction;
QAction* mpAnimationPauseAction;
// Toolbars
QMenu *mpRecentFilesMenu;
QMenu *mpLibrariesMenu;
Expand All @@ -362,6 +367,7 @@ class MainWindow : public QMainWindow
QMenu *mpModelSwitcherMenu;
QToolBar *mpPlotToolBar;
QToolBar *mpTLMSimulationToolbar;
QToolBar *mpAnimationToolBar;
QHash<QString, TransformationsWidget*> mTransformationsWidgetHash;
QTimer *renderTimer;
public slots:
Expand Down
16 changes: 16 additions & 0 deletions OMEdit/OMEditGUI/Util/Helper.cpp
Expand Up @@ -302,6 +302,14 @@ QString Helper::alignInterfacesTip;
QString Helper::tlmCoSimulationSetup;
QString Helper::tlmCoSimulationSetupTip;
QString Helper::tlmCoSimulation;
QString Helper::animationChooseFile;
QString Helper::animationChooseFileTip;
QString Helper::animationInitialize;
QString Helper::animationInitializeTip;
QString Helper::animationPlay;
QString Helper::animationPlayTip;
QString Helper::animationPause;
QString Helper::animationPauseTip;
QString Helper::simulationParams;
QString Helper::simulationParamsTip;
QString Helper::running;
Expand Down Expand Up @@ -515,6 +523,14 @@ void Helper::initHelperVariables()
Helper::tlmCoSimulationSetup = tr("TLM Co-Simulation Setup");
Helper::tlmCoSimulationSetupTip = tr("Opens the TLM co-simulation setup");
Helper::tlmCoSimulation = tr("TLM Co-Simulation");
Helper::animationChooseFile = tr("Animation File");
Helper::animationChooseFileTip = tr("Open an animation.");
Helper::animationInitialize = tr("Initialize");
Helper::animationInitializeTip = tr("Initialize the animation scene");
Helper::animationPlay = tr("Play");
Helper::animationPlayTip = tr("Play the animation");
Helper::animationPause = tr("Pause");
Helper::animationPauseTip = tr("Pause the animation");
Helper::simulationParams = tr("Simulation Parameters");
Helper::simulationParamsTip = tr("Shows the Simulation Parameters dialog");
Helper::running = tr("Running");
Expand Down
8 changes: 8 additions & 0 deletions OMEdit/OMEditGUI/Util/Helper.h
Expand Up @@ -308,6 +308,14 @@ class Helper : public QObject
static QString tlmCoSimulationSetup;
static QString tlmCoSimulationSetupTip;
static QString tlmCoSimulation;
static QString animationChooseFile;
static QString animationChooseFileTip;
static QString animationInitialize;
static QString animationInitializeTip;
static QString animationPlay;
static QString animationPlayTip;
static QString animationPause;
static QString animationPauseTip;
static QString simulationParams;
static QString simulationParamsTip;
static QString running;
Expand Down

0 comments on commit 535913b

Please sign in to comment.