Skip to content

Commit

Permalink
- get a proper viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich authored and adeas31 committed Sep 30, 2016
1 parent 90e7bae commit 361ec40
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 66 deletions.
100 changes: 55 additions & 45 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.cpp
Expand Up @@ -43,39 +43,40 @@
* \param pParent
*/
AnimationWindowContainer::AnimationWindowContainer(MainWindow *pParent)
: MdiArea(pParent),
: QWidget(pParent),
osgViewer::CompositeViewer(),
_sceneView(new osgViewer::View()),
viewerWidget(nullptr),
topWidget(nullptr),
_visFileButton(nullptr),
_playButton(nullptr),
_pauseButton(nullptr),
_initButton(nullptr),
_timeSlider(nullptr),
_timeDisplay(nullptr),
_RTFactorDisplay(nullptr)
_RTFactorDisplay(nullptr),
_renderTimer()
{
if (mpMainWindow->getOptionsDialog()->getAnimationPage()->getAnimationViewMode().compare(Helper::subWindow) == 0) {
setViewMode(QMdiArea::SubWindowView);
} else {
setViewMode(QMdiArea::TabbedView);
}

setThreadingModel(osgViewer::CompositeViewer::SingleThreaded);
//the viewer widget
osg::ref_ptr<osg::Node> rootNode = osgDB::readNodeFile("D:/Programming/OPENMODELICA_GIT/OpenModelica/build/bin/dumptruck.osg");
setupViewWidget(rootNode);
osg::ref_ptr<osg::Node> rootNode = osgDB::readRefNodeFile("D:/Programming/OPENMODELICA_GIT/OpenModelica/build/bin/dumptruck.osg");
viewerWidget = setupViewWidget(rootNode);
//the control widgets
topWidget = AnimationWindowContainer::setupAnimationWidgets();
}

// dont show this widget at startup
setVisible(true);
void AnimationWindowContainer::renderSlotFunction()
{
//update();
frame();
}

/*!
* \brief AnimationWindowContainer::setupViewWidget
* creates the widget for the osg viewer
* \return the widget
*/
void AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootNode)
QWidget* AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootNode)
{
//get context
osg::ref_ptr<osg::DisplaySettings> ds = osg::DisplaySettings::instance().get();
Expand All @@ -85,7 +86,7 @@ void AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootNode)
traits->x = 100;
traits->y = 100;
traits->width = 300;
traits->height = 500;
traits->height = 300;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
Expand All @@ -94,19 +95,20 @@ void AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootNode)
osg::ref_ptr<osgQt::GraphicsWindowQt> gw = new osgQt::GraphicsWindowQt(traits.get(),this);

//add a scene to viewer
osgViewer::CompositeViewer::addView(_sceneView);
addView(_sceneView);

//get the viewer widget
osg::ref_ptr<osg::Camera> camera = _sceneView->getCamera();
camera->setGraphicsContext(gw);
const osg::GraphicsContext::Traits* traits2 = gw->getTraits();
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);
camera->setViewport(new osg::Viewport(0, 0, traits2->width, traits2->height));
camera->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(traits2->width) / static_cast<double>(traits2->height), 1.0f, 10000.0f);
_sceneView->setSceneData(rootNode);
_sceneView->addEventHandler(new osgViewer::StatsHandler());
_sceneView->setCameraManipulator(new osgGA::MultiTouchTrackballManipulator());
gw->setTouchEventsEnabled(true);
viewerWidget = gw->getGLWidget();
return gw->getGLWidget();
}


Expand All @@ -117,11 +119,13 @@ void AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootNode)
*/
QWidget* AnimationWindowContainer::setupAnimationWidgets()
{
// control widgets
_timeSlider = new QSlider(Qt::Horizontal,this);
_timeSlider->setFixedHeight(30);
_timeSlider->setMinimum(0);
_timeSlider->setMaximum(100);
_timeSlider->setSliderPosition(50);
_visFileButton = new QPushButton("Choose File",this);
_playButton = new QPushButton("Play",this);
_pauseButton = new QPushButton("Pause",this);
_initButton = new QPushButton("Initialize",this);
Expand All @@ -130,8 +134,9 @@ QWidget* AnimationWindowContainer::setupAnimationWidgets()
_RTFactorDisplay = new QLabel(this);
_RTFactorDisplay->setText(QString("RT-Factor: ").append(QString::fromStdString("0.000")));

//make a row layout
//layout for all control widgets
QHBoxLayout* rowLayOut = new QHBoxLayout();
rowLayOut->addWidget(_visFileButton);
rowLayOut->addWidget(_initButton);
rowLayOut->addWidget(_playButton);
rowLayOut->addWidget(_pauseButton);
Expand All @@ -143,40 +148,45 @@ QWidget* AnimationWindowContainer::setupAnimationWidgets()
widgetRowBox->setFixedHeight(40);

topWidget = new QWidget(this);
QVBoxLayout* mainRowLayout = new QVBoxLayout(this);
//mainRowLayout->addWidget(viewerWidget);
mainRowLayout->addWidget(widgetRowBox);
topWidget->setLayout(mainRowLayout);
QVBoxLayout* mainVLayout = new QVBoxLayout(this);
//mainVLayout->addWidget(viewerWidget);
mainVLayout->addWidget(widgetRowBox);
topWidget->setLayout(mainVLayout);

// Connect the buttons to the corresponding slot functions.
//QObject::connect(playButton, SIGNAL(clicked()), this, SLOT(playSlotFunction()));
//QObject::connect(pauseButton, SIGNAL(clicked()), this, SLOT(pauseSlotFunction()));
//QObject::connect(initButton, SIGNAL(clicked()), this, SLOT(initSlotFunction()));
QObject::connect(_visFileButton, SIGNAL(clicked()), this, SLOT(animationFileSlotFunction()));
QObject::connect(_playButton, SIGNAL(clicked()), this, SLOT(playSlotFunction()));
QObject::connect(_pauseButton, SIGNAL(clicked()), this, SLOT(pauseSlotFunction()));
QObject::connect(_initButton, SIGNAL(clicked()), this, SLOT(initSlotFunction()));
return topWidget;
}


/*!
* \brief AnimationWindowContainer::getUniqueName
* Returns a unique name for new animation window.
* \param name
* \param number
* \return
*/
QString AnimationWindowContainer::getUniqueName(QString name, int number)
{
QString newName;
newName = name + QString::number(number);

foreach (QMdiSubWindow *pWindow, subWindowList()) {
if (pWindow->widget()->windowTitle().compare(newName) == 0) {
newName = getUniqueName(name, ++number);
break;
}
}
return newName;
void AnimationWindowContainer::showWidgets(){
viewerWidget->show();
show();
}


void AnimationWindowContainer::playSlotFunction(){
std::cout<<"playSlotFunction "<<std::endl;
}

void AnimationWindowContainer::pauseSlotFunction(){
std::cout<<"pauseSlotFunction "<<std::endl;
}

void AnimationWindowContainer::initSlotFunction(){
std::cout<<"initSlotFunction "<<std::endl;
}

void AnimationWindowContainer::animationFileSlotFunction(){
std::cout<<"animationFileSlotFunction "<<std::endl;
QFileDialog dialog(this);
QString fileName = dialog.getOpenFileName(this,tr("Open Visualiation File"), "./", tr("Visualization Files (*.mat *.fmu)"));
}





47 changes: 27 additions & 20 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.h
Expand Up @@ -49,35 +49,42 @@
#include <osg/MatrixTransform>
#include <osg/GraphicsContext>

//#include <QtOpenGL/QGLWidget>
#include <osgQt/GraphicsWindowQt>

#include <string>


class MainWindow;

class AnimationWindowContainer : public MdiArea, public osgViewer::CompositeViewer
class AnimationWindowContainer : public QWidget, public osgViewer::CompositeViewer
{
Q_OBJECT
public:
AnimationWindowContainer(MainWindow *pParent);
QString getUniqueName(QString name = QString("Animation"), int number = 4);
QWidget* setupAnimationWidgets();
void setupViewWidget(osg::ref_ptr<osg::Node> rootNode);

//osg viewer
osgViewer::View* _sceneView;
QWidget* viewerWidget;
public:
AnimationWindowContainer(MainWindow *pParent);
QWidget* setupAnimationWidgets();
QWidget* setupViewWidget(osg::ref_ptr<osg::Node> rootNode);
void showWidgets();

//widgets
QWidget* topWidget;
QPushButton* _playButton;
QPushButton* _pauseButton;
QPushButton* _initButton;
QSlider* _timeSlider;
QLabel* _timeDisplay;
QLabel* _RTFactorDisplay;
public slots:
void playSlotFunction();
void pauseSlotFunction();
void initSlotFunction();
void renderSlotFunction();
void animationFileSlotFunction();

private:
//osg viewer
osgViewer::View* _sceneView;
//widgets
QWidget* viewerWidget;
QWidget* topWidget;
QPushButton* _visFileButton;
QPushButton* _playButton;
QPushButton* _pauseButton;
QPushButton* _initButton;
QSlider* _timeSlider;
QLabel* _timeDisplay;
QLabel* _RTFactorDisplay;
QTimer _renderTimer;
};

#endif // ANIMATIONWINDOWCONTAINER_H
8 changes: 7 additions & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -220,8 +220,12 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, bool debug, QWidget *parent
addDockWidget(Qt::RightDockWidgetArea, mpDocumentationDockWidget);
mpDocumentationDockWidget->hide();
connect(mpDocumentationDockWidget, SIGNAL(visibilityChanged(bool)), SLOT(documentationDockWidgetVisibilityChanged(bool)));
// Create an object of AnimationWindowContainer
// Create an object of AnimationWindowContainer and render it periodically
mpAnimationWindowContainer = new AnimationWindowContainer(this);
renderTimer = new QTimer();
QObject::connect(renderTimer, SIGNAL(timeout()), mpAnimationWindowContainer, SLOT(renderSlotFunction()));
renderTimer->start(10);

// Create an object of PlotWindowContainer
mpPlotWindowContainer = new PlotWindowContainer(this);
// create an object of VariablesWidget
Expand Down Expand Up @@ -3074,6 +3078,8 @@ void MainWindow::switchToAnimationPerspective()
{
storePlotWindowsStateAndGeometry();
mpCentralStackedWidget->setCurrentWidget(mpAnimationWindowContainer);
mpAnimationWindowContainer->showWidgets();
//mpAnimationWindowContainer->viewerWidget->show();
}

/*!
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -363,6 +363,7 @@ class MainWindow : public QMainWindow
QToolBar *mpPlotToolBar;
QToolBar *mpTLMSimulationToolbar;
QHash<QString, TransformationsWidget*> mTransformationsWidgetHash;
QTimer *renderTimer;
public slots:
void createNewModelicaClass();
void openModelicaFile();
Expand Down

0 comments on commit 361ec40

Please sign in to comment.