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