]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmick.h
0a880875e5280727c533608da706f958c901e203
[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     /// Returns the TreeHandlerMap (ref)
115     TreeHandlerMapType& GetTreeHandlerMap() { return mTreeHandlerMap; }
116     /// Returns the TreeHandlerMap (const ref)
117     const TreeHandlerMapType& GetTreeHandlerMap() const
118     { return mTreeHandlerMap; }    
119
120     /// Add the files to the given TreeHandler
121     void AddFiles(const std::string& handler,
122                   const std::vector<std::string>& filenames);
123
124     /// Add a dir to the given TreeHandler
125     void AddDir(const std::string& handler, const std::string& path, 
126                 bool recurse);
127
128         /// Removes a file from the given TreeHandler
129         void RemoveFile(const std::string& d, 
130                         tree::Node* filename);
131
132         ///Deletes the given drive name from the databases
133         void DeleteDrive(const std::string& drive);
134   
135
136         /// Copies the files into the local directory
137         void CopyFiles(const std::vector<std::string>& filenames, const std::string& d );
138   
139
140         ///Synchronizes the loaded data with the database d. If repair is true the database will be updated, otherwise 
141         ///only a warning sign will be issued
142         std::string Synchronize(const std::string& d, bool repair, bool checkAttributes);
143
144     /// Prints the tree handled by the handler
145     void Print(const std::string& handler);
146         
147     ///create a DB from a given descriptor file and for a specific location
148         SQLiteTreeHandler* createDB(const std::string &i_name, 
149                                 const std::string &i_locDesc, 
150                                 const std::string &i_locDB);
151
152         /// add an existent DB 
153         void addDB(const std::string &i_nameDB, const std::string &i_locationDB);
154
155     /// Returns the TreeHandler with a given name
156     TreeHandler* GetTreeHandler(const std::string& name) const;
157
158         /// 
159         SQLiteTreeHandler* GetLocalDatabase() { return mLocalDatabase; }
160
161     const SQLiteTreeHandler* GetLocalDatabase() const     { return mLocalDatabase; }
162
163         ///Returns the given setting value for the given setting parameter
164         void GetSetting(const std::string& name, std::string& value);
165
166         ///Updates the settings file
167         void UpdateSetting(const std::string& name, const std::string& value);
168
169         /// add DB from Settings file
170     void addDBSettings();
171
172         ///Edits the field described by the name and key provided with the value given
173         void EditField(tree::Node* node, const std::string& d, const std::string& name, const std::string& key, const std::string& val);
174
175         /// Returns the attributes in results described in params
176         void GetAttributes(const std::string& d, 
177           const std::string& filename, 
178           const std::vector<std::string>& params, 
179           std::vector<std::string>& results);
180   
181     /// 
182     const std::string& GetHomeDirectory();
183     const std::string& GetUserSettingsDirectory();
184     void CreateUserSettingsDirectory();
185     const std::string& GetLocalDatabasePath();
186         
187
188
189     //=============================================
190   private:
191         SQLiteTreeHandler* mLocalDatabase;
192         TreeHandlerMapType mTreeHandlerMap;
193         Synchronizer* mSynchronizer;
194
195     std::string mCurrentDirectory;
196     std::string mHomeDirectory;
197     std::string mUserSettingsDirectory;
198     std::string mLocalDatabasePath;
199         Settings        *mSettings;
200     TreeHandlerImageAdder mImageAdder;
201         std::string mLocalDBName;
202         std::string mLocalDescpName;
203   };
204   // EO class Gimmick
205   //=======================================================================
206
207
208 } // EO namespace creaImageIO
209
210 // EOF
211 #endif  
212
213