Commit 4a509302 authored by cornimueller's avatar cornimueller
Browse files

[ADD] Each WGEViewer as a name, which can be used to identify them.

parent 44bba81c
......@@ -22,6 +22,7 @@
//
//---------------------------------------------------------------------------
#include <string>
#include <iostream>
#include <osg/ShapeDrawable>
......@@ -44,9 +45,11 @@
#include "WGEViewer.h"
WGEViewer::WGEViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height, WGECamera::ProjectionMode projectionMode ):
WGEGraphicsWindow( wdata, x, y, width, height ),
boost::enable_shared_from_this< WGEViewer >()
WGEViewer::WGEViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode )
: WGEGraphicsWindow( wdata, x, y, width, height ),
boost::enable_shared_from_this< WGEViewer >(),
m_name( name )
{
try
{
......@@ -145,4 +148,3 @@ void WGEViewer::close()
// forward close event
WGEGraphicsWindow::close();
}
......@@ -25,6 +25,8 @@
#ifndef WGEVIEWER_H
#define WGEVIEWER_H
#include <string>
#include <boost/shared_ptr.hpp>
#include <osg/Node>
......@@ -56,6 +58,7 @@ public:
/**
* Default constructor.
*
* \param name the name of the viewer
* \param wdata the WindowData instance for the widget to use as render widget
* \param x X coordinate of widget where to create the context.
* \param y Y coordinate of widget where to create the context.
......@@ -64,7 +67,7 @@ public:
* \param projectionMode Projection mode of the viewer.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
WGEViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height,
WGEViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height,
WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
/**
......@@ -134,6 +137,14 @@ public:
*/
osg::ref_ptr<osg::Node> getNode();
/**
* Returns the name of the viewer.
*/
std::string getName() const
{
return m_name;
}
protected:
/**
......@@ -141,6 +152,11 @@ protected:
*/
osg::ref_ptr< osgViewer::Viewer > m_View;
/**
* The name of the viewer.
*/
std::string m_name;
private:
};
......
......@@ -86,28 +86,35 @@ void WGraphicsEngine::setShaderPath( std::string path )
m_shaderPath = path;
}
boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer(
osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height, WGECamera::ProjectionMode projectionMode )
boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode )
{
// init the composite viewer if not already done
if ( m_Viewer == osg::ref_ptr< osgViewer::CompositeViewer >() )
{
}
boost::shared_ptr<WGEViewer> viewer = boost::shared_ptr<WGEViewer>( new WGEViewer( wdata, x, y, width, height, projectionMode ) );
boost::shared_ptr<WGEViewer> viewer = boost::shared_ptr<WGEViewer>(
new WGEViewer( name, wdata, x, y, width, height, projectionMode ) );
viewer->setScene( getScene() );
// finally add view
m_Viewer->addView( viewer->getViewer().get() );
// store it in viewer list
// XXX is this list needed? If yes, someone has to care about a deregisterViewer function
// boost::mutex::scoped_lock lock(m_ViewerLock);
//m_Viewers.push_back( viewer );
// TODO(cornimueller): someone has to care about a deregisterViewer function
boost::mutex::scoped_lock lock( m_ViewersLock );
assert( m_Viewers.insert( make_pair( name, viewer ) ).second == true );
m_ViewersLock.unlock();
return viewer;
}
boost::shared_ptr<WGEViewer> WGraphicsEngine::getViewerByName( std::string name )
{
return m_Viewers[name];
}
void WGraphicsEngine::threadMain()
{
WLogger::getLogger()->addLogMessage( "Starting Graphics Engine", "GE", LL_INFO );
......
......@@ -25,7 +25,7 @@
#ifndef WGRAPHICSENGINE_H
#define WGRAPHICSENGINE_H
#include <list>
#include <map>
#include <string>
......@@ -88,6 +88,7 @@ public:
/**
* Creates a new viewer. Does basic initialization and sets the default scene.
*
* \param name the name of the viewer
* \param wdata the WindowData instance for the widget to use as render widget
* \param x X coordinate of widget where to create the context.
* \param y Y coordinate of widget where to create the context.
......@@ -97,8 +98,13 @@ public:
* \return the new instance, ready to be used.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
boost::shared_ptr<WGEViewer> createViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height,
WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
boost::shared_ptr<WGEViewer> createViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
/**
* Searchs for a viewer with a given name and returns it, if found.
*/
boost::shared_ptr<WGEViewer> getViewerByName( std::string name );
protected:
......@@ -118,14 +124,14 @@ protected:
osg::ref_ptr<WGEScene> m_rootNode;
/**
* All registered viewer.
* All registered viewers.
*/
std::list<boost::shared_ptr<WGEViewer> > m_Viewers;
std::map< std::string, boost::shared_ptr< WGEViewer > > m_Viewers;
/**
* Mutex used to lock the list of viewers.
* Mutex used to lock the map of viewers.
*/
boost::mutex m_ViewerLock;
boost::mutex m_ViewersLock;
/**
* Path to the shaders.
......
......@@ -73,7 +73,7 @@ void WMainWindow::setupGUI()
m_centralwidget->setObjectName( QString::fromUtf8( "centralwidget" ) );
setCentralWidget( m_centralwidget );
m_mainGLWidget = boost::shared_ptr< WQtGLWidget >( new WQtGLWidget( this, WGECamera::ORTHOGRAPHIC ) );
m_mainGLWidget = boost::shared_ptr< WQtGLWidget >( new WQtGLWidget( "main", this, WGECamera::ORTHOGRAPHIC ) );
m_mainGLWidget->initialize();
setCentralWidget( m_mainGLWidget.get() );
......
......@@ -22,6 +22,7 @@
//
//---------------------------------------------------------------------------
#include <string>
#include <iostream>
#include <QtGui/QKeyEvent>
......@@ -34,8 +35,9 @@
#include "../../kernel/WKernel.h"
WQtGLWidget::WQtGLWidget( QWidget* parent, WGECamera::ProjectionMode projectionMode )
WQtGLWidget::WQtGLWidget( std::string nameOfViewer, QWidget* parent, WGECamera::ProjectionMode projectionMode )
: QGLWidget( parent ),
m_nameOfViewer( nameOfViewer ),
m_recommendedSize(),
m_isInitialized( new WConditionOneShot(), false )
{
......@@ -80,7 +82,8 @@ void WQtGLWidget::initialize()
#endif
// create viewer
m_Viewer = WKernel::getRunningKernel()->getGraphicsEngine()->createViewer( wdata, x(), y(), width(), height(), m_initialProjectionMode );
m_Viewer = WKernel::getRunningKernel()->getGraphicsEngine()->createViewer(
m_nameOfViewer, wdata, x(), y(), width(), height(), m_initialProjectionMode );
m_isInitialized( true );
}
......
......@@ -25,6 +25,7 @@
#ifndef WQTGLWIDGET_H
#define WQTGLWIDGET_H
#include <string>
#include <QtOpenGL/QGLWidget>
#include <QtGui/QWidget>
......@@ -47,12 +48,14 @@ public:
/**
* Default constructor.
*
* \param nameOfViewer Name of the Viewer
* \param parent Parent widget.
* \param projectionMode decides whether the widget uses perspective or othographic projection
*
* \return
*/
explicit WQtGLWidget( QWidget* parent = 0, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
explicit WQtGLWidget( std::string nameOfViewer, QWidget* parent = 0,
WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
/**
* Destructor.
......@@ -105,6 +108,11 @@ protected:
*/
boost::shared_ptr<WGEViewer> m_Viewer;
/**
* The name of the viewer.
*/
std::string m_nameOfViewer;
// The GraphincsWindowWin32 implementation already takes care of message handling.
// We don't want to relay these on Windows, it will just cause duplicate messages
// with further problems downstream (i.e. not being able to throw the trackball
......
......@@ -47,7 +47,7 @@ WQtNavGLWidget::WQtNavGLWidget( QString title, int maxValue, std::string sliderT
QVBoxLayout* layout = new QVBoxLayout();
m_glWidget = boost::shared_ptr<WQtGLWidget>( new WQtGLWidget( panel, WGECamera::ORTHOGRAPHIC ) );
m_glWidget = boost::shared_ptr<WQtGLWidget>( new WQtGLWidget( title.toStdString() , panel, WGECamera::ORTHOGRAPHIC ) );
layout->addWidget( m_glWidget.get() );
layout->addWidget( slider );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment