33 #include <boost/regex.hpp>
35 #include "../common/WStringUtils.h"
36 #include "../common/exceptions/WFileNotFound.h"
37 #include "../common/exceptions/WFileOpenFailed.h"
38 #include "../graphicsEngine/WGEProjectFileIO.h"
41 #include "WProjectFile.h"
42 #include "WRoiProjectFileIO.h"
43 #include "combiner/WModuleProjectFileCombiner.h"
58 m_moduleIO = std::dynamic_pointer_cast< WModuleProjectFileCombiner >( p1->clone(
this ) );
76 if( ( *it )->getApplyOrder() == WProjectFileIO::POST_MODULES )
78 m_parsers.push_back( ( *it )->clone(
this ) );
82 m_parsers.push_front( ( *it )->clone(
this ) );
86 m_writers.push_back( ( *it )->clone(
this ) );
96 m_signalLoadDoneConnection( m_signalLoadDone.connect( doneCallback ) )
104 m_moduleIO = std::dynamic_pointer_cast< WModuleProjectFileCombiner >( p1->clone(
this ) );
109 m_parsers.push_back( p2->clone(
this ) );
110 m_writers.push_back( p2->clone(
this ) );
113 m_parsers.push_back( p3->clone(
this ) );
114 m_writers.push_back( p3->clone(
this ) );
122 if( ( *it )->getApplyOrder() == WProjectFileIO::POST_MODULES )
124 m_parsers.push_back( ( *it )->clone(
this ) );
128 m_parsers.push_front( ( *it )->clone(
this ) );
132 m_writers.push_back( ( *it )->clone(
this ) );
172 std::list< std::shared_ptr< WProjectFileIO > > l( writer.begin(), writer.end() );
181 std::ofstream output(
m_project.string().c_str() );
182 if( !output.is_open() )
185 std::string(
"\" could not be opened for write access." ) );
189 for( std::list< std::shared_ptr< WProjectFileIO > >::const_iterator iter = writer.begin(); iter != writer.end(); ++iter )
191 ( *iter )->save( output );
209 std::vector< std::string > errors;
210 std::vector< std::string > warnings;
213 std::ifstream input(
m_project.string().c_str() );
214 if( !input.is_open() )
216 errors.push_back( std::string(
"The project file \"" ) +
m_project.string() + std::string(
"\" does not exist." ) );
227 static const boost::regex commentRe(
"^ *//.*$" );
233 boost::smatch matches;
235 while( std::getline( input, line ) )
241 for( std::list< std::shared_ptr< WProjectFileIO > >::const_iterator iter =
m_parsers.begin(); iter !=
m_parsers.end(); ++iter )
245 if( ( *iter )->parse( line, i ) )
252 catch(
const std::exception& e )
260 if( !match && !line.empty() && !boost::regex_match( line, matches, commentRe ) )
263 wlog::warn(
"Project Loader" ) <<
"Line " << i <<
": Malformed. Skipping.";
270 for( std::list< std::shared_ptr< WProjectFileIO > >::const_iterator iter =
m_parsers.begin(); iter !=
m_parsers.end(); ++iter )
276 std::copy( ( *iter )->getErrors().begin(), ( *iter )->getErrors().end(), std::back_inserter( errors ) );
277 std::copy( ( *iter )->getWarnings().begin(), ( *iter )->getWarnings().end(), std::back_inserter( warnings ) );
279 catch(
const std::exception& e )
281 errors.push_back(
"Exception while applying settings: " + std::string( e.what() ) );
311 if( it == w->get().end() )
314 w->get().push_back( parser );
Thrown whenever a file was not found.
Thrown whenever a file could not be opened.
IO class for writing the graphics engine state to a project file.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::shared_ptr< WModuleContainer > getRootContainer() const
Returns the root module container.
This class is able to parse project files and create the appropriate module graph inside a specified ...
std::shared_ptr< WProjectFileIO > SPtr
Abbreviation for a shared pointer.
Class loading project files.
std::list< std::shared_ptr< WProjectFileIO > > m_writers
The writer instances.
static ParserList m_additionalParsers
List of all additional parser prototypes.
virtual ~WProjectFile()
Destructor.
boost::filesystem::path m_project
The project file to parse.
ProjectLoadCallbackSignal m_signalLoadDone
Signal used to callback someone that the loader was finished.
static void deregisterParser(WProjectFileIO::SPtr parser)
Remove parser from registry.
virtual void load()
Parses the project file and applies it.
boost::function< void(boost::filesystem::path, std::vector< std::string >, std::vector< std::string >) > ProjectLoadCallback
A callback function type reporting bach a finished load job.
virtual void threadMain()
Function that has to be overwritten for execution.
boost::signals2::connection m_signalLoadDoneConnection
Connection managing the signal m_signalLoadDone.
static std::shared_ptr< WProjectFileIO > getModuleWriter()
Returns an instance of the module writer.
virtual void onThreadException(const WException &e)
Do custom exception handling.
virtual void save()
Saves the current state to the file specified in the constructor.
std::list< std::shared_ptr< WProjectFileIO > > m_parsers
The parser instances.
std::shared_ptr< WModuleProjectFileCombiner > m_moduleIO
This is the only WProjectFileIO instance which is needed.
static void registerParser(WProjectFileIO::SPtr parser)
Register a custom project file parser.
WProjectFile(boost::filesystem::path project)
Default constructor.
static std::shared_ptr< WProjectFileIO > getROIWriter()
Returns an instance of the ROI writer.
std::shared_ptr< WModule > mapToModule(unsigned int id) const
Map a given project file ID to a module.
unsigned int mapFromModule(std::shared_ptr< WModule > module) const
Map a given module to project file ID.
static std::shared_ptr< WProjectFileIO > getCameraWriter()
Returns an instance of the Camera writer.
IO Class for writing the ROI structure to a project file.
std::shared_ptr< WSharedObjectTicketRead< S > > ReadTicket
Type for read tickets.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
std::shared_ptr< WSharedObjectTicketWrite< S > > WriteTicket
Type for write tickets.
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
This class provides a common interface for thread-safe access to sequence containers (list,...
void remove(const typename S::value_type &element)
Searches and removes the specified element.
S::iterator Iterator
A typedef for the correct iterator to traverse this sequence container.
S::const_iterator ConstIterator
A typedef for the correct const iterator useful to traverse this sequence container.
Base class for all classes needing to be executed in a separate thread.
virtual void run()
Run thread.
void handleDeadlyException(const WException &e, std::string sender="WThreadedRunner")
Handle the specified exception which was not caught in the thread, which basically means the thread h...
std::string toString(const T &value)
Convert a given value to a string.
WStreamedLogger warn(const std::string &source)
Logging a warning message.
WStreamedLogger info(const std::string &source)
Logging an information message.
WStreamedLogger error(const std::string &source)
Logging an error message.