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>
41 #define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
49 #ifdef TRACKING_MEMORY_LEAKS
51 #pragma warning(disable : 4291)
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 );
63 #define OMISCID_NEW new( __LINE__, __FILE__ )
65 #else // TRACKING_MEMORY_LEAKS is not defined
67 #define OMISCID_NEW new
75 * \defgroup Controller Controller
81 * \defgroup Model Model
84 * \defgroup GUI Top level graphical user interfaces
87 * \defgroup IO Image I/O classes
90 * \defgroup Tree Attributed tree management
93 * \defgroup Previewer Preview related
100 //=======================================================================
101 /// Central controler of the gimmick application
105 /// the selected attributes by end-user
108 // name of database to get attributes
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;
118 class CREAIMAGEIO_EXPORT Gimmick
127 typedef TreeHandlerImageAdder::Progress AddProgress;
128 typedef TreeHandlerImageAdder::ProgressCallbackType AddProgressCallbackType;
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); }
141 const AddProgress& GetAddProgress() const { return mImageAdder.GetProgress(); }
143 /// Initializes with default values (read/creates databases, etc.)
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");
149 /// Finalize (closes databases, etc.)
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);
157 /// Type of map from TreeHandler name to TreeHandler*
158 typedef std::map<std::string, TreeHandler*> TreeHandlerMapType;
160 typedef std::map<std::string, TreeHandler*>::const_iterator ItTreeHandlerMap;
162 /// Returns the TreeHandlerMap (ref)
163 TreeHandlerMapType& GetTreeHandlerMap() { return mTreeHandlerMap; }
165 /// Returns the TreeHandlerMap (const ref)
166 const TreeHandlerMapType& GetTreeHandlerMap() const
167 { return mTreeHandlerMap; }
169 /// Add the files to the given TreeHandler
170 void AddFiles(const std::string& handler,
171 const std::vector<std::string>& filenames);
173 /// Add a dir to the given TreeHandler
174 void AddDir(const std::string& handler, const std::string& path,
177 /// Removes a file from the given TreeHandler
178 void RemoveFile(const std::string& d,
179 tree::Node* filename);
181 ///Deletes the given drive name from the databases
182 void DeleteDrive(const std::string& drive);
185 /// Copies the files into the local directory
186 void CopyFiles(const std::vector<std::string>& filenames, const std::string& d );
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);
193 /// Prints the tree handled by the handler
194 void Print(const std::string& handler);
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);
201 /// add an existent DB
202 void addDB(const std::string &i_nameDB, const std::string &i_locationDB);
204 /// Returns the TreeHandler with a given name
205 TreeHandler* GetTreeHandler(const std::string& name) const;
208 SQLiteTreeHandler* GetLocalDatabase() { return mLocalDatabase; }
210 const SQLiteTreeHandler* GetLocalDatabase() const { return mLocalDatabase; }
212 ///Returns the given setting value for the given setting parameter
213 void GetSetting(const std::string& name, std::string& value);
215 ///Updates the settings file
216 void UpdateSetting(const std::string& name, const std::string& value);
218 /// add DB from Settings file
219 void addDBSettings();
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);
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);
230 /// get Values for given attributes
231 void GetAttributes(const std::string filename, std::map<std::string, std::string> &i_res, OutputAttr i_attr);
233 const std::string& GetHomeDirectory();
234 const std::string& GetUserSettingsDirectory();
235 void CreateUserSettingsDirectory();
236 const std::string& GetLocalDatabasePath();
238 /// Decide if attributes are available through database
239 void fillVectInfos(std::vector<std::string> i_attr, OutputAttr &infos);
241 /// Get Add Opertaion summary
242 const std::string getSummary();
243 //=============================================
245 SQLiteTreeHandler* mLocalDatabase;
246 TreeHandlerMapType mTreeHandlerMap;
247 Synchronizer* mSynchronizer;
249 std::string mCurrentDirectory;
250 std::string mHomeDirectory;
251 std::string mUserSettingsDirectory;
252 std::string mLocalDatabasePath;
254 TreeHandlerImageAdder mImageAdder;
255 std::string mLocalDBName;
256 std::string mLocalDescpName;
259 //=======================================================================
262 } // EO namespace creaImageIO