Commit 375cefc6 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD] - implemented auto display feature. This adds a default display module...

[ADD] - implemented auto display feature. This adds a default display module to a dataset after it got loaded. It can be disabled by the useAutoDisplay preference in walnut.cfg.
parent 4b3603e8
...@@ -14,6 +14,7 @@ default="Coordinate System Module,HUD,Navigation Slice Module" ...@@ -14,6 +14,7 @@ default="Coordinate System Module,HUD,Navigation Slice Module"
# hideSagittal = yes # hide the sagittal view widget # hideSagittal = yes # hide the sagittal view widget
# toolBarIconText = no # show text next to module's icon # toolBarIconText = no # show text next to module's icon
# useToolBarBreak = no # put compatibles toolbar in separate row # useToolBarBreak = no # put compatibles toolbar in separate row
# useAutoDisplay = no # automatically add a standard module after loading a data module.
[ge] # Settings for the graphics engine [ge] # Settings for the graphics engine
# bgColor.r = .9 # background color (red part) # bgColor.r = .9 # background color (red part)
......
...@@ -61,9 +61,22 @@ public: ...@@ -61,9 +61,22 @@ public:
*/ */
virtual const std::string getDescription() const = 0; virtual const std::string getDescription() const = 0;
/**
* Checks whether the actual prototype has the specified runtime type.
*
* \return true if you can safely cast this instance to the specified type.
*/
template < typename T > bool isA();
protected: protected:
private: private:
}; };
template < typename T >
bool WPrototyped::isA()
{
return dynamic_cast< T* >( this );
}
#endif // WPROTOTYPED_H #endif // WPROTOTYPED_H
...@@ -51,6 +51,11 @@ ...@@ -51,6 +51,11 @@
#include "../../common/WColor.h" #include "../../common/WColor.h"
#include "../../common/WPreferences.h" #include "../../common/WPreferences.h"
#include "../../kernel/WKernel.h" #include "../../kernel/WKernel.h"
#include "../../modules/data/WMData.h"
#include "../../dataHandler/WEEG.h"
#include "../../dataHandler/WDataSetSingle.h"
#include "../../dataHandler/WDataSetFibers.h"
#include "../../graphicsEngine/WROIBox.h" #include "../../graphicsEngine/WROIBox.h"
...@@ -182,8 +187,55 @@ void WMainWindow::setupPermanentToolBar() ...@@ -182,8 +187,55 @@ void WMainWindow::setupPermanentToolBar()
addToolBar( Qt::TopToolBarArea, m_permanentToolBar ); addToolBar( Qt::TopToolBarArea, m_permanentToolBar );
} }
void WMainWindow::autoAdd( boost::shared_ptr< WModule > module, std::string proto )
{
// get the prototype.
if ( !WKernel::getRunningKernel()->getRootContainer()->applyModule( module, proto, true ) )
{
WLogger::getLogger()->addLogMessage( "Auto Display active but module " + proto + " could not be added.",
"GUI", LL_ERROR );
}
}
void WMainWindow::moduleSpecificSetup( boost::shared_ptr< WModule > module ) void WMainWindow::moduleSpecificSetup( boost::shared_ptr< WModule > module )
{ {
// Add all special handlings here. This method is called whenever a module is marked "ready". You can set up the gui for special modules,
// load certain modules for datasets and so on.
// The Data Modules also play an special role. To have modules being activated when certain data got loaded, we need to hook it up here.
bool useAutoDisplay = true;
WPreferences::getPreference( "qt4gui.useAutoDisplay", &useAutoDisplay );
if ( useAutoDisplay && module->getType() == MODULE_DATA )
{
WLogger::getLogger()->addLogMessage( "Auto Display active and Data module added. The proper module will be added.",
"GUI", LL_DEBUG );
// data modules contain an member denoting the real data type. Currently we only have one data module and a not very modulated data
// structures.
boost::shared_ptr< WMData > dataModule = boost::shared_static_cast< WMData >( module );
// grab data and identify type
if ( dataModule->getDataSet()->isA< WDataSetSingle >() )
{
// it is a dataset single
// load a nav slice module if a WDataSetSingle is available!?
WLogger::getLogger()->addLogMessage( "Data module added. Implement this method to have Navigation slices added automatically.",
"GUI", LL_INFO );
//autoAdd( module, "Direct Volume endering" );
}
else if ( dataModule->getDataSet()->isA< WDataSetFibers >() )
{
// it is a fiber dataset -> add the FiberDisplay module
autoAdd( module, "Fiber Display" );
}
else if ( dataModule->getDataSet()->isA< WEEG >() )
{
// it is a eeg dataset -> add the eegView module?
autoAdd( module, "EEG View" );
}
}
// nav slices use separate buttons for slice on/off switching // nav slices use separate buttons for slice on/off switching
if ( module->getName() == "Navigation Slice Module" ) if ( module->getName() == "Navigation Slice Module" )
{ {
......
...@@ -225,6 +225,14 @@ private: ...@@ -225,6 +225,14 @@ private:
* boost signal object * boost signal object
*/ */
boost::signals2::signal2< void, boost::shared_ptr< WModule >, boost::shared_ptr< WModule > > m_moduleButtonSignal; boost::signals2::signal2< void, boost::shared_ptr< WModule >, boost::shared_ptr< WModule > > m_moduleButtonSignal;
/**
* Combine a module with a prototype only if the module is available. Else, nothing happens.
*
* \param module the module to be combined.
* \param proto the prototype to combine with the module.
*/
void autoAdd( boost::shared_ptr< WModule > module, std::string proto );
}; };
#endif // WMAINWINDOW_H #endif // WMAINWINDOW_H
...@@ -274,9 +274,24 @@ void WModuleContainer::addDefaultNotifier( MODULE_SIGNAL signal, t_ModuleErrorSi ...@@ -274,9 +274,24 @@ void WModuleContainer::addDefaultNotifier( MODULE_SIGNAL signal, t_ModuleErrorSi
} }
} }
boost::shared_ptr< WModule > WModuleContainer::applyModule( boost::shared_ptr< WModule > applyOn, std::string what ) boost::shared_ptr< WModule > WModuleContainer::applyModule( boost::shared_ptr< WModule > applyOn, std::string what, bool tryOnly )
{ {
return applyModule( applyOn, WModuleFactory::getModuleFactory()->getPrototypeByName( what ) ); boost::shared_ptr< WModule >prototype = boost::shared_ptr< WModule >();
if ( tryOnly )
{
// isPrototypeAvailable returns the prototype or NULL if not found, but does not throw an exception
prototype = WModuleFactory::getModuleFactory()->isPrototypeAvailable( what );
if( !prototype )
{
return prototype;
}
}
else
{
prototype = WModuleFactory::getModuleFactory()->getPrototypeByName( what );
}
return applyModule( applyOn, prototype );
} }
boost::shared_ptr< WModule > WModuleContainer::applyModule( boost::shared_ptr< WModule > applyOn, boost::shared_ptr< WModule > WModuleContainer::applyModule( boost::shared_ptr< WModule > applyOn,
......
...@@ -123,10 +123,13 @@ public: ...@@ -123,10 +123,13 @@ public:
* *
* \param applyOn the module which already has to be in the container and to apply the other one on. * \param applyOn the module which already has to be in the container and to apply the other one on.
* \param what the prototype name of the module to apply on the other one specified. * \param what the prototype name of the module to apply on the other one specified.
* \param tryOnly If set to false and the prototype "what" does not exist this will throw an exception. If set to true and the prototype does
* not exist, the nothing will happen.
* *
* \return the newly created module connected with the one specified in applyOn. * \return the newly created module connected with the one specified in applyOn. If the prototype could not be found and tryOnly was set to
* true it will return NULL.
*/ */
virtual boost::shared_ptr< WModule > applyModule( boost::shared_ptr< WModule > applyOn, std::string what ); virtual boost::shared_ptr< WModule > applyModule( boost::shared_ptr< WModule > applyOn, std::string what, bool tryOnly = false );
/** /**
* Function combines two modules. This runs synchronously. It might take some time to finish since combination of modules is * Function combines two modules. This runs synchronously. It might take some time to finish since combination of modules is
......
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