Commit 3cf6d77a authored by cornimueller's avatar cornimueller
Browse files

[ADD] Added ability to create a new dock widget with an OSG view from within a module

parent 763f1d86
......@@ -113,14 +113,14 @@ 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 )
{
m_Viewers[name]->close();
boost::mutex::scoped_lock lock( m_ViewersLock );
m_Viewers.erase( name );
m_ViewersLock.unlock();
}
m_ViewersLock.unlock();
}
boost::shared_ptr<WGEViewer> WGraphicsEngine::getViewerByName( std::string name )
......
......@@ -97,6 +97,20 @@ public:
*/
virtual boost::signals2::signal1< void, std::string >* getPickSignal() = 0;
/**
* Instruct the MainWindow to create a new custom widget.
*
* \param title The title of the widget
*/
virtual void createCustomWidget( std::string title ) = 0;
/**
* Instruct the MainWindow to close a custom widget.
*
* \param title The title of the widget
*/
virtual void closeCustomWidget( std::string title ) = 0;
protected:
/**
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include "WCreateCustomDockWidgetEvent.h"
WCreateCustomDockWidgetEvent::WCreateCustomDockWidgetEvent( std::string title )
: QEvent( CUSTOM_TYPE ),
m_title( title )
{
}
std::string WCreateCustomDockWidgetEvent::getTitle() const
{
return m_title;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WCREATECUSTOMDOCKWIDGETEVENT_H
#define WCREATECUSTOMDOCKWIDGETEVENT_H
#include <string>
#include <QtCore/QEvent>
/**
* A Qt event to create a new custom dock widget if posted to the WMainWindow.
*/
class WCreateCustomDockWidgetEvent : public QEvent
{
public:
/**
* constructor
*
* \param title The title of the widget to create.
*/
explicit WCreateCustomDockWidgetEvent( std::string title );
/**
* Get the title of the widget to create.
*
* \return title of the widget to create
*/
std::string getTitle() const;
/**
* Constant which saves the number used to distinguish this event from other
* custom events.
*/
static const QEvent::Type CUSTOM_TYPE = static_cast< QEvent::Type >( 51051 );
protected:
private:
/**
* the title of the widget to create
*/
std::string m_title;
};
#endif // WCREATECUSTOMDOCKWIDGETEVENT_H
......@@ -25,6 +25,7 @@
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <boost/thread.hpp>
......@@ -41,6 +42,8 @@
#include "../../kernel/WKernel.h"
#include "WQtNavGLWidget.h"
#include "WCreateCustomDockWidgetEvent.h"
#include "WQtCustomDockWidget.h"
#include "../icons/WIcons.h"
......@@ -245,6 +248,15 @@ void WMainWindow::closeEvent( QCloseEvent* e )
m_navCoronal->close();
m_navSagittal->close();
// delete CustomDockWidgets
boost::mutex::scoped_lock lock( m_customDockWidgetsLock );
for( std::map< std::string, boost::shared_ptr< WQtCustomDockWidget > >::iterator it = m_customDockWidgets.begin();
it != m_customDockWidgets.end(); ++it )
{
it->second->close();
}
m_customDockWidgetsLock.unlock();
// finally close
e->accept();
}
......@@ -254,6 +266,41 @@ void WMainWindow::closeEvent( QCloseEvent* e )
}
}
void WMainWindow::customEvent( QEvent* event )
{
if( event->type() == WCreateCustomDockWidgetEvent::CUSTOM_TYPE )
{
// CreateCustomDockWidgetEvent
WCreateCustomDockWidgetEvent* ccdwEvent = static_cast< WCreateCustomDockWidgetEvent* >( event );
std::string title = ccdwEvent->getTitle();
boost::shared_ptr< WQtCustomDockWidget > widget = boost::shared_ptr< WQtCustomDockWidget >( new WQtCustomDockWidget( title, this ) );
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();
}
else
{
// other event
QMainWindow::customEvent( event );
}
}
void WMainWindow::closeCustomDockWidget( std::string title )
{
boost::mutex::scoped_lock lock( m_customDockWidgetsLock );
if (m_customDockWidgets.count( title ) > 0 )
{
m_customDockWidgets[title]->close();
m_customDockWidgets.erase( title );
}
m_customDockWidgetsLock.unlock();
}
void WMainWindow::slotActivateModule( QString module )
{
// TODO(schurade): do we really need the signal? Why can't we use the kernel directly?
......
......@@ -28,6 +28,7 @@
#include <list>
#include <string>
#include <vector>
#include <map>
#include <boost/shared_ptr.hpp>
#include <boost/program_options.hpp>
......@@ -41,6 +42,7 @@
#include "WQtNavGLWidget.h"
#include "ribbonMenu/WQtRibbonMenu.h"
#include "WQtCustomDockWidget.h"
#include "WIconManager.h"
#include "WPropertyManager.h"
......@@ -111,6 +113,13 @@ public:
*/
boost::signals2::signal1< void, std::string >* getPickSignal();
/**
* Close one of the custom dock widget saved in the map of customDockWidgets
*
* \param title the title of the widget to close
*/
void closeCustomDockWidget( std::string title );
protected:
/**
......@@ -120,6 +129,14 @@ protected:
*/
void closeEvent( QCloseEvent* e );
/**
* Handle custom events.
* Currently only WCreateCustomDockWidgetEvent.
*
* \param event the custom event
*/
virtual void customEvent( QEvent* event );
public slots:
/**
* gets called when menu option or toolbar button load is activated
......@@ -149,6 +166,16 @@ private:
boost::shared_ptr< WQtNavGLWidget > m_navCoronal; //!< the coronal view widget GL widget of the GUI
boost::shared_ptr< WQtNavGLWidget > m_navSagittal; //!< the sgittal view widget GL widget of the GUI
/**
* All registered WQtCustomDockWidgets.
*/
std::map< std::string, boost::shared_ptr< WQtCustomDockWidget > > m_customDockWidgets;
/**
* Mutex used to lock the map of WQtCustomDockWidgets.
*/
boost::mutex m_customDockWidgetsLock;
boost::signals2::signal1< void, std::vector< std::string > > m_loaderSignal;
boost::signals2::signal2< void, boost::shared_ptr< WModule >, boost::shared_ptr< WModule > > m_moduleButtonSignal;
......
......@@ -39,6 +39,7 @@
#include "../../modules/data/WMData.h"
#include "WQt4Gui.h"
#include "WCreateCustomDockWidgetEvent.h"
WQt4Gui::WQt4Gui( int argc, char** argv ):
WGUI( argc, argv )
......@@ -215,3 +216,12 @@ boost::signals2::signal1< void, std::string >* WQt4Gui::getPickSignal()
return m_gui->getPickSignal();
}
void WQt4Gui::createCustomWidget( std::string title )
{
QCoreApplication::postEvent( m_gui, new WCreateCustomDockWidgetEvent( title ) );
}
void WQt4Gui::closeCustomWidget( std::string title )
{
m_gui->closeCustomDockWidget( title );
}
......@@ -97,6 +97,21 @@ public:
boost::signals2::signal1< void, std::string >* getPickSignal();
/**
* Instruct the WMainWindow to create a new custom widget.
*
* \param title The title of the widget
*/
virtual void createCustomWidget( std::string title );
/**
* Instruct the WMainWindow to close a custom widget.
*
* \param title The title of the widget
*/
virtual void closeCustomWidget( std::string title );
protected:
private:
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include "WQtCustomDockWidget.h"
#include <QtGui/QCloseEvent>
WQtCustomDockWidget::WQtCustomDockWidget( std::string title, QWidget* parent )
: QDockWidget( QString::fromStdString( title ), parent )
{
// setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
m_glWidget = boost::shared_ptr< WQtGLWidget >( new WQtGLWidget( title, this, WGECamera::PERSPECTIVE ) );
m_glWidget->initialize();
setWidget( m_glWidget.get() );
}
void WQtCustomDockWidget::closeEvent( QCloseEvent* event )
{
// forward events
m_glWidget->close();
event->accept();
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WQTCUSTOMDOCKWIDGET_H
#define WQTCUSTOMDOCKWIDGET_H
#include <string>
#include <QtGui/QDockWidget>
#include "WQtGLWidget.h"
/**
* Dock Widget which is created by a module to display custom information.
*/
class WQtCustomDockWidget : public QDockWidget
{
public:
/**
* constructor
*
* \param title the title of the widget
* \param parent the parent of the widget
*/
WQtCustomDockWidget( std::string title, QWidget* parent );
protected:
/**
* Event handler for close events
*
* \param event the event description.
*/
virtual void closeEvent( QCloseEvent* event );
private:
/**
* the included GL widget
*/
boost::shared_ptr<WQtGLWidget> m_glWidget;
};
#endif // WQTCUSTOMDOCKWIDGET_H
......@@ -40,6 +40,7 @@
#include "../modules/eegTest/WMEEGTest.h"
#include "../modules/textureList/WMTextureList.h"
#include "../modules/hud/WMHud.h"
#include "../modules/eegView/WMEEGView.h"
#include "exceptions/WPrototypeUnknown.h"
#include "exceptions/WPrototypeNotUnique.h"
......@@ -79,6 +80,7 @@ void WModuleFactory::load()
m_prototypes.insert( boost::shared_ptr< WModule >( new WMDistanceMap() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMTextureList() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMHud() ) );
m_prototypes.insert( boost::shared_ptr< WModule >( new WMEEGView() ) );
lock.unlock();
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include "WMEEGView.h"
#include "../../kernel/WKernel.h"
WMEEGView::WMEEGView()
: WModule()
{
}
WMEEGView::~WMEEGView()
{
}
boost::shared_ptr< WModule > WMEEGView::factory() const
{
return boost::shared_ptr< WModule >( new WMEEGView() );
}
const std::string WMEEGView::getName() const
{
return "EEG View";
}
const std::string WMEEGView::getDescription() const
{
return "Test module to open an EEG View.";
}
void WMEEGView::moduleMain()
{
// do initialization
//std::cout << "Load EEG View module\n";
WKernel::getRunningKernel()->getGui()->createCustomWidget( "EEG View" );
ready();
waitForStop();
WKernel::getRunningKernel()->getGui()->closeCustomWidget( "EEG View" );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WMEEGVIEW_H
#define WMEEGVIEW_H
#include <string>
#include "../../kernel/WModule.h"
/**
* Test module to open a new widget and display EEG data
*/
class WMEEGView: public WModule
{
public:
/**
* default constructor
*/
WMEEGView();
/**
* destructor
*/
virtual ~WMEEGView();
/**
* Due to the prototype design pattern used to build modules, this method
* returns a new instance of this method.
* NOTE: it should never be initialized or modified in some other way. A
* simple new instance is required.
*
* \return the prototype used to create every module in OpenWalnut.
*/
virtual boost::shared_ptr< WModule > factory() const;
/**
* Gets the name of this module.
*
* \return the name.
*/
virtual const std::string getName() const;
/**
* Gets the description for this module.
*
* \return the description
*/
virtual const std::string getDescription() const;
protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void moduleMain();
private:
};
#endif // WMEEGVIEW_H
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