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