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