]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/BaseObjects/Parameters.h
Cast image filter added. ROI filter modified.
[cpPlugins.git] / lib / cpPlugins / BaseObjects / Parameters.h
1 #ifndef __cpPlugins__BaseObjects__Parameters__h__
2 #define __cpPlugins__BaseObjects__Parameters__h__
3
4 #include <cpPlugins/Config.h>
5
6 #include <map>
7 #include <ostream>
8 #include <sstream>
9 #include <typeinfo>
10 #include <vector>
11 #include <itkTimeStamp.h>
12
13 // Some forward declarations
14 namespace tinyxml2
15 {
16   class XMLElement;
17   class XMLDocument;
18 }
19
20 // -------------------------------------------------------------------------
21 #define cpPlugins_BaseObjects_Parameters_Configure( Y )                 \
22   void ConfigureAs##Y( const std::string& name, const T##Y& init );     \
23   bool Has##Y( const std::string& name ) const
24
25 // -------------------------------------------------------------------------
26 #define cpPlugins_BaseObjects_Parameters_ConfigureList( Y )             \
27   void ConfigureAs##Y##List( const std::string& name );                 \
28   bool Has##Y##List( const std::string& name ) const
29
30 // -------------------------------------------------------------------------
31 #define cpPlugins_BaseObjects_Parameters_GetSet( Y )    \
32   T##Y Get##Y( const std::string& name ) const;         \
33   void Set##Y( const std::string& name, const T##Y& v )
34
35 // -------------------------------------------------------------------------
36 #define cpPlugins_BaseObjects_Parameters_GetSetList( Y )                \
37   std::vector< T##Y > Get##Y##List( const std::string& name ) const;    \
38   void AddTo##Y##List( const std::string& name, const T##Y& v );        \
39   void Clear##Y##List( const std::string& name )
40
41 // -------------------------------------------------------------------------
42 namespace cpPlugins
43 {
44   namespace QT { class ParametersDialog; }
45
46   namespace BaseObjects
47   {
48     class ProcessObject;
49
50     /**
51      */
52     class cpPlugins_EXPORT Parameters
53     {
54       // Frienship with forward declaration to improve Qt dialog execution
55       friend class cpPlugins::QT::ParametersDialog;
56       friend std::ostream& operator<<( std::ostream& o, const Parameters& p )
57         {
58           for(
59             auto i = p.m_Parameters.begin( );
60             i != p.m_Parameters.end( );
61             ++i
62             )
63             o << i->first << ": ("
64               << i->second.first << " | "
65               << i->second.second << ")"
66               << std::endl;
67           return( o );
68         }
69
70     public:
71       typedef Parameters Self;
72
73       enum Type
74       {
75         String       , Bool             , Int              ,
76         Uint         , Real             , OpenFileName     ,
77         SaveFileName , PathName         , StringList       ,
78         BoolList     , IntList          , UintList         ,
79         RealList     , OpenFileNameList , SaveFileNameList ,
80         PathNameList , Choices          , NoType
81       };
82
83       typedef bool          TBool;
84       typedef long          TInt;
85       typedef unsigned long TUint;
86       typedef double        TReal;
87       typedef std::string   TString;
88       typedef std::string   TOpenFileName;
89       typedef std::string   TSaveFileName;
90       typedef std::string   TPathName;
91
92       typedef std::pair< Self::Type, std::string > TParameter;
93       typedef std::map< std::string, TParameter >  TParameters;
94
95     public:
96       cpPlugins_BaseObjects_Parameters_Configure( String );
97       cpPlugins_BaseObjects_Parameters_Configure( Bool );
98       cpPlugins_BaseObjects_Parameters_Configure( Int );
99       cpPlugins_BaseObjects_Parameters_Configure( Uint );
100       cpPlugins_BaseObjects_Parameters_Configure( Real );
101       cpPlugins_BaseObjects_Parameters_Configure( OpenFileName );
102       cpPlugins_BaseObjects_Parameters_Configure( SaveFileName );
103       cpPlugins_BaseObjects_Parameters_Configure( PathName );
104
105       cpPlugins_BaseObjects_Parameters_ConfigureList( String );
106       cpPlugins_BaseObjects_Parameters_ConfigureList( Bool );
107       cpPlugins_BaseObjects_Parameters_ConfigureList( Int );
108       cpPlugins_BaseObjects_Parameters_ConfigureList( Uint );
109       cpPlugins_BaseObjects_Parameters_ConfigureList( Real );
110       cpPlugins_BaseObjects_Parameters_ConfigureList( OpenFileName );
111       cpPlugins_BaseObjects_Parameters_ConfigureList( SaveFileName );
112       cpPlugins_BaseObjects_Parameters_ConfigureList( PathName );
113
114       cpPlugins_BaseObjects_Parameters_GetSet( Bool );
115       cpPlugins_BaseObjects_Parameters_GetSet( Int );
116       cpPlugins_BaseObjects_Parameters_GetSet( Uint );
117       cpPlugins_BaseObjects_Parameters_GetSet( Real );
118       cpPlugins_BaseObjects_Parameters_GetSet( OpenFileName );
119       cpPlugins_BaseObjects_Parameters_GetSet( SaveFileName );
120       cpPlugins_BaseObjects_Parameters_GetSet( PathName );
121
122       cpPlugins_BaseObjects_Parameters_GetSetList( String );
123       cpPlugins_BaseObjects_Parameters_GetSetList( Bool );
124       cpPlugins_BaseObjects_Parameters_GetSetList( Int );
125       cpPlugins_BaseObjects_Parameters_GetSetList( Uint );
126       cpPlugins_BaseObjects_Parameters_GetSetList( Real );
127       cpPlugins_BaseObjects_Parameters_GetSetList( OpenFileName );
128       cpPlugins_BaseObjects_Parameters_GetSetList( SaveFileName );
129       cpPlugins_BaseObjects_Parameters_GetSetList( PathName );
130
131     public:
132       Parameters( );
133       virtual ~Parameters( );
134
135       ProcessObject* GetProcessObject( );
136       const ProcessObject* GetProcessObject( ) const;
137       void SetProcessObject( ProcessObject* po );
138       virtual void Modified( ) const;
139
140       // Parameters container configuration
141       void Clear( );
142
143       // Get methods
144       void GetNames( std::vector< std::string >& container ) const;
145       Type GetType( const std::string& name ) const;
146       std::string GetTypeAsString( const std::string& name ) const;
147       static Type GetTypeFromString( const std::string& t );
148
149       // Base string methods
150       std::string GetString(
151         const std::string& name, bool force = true
152         ) const;
153       void SetString(
154         const std::string& name, const std::string& v, bool force = true
155         );
156
157       void ConfigureAsChoices(
158         const std::string& name, const std::vector< std::string >& choices
159         );
160       void ConfigureAsRealTypesChoices( const std::string& name );
161       void ConfigureAsIntTypesChoices( const std::string& name );
162       void ConfigureAsScalarTypesChoices( const std::string& name );
163       std::vector< std::string > GetChoices( const std::string& name ) const;
164       std::string GetSelectedChoice( const std::string& name ) const;
165       bool SetSelectedChoice(
166         const std::string& name, const std::string& choice
167         );
168
169       std::string GetAcceptedFileExtensions( const std::string& name ) const;
170       void SetAcceptedFileExtensions(
171         const std::string& name, const std::string& extensions
172         );
173
174       // XML "streaming"
175       bool ToXML(
176         tinyxml2::XMLDocument* doc,
177         tinyxml2::XMLElement* parent_elem
178         ) const;
179       bool FromXML( const tinyxml2::XMLElement* filter_elem );
180
181     protected:
182       TParameters& GetRawParameters( );
183       const TParameters& GetRawParameters( ) const;
184
185       template< unsigned int _Enum >
186       inline void _Configure( const std::string& name );
187
188       template< unsigned int _Enum >
189       inline bool _Has( const std::string& name ) const;
190
191       template< class _Type, unsigned int _Enum >
192       inline _Type _Get( const std::string& name ) const;
193
194       template< class _Type, unsigned int _Enum >
195       inline void _Set( const std::string& name, const _Type& v );
196
197       template< class _Type, unsigned int _Enum >
198       inline std::vector< _Type > _GetList( const std::string& name ) const;
199
200       template< class _Type, unsigned int _Enum >
201       inline void _AddToList( const std::string& name, const _Type& v );
202
203       template< unsigned int _Enum >
204       inline void _ClearList( const std::string& name );
205
206     private:
207       // Purposely not implemented
208       Parameters( const Self& other );
209       Self& operator=( const Self& other );
210
211     protected:
212       ProcessObject*                       m_ProcessObject;
213       TParameters                          m_Parameters;
214       std::map< std::string, std::string > m_AcceptedFileExtensions;
215     };
216
217   } // ecapseman
218
219 } // ecapseman
220
221 #endif // __cpPlugins__BaseObjects__Parameters__h__
222
223 // eof - $RCSfile$