2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
29 #ifndef __creaImageIOGimmick_h_INCLUDED__
30 #define __creaImageIOGimmick_h_INCLUDED__
32 #include <creaImageIOSQLiteTreeHandler.h>
33 #include <creaImageIOTreeHandlerImageAdder.h>
34 #include <creaImageIOSynchron.h>
35 #include <creaImageIOSettings.h>
42 #define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
48 #ifdef TRACKING_MEMORY_LEAKS
50 #pragma warning(disable : 4291)
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 );
62 #define OMISCID_NEW new( __LINE__, __FILE__ )
64 #else // TRACKING_MEMORY_LEAKS is not defined
66 #define OMISCID_NEW new
74 * \defgroup Controller Controller
80 * \defgroup Model Model
83 * \defgroup GUI Top level graphical user interfaces
86 * \defgroup IO Image I/O classes
89 * \defgroup Tree Attributed tree management
92 * \defgroup Previewer Preview related
99 //=======================================================================
100 /// Central controler of the gimmick application
104 /// the selected attributes by end-user
107 // name of database to get attributes
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;
117 class CREAIMAGEIO_EXPORT Gimmick
126 typedef TreeHandlerImageAdder::Progress AddProgress;
127 typedef TreeHandlerImageAdder::ProgressCallbackType AddProgressCallbackType;
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); }
140 const AddProgress& GetAddProgress() const { return mImageAdder.GetProgress(); }
142 /// Initializes with default values (read/creates databases, etc.)
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");
148 /// Finalize (closes databases, etc.)
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);
156 /// Type of map from TreeHandler name to TreeHandler*
157 typedef std::map<std::string, TreeHandler*> TreeHandlerMapType;
159 typedef std::map<std::string, TreeHandler*>::const_iterator ItTreeHandlerMap;
161 /// Returns the TreeHandlerMap (ref)
162 TreeHandlerMapType& GetTreeHandlerMap() { return mTreeHandlerMap; }
164 /// Returns the TreeHandlerMap (const ref)
165 const TreeHandlerMapType& GetTreeHandlerMap() const
166 { return mTreeHandlerMap; }
168 /// Add the files to the given TreeHandler
169 void AddFiles(const std::string& handler,
170 const std::vector<std::string>& filenames);
172 /// Add a dir to the given TreeHandler
173 void AddDir(const std::string& handler, const std::string& path,
176 /// Removes a file from the given TreeHandler
177 void RemoveFile(const std::string& d,
178 tree::Node* filename);
180 ///Deletes the given drive name from the databases
181 void DeleteDrive(const std::string& drive);
184 /// Copies the files into the local directory
185 void CopyFiles(const std::vector<std::string>& filenames, const std::string& d );
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);
192 /// Prints the tree handled by the handler
193 void Print(const std::string& handler);
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);
200 /// add an existent DB
201 void addDB(const std::string &i_nameDB, const std::string &i_locationDB);
203 /// Returns the TreeHandler with a given name
204 TreeHandler* GetTreeHandler(const std::string& name) const;
207 SQLiteTreeHandler* GetLocalDatabase() { return mLocalDatabase; }
209 const SQLiteTreeHandler* GetLocalDatabase() const { return mLocalDatabase; }
211 ///Returns the given setting value for the given setting parameter
212 void GetSetting(const std::string& name, std::string& value);
214 ///Updates the settings file
215 void UpdateSetting(const std::string& name, const std::string& value);
217 /// add DB from Settings file
218 void addDBSettings();
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);
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);
229 /// get Values for given attributes
230 void GetAttributes(const std::string filename, std::map<std::string, std::string> &i_res, OutputAttr i_attr);
232 const std::string& GetHomeDirectory();
233 const std::string& GetUserSettingsDirectory();
234 void CreateUserSettingsDirectory();
235 const std::string& GetLocalDatabasePath();
237 /// Decide if attributes are available through database
238 void fillVectInfos(std::vector<std::string> i_attr, OutputAttr &infos);
240 /// Get Add Opertaion summary
241 const std::string getSummary();
242 //=============================================
244 SQLiteTreeHandler* mLocalDatabase;
245 TreeHandlerMapType mTreeHandlerMap;
246 Synchronizer* mSynchronizer;
248 std::string mCurrentDirectory;
249 std::string mHomeDirectory;
250 std::string mUserSettingsDirectory;
251 std::string mLocalDatabasePath;
253 TreeHandlerImageAdder mImageAdder;
254 std::string mLocalDBName;
255 std::string mLocalDescpName;
258 //=======================================================================
261 } // EO namespace creaImageIO