33 #include <boost/regex.hpp>
35 #include "../WKernel.h"
36 #include "../WModuleCombiner.h"
37 #include "../WModuleFactory.h"
38 #include "../WModuleConnector.h"
39 #include "../WModule.h"
40 #include "../WDataModule.h"
41 #include "../WModuleInputConnector.h"
42 #include "../WModuleOutputConnector.h"
43 #include "../exceptions/WModuleConnectorNotFound.h"
45 #include "../../common/exceptions/WFileNotFound.h"
46 #include "../../common/WStringUtils.h"
47 #include "../../common/WProperties.h"
48 #include "../../common/WPropertyBase.h"
49 #include "../../common/WPropertyVariable.h"
50 #include "../../common/WPropertyTypes.h"
51 #include "../../common/WLogger.h"
52 #include "../WProjectFile.h"
53 #include "../../graphicsEngine/WGEColormapping.h"
55 #include "WModuleProjectFileCombiner.h"
79 p->setProject( project );
86 static const boost::regex modRe(
"^ *MODULE:([0-9]*):(.*)$" );
87 static const boost::regex dataRe(
"^ *DATA:([0-9]*):\"?([^\"]*)\"?$" );
88 static const boost::regex conRe(
"^ *CONNECTION:\\(([0-9]*),(.*)\\)->\\(([0-9]*),(.*)\\)$" );
89 static const boost::regex propRe(
"^ *PROPERTY:\\(([0-9]*),(.*)\\)=(.*)$" );
91 boost::smatch matches;
92 if( boost::regex_match( line, matches, modRe ) )
98 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Module \"" << matches[2] <<
"\" with ID " << matches[1];
106 addError(
"There is no prototype available for module \"" + matches[2] +
"\". Skipping." );
108 else if( proto->getType() == MODULE_DATA )
110 addError(
"Data modules are not allowed to be specified in a \"MODULE\" Statement. Use the \"DATA\" statement instead. Skipping." );
116 module->setRestoreNeeded();
118 m_modules.insert(
ModuleID( string_utils::fromString< unsigned int >( matches[1] ), module ) );
121 else if( boost::regex_match( line, matches, dataRe ) )
126 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Data \"" << matches[2] <<
"\" with ID " << matches[1];
132 addError(
"There is no prototype available for module \"Data Module\". This should not happen!. Skipping." );
136 std::string parameter = std::string( matches[2] );
140 module->setRestoreNeeded();
141 if( parameter.empty() )
143 addError(
"Data modules need an additional filename parameter. Skipping." );
147 boost::static_pointer_cast<
WDataModule >( module )->setFilename( parameter );
148 m_modules.insert(
ModuleID( string_utils::fromString< unsigned int >( matches[1] ), module ) );
152 else if( boost::regex_match( line, matches, conRe ) )
158 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Connection between \"" << matches[2] <<
"\" of module "
159 << matches[1] <<
" and \"" << matches[4] <<
"\" of module " << matches[3] <<
".";
163 Connector( string_utils::fromString< unsigned int >( matches[3] ), matches[4] ) ) );
165 else if( boost::regex_match( line, matches, propRe ) )
172 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Property \"" << matches[2] <<
"\" of module " << matches[1]
173 <<
" set to " << matches[3];
191 for( std::map<
unsigned int, boost::shared_ptr< WModule > >::const_iterator iter =
m_modules.begin(); iter !=
m_modules.end(); ++iter )
198 for( std::map<
unsigned int, boost::shared_ptr< WModule > >::iterator iter =
m_modules.begin(); iter !=
m_modules.end(); ++iter )
200 ( *iter ).second->isReadyOrCrashed().wait();
203 if( ( *iter ).second->isCrashed()() )
205 addError(
"In the module with ID " + ( *iter ).first +
206 std::string(
" a problem occurred. Connections and properties relating to this module will fail." ) );
215 if( !
m_modules.count( ( *iter ).first.first ) )
218 ( *iter ).first.second + std::string(
"\" for. Skipping." ) );
221 boost::shared_ptr< WModule > m =
m_modules[ ( *iter ).first.first ];
224 boost::shared_ptr< WPropertyBase > prop = m->getProperties()->findProperty( ( *iter ).first.second );
227 addWarning(
"The module \"" + m->getName() + std::string(
"\" has no property named \"" ) + ( *iter ).first.second +
228 std::string(
"\". Skipping." ) );
233 if( prop->getPurpose() != PV_PURPOSE_INFORMATION )
236 bool result = prop->setAsString( ( *iter ).second );
239 addWarning(
"Failed to set property " + ( *iter ).first.second +
" in module \"" + m->getName() +
"\"." );
244 addWarning(
"The module \"" + m->getName() +
"\" has a property named \"" +
245 ( *iter ).first.second +
"\" which is an INFORMATION property. Skipping." );
259 boost::shared_ptr< WModule > m1;
264 c2.second +
"). Skipping." );
269 boost::shared_ptr< WModule > m2;
274 "," + c2.second +
"). Skipping." );
283 boost::shared_ptr< WModuleOutputConnector > con1;
286 con1 = m1->getOutputConnector( c1.second );
290 addError(
"There is no output connector \"" + c1.second +
"\" in module \"" + m1->getName() +
"\"" );
293 boost::shared_ptr< WModuleInputConnector > con2;
296 con2 = m2->getInputConnector( c2.second );
300 addError(
"There is no input connector \"" + c2.second +
"\" in module \"" + m2->getName() +
"\"" );
307 con1->connect( con2 );
313 ") could not be created. Incompatible connectors?. Skipping." );
322 for( std::map<
unsigned int, boost::shared_ptr< WModule > >::iterator iter =
m_modules.begin(); iter !=
m_modules.end(); ++iter )
324 ( *iter ).second->reportRestoreComplete();
345 std::map< boost::shared_ptr< WModule >,
unsigned int > moduleToIDMap;
347 output <<
"//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
348 "// Modules and Properties" << std::endl <<
349 "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
357 moduleToIDMap[ ( *iter ) ] = i;
360 if( ( *iter )->getType() == MODULE_DATA )
362 output <<
"DATA:" << i <<
":" << boost::static_pointer_cast<
WDataModule >( ( *iter ) )->getFilename().string() << std::endl;
366 output <<
"MODULE:" << i <<
":" << ( *iter )->
getName() << std::endl;
380 output <<
"//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
381 "// Connections" << std::endl <<
382 "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
391 for( WModule::OutputConnectorList::const_iterator citer = outs.begin(); citer != outs.end(); ++citer )
394 boost::unique_lock<boost::shared_mutex> lock( ( *citer )->m_connectionListLock );
395 for( std::set<boost::shared_ptr<WModuleConnector> >::const_iterator iciter = ( *citer )->m_connected.begin();
396 iciter != ( *citer )->m_connected.end(); ++iciter )
399 boost::shared_ptr< WModule > theOtherModule = ( *iciter )->m_module.lock();
400 output <<
"CONNECTION:(" << moduleToIDMap[ ( *iter ) ] <<
"," << ( *citer )->getName() <<
")->(" <<
401 moduleToIDMap[ theOtherModule ] <<
"," << ( *iciter )->getName() <<
")" << std::endl;
411 ModuleIDMap::const_iterator it =
m_modules.find(
id );
417 return ( *it ).second;
423 boost::bind( &ModuleIDMap::value_type::second, _1 ) == module
427 return std::numeric_limits< unsigned int >::max();
430 return ( *it ).first;
boost::shared_ptr< WModuleContainer > getRootContainer() const
Returns the root module container.
virtual const std::string getName() const =0
Gets the name of this prototype.
Base for all data loader modules.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::pair< unsigned int, std::string > Connector
A connector is described by ID and name.
virtual void apply()
Apply the internal module structure to the target container.
std::pair< unsigned int, boost::shared_ptr< WModule > > ModuleID
The module ID type.
OpenWalnut kernel, managing modules and interaction between UI, GE and DataHandler.
std::vector< boost::shared_ptr< WModuleOutputConnector > > OutputConnectorList
The type for the list of output connectors.
void addWarning(std::string description)
Add an warning.
virtual SPtr clone(WProjectFile *project) const
Create a clone of the IO.
virtual boost::shared_ptr< WModule > mapToModule(unsigned int id) const
Map a given project file ID to a module.
std::pair< Property, std::string > PropertyValue
A property value is a property and the new value as string.
virtual ~WModuleProjectFileCombiner()
Destructor.
General purpose exception and therefore base class for all kernel related exceptions.
virtual void save(std::ostream &output)
Saves the state to the specified stream.
std::pair< unsigned int, std::string > Property
A property is a pair of ID and name.
Class loading project files.
std::list< PropertyValue > m_properties
All properties.
This is a base class for all module combination classes.
ModuleContainerType::const_iterator ModuleConstIterator
The const iterator type of the container.
void addError(std::string description)
Add an error.
boost::shared_ptr< WProjectFileIO > SPtr
Abbreviation for a shared pointer.
static boost::shared_ptr< WGEColormapping > instance()
Returns instance of the module factory to use to create modules.
std::string toString(const T &value)
Convert a given value to a string.
std::list< Connection > m_connections
All connections.
boost::shared_ptr< WModuleContainer > m_container
The module container to use for the modules.
boost::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
static SPtr getModuleFactory()
Returns instance of the module factory to use to create modules.
A base class for all parts of OpenWalnut which can be serialized to a project file.
void printProperties(std::ostream &output, boost::shared_ptr< WProperties > props, std::string indent, std::string prefix, unsigned int index, std::string indexPrefix="")
Recursively prints the properties and nested properties.
virtual bool parse(std::string line, unsigned int lineNumber)
This method parses the specified line and interprets it to fill the internal module graph structure...
std::pair< Connector, Connector > Connection
A connection is a pair of connectors.
virtual unsigned int mapFromModule(boost::shared_ptr< WModule > module) const
Map a given module to project file ID.
WModuleProjectFileCombiner()
Creates an empty combiner.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
boost::shared_ptr< WSharedObjectTicketRead< ModuleContainerType > > ReadTicket
Type for read tickets.
virtual void done()
Called whenever the end of the project file has been reached.
std::map< unsigned int, boost::shared_ptr< WModule > > m_modules
All Modules.