]> Creatis software - creaImageIO.git/blob - src/creaImageIOGimmick.h
9e0f96636dbeeba28dc80d439aa6d399253fa03d
[creaImageIO.git] / src / creaImageIOGimmick.h
1 #ifndef __creaImageIOGimmick_h_INCLUDED__
2 #define __creaImageIOGimmick_h_INCLUDED__
3
4 #include <creaImageIOSQLiteTreeHandler.h>
5 #include <creaImageIOTreeHandlerImageAdder.h>
6 #include <creaImageIOSynchron.h>
7 #include <creaImageIOSettings.h>
8
9
10
11
12 #ifdef _DEBUG
13 #include <crtdbg.h>
14 #define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
15 #else
16 #define DEBUG_NEW new
17 #endif
18 // Only when asked
19 /*
20 #ifdef TRACKING_MEMORY_LEAKS
21 #ifdef WIN32
22 #pragma warning(disable : 4291)
23 #endif
24
25 void * operator new( size_t size, int line, const char *file );
26 void * operator new[]( size_t size, int line, const char *file );
27 void operator delete( void *p );
28 void operator delete[]( void *p );
29
30 #ifdef OMISCID_NEW
31 #undef OMISCID_NEW
32 #endif
33
34 #define OMISCID_NEW new( __LINE__, __FILE__ )
35
36 #else // TRACKING_MEMORY_LEAKS is not defined
37
38 #define OMISCID_NEW new
39
40 #endif*/
41
42
43 namespace creaImageIO
44 {
45         /**
46         * \defgroup Controller Controller
47         */
48         /**
49         * \defgroup View View
50         */
51         /**
52         * \defgroup Model Model
53         */
54         /**
55         * \defgroup GUI Top level graphical user interfaces
56         */
57         /**
58         * \defgroup IO Image I/O classes
59         */
60         /**
61         * \defgroup Tree Attributed tree management
62         */
63         /**
64         * \defgroup Previewer Preview related
65         */
66
67         /**
68         * \ingroup Controller
69         */
70
71   //=======================================================================
72   /// Central controler of the gimmick application
73
74
75
76         /// the selected attributes by end-user
77         typedef struct
78         {
79                 // name of database to get attributes
80                 std::string db;
81                 // attributes available in this databse
82                 std::vector<std::string> inside;
83                 // attributes not available in this databse
84                 std::vector<std::string> outside;
85                 //
86                 bool mult;
87         }OutputAttr;
88
89   class CREAIMAGEIO_EXPORT Gimmick
90   {
91   public:
92     /// Ctor
93     Gimmick();
94     /// Dtor
95     ~Gimmick();
96     
97     ///
98     typedef TreeHandlerImageAdder::Progress AddProgress;
99     typedef TreeHandlerImageAdder::ProgressCallbackType AddProgressCallbackType;
100     
101     /// Adds the function f to the list of functions to call 
102     /// when addition operations progres.
103     /// f is of type AddProgressCallbackType which is:
104     /// void (*AddProgressCallbackType)(AddProgress&)
105     /// To pass a member function 'f' of an instance 'c' of a class 'C' 
106     /// as callback you have to 'bind' it, i.e. call:
107     /// ConnectAddProgressObserver ( boost::bind( &C::f , c, _1 ) );
108      void ConnectAddProgressObserver( AddProgressCallbackType callback )
109     { mImageAdder.ConnectProgressObserver(callback); }
110     
111     ///
112     const AddProgress& GetAddProgress() const { return mImageAdder.GetProgress(); }
113
114     /// Initializes with default values (read/creates databases, etc.)
115     void Initialize();
116
117         /// Initializes with the local database descriptor in the path given (read/creates databases, etc.)
118         void Initialize(const std::string namedescp, const std::string namedb = "Local Database");
119     
120     /// Finalize (closes databases, etc.)
121     void Finalize();
122
123     /// Sets level for messages "Gimmick!" 
124     static void SetMessageLevel(int level);
125     /// Sets level for debug messages "Gimmick! DEBUG" 
126     static void SetDebugMessageLevel(int level);
127     
128     /// Type of map from TreeHandler name to TreeHandler*
129         typedef std::map<std::string, TreeHandler*> TreeHandlerMapType;
130
131         typedef std::map<std::string, TreeHandler*>::const_iterator ItTreeHandlerMap;
132
133     /// Returns the TreeHandlerMap (ref)
134     TreeHandlerMapType& GetTreeHandlerMap() { return mTreeHandlerMap; }
135         
136     /// Returns the TreeHandlerMap (const ref)
137     const TreeHandlerMapType& GetTreeHandlerMap() const
138     { return mTreeHandlerMap; }    
139
140     /// Add the files to the given TreeHandler
141     void AddFiles(const std::string& handler,
142                   const std::vector<std::string>& filenames);
143
144     /// Add a dir to the given TreeHandler
145     void AddDir(const std::string& handler, const std::string& path, 
146                 bool recurse);
147
148         /// Removes a file from the given TreeHandler
149         void RemoveFile(const std::string& d, 
150                         tree::Node* filename);
151
152         ///Deletes the given drive name from the databases
153         void DeleteDrive(const std::string& drive);
154   
155
156         /// Copies the files into the local directory
157         void CopyFiles(const std::vector<std::string>& filenames, const std::string& d );
158   
159
160         ///Synchronizes the loaded data with the database d. If repair is true the database will be updated, otherwise 
161         ///only a warning sign will be issued
162         std::string Synchronize(const std::string& d, bool repair, bool checkAttributes);
163
164     /// Prints the tree handled by the handler
165     void Print(const std::string& handler);
166         
167     ///create a DB from a given descriptor file and for a specific location
168         SQLiteTreeHandler* createDB(const std::string &i_name, 
169                                 const std::string &i_locDesc, 
170                                 const std::string &i_locDB);
171
172         /// add an existent DB 
173         void addDB(const std::string &i_nameDB, const std::string &i_locationDB);
174
175     /// Returns the TreeHandler with a given name
176     TreeHandler* GetTreeHandler(const std::string& name) const;
177
178         /// 
179         SQLiteTreeHandler* GetLocalDatabase() { return mLocalDatabase; }
180
181     const SQLiteTreeHandler* GetLocalDatabase() const     { return mLocalDatabase; }
182
183         ///Returns the given setting value for the given setting parameter
184         void GetSetting(const std::string& name, std::string& value);
185
186         ///Updates the settings file
187         void UpdateSetting(const std::string& name, const std::string& value);
188
189         /// add DB from Settings file
190     void addDBSettings();
191
192         ///Edits the field described by the name and key provided with the value given
193         void EditField(tree::Node* node, const std::string& d, const std::string& name, const std::string& key, const std::string& val);
194
195         /// Returns the attributes in results described in params
196         void GetAttributes(const std::string& d, 
197           const std::string& filename, 
198           const std::vector<std::string>& params, 
199           std::vector<std::string>& results);
200   
201         /// get Values for given attributes
202         void GetAttributes(const std::string filename, std::map<std::string, std::string> &i_res, OutputAttr i_attr);
203     
204     const std::string& GetHomeDirectory();
205     const std::string& GetUserSettingsDirectory();
206     void CreateUserSettingsDirectory();
207     const std::string& GetLocalDatabasePath();
208         
209         /// Decide if attributes are available through database
210         void fillVectInfos(std::vector<std::string> i_attr, OutputAttr &infos);
211
212     /// Get Add Opertaion summary
213     const std::string getSummary();
214     //=============================================
215   private:
216         SQLiteTreeHandler* mLocalDatabase;
217         TreeHandlerMapType mTreeHandlerMap;
218         Synchronizer* mSynchronizer;
219
220     std::string mCurrentDirectory;
221     std::string mHomeDirectory;
222     std::string mUserSettingsDirectory;
223     std::string mLocalDatabasePath;
224         Settings        *mSettings;
225     TreeHandlerImageAdder mImageAdder;
226         std::string mLocalDBName;
227         std::string mLocalDescpName;
228   };
229   // EO class Gimmick
230   //=======================================================================
231
232
233 } // EO namespace creaImageIO
234
235 // EOF
236 #endif  
237
238