Skip to content

Commit

Permalink
- get osgviewer and widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich authored and adeas31 committed Sep 30, 2016
1 parent 795f673 commit 90e7bae
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 36 deletions.
118 changes: 90 additions & 28 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.cpp
Expand Up @@ -44,55 +44,117 @@
*/
AnimationWindowContainer::AnimationWindowContainer(MainWindow *pParent)
: MdiArea(pParent),
osgViewer::CompositeViewer()
osgViewer::CompositeViewer(),
_sceneView(new osgViewer::View()),
viewerWidget(nullptr),
topWidget(nullptr),
_playButton(nullptr),
_pauseButton(nullptr),
_initButton(nullptr),
_timeSlider(nullptr),
_timeDisplay(nullptr),
_RTFactorDisplay(nullptr)
{
if (mpMainWindow->getOptionsDialog()->getAnimationPage()->getAnimationViewMode().compare(Helper::subWindow) == 0) {
setViewMode(QMdiArea::SubWindowView);
} else {
setViewMode(QMdiArea::TabbedView);
}

//time slider
_timeSlider = new QSlider(Qt::Horizontal, this);
_timeSlider->setFixedHeight(30);
_timeSlider->setMinimum(0);
_timeSlider->setMaximum(100);
_timeSlider->setSliderPosition(50);

//osg::ref_ptr<osgQt::GraphicsWindowQt> window = createGraphicsWindow(0, 0, 100, 100);
_sceneView = new osgViewer::View();
osgViewer::CompositeViewer::addView(_sceneView);
osg::ref_ptr<osg::Camera> camera = _sceneView->getCamera();

osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits();


//the viewer widget
osg::ref_ptr<osg::Node> rootNode = osgDB::readNodeFile("D:/Programming/OPENMODELICA_GIT/OpenModelica/build/bin/dumptruck.osg");
setupViewWidget(rootNode);
topWidget = AnimationWindowContainer::setupAnimationWidgets();

// dont show this widget at startup
setVisible(false);
setVisible(true);
}

/*
osg::ref_ptr<osgQt::GraphicsWindowQt> AnimationWindowContainer::createGraphicsWindow(int x, int y, int w, int h,
const std::string& name, bool windowDecoration)
/*!
* \brief AnimationWindowContainer::setupViewWidget
* creates the widget for the osg viewer
* \return the widget
*/
void AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootNode)
{
//get context
osg::ref_ptr<osg::DisplaySettings> ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits();
traits->windowName = name;
traits->windowDecoration = windowDecoration;
traits->x = x;
traits->y = y;
traits->width = w;
traits->height = h;
traits->windowName = "";
traits->windowDecoration = false;
traits->x = 100;
traits->y = 100;
traits->width = 300;
traits->height = 500;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
osg::ref_ptr<osgQt::GraphicsWindowQt> gw = new osgQt::GraphicsWindowQt(traits.get(),this);

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

//get the viewer widget
osg::ref_ptr<osg::Camera> camera = _sceneView->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());
gw->setTouchEventsEnabled(true);
viewerWidget = gw->getGLWidget();
}


return new osgQt::GraphicsWindowQt(traits.get());
/*!
* \brief AnimationWindowContainer::setupAnimationWidgets
* creates the widgets for the animation
* \return void
*/
QWidget* AnimationWindowContainer::setupAnimationWidgets()
{
_timeSlider = new QSlider(Qt::Horizontal,this);
_timeSlider->setFixedHeight(30);
_timeSlider->setMinimum(0);
_timeSlider->setMaximum(100);
_timeSlider->setSliderPosition(50);
_playButton = new QPushButton("Play",this);
_pauseButton = new QPushButton("Pause",this);
_initButton = new QPushButton("Initialize",this);
_timeDisplay = new QLabel(this);
_timeDisplay->setText(QString("Time [s]: ").append(QString::fromStdString("0.000")));
_RTFactorDisplay = new QLabel(this);
_RTFactorDisplay->setText(QString("RT-Factor: ").append(QString::fromStdString("0.000")));

//make a row layout
QHBoxLayout* rowLayOut = new QHBoxLayout();
rowLayOut->addWidget(_initButton);
rowLayOut->addWidget(_playButton);
rowLayOut->addWidget(_pauseButton);
rowLayOut->addWidget(_timeSlider);
rowLayOut->addWidget(_RTFactorDisplay);
rowLayOut->addWidget(_timeDisplay);
QGroupBox* widgetRowBox = new QGroupBox(this);
widgetRowBox->setLayout(rowLayOut);
widgetRowBox->setFixedHeight(40);

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

// 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()));
return topWidget;
}
*/


/*!
* \brief AnimationWindowContainer::getUniqueName
Expand Down
23 changes: 18 additions & 5 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.h
Expand Up @@ -37,6 +37,8 @@

#include "MainWindow.h"

#include <iostream>

#include <osgViewer/CompositeViewer>
#include <osgViewer/View>
#include <osgDB/ReadFile>
Expand All @@ -47,8 +49,8 @@
#include <osg/MatrixTransform>
#include <osg/GraphicsContext>

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



Expand All @@ -60,11 +62,22 @@ class AnimationWindowContainer : public MdiArea, public osgViewer::CompositeView
public:
AnimationWindowContainer(MainWindow *pParent);
QString getUniqueName(QString name = QString("Animation"), int number = 4);
QSlider* _timeSlider;
//osg::ref_ptr<osgQt::GraphicsWindowQt> createGraphicsWindow(int x, int y, int w, int h, const std::string& name, bool windowDecoration)
QWidget* setupAnimationWidgets();
void setupViewWidget(osg::ref_ptr<osg::Node> rootNode);

//osg viewer
osgViewer::View* _sceneView;
osg::ref_ptr<osg::GraphicsContext::Traits> traits;
QWidget* viewerWidget;

//widgets
QWidget* topWidget;
QPushButton* _playButton;
QPushButton* _pauseButton;
QPushButton* _initButton;
QSlider* _timeSlider;
QLabel* _timeDisplay;
QLabel* _RTFactorDisplay;

};

#endif // ANIMATIONWINDOWCONTAINER_H
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/OMEditGUI.pro
Expand Up @@ -28,9 +28,9 @@
#
#/

QT += network core gui webkit xml xmlpatterns svg
QT += network core gui webkit xml xmlpatterns svg opengl
greaterThan(QT_MAJOR_VERSION, 4) {
QT += printsupport widgets webkitwidgets
QT += printsupport widgets webkitwidgets opengl
}

TRANSLATIONS = Resources/nls/OMEdit_de.ts \
Expand Down Expand Up @@ -82,7 +82,7 @@ win32 {
-L$$(OMBUILDDIR)/lib/omc -lomantlr3 -lOMPlot -lomqwt \
-lOpenModelicaCompiler -lOpenModelicaRuntimeC -lfmilib -lModelicaExternalC -lomcgc -lpthread \
-lws2_32 \
-L$$(OMDEV)/tools/msys/mingw32/lib -llibosg.dll -llibosgViewer.dll -llibosgQt.dll -llibOpenThreads.dll
-L$$(OMDEV)/tools/msys/mingw32/lib -llibosg.dll -llibosgViewer.dll -llibosgQt.dll -llibOpenThreads.dll -llibosgDB.dll -llibosgGA.dll
INCLUDEPATH += $$(OMBUILDDIR)/include/omplot \
$$(OMBUILDDIR)/include/omplot/qwt \
$$(OMBUILDDIR)/include/omc/antlr3 $$(OMBUILDDIR)/include/omc/c
Expand Down

0 comments on commit 90e7bae

Please sign in to comment.