Skip to content

Commit

Permalink
- somehow integrated the viewer in the animationwidget
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich committed Aug 25, 2016
1 parent f1fb176 commit 2665e73
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
37 changes: 24 additions & 13 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.cpp
Expand Up @@ -35,6 +35,8 @@
#include "AnimationWindowContainer.h"


const double HEIGHT_CONTROLWIDGETS = 40;

/*!
\class AnimationWindowContainer
\brief A MDI area for animation windows.
Expand Down Expand Up @@ -65,6 +67,9 @@ AnimationWindowContainer::AnimationWindowContainer(MainWindow *pParent)
//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);
//the control widgets
_topWidget = AnimationWindowContainer::setupAnimationWidgets();
}
Expand All @@ -82,27 +87,27 @@ QWidget* AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootN
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits();
traits->windowName = "";
traits->windowDecoration = false;
traits->x = 100;
traits->y = 100;
traits->width = 300;
traits->height = 300;
traits->x = 0;
traits->y = 0;

traits->width = this->parentWidget()->width();
traits->height = this->parentWidget()->height();
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);
osg::ref_ptr<osgQt::GraphicsWindowQt> gw = new osgQt::GraphicsWindowQt(traits.get());

//add a scene to viewer
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, traits2->width, traits2->height));
camera->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(traits2->width) / static_cast<double>(traits2->height), 1.0f, 10000.0f);
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());
Expand Down Expand Up @@ -141,13 +146,13 @@ QWidget* AnimationWindowContainer::setupAnimationWidgets()
rowLayOut->addWidget(_timeSlider);
rowLayOut->addWidget(_RTFactorDisplay);
rowLayOut->addWidget(_timeDisplay);
QGroupBox* widgetRowBox = new QGroupBox(this);
QGroupBox* widgetRowBox = new QGroupBox();
widgetRowBox->setLayout(rowLayOut);
widgetRowBox->setFixedHeight(40);
widgetRowBox->setFixedHeight(HEIGHT_CONTROLWIDGETS);

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

Expand Down Expand Up @@ -209,12 +214,16 @@ void AnimationWindowContainer::loadVisualization(){
void AnimationWindowContainer::chooseAnimationFileSlotFunction(){
std::cout<<"animationFileSlotFunction "<<std::endl;
QFileDialog dialog(this);
std::string file = dialog.getOpenFileName(this,tr("Open Visualiation File"), "./", tr("Visualization FMU(*.fmu);; Visualization MAT(*.mat)")).toStdString();;
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;
loadVisualization();
}
else
std::cout<<"No Visualization selected!"<<std::endl;

}

Expand Down Expand Up @@ -251,6 +260,8 @@ void AnimationWindowContainer::pauseSlotFunction(){
*/
void AnimationWindowContainer::initSlotFunction(){
std::cout<<"initSlotFunction "<<std::endl;
_visualizer->initVisualization();

}

/*!
Expand Down
20 changes: 3 additions & 17 deletions OMEdit/OMEditGUI/Animation/Visualizer.cpp
Expand Up @@ -99,7 +99,7 @@ void OMVisualBase::initVisObjects()
}
else
{
std::cout<<"shape._id "<<shape._id;
//std::cout<<"shape._id "<<shape._id;

shape._type = std::string(expNode->value());

Expand Down Expand Up @@ -391,12 +391,10 @@ void VisualizerMAT::updateVisAttributes(const double time)

for (auto& shape : _baseData->_shapes)
{
std::cout<<"shape "<<shape._id <<std::endl;
//std::cout<<"shape "<<shape._id <<std::endl;

// Get the values for the scene graph objects
updateObjectAttributeMAT(&shape._length, time, tmpReaderPtr);
std::cout<<"shape "<<shape._id <<" done"<<std::endl;

updateObjectAttributeMAT(&shape._width, time, tmpReaderPtr);
updateObjectAttributeMAT(&shape._height, time, tmpReaderPtr);

Expand Down Expand Up @@ -431,7 +429,6 @@ void VisualizerMAT::updateVisAttributes(const double time)
updateObjectAttributeMAT(&shape._color[2], time, tmpReaderPtr);

updateObjectAttributeMAT(&shape._specCoeff, time, tmpReaderPtr);
std::cout<<"shape "<<shape._id <<" done2"<<std::endl;

rT = rotateModelica2OSG(osg::Vec3f(shape._r[0].exp, shape._r[1].exp, shape._r[2].exp),
osg::Vec3f(shape._rShape[0].exp, shape._rShape[1].exp, shape._rShape[2].exp),
Expand All @@ -441,26 +438,15 @@ void VisualizerMAT::updateVisAttributes(const double time)
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);
std::cout<<"shape "<<shape._id <<" done3"<<std::endl;

assemblePokeMatrix(shape._mat, rT._T, rT._r);
std::cout<<"shape "<<shape._id <<" done4"<<std::endl;

// Update the shapes.
_nodeUpdater->_shape = shape;
//shape.dumpVisAttributes();
std::cout<<"shape "<<shape._id <<" done5"<<std::endl;

// Get the scene graph nodes and stuff.
child = _viewerStuff->getScene().getRootNode()->getChild(shapeIdx); // the transformation
std::cout<<"shape "<<shape._id <<" done6"<<std::endl;

child->accept(*_nodeUpdater);
std::cout<<"shape "<<shape._id <<" done7"<<std::endl;

++shapeIdx;
std::cout<<"shape "<<shape._id <<" done8"<<std::endl;

}
}
catch (std::exception& ex)
Expand Down Expand Up @@ -497,7 +483,7 @@ double VisualizerMAT::omcGetVarValue(ModelicaMatReader* reader, const char* varN
ModelicaMatVariable_t* var = nullptr;
var = omc_matlab4_find_var(reader, varName);
if (var == nullptr)
std::cout<<"Did not get variable from result file. Variable name is "<<std::endl;
std::cout<<"Did not get variable from result file. Variable name is "<<std::string(varName)<<std::endl;
else
omc_matlab4_val(&val, reader, var, time);

Expand Down
10 changes: 8 additions & 2 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -157,7 +157,7 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, bool debug, QWidget *parent
connect(pAlgorithmicDebuggingShortcut, SIGNAL(activated()), SLOT(switchToAlgorithmicDebuggingPerspectiveSlot()));
mpPerspectiveTabbar->setTabToolTip(3, tr("Changes to debugging perspective (%1)").arg(pAlgorithmicDebuggingShortcut->key().toString()));
// 3d animation perspective
mpPerspectiveTabbar->addTab(QIcon(":/Resources/icons/debugger.svg"), tr("Animation"));
mpPerspectiveTabbar->addTab(QIcon(":/Resources/icons/animation.png"), tr("Animation"));
QShortcut *pAnimationShortcut = new QShortcut(QKeySequence("Ctrl+f6"), this);
connect(pAnimationShortcut, SIGNAL(activated()), SLOT(switchToAnimationPerspectiveSlot()));
mpPerspectiveTabbar->setTabToolTip(4, tr("Changes to animation perspective (%1)").arg(pAnimationShortcut->key().toString()));
Expand Down Expand Up @@ -3095,7 +3095,13 @@ void MainWindow::switchToAnimationPerspective()
storePlotWindowsStateAndGeometry();
mpCentralStackedWidget->setCurrentWidget(mpAnimationWindowContainer);
mpAnimationWindowContainer->showWidgets();
//mpAnimationWindowContainer->viewerWidget->show();
mpVariablesDockWidget->hide();
mpStackFramesDockWidget->hide();
mpBreakpointsDockWidget->hide();
mpLocalsDockWidget->hide();
mpTargetOutputDockWidget->hide();
mpGDBLoggerDockWidget->hide();
mpWelcomePageWidget->hide();
}

/*!
Expand Down

0 comments on commit 2665e73

Please sign in to comment.