Commit c2cba989 authored by cornimueller's avatar cornimueller
Browse files

[ADD] Various changes for the EEG View module and CustomDockWidgets:

 * EEG View module is properly connected to EEG-Input and properties are handled (currenty only the "active"-property).
 * createCustomWidget stops to wait also on module-shutdown.
 * createCustomWidget returns created widget.
 * WQtCustomDockWidget sets its scene to a blank group node and offers a get-method for it.
 * There's no problem to try to create an already existing CustomWidget. The old one is returned and can be used.
 * Added getCustomDockWidget() method to WMainWindow.
 * Improved getViewerByName() method in WGraphicsEngine.
parent 0123a060
......@@ -133,7 +133,7 @@ boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer( std::string name, os
void WGraphicsEngine::closeViewer( const std::string name )
{
boost::mutex::scoped_lock lock( m_ViewersLock );
if (m_Viewers.count( name ) > 0 )
if( m_Viewers.count( name ) > 0 )
{
m_Viewers[name]->close();
......@@ -142,9 +142,14 @@ void WGraphicsEngine::closeViewer( const std::string name )
m_ViewersLock.unlock();
}
boost::shared_ptr<WGEViewer> WGraphicsEngine::getViewerByName( std::string name )
boost::shared_ptr< WGEViewer > WGraphicsEngine::getViewerByName( std::string name )
{
return m_Viewers[name];
boost::mutex::scoped_lock lock( m_ViewersLock );
boost::shared_ptr< WGEViewer > out = m_Viewers.count( name ) > 0 ?
m_Viewers[name] :
boost::shared_ptr< WGEViewer >();
m_ViewersLock.unlock();
return out;
}
void WGraphicsEngine::threadMain()
......
......@@ -98,7 +98,7 @@ 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( std::string name, osg::ref_ptr<WindowData> wdata, int x, int y,
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,
WColor bgColor = WColor( .9, .9, .9 ) );
......@@ -111,9 +111,11 @@ public:
/**
* Searches for a viewer with a given name and returns it, if found.
* \param name The name of the viewer
*
* \param name the name of the viewer
* \returns a shared pointer to the viewer or NULL if not found
*/
boost::shared_ptr<WGEViewer> getViewerByName( std::string name );
boost::shared_ptr< WGEViewer > getViewerByName( std::string name );
/**
* Returns the currently selected default font usable in osgText nodes.
......
......@@ -35,6 +35,7 @@
#include "../common/WFlag.h"
#include "../kernel/WModule.h"
#include "../graphicsEngine/WGECamera.h"
#include "WCustomWidget.h"
/**
......@@ -101,10 +102,13 @@ public:
/**
* Instruct the MainWindow to create a new custom widget.
*
* \param title The title of the widget
* \param projectionMode The kind of projection which should be used
* \param title the title of the widget
* \param projectionMode the kind of projection which should be used
* \param shutdownCondition condition to wait for the shutdown of a module
* \return the created widget
*/
virtual void createCustomWidget( std::string title, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC ) = 0;
virtual boost::shared_ptr< WCustomWidget > createCustomWidget( std::string title, WGECamera::ProjectionMode projectionMode,
boost::shared_ptr< WCondition > shutdownCondition ) = 0;
/**
* Instruct the MainWindow to close a custom widget.
......
......@@ -24,15 +24,14 @@
#include <string>
#include "../../common/WConditionOneShot.h"
#include "WCreateCustomDockWidgetEvent.h"
WCreateCustomDockWidgetEvent::WCreateCustomDockWidgetEvent(
std::string title, WGECamera::ProjectionMode projectionMode, boost::shared_ptr< WConditionOneShot > condition )
WCreateCustomDockWidgetEvent::WCreateCustomDockWidgetEvent( std::string title, WGECamera::ProjectionMode projectionMode,
boost::shared_ptr< WFlag< boost::shared_ptr< WCustomWidget > > > flag )
: QEvent( CUSTOM_TYPE ),
m_title( title ),
m_projectionMode( projectionMode ),
m_condition( condition )
m_flag( flag )
{
}
......@@ -46,7 +45,7 @@ WGECamera::ProjectionMode WCreateCustomDockWidgetEvent::getProjectionMode() cons
return m_projectionMode;
}
boost::shared_ptr< WConditionOneShot > WCreateCustomDockWidgetEvent::getCondition() const
boost::shared_ptr< WFlag< boost::shared_ptr< WCustomWidget > > > WCreateCustomDockWidgetEvent::getFlag() const
{
return m_condition;
return m_flag;
}
......@@ -29,7 +29,8 @@
#include <QtCore/QEvent>
#include "../../graphicsEngine/WGECamera.h"
#include "../../common/WConditionOneShot.h"
#include "../../common/WFlag.h"
#include "../WCustomWidget.h"
/**
* A Qt event to create a new custom dock widget if posted to the WMainWindow.
......@@ -38,14 +39,14 @@ class WCreateCustomDockWidgetEvent : public QEvent
{
public:
/**
* constructor
* Constructor
*
* \param title The title of the widget to create.
* \param projectionMode The kind of projection which should be used
* \param condition The condition which waits until the widget is created.
* \param title the title of the widget to create.
* \param projectionMode the kind of projection which should be used
* \param flag The WFlag which contains the widget after its creation.
*/
explicit WCreateCustomDockWidgetEvent(
std::string title, WGECamera::ProjectionMode projectionMode, boost::shared_ptr< WConditionOneShot > condition );
explicit WCreateCustomDockWidgetEvent( std::string title, WGECamera::ProjectionMode projectionMode,
boost::shared_ptr< WFlag< boost::shared_ptr< WCustomWidget > > > flag );
/**
* Get the title of the widget to create.
......@@ -62,11 +63,11 @@ public:
WGECamera::ProjectionMode getProjectionMode() const;
/**
* Get the condition which waits until the widget is created.
* Get the WFlag which contains the widget after its creation.
*
* \return a shared pointer to the condition
* \return a shared pointer to the WFlag
*/
boost::shared_ptr< WConditionOneShot > getCondition() const;
boost::shared_ptr< WFlag< boost::shared_ptr< WCustomWidget > > > getFlag() const;
/**
* Constant which saves the number used to distinguish this event from other
......@@ -87,9 +88,9 @@ private:
WGECamera::ProjectionMode m_projectionMode;
/**
* Condition which waits until the widget is created.
* WFlag which contains the widget after its creation.
*/
boost::shared_ptr< WConditionOneShot > m_condition;
boost::shared_ptr< WFlag< boost::shared_ptr< WCustomWidget > > > m_flag;
};
#endif // WCREATECUSTOMDOCKWIDGETEVENT_H
......@@ -292,16 +292,23 @@ void WMainWindow::customEvent( QEvent* event )
WCreateCustomDockWidgetEvent* ccdwEvent = static_cast< WCreateCustomDockWidgetEvent* >( event );
std::string title = ccdwEvent->getTitle();
boost::shared_ptr< WQtCustomDockWidget > widget = boost::shared_ptr< WQtCustomDockWidget >(
new WQtCustomDockWidget( title, this, ccdwEvent->getProjectionMode() ) );
addDockWidget( Qt::BottomDockWidgetArea, widget.get() );
// store it in CustomDockWidget list
boost::mutex::scoped_lock lock( m_customDockWidgetsLock );
assert( m_customDockWidgets.insert( make_pair( title, widget ) ).second == true );
m_customDockWidgetsLock.unlock();
if( m_customDockWidgets.count( title ) == 0 )
{
boost::shared_ptr< WQtCustomDockWidget > widget = boost::shared_ptr< WQtCustomDockWidget >(
new WQtCustomDockWidget( title, this, ccdwEvent->getProjectionMode() ) );
addDockWidget( Qt::BottomDockWidgetArea, widget.get() );
// store it in CustomDockWidget list
m_customDockWidgets.insert( make_pair( title, widget ) );
ccdwEvent->getCondition()->notify();
ccdwEvent->getFlag()->set( widget );
}
else
{
ccdwEvent->getFlag()->set( m_customDockWidgets[title] );
}
m_customDockWidgetsLock.unlock();
}
else
{
......@@ -310,10 +317,21 @@ void WMainWindow::customEvent( QEvent* event )
}
}
boost::shared_ptr< WQtCustomDockWidget > WMainWindow::getCustomDockWidget( std::string title )
{
boost::mutex::scoped_lock lock( m_customDockWidgetsLock );
boost::shared_ptr< WQtCustomDockWidget > out = m_customDockWidgets.count( title ) > 0 ?
m_customDockWidgets[title] :
boost::shared_ptr< WQtCustomDockWidget >();
m_customDockWidgetsLock.unlock();
return out;
}
void WMainWindow::closeCustomDockWidget( std::string title )
{
boost::mutex::scoped_lock lock( m_customDockWidgetsLock );
if (m_customDockWidgets.count( title ) > 0 )
if( m_customDockWidgets.count( title ) > 0 )
{
m_customDockWidgets[title]->close();
......
......@@ -122,6 +122,15 @@ public:
*/
boost::signals2::signal1< void, std::string >* getPickSignal();
/**
* Searches for a custom dock widget with a given name and returns it, if
* found.
*
* \param name the name of the widget
* \returns a shared pointer to the widget or NULL if not found
*/
boost::shared_ptr< WQtCustomDockWidget > getCustomDockWidget( std::string name );
/**
* Close one of the custom dock widget saved in the map of customDockWidgets
*
......
......@@ -227,11 +227,19 @@ boost::signals2::signal1< void, std::string >* WQt4Gui::getPickSignal()
return m_mainWindow->getPickSignal();
}
void WQt4Gui::createCustomWidget( std::string title, WGECamera::ProjectionMode projectionMode )
boost::shared_ptr< WCustomWidget > WQt4Gui::createCustomWidget( std::string title, WGECamera::ProjectionMode projectionMode,
boost::shared_ptr< WCondition > shutdownCondition )
{
boost::shared_ptr< WConditionOneShot > condition( new WConditionOneShot );
QCoreApplication::postEvent( m_mainWindow, new WCreateCustomDockWidgetEvent( title, projectionMode, condition ) );
condition->wait();
boost::shared_ptr< WFlag< boost::shared_ptr< WCustomWidget > > > widgetFlag(
new WFlag< boost::shared_ptr< WCustomWidget > >( new WConditionOneShot, boost::shared_ptr< WCustomWidget >() ) );
QCoreApplication::postEvent( m_mainWindow, new WCreateCustomDockWidgetEvent( title, projectionMode, widgetFlag ) );
WConditionSet conditionSet;
conditionSet.add( widgetFlag->getCondition() );
conditionSet.add( shutdownCondition );
conditionSet.wait();
return widgetFlag->get();
}
void WQt4Gui::closeCustomWidget( std::string title )
......
......@@ -100,10 +100,13 @@ public:
/**
* Instruct the WMainWindow to create a new custom widget.
*
* \param title The title of the widget
* \param projectionMode The kind of projection which should be used
* \param title the title of the widget
* \param projectionMode the kind of projection which should be used
* \param shutdownCondition condition to wait for the shutdown of a module
* \return the created widget
*/
virtual void createCustomWidget( std::string title, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
virtual boost::shared_ptr< WCustomWidget > createCustomWidget( std::string title, WGECamera::ProjectionMode projectionMode,
boost::shared_ptr< WCondition > shutdownCondition );
/**
* Instruct the WMainWindow to close a custom widget.
......
......@@ -24,9 +24,11 @@
#include <string>
#include "WQtCustomDockWidget.h"
#include <QtGui/QCloseEvent>
#include "WQtCustomDockWidget.h"
#include "../../graphicsEngine/WGEViewer.h"
WQtCustomDockWidget::WQtCustomDockWidget( std::string title, QWidget* parent, WGECamera::ProjectionMode projectionMode )
: QDockWidget( QString::fromStdString( title ), parent )
{
......@@ -35,10 +37,17 @@ WQtCustomDockWidget::WQtCustomDockWidget( std::string title, QWidget* parent, WG
m_glWidget = boost::shared_ptr< WQtGLWidget >( new WQtGLWidget( title, this, projectionMode ) );
m_glWidget->initialize();
m_scene = new osg::Group;
m_glWidget->getViewer()->setScene( m_scene );
setWidget( m_glWidget.get() );
}
osg::ref_ptr< osg::Group > WQtCustomDockWidget::getScene() const
{
return m_scene;
}
void WQtCustomDockWidget::closeEvent( QCloseEvent* event )
{
// forward events
......
......@@ -28,11 +28,13 @@
#include <string>
#include <QtGui/QDockWidget>
#include "WQtGLWidget.h"
#include "../WCustomWidget.h"
/**
* Dock Widget which is created by a module to display custom information.
*/
class WQtCustomDockWidget : public QDockWidget
class WQtCustomDockWidget : public QDockWidget,
public WCustomWidget
{
public:
/**
......@@ -44,6 +46,13 @@ public:
*/
WQtCustomDockWidget( std::string title, QWidget* parent, WGECamera::ProjectionMode projectionMode );
/**
* Get the scene which is displayed by the GL widget
*
* \return the scene as osg::ref_ptr
*/
virtual osg::ref_ptr< osg::Group > getScene() const;
protected:
/**
* Event handler for close events
......@@ -57,6 +66,11 @@ private:
* the included GL widget
*/
boost::shared_ptr<WQtGLWidget> m_glWidget;
/**
* the scene which is displayed by the GL widget
*/
osg::ref_ptr< osg::Group > m_scene;
};
#endif // WQTCUSTOMDOCKWIDGET_H
......@@ -143,6 +143,11 @@ WQtGLWidget::CameraManipulators WQtGLWidget::getCameraManipulators()
return m_CurrentManipulator;
}
boost::shared_ptr< WGEViewer > WQtGLWidget::getViewer() const
{
return m_Viewer;
}
void WQtGLWidget::paintEvent( QPaintEvent* /*event*/ )
{
// m_Viewer->paint();
......
......@@ -103,6 +103,13 @@ public:
*/
CameraManipulators getCameraManipulators();
/**
* Get the included viewer.
*
* \return a shared pointer to the viewer
*/
boost::shared_ptr< WGEViewer > getViewer() const;
/**
* Determines whether the widget is properly initialized.
*
......
......@@ -76,27 +76,71 @@ const std::string WMEEGView::getDescription() const
void WMEEGView::moduleMain()
{
// do initialization
WKernel::getRunningKernel()->getGui()->createCustomWidget( "EEG View", WGECamera::TWO_D );
boost::shared_ptr< WGEViewer > viewer = WGraphicsEngine::getGraphicsEngine()->getViewerByName( "EEG View" );
if( viewer.get() )
m_widget = WKernel::getRunningKernel()->getGui()->createCustomWidget(
"EEG View", WGECamera::TWO_D, m_shutdownFlag.getCondition() );
if( m_widget.get() )
{
infoLog() << "Successfully created EEG View widget.";
debugLog() << "Succesfully opened EEG View widget.";
m_node = createText();
m_widget->getScene()->addChild( m_node );
viewer->setScene( createText() );
// signal ready
ready();
waitForStop();
}
else
{
warnLog() << "Could not create EEG View widget.";
}
ready();
waitForStop();
WKernel::getRunningKernel()->getGui()->closeCustomWidget( "EEG View" );
// This should also delete the scene which was only referenced by this viewer.
}
void WMEEGView::connectors()
{
// initialize connectors
m_input = boost::shared_ptr< WModuleInputData< WEEG > >( new WModuleInputData< WEEG >(
shared_from_this(), "in", "Loaded EEG-dataset." ) );
// add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
addConnector( m_input );
// call WModules initialization
WModule::connectors();
}
void WMEEGView::properties()
{
// properties
m_properties->addBool( "active", true, true )->connect( boost::bind( &WMEEGView::slotPropertyChanged, this, _1 ) );
}
void WMEEGView::slotPropertyChanged( std::string propertyName )
{
if( propertyName == "active" )
{
if ( m_properties->getValue< bool >( propertyName ) )
{
if( !m_widget->getScene()->containsNode( m_node) )
{
m_widget->getScene()->addChild( m_node );
}
}
else
{
m_widget->getScene()->removeChild( m_node );
}
}
else
{
// instead of WLogger we must use std::cerr since WLogger needs to much time!
std::cerr << propertyName << std::endl;
assert( 0 && "This property name is not supported by this function yet." );
}
}
osg::Node* WMEEGView::createText()
{
osg::Geode* geode = new osg::Geode();
......
......@@ -27,6 +27,8 @@
#include <string>
#include "../../dataHandler/WEEG.h"
#include "../../kernel/WModuleInputData.h"
#include "../../kernel/WModule.h"
/**
......@@ -69,13 +71,45 @@ public:
*/
virtual const std::string getDescription() const;
/**
* Determine what to do if a property was changed.
* \param propertyName Name of the property.
*/
void slotPropertyChanged( std::string propertyName );
protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void moduleMain();
/**
* Initialize connectors in this function.
*/
virtual void connectors();
/**
* Initialize properties in this function.
*/
virtual void properties();
private:
/**
* Loaded EEG-Dataset
*/
boost::shared_ptr< WModuleInputData< WEEG > > m_input;
/**
* Custom widget which is used by this module to display its data.
*/
boost::shared_ptr< WCustomWidget > m_widget;
/**
* OSG node for this module. All other OSG nodes of this module should be
* placed as child to this node.
*/
osg::ref_ptr< osg::Node > m_node;
/**
* Sample HUD-Text. Copied from an OSG-Example
*
......
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