Commit 8a01fe4e authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - extended module factory to provide a better compatibles list

parent a40ceb0b
......@@ -709,14 +709,45 @@ void WQtDatasetBrowser::createCompatibleButtons( boost::shared_ptr< WModule >mod
{
// every module may have compatibles: create ribbon menu entry
// NOTE: if module is NULL, getCompatiblePrototypes returns the list of modules without input connector (nav slices and so on)
std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > comps = WModuleFactory::getModuleFactory()->getCompatiblePrototypes( module );
WModuleFactory::CompatiblesList comps = WModuleFactory::getModuleFactory()->getCompatiblePrototypes( module );
for ( WModuleFactory::CompatiblesList::const_iterator groups = comps.begin(); groups != comps.end(); ++groups )
{
WQtApplyModulePushButton* currentButton = new WQtApplyModulePushButton( m_mainWindow->getCompatiblesToolBar(), m_mainWindow->getIconManager(),
*( *groups ).second.begin(), m_showToolBarText
);
m_mainWindow->getCompatiblesToolBar()->addWidget( currentButton );
}
/*
boost::shared_ptr< WModule > currentModule; // always save the current module to identify consecutive applycombiners with equal target
WQtApplyModulePushButton* currentButton;
typedef std::vector< std::vector< QAction* > > ActionList;
ActionList actions;
// each combiner can now be added to an existing group or
for ( std::vector< boost::shared_ptr< WApplyPrototypeCombiner > >::const_iterator iter = comps.begin(); iter != comps.end(); ++iter )
{
// This combiner does not belong to the previous group --> create a new toolbutton
if ( currentModule != ( *iter )->getTargetPrototype() )
{
// it is different from the previous one -> create a new button and add it
currentModule = ( *iter )->getTargetPrototype();
currentButton = new WQtApplyModulePushButton( m_mainWindow->getCompatiblesToolBar(), m_mainWindow->getIconManager(),
*iter, m_showToolBarText
);
m_mainWindow->getCompatiblesToolBar()->addWidget( currentButton );
}
else
{
}
*/
// ensure that only modules in the whitelist cause buttons to be created
/*if( !m_moduleWhiteList.empty() )
{
......@@ -728,7 +759,7 @@ void WQtDatasetBrowser::createCompatibleButtons( boost::shared_ptr< WModule >mod
}*/
// This combiner does not belong to the previous group --> create a new toolbutton
if ( currentModule != ( *iter )->getTargetPrototype() )
/*if ( currentModule != ( *iter )->getTargetPrototype() )
{
// it is different from the previous one -> create a new button and add it
......@@ -757,8 +788,8 @@ void WQtDatasetBrowser::createCompatibleButtons( boost::shared_ptr< WModule >mod
std::string name = ( *iter )->getSrcModule()->getName() + ":" + ( *iter )->getSrcConnector() + " -> " +
( *iter )->getTargetPrototype()->getName() + ":" + ( *iter )->getTargetConnector();
menu->addAction( name.c_str() );
}
}
}*/
// }
}
void WQtDatasetBrowser::changeTreeItem()
......
......@@ -35,8 +35,14 @@ WQtApplyModulePushButton::WQtApplyModulePushButton( QWidget* parent, WIconManage
setAutoRaise( false );
// nice tooltip
std::string tooltip = combiner->getSrcModule()->getName() + ":" + combiner->getSrcConnector() + "->" +
combiner->getTargetPrototype()->getName() + ":" + combiner->getTargetConnector();
std::string from = "";
// might be null ( for example if a module should be added that does not require an input)
if ( combiner->getSrcModule() )
{
from = combiner->getSrcModule()->getName() + ":" + combiner->getSrcConnector() + " -> ";
}
std::string tooltip = from + combiner->getTargetPrototype()->getName() + ":" + combiner->getTargetConnector();
setToolTip( tooltip.c_str() );
if ( useText )
......
......@@ -242,19 +242,18 @@ WModuleFactory::PrototypeSharedContainerType::ReadTicket WModuleFactory::getProt
*
* \return true if lhs < rhs
*/
bool compatiblesSort( boost::shared_ptr< WApplyPrototypeCombiner > lhs, boost::shared_ptr< WApplyPrototypeCombiner > rhs )
bool compatiblesSort( WModuleFactory::CompatiblesGroup lhs, WModuleFactory::CompatiblesGroup rhs )
{
return ( lhs->getTargetPrototype()->getName() < rhs->getTargetPrototype()->getName() );
return ( lhs.first->getName() < rhs.first->getName() );
}
std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > WModuleFactory::getCompatiblePrototypes( boost::shared_ptr< WModule > module )
WModuleFactory::CompatiblesList WModuleFactory::getCompatiblePrototypes( boost::shared_ptr< WModule > module )
{
std::vector< boost::shared_ptr < WApplyPrototypeCombiner > > compatibles;
CompatiblesList compatibles;
// for this a read lock is sufficient, gets unlocked if it looses scope
PrototypeSharedContainerType::ReadTicket l = m_prototypes.getReadTicket();
// First, add all modules with no input connector.
for( PrototypeContainerConstIteratorType listIter = l->get().begin(); listIter != l->get().end();
++listIter )
......@@ -263,8 +262,14 @@ std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > WModuleFactory::getC
WModule::InputConnectorList pcons = ( *listIter )->getInputConnectors();
if( pcons.size() == 0 )
{
// the modules which match every time need their own groups
std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > lComp;
// NOTE: it is OK here to use the variable module even if it is NULL as the combiner in this case only adds the specified module
compatibles.push_back( boost::shared_ptr< WApplyPrototypeCombiner >( new WApplyPrototypeCombiner( module, "", *listIter, "" ) ) );
lComp.push_back( boost::shared_ptr< WApplyPrototypeCombiner >( new WApplyPrototypeCombiner( module, "", *listIter, "" ) ) );
// add this list
compatibles.push_back( CompatiblesGroup( ( *listIter ), lComp ) );
}
}
......@@ -297,6 +302,9 @@ std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > WModuleFactory::getC
continue;
}
// this list contains all connections for the current module
std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > lComp;
// iterate connector list, first find all matches of the output connectors with all inputs
for ( WModule::OutputConnectorList::const_iterator outIter = cons.begin(); outIter != cons.end(); ++outIter )
{
......@@ -307,7 +315,7 @@ std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > WModuleFactory::getC
if ( ( *outIter )->connectable( *inIter ) && ( *inIter )->connectable( *outIter ) )
{
// create a apply-prototype combiner
compatibles.push_back( boost::shared_ptr< WApplyPrototypeCombiner >(
lComp.push_back( boost::shared_ptr< WApplyPrototypeCombiner >(
new WApplyPrototypeCombiner( module, ( *outIter )->getName(), *listIter, ( *inIter )->getName() ) )
);
......@@ -315,6 +323,12 @@ std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > WModuleFactory::getC
}
}
}
// add the group
if ( lComp.size() != 0 )
{
compatibles.push_back( CompatiblesGroup( ( *listIter ), lComp ) );
}
}
// unlock. No locking needed for further steps.
......
......@@ -143,6 +143,19 @@ public:
template <typename T>
static bool isA( boost::shared_ptr< WModule > module );
/**
* A group of compatibles connections to and from a specified module.
*/
typedef std::pair< boost::shared_ptr< WModule >, std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > > CompatiblesGroup;
/**
* A type used for defining lists of properties. It basically is a list of lists, each containing several ApplyPrototypeCombiner instances.
* The Idea is to group combiners by the module they target. The reason why this is a list of pairs is that the first item always is the
* prototype pointer to the target, as not every ApplyPrototypeCombiner Instance necessarily has the prototype as target (as source for
* example)
*/
typedef std::vector< CompatiblesGroup > CompatiblesList;
/**
* Returns a set of module combiners with module combinations compatible with the specified one.
*
......@@ -153,9 +166,7 @@ public:
*
* \return set of compatible combiners.
*/
std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > getCompatiblePrototypes(
boost::shared_ptr< WModule > module = boost::shared_ptr< WModule >()
);
CompatiblesList getCompatiblePrototypes( boost::shared_ptr< WModule > module = boost::shared_ptr< WModule >() );
/**
* This method uses a newly created instance of WModule and initializes it properly. After using this method, the module 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