]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmick.h
6c3b1cc6e231754cced691044bd385d7009da19a
[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     /// Initialize (read/creates databases, etc.)
67     void Initialize();
68     
69     /// Finalize (closes databases, etc.)
70     void Finalize();
71
72     /// Sets level for messages "Gimmick!" 
73     static void SetMessageLevel(int level);
74     /// Sets level for debug messages "Gimmick! DEBUG" 
75     static void SetDebugMessageLevel(int level);
76     
77     /// Type of map from TreeHandler name to TreeHandler*
78     typedef std::map<std::string, TreeHandler*> TreeHandlerMapType;
79
80     /// Returns the TreeHandlerMap (ref)
81     TreeHandlerMapType& GetTreeHandlerMap() { return mTreeHandlerMap; }
82     /// Returns the TreeHandlerMap (const ref)
83     const TreeHandlerMapType& GetTreeHandlerMap() const
84     { return mTreeHandlerMap; }
85     
86
87     /// Add the files to the given TreeHandler
88     void AddFiles(const std::string& handler,
89                   const std::vector<std::string>& filenames);
90
91     /// Add a dir to the given TreeHandler
92     void AddDir(const std::string& handler, const std::string& path, 
93                 bool recurse);
94
95         /// Removes a file from the given TreeHandler
96         void RemoveFile(const std::string& d, 
97                         tree::Node* filename);
98
99         /// Copies the files into the local directory
100         void CopyFiles(const std::vector<std::string>& filenames, const std::string& d );
101   
102
103         ///Synchronizes the loaded data with the database d. If repair is true the database will be updated, otherwise 
104         ///only a warning sign will be issued
105         std::string Synchronize(const std::string& d, bool repair, bool checkAttributes);
106
107     /// Prints the tree handled by the handler
108     void Print(const std::string& handler);
109         
110     ///create a DB from a given descriptor file and for a specific location
111     SQLiteTreeHandler *createDB(const std::string &i_name, 
112                                 const std::string &i_locDesc, 
113                                 const std::string &i_locDB);
114
115         // add an existent DB 
116         void addDB(const std::string &i_nameDB, const std::string &i_locationDB);
117
118     /// Returns the TreeHandler with a given name
119     TreeHandler* GetTreeHandler(const std::string& name) const;
120
121         /// Returns the TimestampDatabase
122         TimestampDatabaseHandler* GetTimestampDatabase() const;
123     /// 
124     SQLiteTreeHandler* GetLocalDatabase() { return mLocalDatabase; }
125
126     const SQLiteTreeHandler* GetLocalDatabase() const 
127     { return mLocalDatabase; }
128
129         // add DB from Settings file
130     void addDBSettings();
131
132     /// 
133     const std::string& GetHomeDirectory();
134     const std::string& GetUserSettingsDirectory();
135     void CreateUserSettingsDirectory();
136     const std::string& GetLocalDatabasePath();
137         const std::string& GetTimestampDatabasePath();
138
139
140     //=============================================
141   private:
142     SQLiteTreeHandler* mLocalDatabase;
143         TimestampDatabaseHandler* mTimestampDatabase;
144     TreeHandlerMapType mTreeHandlerMap;
145         Synchronizer* mSynchronizer;
146
147     std::string mCurrentDirectory;
148     std::string mHomeDirectory;
149     std::string mUserSettingsDirectory;
150     std::string mLocalDatabasePath;
151         std::string mTimestampDatabasePath;
152         Settings        *mSettings;
153     TreeHandlerImageAdder mImageAdder;
154   };
155   // EO class Gimmick
156   //=======================================================================
157
158
159 } // EO namespace creaImageIO
160
161 // EOF
162 #endif  
163
164