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

[FIX #101] auto-add modules can now be unique. This fixes issue 101. These...

[FIX #101] auto-add modules can now be unique. This fixes issue 101. These modules can be added manually multiple times, but only once by project file/auto-add.
parent cf789ad5
......@@ -492,6 +492,27 @@ WModuleContainer::ModuleSharedContainerType::ReadTicket WModuleContainer::getMod
return m_modules.getReadTicket();
}
WModuleContainer::ModuleVectorType WModuleContainer::getModules( std::string name ) const
{
// get the list of all first.
WModuleContainer::ModuleSharedContainerType::ReadTicket lock = getModules();
// put results in here
WModuleContainer::ModuleVectorType result;
// handle each module
for( ModuleConstIterator listIter = lock->get().begin(); listIter != lock->get().end(); ++listIter )
{
// check name
if( name == ( *listIter )->getName() )
{
result.push_back( ( *listIter ) );
}
}
return result;
}
WCombinerTypes::WCompatiblesList WModuleContainer::getPossibleConnections( boost::shared_ptr< WModule > module )
{
WCombinerTypes::WCompatiblesList complist;
......
......@@ -61,6 +61,11 @@ public:
// the following typedefs are for convenience; to help accessing the container in a thread safe way.
/**
* A vector of modules
*/
typedef std::vector< boost::shared_ptr< WModule > > ModuleVectorType;
/**
* For shortening: a type defining a shared vector of WModule pointers.
*/
......@@ -257,13 +262,23 @@ public:
DataModuleListType getDataModules();
/**
* Method returns a read ticket allowing read-access to the list of modules.
* Method returns a read ticket allowing read-access to the list of modules inside the container.
* \note If done, ensure the ticket gets destroyed.
*
* \return the read ticket.
*/
ModuleSharedContainerType::ReadTicket getModules() const;
/**
* Queries the container to find all modules with a given name. This can be useful to check for existence of certain modules inside the
* container.
*
* \param name name of the modules to find
*
* \return the vector of modules. Empty if nothing was found.
*/
ModuleVectorType getModules( std::string name ) const;
/**
* This method creates a list of combiner instances, for each possible connection that can be made between the specified module and the
* module currently inside the container. It might be possible that a module which is contained in the returned list is not associated
......
......@@ -94,8 +94,7 @@
WMainWindow::WMainWindow():
QMainWindow(),
m_currentCompatiblesToolbar( NULL ),
m_iconManager(),
m_navSlicesAlreadyLoaded( false )
m_iconManager()
{
}
......@@ -460,8 +459,14 @@ void WMainWindow::setupGUI()
restoreSavedState();
}
void WMainWindow::autoAdd( boost::shared_ptr< WModule > module, std::string proto )
void WMainWindow::autoAdd( boost::shared_ptr< WModule > module, std::string proto, bool onlyOnce )
{
// if only one module should be added, and there already is one --- skip.
if( onlyOnce && !WKernel::getRunningKernel()->getRootContainer()->getModules( proto ).empty() )
{
return;
}
// get the prototype.
if( !WKernel::getRunningKernel()->getRootContainer()->applyModule( module, proto, true ) )
{
......@@ -496,11 +501,7 @@ void WMainWindow::moduleSpecificSetup( boost::shared_ptr< WModule > module )
{
// it is a dataset single
// load a nav slice module if a WDataSetSingle is available!?
if( !m_navSlicesAlreadyLoaded )
{
autoAdd( module, "Navigation Slices" );
m_navSlicesAlreadyLoaded = true;
}
autoAdd( module, "Navigation Slices", true );
}
else if( dataModule->getDataSet()->isA< WDataSetFibers >() )
{
......
......@@ -347,10 +347,9 @@ private:
*
* \param module the module to be combined.
* \param proto the prototype to combine with the module.
* \param onlyOnce if true, it is ensured that only one module is in the container.
*/
void autoAdd( boost::shared_ptr< WModule > module, std::string proto );
bool m_navSlicesAlreadyLoaded; //!< if true, the navslices have been loaded already
void autoAdd( boost::shared_ptr< WModule > module, std::string proto, bool onlyOnce = false );
/**
* Loads the window states and geometries from a file.
......
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