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;