X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FParameters.h;h=3bf5d0140b8d068e36765a26208599dd0e284e6f;hb=6ffc11d77924d6ab7e94db95d41105982ac73e00;hp=0e54f0f7fdfae594e9fd9a55cb7042fde4a22a10;hpb=e18f55af541dba9026284beb6f12ef06b12e6f47;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Parameters.h b/lib/cpPlugins/Interface/Parameters.h index 0e54f0f..3bf5d01 100644 --- a/lib/cpPlugins/Interface/Parameters.h +++ b/lib/cpPlugins/Interface/Parameters.h @@ -1,49 +1,186 @@ #ifndef __CPPLUGINS__INTERFACE__PARAMETERS__H__ #define __CPPLUGINS__INTERFACE__PARAMETERS__H__ +#include + #include #include +#include #include #include -#include + +#include +#include + +// Some forward declarations +class TiXmlElement; + +// ------------------------------------------------------------------------- +#define cpPlugins_Parameters_Configure( Y ) \ + void ConfigureAs##Y( const std::string& name ) \ + { \ + this->m_Parameters[ name ] = TParameter( Self::Y, "" ); \ + this->Modified( ); \ + } \ + bool Has##Y( const std::string& name ) const \ + { \ + auto i = this->m_Parameters.find( name ); \ + if( i != this->m_Parameters.end( ) ) \ + return( i->second.first == Self::Y ); \ + else \ + return( false ); \ + } + +// ------------------------------------------------------------------------- +#define cpPlugins_Parameters_GetSet( Y ) \ + T##Y Get##Y( const std::string& name ) const \ + { \ + auto i = this->m_Parameters.find( name ); \ + if( i != this->m_Parameters.end( ) ) \ + { \ + if( i->second.first == Self::Y ) \ + { \ + if( typeid( T##Y ) != typeid( std::string ) ) \ + { \ + std::istringstream tok_str( i->second.second ); \ + T##Y v; \ + tok_str >> v; \ + return( v ); \ + } \ + else \ + { \ + const T##Y* ptr = \ + reinterpret_cast< const T##Y* >( \ + &( i->second.second ) \ + ); \ + return( *ptr ); \ + } \ + } \ + } \ + return( T##Y( 0 ) ); \ + } \ + void Set##Y( const std::string& name, const T##Y& v ) \ + { \ + auto i = this->m_Parameters.find( name ); \ + if( i != this->m_Parameters.end( ) ) \ + { \ + if( i->second.first == Self::Y ) \ + { \ + if( typeid( T##Y ) != typeid( std::string ) ) \ + { \ + std::stringstream str; \ + str << v; \ + if( i->second.second != str.str( ) ) \ + { \ + i->second.second = str.str( ); \ + this->Modified( ); \ + } \ + } \ + else \ + { \ + const std::string* str = \ + reinterpret_cast< const std::string* >( &v ); \ + if( i->second.second != *str ) \ + { \ + i->second.second = *str; \ + this->Modified( ); \ + } \ + } \ + } \ + } \ + } + +// ------------------------------------------------------------------------- +#define cpPlugins_Parameters_GetSetList( Y ) \ + std::vector< T##Y > Get##Y##List( const std::string& name ) const \ + { \ + std::vector< T##Y > lst; \ + std::vector< std::string >* slst = \ + reinterpret_cast< std::vector< std::string >* >( &lst ); \ + auto i = this->m_Parameters.find( name ); \ + if( i != this->m_Parameters.end( ) ) \ + { \ + if( i->second.first == Self::Y##List ) \ + { \ + std::istringstream str( i->second.second ); \ + std::string token; \ + while( std::getline( str, token, '#' ) ) \ + { \ + if( typeid( T##Y ) != typeid( std::string ) ) \ + { \ + std::istringstream tok_str( token ); \ + T##Y v; \ + tok_str >> v; \ + lst.push_back( v ); \ + } \ + else \ + slst->push_back( token ); \ + } \ + } \ + } \ + return( lst ); \ + } \ + void AddTo##Y##List( const std::string& name, const T##Y& v ) \ + { \ + auto i = this->m_Parameters.find( name ); \ + if( i != this->m_Parameters.end( ) ) \ + { \ + if( i->second.first == Self::Y##List ) \ + { \ + std::stringstream str; \ + if( i->second.second != "" ) \ + str << i->second.second << "#"; \ + str << v; \ + i->second.second = str.str( ); \ + this->Modified( ); \ + } \ + } \ + } \ + void Clear##Y##List( const std::string& name ) \ + { \ + auto i = this->m_Parameters.find( name ); \ + if( i != this->m_Parameters.end( ) ) \ + { \ + if( i->second.first == Self::Y##List ) \ + { \ + if( i->second.second != "" ) \ + { \ + i->second.second = ""; \ + this->Modified( ); \ + } \ + } \ + } \ + } namespace cpPlugins { namespace Interface { + // Some forward declarations + class ProcessObject; + class ParametersQtDialog; + /** */ class cpPlugins_Interface_EXPORT Parameters + : public itk::Object { - // ------------------------------------------------------------------- - friend std::ostream& operator<<( - std::ostream& os, const Parameters& p - ) - { - Parameters::TParameters::const_iterator pIt = - p.m_Parameters.begin( ); - for( ; pIt != p.m_Parameters.end( ); ++pIt ) - { - os - << pIt->first << ": (" - << pIt->second.first << ", " - << pIt->second.second << ")" - << std::endl; - - } // rof - return( os ); - } + friend class ParametersQtDialog; public: - typedef Parameters Self; + typedef Parameters Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; enum Type { - String , Bool , Int , - Uint , Real , Index , - Point , StringList , BoolList , - IntList , UintList , RealList , - IndexList , PointList , NoType + String , Bool , Int , + Uint , Real , OpenFileName , + SaveFileName , PathName , StringList , + BoolList , IntList , UintList , + RealList , OpenFileNameList , SaveFileNameList , + PathNameList , Choices , NoType }; typedef bool TBool; @@ -51,109 +188,117 @@ namespace cpPlugins typedef unsigned long TUint; typedef double TReal; typedef std::string TString; + typedef std::string TOpenFileName; + typedef std::string TSaveFileName; + typedef std::string TPathName; - typedef std::pair< Self::Type, TString > TParameter; - typedef std::map< TString, TParameter > TParameters; + typedef std::pair< Self::Type, std::string > TParameter; + typedef std::map< std::string, TParameter > TParameters; public: - Parameters( ); - Parameters( const Self& other ); - virtual ~Parameters( ); + itkNewMacro( Self ); + itkTypeMacro( cpPlugins::Interface::Parameters, itk::Object ); - Self& operator=( const Self& other ); + cpPlugins_Parameters_Configure( String ); + cpPlugins_Parameters_Configure( Bool ); + cpPlugins_Parameters_Configure( Int ); + cpPlugins_Parameters_Configure( Uint ); + cpPlugins_Parameters_Configure( Real ); + cpPlugins_Parameters_Configure( OpenFileName ); + cpPlugins_Parameters_Configure( SaveFileName ); + cpPlugins_Parameters_Configure( PathName ); + cpPlugins_Parameters_Configure( StringList ); + cpPlugins_Parameters_Configure( BoolList ); + cpPlugins_Parameters_Configure( IntList ); + cpPlugins_Parameters_Configure( UintList ); + cpPlugins_Parameters_Configure( RealList ); + cpPlugins_Parameters_Configure( OpenFileNameList ); + cpPlugins_Parameters_Configure( SaveFileNameList ); + cpPlugins_Parameters_Configure( PathNameList ); + cpPlugins_Parameters_Configure( Choices ); + + cpPlugins_Parameters_GetSet( Bool ); + cpPlugins_Parameters_GetSet( Int ); + cpPlugins_Parameters_GetSet( Uint ); + cpPlugins_Parameters_GetSet( Real ); + cpPlugins_Parameters_GetSet( OpenFileName ); + cpPlugins_Parameters_GetSet( SaveFileName ); + cpPlugins_Parameters_GetSet( PathName ); + + cpPlugins_Parameters_GetSetList( String ); + cpPlugins_Parameters_GetSetList( Bool ); + cpPlugins_Parameters_GetSetList( Int ); + cpPlugins_Parameters_GetSetList( Uint ); + cpPlugins_Parameters_GetSetList( Real ); + cpPlugins_Parameters_GetSetList( OpenFileName ); + cpPlugins_Parameters_GetSetList( SaveFileName ); + cpPlugins_Parameters_GetSetList( PathName ); + + public: + // To impact pipeline + virtual ProcessObject* GetProcessObject( ); + virtual const ProcessObject* GetProcessObject( ) const; + virtual void SetProcessObject( ProcessObject* v ); + virtual void Modified( ) const; + // Parameters container configuration void Clear( ); - void Configure( const Self::Type& type, const TString& name ); - void SetValueAsString( const TString& name, const TString& v ); - void SetValueAsBool( const TString& name, const TBool& v ); - void SetValueAsInt( const TString& name, const TInt& v ); - void SetValueAsUint( const TString& name, const TUint& v ); - void SetValueAsReal( const TString& name, const TReal& v ); - void SetValueAsIndex( const TString& name, const TUint& n, ... ); - void SetValueAsPoint( const TString& name, const TUint& n, ... ); - - void AddValueToStringList( const TString& name, const TString& v ); - void AddValueToBoolList( const TString& name, const TBool& v ); - void AddValueToIntList( const TString& name, const TInt& v ); - void AddValueToUintList( const TString& name, const TUint& v ); - void AddValueToRealList( const TString& name, const TReal& v ); - void AddValueToIndexList( const TString& name, const TUint& n, ... ); - void AddValueToPointList( const TString& name, const TUint& n, ... ); - - void ClearStringList( const TString& name ); - void ClearBoolList( const TString& name ); - void ClearIntList( const TString& name ); - void ClearUintList( const TString& name ); - void ClearRealList( const TString& name ); - void ClearIndexList( const TString& name ); - void ClearPointList( const TString& name ); - - std::vector< TString > GetParameters( ) const; - Self::Type GetParameterType( const TString& name ) const; - const TString& GetRawValue( const TString& name ) const; - const TString& GetValueAsString( const TString& name ) const; - TBool GetValueAsBool( const TString& name ) const; - TInt GetValueAsInt( const TString& name ) const; - TUint GetValueAsUint( const TString& name ) const; - TReal GetValueAsReal( const TString& name ) const; - - template< class I > - I GetValueAsIndex( const TString& name ) const; - - template< class P > - P GetValueAsPoint( const TString& name ) const; - - void GetValueAsStringList( - std::vector< TString >& lst, const TString& name - ) const; - void GetValueAsBoolList( - std::vector< TBool >& lst, const TString& name - ) const; - void GetValueAsIntList( - std::vector< TInt >& lst, const TString& name - ) const; - void GetValueAsUintList( - std::vector< TUint >& lst, const TString& name - ) const; - void GetValueAsRealList( - std::vector< TReal >& lst, const TString& name - ) const; - template< class I > - void GetValueAsIndexList( - std::vector< I >& lst, const TString& name - ) const; + // Get methods + void GetNames( std::vector< std::string >& container ) const; + Type GetType( const std::string& name ) const; + std::string GetTypeAsString( const std::string& name ) const; + static Type GetTypeFromString( const std::string& t ); - template< class P > - void GetValueAsPointList( - std::vector< P >& lst, const TString& name + // Base string methods + std::string GetString( + const std::string& name, bool force = true ) const; + void SetString( + const std::string& name, const std::string& v, bool force = true + ); + + void ConfigureAsChoices( + const std::string& name, const std::vector< std::string >& choices + ); + std::vector< std::string > GetChoices( const std::string& name ) const; + std::string GetSelectedChoice( const std::string& name ) const; + bool SetSelectedChoice( + const std::string& name, const std::string& choice + ); - bool HasStringValue( const TString& name ) const; - bool HasBoolValue( const TString& name ) const; - bool HasIntValue( const TString& name ) const; - bool HasUintValue( const TString& name ) const; - bool HasRealValue( const TString& name ) const; - bool HasIndexValue( const TString& name ) const; - bool HasPointValue( const TString& name ) const; - bool HasStringListValue( const TString& name ) const; - bool HasBoolListValue( const TString& name ) const; - bool HasIntListValue( const TString& name ) const; - bool HasUintListValue( const TString& name ) const; - bool HasRealListValue( const TString& name ) const; - bool HasIndexListValue( const TString& name ) const; - bool HasPointListValue( const TString& name ) const; + std::string GetAcceptedFileExtensions( const std::string& name ) const; + void SetAcceptedFileExtensions( + const std::string& name, const std::string& extensions + ); + + // XML "streaming" + bool ToXML( TiXmlElement* parent_elem ) const; + bool FromXML( const TiXmlElement* filter_elem ); protected: - TParameters m_Parameters; + Parameters( ); + virtual ~Parameters( ); + void PrintSelf( std::ostream& os, itk::Indent indent ) const; + + TParameters& GetRawParameters( ); + const TParameters& GetRawParameters( ) const; + + private: + // Purposely not implemented + Parameters( const Self& other ); + Self& operator=( const Self& other ); + + protected: + TParameters m_Parameters; + std::map< std::string, std::string > m_AcceptedFileExtensions; + ProcessObject* m_Process; }; } // ecapseman } // ecapseman -#include - #endif // __CPPLUGINS__INTERFACE__PARAMETERS__H__ // eof - $RCSfile$