1 #include <cpPlugins/Interface/Parameters.h>
2 #include <cpPlugins/Interface/ProcessObject.h>
6 // -------------------------------------------------------------------------
8 ProcessObject* cpPlugins::Interface::Parameters::
11 return( this->m_Process );
14 // -------------------------------------------------------------------------
15 const cpPlugins::Interface::
16 ProcessObject* cpPlugins::Interface::Parameters::
17 GetProcessObject( ) const
19 return( this->m_Process );
22 // -------------------------------------------------------------------------
23 void cpPlugins::Interface::Parameters::
24 SetProcessObject( ProcessObject* v )
29 // -------------------------------------------------------------------------
30 void cpPlugins::Interface::Parameters::
33 this->Superclass::Modified( );
34 if( this->m_Process != NULL )
35 this->m_Process->Modified( );
38 // -------------------------------------------------------------------------
39 void cpPlugins::Interface::Parameters::
42 this->m_Parameters.clear( );
46 // -------------------------------------------------------------------------
47 #define cpPlugins_Parameters_Configure( Y ) \
48 void cpPlugins::Interface::Parameters:: \
49 ConfigureAs##Y( const TString& name ) \
51 this->m_Parameters[ name ] = TParameter( Self::Y, "" ); \
55 cpPlugins_Parameters_Configure( String );
56 cpPlugins_Parameters_Configure( Bool );
57 cpPlugins_Parameters_Configure( Int );
58 cpPlugins_Parameters_Configure( Uint );
59 cpPlugins_Parameters_Configure( Real );
60 cpPlugins_Parameters_Configure( Index );
61 cpPlugins_Parameters_Configure( Point );
62 cpPlugins_Parameters_Configure( Vector );
63 cpPlugins_Parameters_Configure( StringList );
64 cpPlugins_Parameters_Configure( BoolList );
65 cpPlugins_Parameters_Configure( IntList );
66 cpPlugins_Parameters_Configure( UintList );
67 cpPlugins_Parameters_Configure( RealList );
68 cpPlugins_Parameters_Configure( IndexList );
69 cpPlugins_Parameters_Configure( PointList );
70 cpPlugins_Parameters_Configure( VectorList );
71 cpPlugins_Parameters_Configure( Choices );
73 // -------------------------------------------------------------------------
74 void cpPlugins::Interface::Parameters::
76 const TString& name, const std::vector< TString >& choices
79 // It is invalid not to give choices when configuring
80 if( choices.size( ) == 0 )
83 std::stringstream str_choices;
84 str_choices << choices[ 0 ];
85 for( unsigned int i = 1; i < choices.size( ); ++i )
86 str_choices << "#" << choices[ i ];
88 this->m_Parameters[ name ] =
89 TParameter( Self::Choices, str_choices.str( ) );
93 // -------------------------------------------------------------------------
94 void cpPlugins::Interface::Parameters::
95 GetNames( std::vector< TString >& container ) const
98 TParameters::const_iterator i = this->m_Parameters.begin( );
99 for( ; i != this->m_Parameters.end( ); ++i )
100 container.push_back( i->first );
103 // -------------------------------------------------------------------------
104 cpPlugins::Interface::Parameters::
105 Type cpPlugins::Interface::Parameters::
106 GetType( const TString& name ) const
108 TParameters::const_iterator i = this->m_Parameters.find( name );
109 if( i != this->m_Parameters.end( ) )
110 return( i->second.first );
112 return( Self::NoType );
115 // -------------------------------------------------------------------------
116 #define cpPlugins_Parameters_Has( Y ) \
117 bool cpPlugins::Interface::Parameters:: \
118 Has##Y( const TString& name ) const \
120 TParameters::const_iterator i = this->m_Parameters.find( name ); \
121 if( i != this->m_Parameters.end( ) ) \
122 return( i->second.first == Self::Y ); \
127 cpPlugins_Parameters_Has( String );
128 cpPlugins_Parameters_Has( Bool );
129 cpPlugins_Parameters_Has( Int );
130 cpPlugins_Parameters_Has( Uint );
131 cpPlugins_Parameters_Has( Real );
132 cpPlugins_Parameters_Has( Index );
133 cpPlugins_Parameters_Has( Point );
134 cpPlugins_Parameters_Has( Vector );
135 cpPlugins_Parameters_Has( StringList );
136 cpPlugins_Parameters_Has( BoolList );
137 cpPlugins_Parameters_Has( IntList );
138 cpPlugins_Parameters_Has( UintList );
139 cpPlugins_Parameters_Has( RealList );
140 cpPlugins_Parameters_Has( IndexList );
141 cpPlugins_Parameters_Has( PointList );
142 cpPlugins_Parameters_Has( VectorList );
143 cpPlugins_Parameters_Has( Choices );
145 // -------------------------------------------------------------------------
146 cpPlugins::Interface::Parameters::
147 TString cpPlugins::Interface::Parameters::
148 GetString( const TString& name, bool force ) const
150 TParameters::const_iterator i = this->m_Parameters.find( name );
151 if( i != this->m_Parameters.end( ) )
153 if( i->second.first == Self::String || !force )
154 return( i->second.second );
160 // -------------------------------------------------------------------------
161 cpPlugins::Interface::Parameters::
162 TBool cpPlugins::Interface::Parameters::
163 GetBool( const TString& name ) const
165 TParameters::const_iterator i = this->m_Parameters.find( name );
166 if( i != this->m_Parameters.end( ) )
168 if( i->second.first == Self::Bool )
169 return( std::atoi( i->second.second.c_str( ) ) == 1 );
175 // -------------------------------------------------------------------------
176 cpPlugins::Interface::Parameters::
177 TInt cpPlugins::Interface::Parameters::
178 GetInt( const TString& name ) const
180 TParameters::const_iterator i = this->m_Parameters.find( name );
181 if( i != this->m_Parameters.end( ) )
183 if( i->second.first == Self::Int )
184 return( TInt( std::atoi( i->second.second.c_str( ) ) ) );
190 // -------------------------------------------------------------------------
191 cpPlugins::Interface::Parameters::
192 TUint cpPlugins::Interface::Parameters::
193 GetUint( const TString& name ) const
195 TParameters::const_iterator i = this->m_Parameters.find( name );
196 if( i != this->m_Parameters.end( ) )
198 if( i->second.first == Self::Uint )
199 return( TUint( std::atoi( i->second.second.c_str( ) ) ) );
202 return( TUint( 0 ) );
205 // -------------------------------------------------------------------------
206 cpPlugins::Interface::Parameters::
207 TReal cpPlugins::Interface::Parameters::
208 GetReal( const TString& name ) const
210 TParameters::const_iterator i = this->m_Parameters.find( name );
211 if( i != this->m_Parameters.end( ) )
213 if( i->second.first == Self::Real )
215 std::istringstream tok_str( i->second.second );
218 return( TReal( v ) );
223 return( TReal( 0 ) );
226 // -------------------------------------------------------------------------
227 void cpPlugins::Interface::Parameters::
228 GetStringList( std::vector< TString >& lst, const TString& name ) const
231 TParameters::const_iterator i = this->m_Parameters.find( name );
232 if( i == this->m_Parameters.end( ) )
234 if( i->second.first != Self::StringList )
237 std::istringstream str( i->second.second );
239 while( std::getline( str, token, '#' ) )
240 lst.push_back( token );
243 // -------------------------------------------------------------------------
244 void cpPlugins::Interface::Parameters::
245 GetBoolList( std::vector< TBool >& lst, const TString& name ) const
248 TParameters::const_iterator i = this->m_Parameters.find( name );
249 if( i == this->m_Parameters.end( ) )
251 if( i->second.first != Self::BoolList )
254 std::istringstream str( i->second.second );
256 while( std::getline( str, token, '#' ) )
257 lst.push_back( std::atoi( token.c_str( ) ) == 1 );
260 // -------------------------------------------------------------------------
261 void cpPlugins::Interface::Parameters::
262 GetIntList( std::vector< TInt >& lst, const TString& name ) const
265 TParameters::const_iterator i = this->m_Parameters.find( name );
266 if( i == this->m_Parameters.end( ) )
268 if( i->second.first != Self::IntList )
271 std::istringstream str( i->second.second );
273 while( std::getline( str, token, '#' ) )
274 lst.push_back( TInt( std::atoi( token.c_str( ) ) ) );
277 // -------------------------------------------------------------------------
278 void cpPlugins::Interface::Parameters::
279 GetUintList( std::vector< TUint >& lst, const TString& name ) const
282 TParameters::const_iterator i = this->m_Parameters.find( name );
283 if( i == this->m_Parameters.end( ) )
285 if( i->second.first != Self::UintList )
288 std::istringstream str( i->second.second );
290 while( std::getline( str, token, '#' ) )
291 lst.push_back( TUint( std::atoi( token.c_str( ) ) ) );
294 // -------------------------------------------------------------------------
295 void cpPlugins::Interface::Parameters::
296 GetRealList( std::vector< TReal >& lst, const TString& name ) const
299 TParameters::const_iterator i = this->m_Parameters.find( name );
300 if( i == this->m_Parameters.end( ) )
302 if( i->second.first != Self::RealList )
305 std::istringstream str( i->second.second );
307 while( std::getline( str, token, '#' ) )
309 std::istringstream tok_str( token );
312 lst.push_back( TReal( v ) );
317 // -------------------------------------------------------------------------
318 void cpPlugins::Interface::Parameters::
319 GetChoices( std::vector< TString >& choices, const TString& name ) const
322 TParameters::const_iterator i = this->m_Parameters.find( name );
323 if( i == this->m_Parameters.end( ) )
325 if( i->second.first != Self::Choices )
328 std::istringstream str_choices( i->second.second );
329 std::string real_choices;
330 std::getline( str_choices, real_choices, '@' );
331 std::istringstream str( real_choices );
333 while( std::getline( str, token, '#' ) )
334 choices.push_back( token );
337 // -------------------------------------------------------------------------
338 cpPlugins::Interface::Parameters::
339 TString cpPlugins::Interface::Parameters::
340 GetSelectedChoice( const TString& name ) const
342 TParameters::const_iterator i = this->m_Parameters.find( name );
343 if( i == this->m_Parameters.end( ) )
345 if( i->second.first != Self::Choices )
348 std::istringstream str_choices( i->second.second );
349 std::string real_choice;
350 std::getline( str_choices, real_choice, '@' );
351 std::getline( str_choices, real_choice, '@' );
352 return( real_choice );
355 // -------------------------------------------------------------------------
356 void cpPlugins::Interface::Parameters::
357 SetString( const TString& name, const TString& v, bool force )
359 TParameters::iterator i = this->m_Parameters.find( name );
360 if( i == this->m_Parameters.end( ) )
362 if( i->second.first != Self::String && force )
364 i->second.second = v;
368 // -------------------------------------------------------------------------
369 #define cpPlugins_Parameters_Set( Y ) \
370 void cpPlugins::Interface::Parameters:: \
371 Set##Y( const TString& name, const T##Y& v ) \
373 TParameters::iterator i = this->m_Parameters.find( name ); \
374 if( i == this->m_Parameters.end( ) ) \
376 if( i->second.first != Self::Y ) \
378 std::stringstream str; \
380 i->second.second = str.str( ); \
384 cpPlugins_Parameters_Set( Bool );
385 cpPlugins_Parameters_Set( Int );
386 cpPlugins_Parameters_Set( Uint );
387 cpPlugins_Parameters_Set( Real );
389 // -------------------------------------------------------------------------
390 #define cpPlugins_Parameters_Add( Y ) \
391 void cpPlugins::Interface::Parameters:: \
392 AddTo##Y##List( const TString& name, const T##Y& v ) \
394 TParameters::iterator i = this->m_Parameters.find( name ); \
395 if( i == this->m_Parameters.end( ) ) \
397 if( i->second.first != Self::Y##List ) \
399 std::stringstream str; \
400 if( i->second.second == "" ) \
404 i->second.second += str.str( ); \
408 cpPlugins_Parameters_Add( String );
409 cpPlugins_Parameters_Add( Bool );
410 cpPlugins_Parameters_Add( Int );
411 cpPlugins_Parameters_Add( Uint );
412 cpPlugins_Parameters_Add( Real );
414 // -------------------------------------------------------------------------
415 #define cpPlugins_Parameters_Clear( Y ) \
416 void cpPlugins::Interface::Parameters:: \
417 Clear##Y##List( const TString& name ) \
419 TParameters::iterator i = this->m_Parameters.find( name ); \
420 if( i == this->m_Parameters.end( ) ) \
422 if( i->second.first != Self::Y##List ) \
424 i->second.second = ""; \
428 cpPlugins_Parameters_Clear( String );
429 cpPlugins_Parameters_Clear( Bool );
430 cpPlugins_Parameters_Clear( Int );
431 cpPlugins_Parameters_Clear( Uint );
432 cpPlugins_Parameters_Clear( Real );
433 cpPlugins_Parameters_Clear( Index );
434 cpPlugins_Parameters_Clear( Point );
435 cpPlugins_Parameters_Clear( Vector );
437 // -------------------------------------------------------------------------
438 bool cpPlugins::Interface::Parameters::
439 SetSelectedChoice( const TString& name, const TString& choice )
441 TParameters::iterator i = this->m_Parameters.find( name );
442 if( i == this->m_Parameters.end( ) )
444 if( i->second.first != Self::Choices )
447 std::vector< TString > c;
448 this->GetChoices( c, name );
449 if( std::find( c.begin( ), c.end( ), choice ) != c.end( ) )
451 std::istringstream str_choices( i->second.second );
453 std::getline( str_choices, choices, '@' );
454 std::stringstream new_choices;
455 new_choices << choices << "@" << choice;
456 i->second.second = new_choices.str( );
463 // -------------------------------------------------------------------------
464 cpPlugins::Interface::Parameters::
472 // -------------------------------------------------------------------------
473 cpPlugins::Interface::Parameters::
478 // -------------------------------------------------------------------------
479 void cpPlugins::Interface::Parameters::
480 PrintSelf( std::ostream& os, itk::Indent indent ) const
482 TParameters::const_iterator i = this->m_Parameters.begin( );
483 for( ; i != this->m_Parameters.end( ); ++i )
486 << i->second.first << " | "
487 << i->second.second << ")"