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