29 #include <boost/regex.hpp>
31 #include "../common/WStringUtils.h"
32 #include "../common/WProperties.h"
33 #include "../common/WPropertyBase.h"
34 #include "../common/WPropertyVariable.h"
35 #include "../common/WPropertyTypes.h"
36 #include "../common/exceptions/WFileNotFound.h"
37 #include "../common/WLogger.h"
38 #include "../graphicsEngine/WROI.h"
39 #include "../graphicsEngine/WROIBox.h"
40 #include "WROIManager.h"
42 #include "WProjectFile.h"
44 #include "WRoiProjectFileIO.h"
61 p->setProject( project );
68 static const boost::regex branchRe(
"^ *SELECTOR_BRANCH:([0-9]*)$" );
69 static const boost::regex roiBoxRe(
"^ *SELECTOR_ROIBOX:([0-9]*):SELECTOR_BRANCH([0-9]*)$" );
70 static const boost::regex branchPropRe(
"^ *PROPERTY:\\(SELECTOR_BRANCH([0-9]*),(.*)\\)=(.*)$" );
71 static const boost::regex roiBoxPropRe(
"^ *PROPERTY:\\(SELECTOR_ROIBOX([0-9]*),(.*)\\)=(.*)$" );
73 boost::smatch matches;
74 if( boost::regex_match( line, matches, branchRe ) )
76 Branch branch = string_utils::fromString< Branch >( matches[1] );
77 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Branch with ID " << branch;
82 else if( boost::regex_match( line, matches, roiBoxRe ) )
84 Branch parentBranch = string_utils::fromString< Branch >( matches[2] );
85 RoiID roiID = string_utils::fromString< RoiID >( matches[1] );
86 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": ROI with ID " << roiID <<
" in Branch " << parentBranch;
89 m_rois.push_back(
Roi( roiID, parentBranch ) );
91 else if( boost::regex_match( line, matches, branchPropRe ) )
93 Branch branch = string_utils::fromString< Branch >( matches[1] );
94 std::string prop = matches[2];
95 std::string propValue = matches[3];
96 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Property \"" << prop <<
"\" of Branch " << branch
97 <<
" set to " << propValue;
101 else if( boost::regex_match( line, matches, roiBoxPropRe ) )
103 RoiID roiID = string_utils::fromString< RoiID >( matches[1] );
104 std::string prop = matches[2];
105 std::string propValue = matches[3];
106 wlog::debug(
"Project Loader [Parser]" ) <<
"Line " << lineNumber <<
": Property \"" << prop <<
"\" of ROI " << roiID
107 <<
" set to " << propValue;
124 std::map< Branch, boost::shared_ptr< WRMBranch > > branches;
128 boost::shared_ptr< WRMBranch > branch = rm->addBranch();
129 branches[ *i ] = branch;
135 std::string name = ( *propI ).get< 0 >();
136 std::string value = ( *propI ).get< 1 >();
141 prop->setAsString( value );
145 addError(
"The ROI does not have a property named \"" + name +
"\". Skipping." );
151 for( std::vector< Roi >::const_iterator i =
m_rois.begin(); i !=
m_rois.end(); ++i )
154 boost::shared_ptr< WRMBranch > branch = branches[ ( *i ).get< 1 >() ];
158 rm->addRoi( roi, branch );
164 std::string name = ( *propI ).get< 0 >();
165 std::string value = ( *propI ).get< 1 >();
170 prop->setAsString( value );
174 addError(
"The ROI does not have a property named \"" + name +
"\". Skipping." );
189 output <<
"//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
190 "// ROI Structure" << std::endl <<
191 "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
196 unsigned int branchIndex = 0;
197 unsigned int roiIndex = 0;
198 for( WROIManager::Branches::const_iterator branchIter = branches.begin(); branchIter != branches.end(); ++branchIter )
204 output <<
"SELECTOR_BRANCH:" << branchIndex << std::endl;
205 printProperties( output, branch->getProperties(),
"",
"", branchIndex,
"SELECTOR_BRANCH" );
210 for( WROIManager::ROIs::const_iterator roiIter = rois.begin(); roiIter != rois.end(); ++roiIter )
215 output <<
"SELECTOR_ROIBOX:" << roiIndex <<
":SELECTOR_BRANCH" << branchIndex << std::endl;