Commit e4a1f5af authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - cleaned up WGUI interface, adopted modules appropriately

- also see ticket #142
parent 8aa2018e
......@@ -13,6 +13,7 @@ IF( CXXTEST_FOUND )
"common" # no libs for linking required
"WSegmentationFault.cpp"
"WTransferable.cpp"
"WConditionSet.cpp"
"WPrototyped.cpp"
"WStringUtils.h" # since unit tests are already included via the .h file
)
......
......@@ -37,13 +37,25 @@ class WFlag
public:
/**
* Constructor. Uses a given condition to realize the wait/notify functionality.
* Constructor. Uses a given condition to realize the wait/notify functionality. By using this constructor, the specified
* condition gets deleted whenever this WFlag is deleted.
*
* \param condition the condition to use. NOTE: can also be a WConditionOneShot.
* \param initial the initial value of this flag
* \param condition the condition to use.
* \note condition can also be a WConditionOneShot.
* \param initial the initial value of this flag.
*/
WFlag( WCondition* condition, T initial );
/**
* Constructor. Uses a given condition to realize the wait/notify functionality. By using this constructor, the specified
* condition gets NOT explicitely deleted when this WFlag gets deleted.
*
* \param condition the condition to use.
* \note condition can also be a WConditionOneShot.
* \param initial the initial value of this flag.
*/
WFlag( boost::shared_ptr< WCondition > condition, T initial );
/**
* Destructor. It deletes the instance of WCondition specified on construction.
*/
......@@ -82,12 +94,19 @@ public:
*/
virtual void operator()( T value );
/**
* Returns the condition that is used by this flag.
*
* \return the condition
*/
boost::shared_ptr< WCondition > getCondition();
protected:
/**
* The condition to be used for waiting/notifying. Please note, that it gets deleted during destruction.
*/
WCondition* m_condition;
boost::shared_ptr< WCondition > m_condition;
/**
* The flag value.
......@@ -104,6 +123,13 @@ typedef WFlag< bool > WBoolFlag;
template < typename T >
WFlag< T >::WFlag( WCondition* condition, T initial )
{
m_condition = boost::shared_ptr< WCondition >( condition );
m_flag = initial;
}
template < typename T >
WFlag< T >::WFlag( boost::shared_ptr< WCondition > condition, T initial )
{
m_condition = condition;
m_flag = initial;
......@@ -112,7 +138,6 @@ WFlag< T >::WFlag( WCondition* condition, T initial )
template < typename T >
WFlag< T >::~WFlag()
{
delete m_condition;
}
template < typename T >
......@@ -149,5 +174,11 @@ void WFlag< T >::set( T value )
m_condition->notify();
}
template < typename T >
boost::shared_ptr< WCondition > WFlag< T >::getCondition()
{
return m_condition;
}
#endif // WFLAG_H
......@@ -43,8 +43,3 @@ const WFlag< bool >& WGUI::isInitialized() const
return m_isInitialized;
}
void WGUI::slotAddDatasetToBrowser( boost::shared_ptr< WModule > module )
{
addDatasetToBrowser( module, 0 );
}
......@@ -82,25 +82,6 @@ public:
*/
virtual int run() = 0;
/**
* Slot gets called whenever a new module is added.
*
* \param module
*/
virtual void slotAddDatasetToBrowser( boost::shared_ptr< WModule > module );
/**
* adds a dataset to the dataset browser for a give subject
*/
virtual void addDatasetToBrowser( boost::shared_ptr< WModule > module, int subjectId ) = 0;
/**
* adds a module to the dataset browser
*
* \param module
*/
virtual void addModuleToBrowser( boost::shared_ptr< WModule > module ) = 0;
/**
* returns a vector of pointers to the loaded datasets for a given subject.
*
......@@ -111,26 +92,11 @@ public:
*/
virtual std::vector< boost::shared_ptr< WDataSet > > getDataSetList( int subjectId, bool onlyTextures = false ) = 0;
/**
* returns a pointer to the selected module in the dataset browser
*
* \return the module
*/
virtual boost::shared_ptr< WModule > getSelectedModule() = 0;
/**
* getter functions for the signales proved by the gui
*/
virtual boost::signals2::signal1< void, std::vector< std::string > >* getLoadButtonSignal() = 0;
virtual boost::signals2::signal1< void, std::string >* getPickSignal() = 0;
/**
* this function allows modules to register their property object with the gui
*/
virtual void connectProperties( boost::shared_ptr<WProperties> properties ) = 0;
protected:
/**
......
......@@ -28,6 +28,7 @@
#include <vector>
#include <boost/program_options.hpp>
#include <boost/shared_ptr.hpp>
#include <QtGui/QApplication>
#include <QtGui/QFileDialog>
......@@ -35,6 +36,7 @@
#include "WMainWindow.h"
#include "../../kernel/WKernel.h"
#include "../../graphicsEngine/WGraphicsEngine.h"
#include "../../modules/data/WMData.h"
#include "WQt4Gui.h"
......@@ -147,7 +149,7 @@ int WQt4Gui::run()
m_gui->getModuleButtonSignal()->connect( boost::bind( &WKernel::applyModule, m_kernel, _1, _2 ) );
// bind the GUI's slot with the ready signal
t_ModuleGenericSignalHandlerType f = boost::bind( &WGUI::slotAddDatasetToBrowser, this, _1 );
t_ModuleGenericSignalHandlerType f = boost::bind( &WQt4Gui::slotAddDatasetOrModuleToBrowser, this, _1 );
m_kernel->getRootContainer()->addDefaultNotifier( READY, f );
// now we are initialized
......@@ -169,17 +171,22 @@ int WQt4Gui::run()
return qtRetCode;
}
void WQt4Gui::addDatasetToBrowser( boost::shared_ptr< WModule > module, int subjectId )
void WQt4Gui::slotAddDatasetOrModuleToBrowser( boost::shared_ptr< WModule > module )
{
m_gui->getDatasetBrowser()->addDataset( module, subjectId );
}
// get properties from the module and register them
m_gui->getPropertyManager()->connectProperties( module->getProperties() );
void WQt4Gui::addModuleToBrowser( boost::shared_ptr< WModule > module )
{
m_gui->getDatasetBrowser()->addModule( module );
// TODO(schurade): is this differentiation between data and "normal" modules really needed?
if ( boost::shared_dynamic_cast< WMData >( module ).get() )
{
m_gui->getDatasetBrowser()->addDataset( module, 0 );
}
else
{
m_gui->getDatasetBrowser()->addModule( module );
}
}
std::vector< boost::shared_ptr< WDataSet > > WQt4Gui::getDataSetList( int subjectId, bool onlyTextures )
{
return m_gui->getDatasetBrowser()->getDataSetList( subjectId, onlyTextures );
......@@ -190,7 +197,6 @@ boost::shared_ptr< WModule > WQt4Gui::getSelectedModule()
return m_gui->getDatasetBrowser()->getSelectedModule();
}
boost::signals2::signal1< void, std::vector< std::string > >* WQt4Gui::getLoadButtonSignal()
{
return m_gui->getLoaderSignal();
......@@ -201,8 +207,3 @@ boost::signals2::signal1< void, std::string >* WQt4Gui::getPickSignal()
return m_gui->getPickSignal();
}
void WQt4Gui::connectProperties( boost::shared_ptr<WProperties> properties )
{
m_gui->getPropertyManager()->connectProperties( properties );
}
......@@ -64,21 +64,6 @@ public:
*/
virtual int run();
/**
* adds a dataset to the dataset browser
*
* \param module
* \param subjectId
*/
void addDatasetToBrowser( boost::shared_ptr< WModule > module, int subjectId );
/**
* adds a module to the dataset browser
*
* \param module
*/
void addModuleToBrowser( boost::shared_ptr< WModule > module );
/**
* returns a vector of pointers to the loaded datasets for a given subject.
*
......@@ -89,7 +74,6 @@ public:
*/
virtual std::vector< boost::shared_ptr< WDataSet > > getDataSetList( int subjectId, bool onlyTextures = false );
/**
* returns a pointer to the selected module in the dataset browser
*
......@@ -97,6 +81,14 @@ public:
*/
virtual boost::shared_ptr< WModule > getSelectedModule();
/**
* Slot gets called whenever a new module is added.
*
* \param module the module to be added
*
* \note This can be used to add datasets or other modules.
*/
virtual void slotAddDatasetOrModuleToBrowser( boost::shared_ptr< WModule > module );
/**
* getter functions for the signales proved by the gui
......@@ -105,12 +97,6 @@ public:
boost::signals2::signal1< void, std::string >* getPickSignal();
/**
* this function allows modules to register their property object with the gui
* \param properties the properties taht will be registered
*/
virtual void connectProperties( boost::shared_ptr<WProperties> properties );
protected:
private:
......
......@@ -18,6 +18,8 @@ IF( CXXTEST_FOUND )
"WModule.cpp"
"WModuleInputConnector.cpp"
"WModuleOutputConnector.cpp"
"WModuleSignals.cpp"
"WModuleConnectorSignals.cpp"
"WModuleInputData.h"
"WModuleOutputData.h"
"WModuleInputData.cpp"
......
......@@ -43,6 +43,8 @@
#include "exceptions/WModuleUninitialized.h"
#include "../common/WException.h"
#include "../common/WLogger.h"
#include "../common/WCondition.h"
#include "../common/WConditionOneShot.h"
#include "WModule.h"
......@@ -50,11 +52,16 @@ WModule::WModule():
WThreadedRunner(),
m_initialized( new WCondition(), false ),
m_isAssociated( new WCondition(), false ),
m_isUsable( new WCondition(), false )
m_isUsable( new WCondition(), false ),
m_isReady( new WConditionOneShot(), false ),
m_moduleState()
{
// initialize members
m_properties = boost::shared_ptr< WProperties >( new WProperties() );
m_container = boost::shared_ptr< WModuleContainer >();
// our internal state consist out of two conditions: data changed and the exit flag from WThreadedRunner.
m_moduleState.add( m_shutdownFlag.getCondition() );
}
WModule::~WModule()
......@@ -249,13 +256,10 @@ boost::shared_ptr< WProperties > WModule::getProperties() const
void WModule::ready()
{
m_isReady( true );
signal_ready( shared_from_this() );
}
void WModule::connectToGui()
{
}
void WModule::threadMain()
{
#ifdef __linux__
......
......@@ -45,6 +45,7 @@
#include "../common/WLogger.h"
#include "../common/WProperties.h"
#include "../common/WThreadedRunner.h"
#include "../common/WConditionSet.h"
class WModuleConnector;
class WModuleInputConnector;
......@@ -143,12 +144,6 @@ public:
*/
virtual boost::shared_ptr< WModule > factory() const = 0;
/**
* Takes all the relevant GUI signals and connects them to own member functions.
* NOTE: this is only temporal. See ticket 142.
*/
virtual void connectToGui();
/**
* Connects a specified notify function with a signal this module instance is offering.
*
......@@ -356,6 +351,16 @@ protected:
*/
WBoolFlag m_isUsable;
/**
* True if ready() was called.
*/
WBoolFlag m_isReady;
/**
* The internal state of the module. This is, by default, simply the exit flag from WThreadedRunner.
*/
WConditionSet m_moduleState;
/**
* The container this module belongs to.
*/
......
......@@ -100,9 +100,6 @@ void WModuleContainer::add( boost::shared_ptr< WModule > module, bool run )
}
slock.unlock();
// TODO(ebaum,schurade): this should be removes some days
module->connectToGui();
// run it
if ( run )
{
......@@ -131,6 +128,8 @@ void WModuleContainer::remove( boost::shared_ptr< WModule > module )
lock.unlock();
module->setAssociatedContainer( boost::shared_ptr< WModuleContainer >() );
// TODO(ebaum): remove signal subscriptions
// TODO(ebaum): flat or deep removal? What to do with associated modules?
}
......
......@@ -233,14 +233,6 @@ public:
return "testdesc";
}
/**
* Connect anything to GUI.
*/
virtual void connectToGui()
{
// do nothing here
}
/**
* Set up connectors.
*/
......
......@@ -48,6 +48,9 @@ boost::shared_ptr< WModule > WMCoordinateSystem::factory() const
void WMCoordinateSystem::moduleMain()
{
// signal ready state
ready();
createGeometry();
// Since the modules run in a separate thread: wait
......@@ -68,12 +71,6 @@ const std::string WMCoordinateSystem::getDescription() const
return "This module displays coordinate systems as overlay withn the main 3D view.";
}
void WMCoordinateSystem::connectToGui()
{
WKernel::getRunningKernel()->getGui()->connectProperties( m_properties );
WKernel::getRunningKernel()->getGui()->addModuleToBrowser( shared_from_this() );
}
void WMCoordinateSystem::properties()
{
m_properties->addBool( "dataSetAdded", false, true );
......
......@@ -72,12 +72,6 @@ public:
*/
virtual const std::string getDescription() const;
/**
* Connect the listener function of the module to the gui signals
* this has to be called after full initialization fo the gui
*/
void connectToGui();
/**
* 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.
......
......@@ -66,6 +66,9 @@ const std::string WMDistanceMap::getDescription() const
void WMDistanceMap::moduleMain()
{
// signal ready state
ready();
// TODO(wiebel): MC fix this hack when possible by using an input connector.
while ( !WKernel::getRunningKernel() )
{
......@@ -88,7 +91,6 @@ void WMDistanceMap::moduleMain()
boost::shared_ptr< WValueSet< float > > distanceMapValueSet = createOffset( dataSet );
boost::shared_ptr< WMMarchingCubes > mc = boost::shared_ptr< WMMarchingCubes >( new WMMarchingCubes() );
mc->connectToGui();
mc->generateSurface( dataSet->getGrid(), distanceMapValueSet, .4 );
WLogger::getLogger()->addLogMessage( "Rendering surface ...", "Distance Map", LL_INFO );
......
......@@ -106,6 +106,9 @@ void drawChannel( boost::shared_ptr< const WEEG > eegData, size_t channelId, osg
void WMEEGTest::moduleMain()
{
// signal ready state
ready();
// load the sample scene.
//osg::Geode* sceneDataGeode = new osg::Geode();
......
......@@ -74,6 +74,9 @@ boost::shared_ptr< WModule > WMFiberClustering::factory() const
void WMFiberClustering::moduleMain()
{
// signal ready state
ready();
boost::shared_ptr< WDataHandler > dataHandler;
// TODO(math): fix this hack when possible by using an input connector.
while( !WKernel::getRunningKernel() )
......
......@@ -62,6 +62,9 @@ boost::shared_ptr< WModule > WMFiberCulling::factory() const
void WMFiberCulling::moduleMain()
{
// signal ready state
ready();
boost::shared_ptr< WDataHandler > dataHandler;
// TODO(math): fix this hack when possible by using an input connector.
while( !WKernel::getRunningKernel() )
......
......@@ -94,14 +94,11 @@ osg::ref_ptr< osg::Geode > WMFiberDisplay::genFiberGeode( boost::shared_ptr< con
return geode;
}
void WMFiberDisplay::connectToGui()
{
WKernel::getRunningKernel()->getGui()->connectProperties( m_properties );
WKernel::getRunningKernel()->getGui()->addModuleToBrowser( shared_from_this() );
}
void WMFiberDisplay::moduleMain()
{
// signal ready state
ready();
// ready();
// while( !m_FinishRequested )
// {
......
......@@ -73,12 +73,6 @@ public:
*/
virtual boost::shared_ptr< WModule > factory() const;
/**
* Takes all the relevant GUI signals and connects them to own member functions.
* NOTE: this is only temporal. See ticket 142.
*/
virtual void connectToGui();
protected:
/**
* Entry point after loading the module. Runs in separate thread.
......
......@@ -64,13 +64,11 @@ void WMHud::properties()
m_properties->addBool( "showHUD1", false );
}
void WMHud::notifyDataChange( boost::shared_ptr<WModuleConnector> /*input*/,
boost::shared_ptr<WModuleConnector> /*output*/ )
{
}
void WMHud::moduleMain()
{
// signal ready state
ready();
init();
// Since the modules run in a separate thread: wait
......@@ -81,13 +79,6 @@ void WMHud::moduleMain()
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->removeChild( m_rootNode );
}
void WMHud::connectToGui()
{
WKernel::getRunningKernel()->getGui()->connectProperties( m_properties );
WKernel::getRunningKernel()->getGui()->addModuleToBrowser( shared_from_this() );
}
void WMHud::init()
{
m_rootNode = osg::ref_ptr< osg::Projection >( new osg::Projection );
......
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