Commit 91ed945c authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - restructured apply combiner and added new base class for all...

[CHANGE] - restructured apply combiner and added new base class for all combiners which create one-to-one connections.
parent d4d7a9df
......@@ -26,14 +26,14 @@
#include "WQtApplyModuleAction.h"
WQtApplyModuleAction::WQtApplyModuleAction( QWidget* parent, WIconManager* iconManager, boost::shared_ptr< WModuleCombiner > combiner,
WQtApplyModuleAction::WQtApplyModuleAction( QWidget* parent, WIconManager* iconManager, boost::shared_ptr< WApplyCombiner > combiner,
bool advancedText ):
QAction( parent ),
m_combiner( combiner )
{
// nice tooltip
std::string from = "";
/*
// NOTE: all the tooltips and so on for this action are used from the first combiner in the group
// might be null ( for example if a module should be added that does not require an input)
......@@ -41,15 +41,15 @@ WQtApplyModuleAction::WQtApplyModuleAction( QWidget* parent, WIconManager* iconM
{
from = m_combiner->getSrcModule()->getName() + ":" + m_combiner->getSrcConnector() + " -> ";
}
std::string tooltip = from + m_combiner->getTargetPrototype()->getName() + ":" + m_combiner->getTargetConnector();
std::string tooltip = from + m_combiner->getTargetModule()->getName() + ":" + m_combiner->getTargetConnector();
setToolTip( tooltip.c_str() );
setText( advancedText ? tooltip.c_str() : m_combiner->getTargetPrototype()->getName().c_str() );
setIconText( advancedText ? tooltip.c_str() : m_combiner->getTargetPrototype()->getName().c_str() );
setIcon( iconManager->getIcon( m_combiner->getTargetPrototype()->getName().c_str() ) );
setText( advancedText ? tooltip.c_str() : m_combiner->getTargetModule()->getName().c_str() );
setIconText( advancedText ? tooltip.c_str() : m_combiner->getTargetModule()->getName().c_str() );
setIcon( iconManager->getIcon( m_combiner->getTargetModule()->getName().c_str() ) );
// we need to use released signal here, as the pushed signal also gets emitted on newly created buttons which are under the mouse pointer with
// pressed left button.
connect( this, SIGNAL( triggered() ), this, SLOT( applyCombiner() ) );*/
connect( this, SIGNAL( triggered() ), this, SLOT( applyCombiner() ) );
}
WQtApplyModuleAction::~WQtApplyModuleAction()
......
......@@ -32,7 +32,7 @@
#include <QtGui/QAction>
#include "../../../kernel/WModule.h"
#include "../../../kernel/WModuleCombiner.h"
#include "../../../kernel/combiner/WApplyCombiner.h"
#include "../WIconManager.h"
......@@ -53,7 +53,7 @@ public:
* \param combiner the apply combiner which gets applied when triggered
* \param advancedText if true a more complex text showing the used connectors is used instead of the plane target-module name
*/
WQtApplyModuleAction( QWidget* parent, WIconManager* iconManager, boost::shared_ptr< WModuleCombiner > combiner,
WQtApplyModuleAction( QWidget* parent, WIconManager* iconManager, boost::shared_ptr< WApplyCombiner > combiner,
bool advancedText = false );
/**
......@@ -66,7 +66,7 @@ protected:
/**
* The combiner of this action
*/
boost::shared_ptr< WModuleCombiner > m_combiner;
boost::shared_ptr< WApplyCombiner > m_combiner;
private:
public slots:
......
//---------------------------------------------------------------------------
//
// 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 "WModule.h"
#include "combiner/WApplyCombiner.h"
#include "WModuleCombinerTypes.h"
//---------------------------------------------------------------------------
//
// 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 WMODULECOMBINERTYPES_H
#define WMODULECOMBINERTYPES_H
#include <boost/shared_ptr.hpp>
class WModule;
class WApplyCombiner;
/**
* A list of all combiners in a group.
*/
typedef std::vector< boost::shared_ptr< WApplyCombiner > > WCompatibleCombiners;
/**
* A group of compatible connections to and from a specified module, which is additionally stored in the first element of the pair. This first
* element will never be the module to which the compatible connections have been searched for.
*/
typedef std::pair< boost::shared_ptr< WModule >, WCompatibleCombiners > WCompatiblesGroup;
/**
* This is a list of compatible connection groups, which has been created for a specific module.
*/
typedef std::vector< WCompatiblesGroup > WCompatiblesList;
#endif // WMODULECOMBINERTYPES_H
......@@ -267,10 +267,10 @@ WCompatiblesList WModuleFactory::getCompatiblePrototypes( boost::shared_ptr< WMo
if( pcons.size() == 0 )
{
// the modules which match every time need their own groups
std::vector< boost::shared_ptr< WModuleCombiner > > lComp;
std::vector< boost::shared_ptr< WApplyCombiner > > 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
lComp.push_back( boost::shared_ptr< WModuleCombiner >( new WApplyPrototypeCombiner( module, "", *listIter, "" ) ) );
lComp.push_back( boost::shared_ptr< WApplyCombiner >( new WApplyPrototypeCombiner( module, "", *listIter, "" ) ) );
// add this list
compatibles.push_back( WCompatiblesGroup( ( *listIter ), lComp ) );
......@@ -307,7 +307,7 @@ WCompatiblesList WModuleFactory::getCompatiblePrototypes( boost::shared_ptr< WMo
}
// this list contains all connections for the current module
std::vector< boost::shared_ptr< WModuleCombiner > > lComp;
std::vector< boost::shared_ptr< WApplyCombiner > > 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 )
......@@ -319,7 +319,7 @@ WCompatiblesList WModuleFactory::getCompatiblePrototypes( boost::shared_ptr< WMo
if ( ( *outIter )->connectable( *inIter ) && ( *inIter )->connectable( *outIter ) )
{
// create a apply-prototype combiner
lComp.push_back( boost::shared_ptr< WModuleCombiner >(
lComp.push_back( boost::shared_ptr< WApplyCombiner >(
new WApplyPrototypeCombiner( module, ( *outIter )->getName(), *listIter, ( *inIter )->getName() ) )
);
......
//---------------------------------------------------------------------------
//
// 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 "WApplyCombiner.h"
WApplyCombiner::WApplyCombiner( boost::shared_ptr< WModuleContainer > target,
boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > prototype, std::string targetConnector ):
WModuleCombiner( target ),
m_srcModule( srcModule ),
m_srcConnector( srcConnector ),
m_targetModule( prototype ),
m_targetConnector( targetConnector )
{
}
WApplyCombiner::WApplyCombiner( boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > prototype, std::string targetConnector ):
WModuleCombiner(),
m_srcModule( srcModule ),
m_srcConnector( srcConnector ),
m_targetModule( prototype ),
m_targetConnector( targetConnector )
{
}
WApplyCombiner::~WApplyCombiner()
{
// cleanup
}
boost::shared_ptr< WModule > WApplyCombiner::getSrcModule() const
{
return m_srcModule;
}
std::string WApplyCombiner::getSrcConnector() const
{
return m_srcConnector;
}
boost::shared_ptr< WModule > WApplyCombiner::getTargetModule() const
{
return m_targetModule;
}
std::string WApplyCombiner::getTargetConnector() const
{
return m_targetConnector;
}
//---------------------------------------------------------------------------
//
// 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 WAPPLYCOMBINER_H
#define WAPPLYCOMBINER_H
#include <list>
#include <map>
#include <string>
#include <utility>
#include <boost/shared_ptr.hpp>
#include "../WModule.h"
#include "../WModuleCombiner.h"
/**
* Base class for all combiners which apply one connection between two connectors of two modules.
*/
class WApplyCombiner: public WModuleCombiner
{
public:
/**
* Creates a combiner which sets up the specified modules and prototype combination. Specifying a NULL pointer to the srcModule parameter
* causes the combiner to only add the target module without any connections. This is especially useful for modules which do not provide any
* input which must be connected.
*
*
* \param target the target container
* \param srcModule the module whose output should be connected with the prototypes input
* \param srcConnector the output connector of the module
* \param targetModule the module/prototype to use for connecting the module with
* \param targetConnector the input connector of the prototype to connect with srcConnector.
*/
WApplyCombiner( boost::shared_ptr< WModuleContainer > target,
boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > targetModule, std::string targetConnector );
/**
* Creates a combiner which sets up the specified modules and prototype combination. This constructor automatically uses the kernel's root
* container as target container. Specifying a NULL pointer to the srcModule parameter
* causes the combiner to only add the target module without any connections. This is especially useful for modules which do not provide any
* input which must be connected.
*
* \param srcModule the module whose output should be connected with the prototypes input
* \param srcConnector the output connector of the module
* \param targetModule the module/prototype to use for connecting the module with
* \param targetConnector the input connector of the prototype to connect with srcConnector.
*/
WApplyCombiner( boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > targetModule, std::string targetConnector );
/**
* Destructor.
*/
virtual ~WApplyCombiner();
/**
* Apply the internal module structure to the target container. Be aware, that this operation might take some time, as modules can be
* connected only if they are "ready", which, at least with WMData modules, might take some time. It applies the loaded project file.
*/
virtual void apply() = 0;
/**
* Gets the source module. This module's output connector is connected with the target.
*
* \return the source module.
*/
boost::shared_ptr< WModule > getSrcModule() const;
/**
* The output connector of m_srcModule to connect with m_targetConnector.
*
* \return the source module's output connector.
*/
std::string getSrcConnector() const;
/**
* The module/prototype to connect with m_srcModule.
*
* \return the target module prototype.
*/
boost::shared_ptr< WModule > getTargetModule() const;
/**
* The input connector the target module to connect with m_srcConnector.
*
* \return the target module's input connector.
*/
std::string getTargetConnector() const;
protected:
/**
* The source module to connect with the target
*/
boost::shared_ptr< WModule > m_srcModule;
/**
* The output connector of m_srcModule to connect with m_targetConnector.
*/
std::string m_srcConnector;
/**
* The module/prototype to connect with m_srcMdodule.
*/
boost::shared_ptr< WModule > m_targetModule;
/**
* The input connector the target module to connect with m_srcConnector.
*/
std::string m_targetConnector;
private:
};
#endif // WAPPLYCOMBINER_H
......@@ -47,22 +47,16 @@
WApplyPrototypeCombiner::WApplyPrototypeCombiner( boost::shared_ptr< WModuleContainer > target,
boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > prototype, std::string targetConnector ):
WModuleCombiner( target ),
m_srcModule( srcModule ),
m_srcConnector( srcConnector ),
m_targetPrototype( prototype ),
m_targetConnector( targetConnector )
WApplyCombiner( target, srcModule, srcConnector, prototype, targetConnector )
{
// initialize
}
WApplyPrototypeCombiner::WApplyPrototypeCombiner( boost::shared_ptr< WModule > srcModule, std::string srcConnector,
boost::shared_ptr< WModule > prototype, std::string targetConnector ):
WModuleCombiner( WKernel::getRunningKernel()->getRootContainer() ),
m_srcModule( srcModule ),
m_srcConnector( srcConnector ),
m_targetPrototype( prototype ),
m_targetConnector( targetConnector )
WApplyCombiner( srcModule, srcConnector, prototype, targetConnector )
{
// initialize
}
WApplyPrototypeCombiner::~WApplyPrototypeCombiner()
......@@ -70,30 +64,10 @@ WApplyPrototypeCombiner::~WApplyPrototypeCombiner()
// cleanup
}
boost::shared_ptr< WModule > WApplyPrototypeCombiner::getSrcModule() const
{
return m_srcModule;
}
std::string WApplyPrototypeCombiner::getSrcConnector() const
{
return m_srcConnector;
}
boost::shared_ptr< WModule > WApplyPrototypeCombiner::getTargetPrototype() const
{
return m_targetPrototype;
}
std::string WApplyPrototypeCombiner::getTargetConnector() const
{
return m_targetConnector;
}
void WApplyPrototypeCombiner::apply()
{
// create module instance
boost::shared_ptr< WModule > targetModule = WModuleFactory::getModuleFactory()->create( m_targetPrototype );
boost::shared_ptr< WModule > targetModule = WModuleFactory::getModuleFactory()->create( m_targetModule );
// add the target module to the container
m_container->add( targetModule );
......
......@@ -33,12 +33,12 @@
#include <boost/shared_ptr.hpp>
#include "../WModule.h"
#include "../WModuleCombiner.h"
#include "WApplyCombiner.h"
/**
* This class combines an existing module with an specified prototype. The connections to use must be explicitly known.
*/
class WApplyPrototypeCombiner: public WModuleCombiner
class WApplyPrototypeCombiner: public WApplyCombiner
{
public:
......@@ -83,56 +83,8 @@ public:
*/
virtual void apply();
/**
* Gets the source module. This module's output connector is connected with the target.
*
* \return the source module.
*/
boost::shared_ptr< WModule > getSrcModule() const;
/**
* The output connector of m_srcModule to connect with m_targetConnector.
*
* \return the source module's output connector.
*/
std::string getSrcConnector() const;
/**
* The module prototype to connect with m_srcMdodule.
*
* \return the target module prototype.
*/
boost::shared_ptr< WModule > getTargetPrototype() const;
/**
* The input connector the target module to connect with m_srcConnector.
*
* \return the target module's input connector.
*/
std::string getTargetConnector() const;
protected:
/**
* The source module to connect with the target
*/
boost::shared_ptr< WModule > m_srcModule;
/**
* The output connector of m_srcModule to connect with m_targetConnector.
*/
std::string m_srcConnector;
/**
* The module prototype to connect with m_srcMdodule.
*/
boost::shared_ptr< WModule > m_targetPrototype;
/**
* The input connector the target module to connect with m_srcConnector.
*/
std::string m_targetConnector;
private:
};
......
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