Skip to content

Commit

Permalink
- at least something works now
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich committed Sep 1, 2016
1 parent 0cd7cf5 commit c47ebfd
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 113 deletions.
161 changes: 110 additions & 51 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.cpp
Expand Up @@ -45,30 +45,91 @@ const double HEIGHT_CONTROLWIDGETS = 40;
* \brief AnimationWindowContainer::AnimationWindowContainer
* \param pParent
*/
AnimationWindowContainer::AnimationWindowContainer(MainWindow *pParent)
: QWidget(pParent),
AnimationWindowContainer::AnimationWindowContainer(QWidget *pParent)
: QMainWindow(pParent),
osgViewer::CompositeViewer(),
_pathName(""),
_fileName(""),
_sceneView(new osgViewer::View()),
_visualizer(nullptr),
_viewerWidget(nullptr),
_updateTimer(new QTimer())
mPathName(""),
mFileName(""),
mpSceneView(new osgViewer::View()),
mpVisualizer(nullptr),
mpViewerWidget(nullptr),
mpUpdateTimer(new QTimer()),
mpAnimationToolBar(new QToolBar(QString("Animation Toolbar"),this)),
mpAnimationChooseFileAction(nullptr),
mpAnimationInitializeAction(nullptr),
mpAnimationPlayAction(nullptr),
mpAnimationPauseAction(nullptr)
{
setThreadingModel(osgViewer::CompositeViewer::SingleThreaded);
//the viewer widget
osg::ref_ptr<osg::Node> rootNode = osgDB::readRefNodeFile("D:/Programming/OPENMODELICA_GIT/OpenModelica/build/bin/dumptruck.osg");
_viewerWidget = setupViewWidget(rootNode);
_viewerWidget->setParent(this);
_viewerWidget->setWindowFlags(Qt::SubWindow);
//_viewerWidget->setWindowState(Qt::WindowMaximized);
mpViewerWidget = setupViewWidget(rootNode);

//mpViewerWidget->setParent(this);
//mpViewerWidget->setWindowFlags(Qt::SubWindow);
//mpViewerWidget->setWindowState(Qt::WindowMaximized);
mpViewerWidget->setBaseSize(QSize(2000,1000));
//mpViewerWidget->move(100,100);
// do a scene update at every tick
QObject::connect(_updateTimer, SIGNAL(timeout()), this, SLOT(updateSceneFunction()));
_updateTimer->start(100);
}
QObject::connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(updateSceneFunction()));
QObject::connect(mpUpdateTimer, SIGNAL(timeout()), this, SLOT(renderSlotFunction()));
mpUpdateTimer->start(100);

// animation action
mpAnimationChooseFileAction = new QAction(QIcon(":/Resources/icons/openFile.png"), Helper::animationChooseFile, this);
mpAnimationChooseFileAction->setStatusTip(Helper::animationChooseFileTip);
mpAnimationChooseFileAction->setEnabled(true);
mpAnimationInitializeAction = new QAction(QIcon(":/Resources/icons/initialize.png"), Helper::animationInitialize, this);
mpAnimationInitializeAction->setStatusTip(Helper::animationInitializeTip);
mpAnimationInitializeAction->setEnabled(true);
mpAnimationPlayAction = new QAction(QIcon(":/Resources/icons/play.png"), Helper::animationPlay, this);
mpAnimationPlayAction->setStatusTip(Helper::animationPlayTip);
mpAnimationPlayAction->setEnabled(true);
mpAnimationPauseAction = new QAction(QIcon(":/Resources/icons/pause.png"), Helper::animationPause, this);
mpAnimationPauseAction->setStatusTip(Helper::animationPauseTip);
mpAnimationPauseAction->setEnabled(true);

mpAnimationSlider = new QSlider(Qt::Horizontal);
//mpAnimationSlider->setFixedWidth(200);
mpAnimationSlider->setMinimum(0);
mpAnimationSlider->setMaximum(100);
mpAnimationSlider->setSliderPosition(50);
mpAnimationTimeLabel = new QLabel();
mpAnimationTimeLabel->setText(QString(" Time [s]: ").append(QString::fromStdString("0.000")));

mpAnimationToolBar->addAction(mpAnimationChooseFileAction);
mpAnimationToolBar->addSeparator();
mpAnimationToolBar->addAction(mpAnimationInitializeAction);
mpAnimationToolBar->addSeparator();
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)));
addToolBar(Qt::TopToolBarArea,mpAnimationToolBar);



//QVBoxLayout* mainLayout = new QVBoxLayout();
//mainLayout->addWidget(mpViewerWidget);
//QWidget* topWidget = new QWidget();
//topWidget->setLayout(mainLayout);
mpViewerWidget->setParent(this);//important!!

//mpViewerWidget->setParent(topWidget);//kein Einfluss

//setCentralWidget(topWidget); //kein Einfluss

connect(mpAnimationChooseFileAction, SIGNAL(triggered()),this, SLOT(chooseAnimationFileSlotFunction()));
connect(mpAnimationInitializeAction, SIGNAL(triggered()),this, SLOT(initSlotFunction()));
connect(mpAnimationPlayAction, SIGNAL(triggered()),this, SLOT(playSlotFunction()));
connect(mpAnimationPauseAction, SIGNAL(triggered()),this, SLOT(pauseSlotFunction()));



}
/*!
* \brief AnimationWindowContainer::setupViewWidget
* creates the widget for the osg viewer
Expand All @@ -94,17 +155,17 @@ QWidget* AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootN
osg::ref_ptr<osgQt::GraphicsWindowQt> gw = new osgQt::GraphicsWindowQt(traits.get());

//add a scene to viewer
addView(_sceneView);
addView(mpSceneView);

//get the viewer widget
osg::ref_ptr<osg::Camera> camera = _sceneView->getCamera();
osg::ref_ptr<osg::Camera> camera = mpSceneView->getCamera();
camera->setGraphicsContext(gw);
camera->setClearColor(osg::Vec4(0.2, 0.2, 0.6, 1.0));
camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
camera->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(traits->width) / static_cast<double>(traits->height), 1.0f, 10000.0f);
_sceneView->setSceneData(rootNode);
_sceneView->addEventHandler(new osgViewer::StatsHandler());
_sceneView->setCameraManipulator(new osgGA::MultiTouchTrackballManipulator());
camera->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(traits->width/2) / static_cast<double>(traits->height/2), 1.0f, 10000.0f);
mpSceneView->setSceneData(rootNode);
mpSceneView->addEventHandler(new osgViewer::StatsHandler());
mpSceneView->setCameraManipulator(new osgGA::MultiTouchTrackballManipulator());
gw->setTouchEventsEnabled(true);
return gw->getGLWidget();
}
Expand All @@ -117,32 +178,32 @@ void AnimationWindowContainer::loadVisualization(){
VisType visType = VisType::NONE;

// Get visualization type.
if (isFMU(_fileName))
if (isFMU(mFileName))
visType = VisType::FMU;
else if (isMAT(_fileName))
else if (isMAT(mFileName))
visType = VisType::MAT;
else
std::cout<<"unknown visualization type. "<<std::endl;

//init visualizer
if (visType == VisType::MAT){
_visualizer = new VisualizerMAT(_fileName, _pathName);
mpVisualizer = new VisualizerMAT(mFileName, mPathName);
}
else{
std::cout<<"could not init "<<_pathName<<_fileName<<std::endl;
std::cout<<"could not init "<<mPathName<<mFileName<<std::endl;
}

//load the XML File, build osgTree, get initial values for the shapes
bool xmlExists = checkForXMLFile(_fileName, _pathName);
bool xmlExists = checkForXMLFile(mFileName, mPathName);
if (!xmlExists){
std::cout<<"Could not find the visual XML file "<<assembleXMLFileName(_fileName, _pathName)<<std::endl;
std::cout<<"Could not find the visual XML file "<<assembleXMLFileName(mFileName, mPathName)<<std::endl;
}
_visualizer->initData();
_visualizer->setUpScene();
_visualizer->initVisualization();
mpVisualizer->initData();
mpVisualizer->setUpScene();
mpVisualizer->initVisualization();

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


Expand All @@ -155,9 +216,9 @@ void AnimationWindowContainer::chooseAnimationFileSlotFunction(){
std::string file = dialog.getOpenFileName(this,tr("Open Visualiation File"), "./", tr("Visualization MAT(*.mat)")).toStdString();
if (file.compare("")){
std::size_t pos = file.find_last_of("/\\");
_pathName = file.substr(0, pos + 1);
_fileName = file.substr(pos + 1, file.length());
//std::cout<<"file "<<_fileName<<" path "<<_pathName<<std::endl;
mPathName = file.substr(0, pos + 1);
mFileName = file.substr(pos + 1, file.length());
//std::cout<<"file "<<mFileName<<" path "<<mPathName<<std::endl;
loadVisualization();
}
else
Expand All @@ -170,27 +231,27 @@ void AnimationWindowContainer::chooseAnimationFileSlotFunction(){
* overwrite show method to explicitly show the viewer as well
*/
void AnimationWindowContainer::showWidgets(){
_viewerWidget->show();
mpViewerWidget->show();
show();
}

double AnimationWindowContainer::getTimeFraction(){
if (_visualizer==NULL)
if (mpVisualizer==NULL)
return 0.0;
else
return _visualizer->getTimeManager()->getTimeFraction();
return mpVisualizer->getTimeManager()->getTimeFraction();
}

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


Expand All @@ -199,23 +260,23 @@ void AnimationWindowContainer::sliderSetTimeSlotFunction(int value){
* slot function for the play button
*/
void AnimationWindowContainer::playSlotFunction(){
_visualizer->getTimeManager()->setPause(false);
mpVisualizer->getTimeManager()->setPause(false);
}

/*!
* \brief AnimationWindowContainer::pauseSlotFunction
* slot function for the pause button
*/
void AnimationWindowContainer::pauseSlotFunction(){
_visualizer->getTimeManager()->setPause(true);
mpVisualizer->getTimeManager()->setPause(true);
}

/*!
* \brief AnimationWindowContainer::initSlotFunction
* slot function for the init button
*/
void AnimationWindowContainer::initSlotFunction(){
_visualizer->initVisualization();
mpVisualizer->initVisualization();

}

Expand All @@ -224,8 +285,8 @@ void AnimationWindowContainer::initSlotFunction(){
* updates the visualization objects
*/
void AnimationWindowContainer::updateSceneFunction(){
if (!(_visualizer==NULL))
_visualizer->sceneUpdate();
if (!(mpVisualizer==NULL))
mpVisualizer->sceneUpdate();
}

/*!
Expand All @@ -234,6 +295,7 @@ void AnimationWindowContainer::updateSceneFunction(){
*/
void AnimationWindowContainer::renderSlotFunction()
{
std::cout<<"render"<<std::endl;
frame();
}

Expand All @@ -242,12 +304,9 @@ void AnimationWindowContainer::renderSlotFunction()
* returns the current visualization time
*/
double AnimationWindowContainer::getVisTime(){
if (_visualizer==NULL)
if (mpVisualizer==NULL)
return -1.0;
else
return _visualizer->getTimeManager()->getVisTime();
return mpVisualizer->getTimeManager()->getVisTime();
}




31 changes: 22 additions & 9 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.h
Expand Up @@ -37,6 +37,7 @@

#include "AnimationUtil.h"
#include "MainWindow.h"
#include "OMPlot.h"
#include "Visualizer.h"
#include "VisualizerMAT.h"

Expand All @@ -55,14 +56,13 @@
#include <osgViewer/ViewerEventHandlers>



class MainWindow;

class AnimationWindowContainer : public QWidget, public osgViewer::CompositeViewer
class AnimationWindowContainer : public QMainWindow, public osgViewer::CompositeViewer
{
Q_OBJECT
public:
AnimationWindowContainer(MainWindow *pParent);
AnimationWindowContainer(QWidget *pParent);
QWidget* setupViewWidget(osg::ref_ptr<osg::Node> rootNode);
void showWidgets();
void loadVisualization();
Expand All @@ -79,15 +79,28 @@ class AnimationWindowContainer : public QWidget, public osgViewer::CompositeView
void updateSceneFunction();
private:
//to be animated
std::string _pathName;
std::string _fileName;
std::string mPathName;
std::string mFileName;
//osg viewer scene
osgViewer::View* _sceneView;
osgViewer::View* mpSceneView;
//stores the data for the shapes, time management, functionality for updating the values(mat/fmu) etc.
VisualizerAbstract* _visualizer;
VisualizerAbstract* mpVisualizer;
//widgets
QWidget* _viewerWidget;
QTimer* _updateTimer;
QWidget* mpViewerWidget;
QTimer* mpUpdateTimer;
QToolBar* mpAnimationToolBar;
QWidget* topWidget;
QSlider* mpAnimationSlider;
QLabel *mpAnimationTimeLabel;
//actions
QVBoxLayout* mainLayout;
QHBoxLayout* buttonsLayout;
QVBoxLayout* mainRowLayout;

QAction *mpAnimationChooseFileAction;
QAction *mpAnimationInitializeAction;
QAction *mpAnimationPlayAction;
QAction *mpAnimationPauseAction;
};

#endif // ANIMATIONWINDOWCONTAINER_H
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Animation/VisualizerMAT.cpp
Expand Up @@ -86,7 +86,7 @@ void VisualizerMAT::readMat(const std::string& modelFile, const std::string& pat

void VisualizerMAT::updateVisAttributes(const double time)
{
//std::cout<<"updateVisAttributes at "<<time <<std::endl;
std::cout<<"updateVisAttributes at "<<time <<std::endl;
// Update all shapes.
unsigned int shapeIdx = 0;
rAndT rT;
Expand Down

0 comments on commit c47ebfd

Please sign in to comment.