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