]> Creatis software - creaImageIO.git/blob - src2/creaImageIOTreeHandlerImageAdder.h
Various fixes on argument passing:
[creaImageIO.git] / src2 / creaImageIOTreeHandlerImageAdder.h
1 #ifndef __creaImageIOTreeHandlerImageAdder_h_INCLUDED__
2 #define __creaImageIOTreeHandlerImageAdder_h_INCLUDED__
3
4 #include <creaImageIOTreeHandler.h>
5 #include <creaImageIOTimestampDatabaseHandler.h>
6 #include <creaImageIOSynchron.h>
7 #include <creaImageIOImageReader.h>
8 #include <wx/wx.h>
9 #include <wx/progdlg.h>
10 #include <creaWx.h>
11 // Signal/slot mechanism for progress events
12 #include <boost/signal.hpp>
13 #include <boost/bind.hpp>
14
15
16 namespace creaImageIO
17 {
18         /**
19         * \ingroup Model
20         */
21
22   //=======================================================================
23   /// Object which can add images files to a TreeHandler. Is able to parse (recursively) a part of a filesystem to look for known images and load their attributes in order to add the images to a Tree (submission via a TreeHandler::AddBranch)
24
25   class TreeHandlerImageAdder
26   {
27           
28   public:
29     //====================================================================
30     /// Ctor
31     TreeHandlerImageAdder(TreeHandler* tree);
32     /// Dtor
33     ~TreeHandlerImageAdder();
34     /// Sets the TreeHandler
35     void SetTreeHandler(TreeHandler* tree) { mTreeHandler = tree;}
36         /// Sets the TimestampDatabaseHandler
37     void SetTimestampHandler(TimestampDatabaseHandler* tdh) { mTimestampHandler = tdh;}
38         /// Sets the synchronizer
39         void SetSynchronizer(Synchronizer* s){mSynchronizer=s;}
40     //====================================================================
41
42     //====================================================================
43     /// Structure which holds progress information
44     /// To stop the image adder use SetStop()
45     class Progress
46     {
47     public:
48       Progress() { Reset(); }
49       ~Progress() {}
50       
51       void Reset() 
52       {
53         mStop = false;
54         mNumberScannedFiles = 0;
55         mNumberScannedDirs = 0;
56         mNumberHandledFiles = 0;
57         mNumberAddedFiles = 0;
58       }
59
60       int GetNumberScannedFiles() const { return mNumberScannedFiles; }
61       int GetNumberScannedDirs() const { return mNumberScannedDirs; }
62       int GetNumberHandledFiles() const { return mNumberHandledFiles; }
63       int GetNumberAddedFiles() const { return mNumberAddedFiles; }
64
65       void IncNumberScannedFiles() { mNumberScannedFiles++; }
66       void IncNumberScannedDirs() { mNumberScannedDirs++; }
67       void IncNumberHandledFiles() { mNumberHandledFiles++; }
68       void IncNumberAddedFiles() { mNumberAddedFiles++; }
69
70       void SetStop() { mStop = true; }
71       bool GetStop() const { return mStop; }
72
73     private:
74       bool mStop;
75       int mNumberScannedFiles;
76       int mNumberScannedDirs;
77       int mNumberHandledFiles;
78       int mNumberAddedFiles;
79     };
80     //=============================================
81
82     //=============================================
83     const Progress& GetProgress() const { return mProgress; }
84     //=============================================
85
86     //=============================================
87     typedef boost::signal<void (Progress&)>  ProgressSignalType;
88     typedef ProgressSignalType::slot_function_type ProgressCallbackType;
89     //=============================================
90
91    //==================================================================
92     /// Adds the function f to the list of functions to call 
93     /// when the addition progresses.
94     /// f is of type ProgressCallbackType which is:
95     /// void (*ProgressCallbackType)(Progress&)
96     /// To pass a member function 'f' of an instance 'c' of a class 'C' 
97     /// as callback you have to 'bind' it, i.e. call:
98     /// ConnectProgressObserver ( boost::bind( &C::f , c, _1 ) );
99     void ConnectProgressObserver(ProgressCallbackType callback);
100    //==================================================================
101
102     //====================================================================
103     /// Returns if the file can be read or not
104     bool IsHandledFile( const std::string& filename);
105     /// Adds a list of files to the TreeHandler 
106     void AddFiles( const std::vector<std::string>& filename );
107     /// (Recursively) adds the files of a directory to the TreeHandler 
108     void AddDirectory( const std::string& directory, 
109                        bool recurse);
110         /// Removes a file from the databases
111         void RemoveFile(tree::Node* node);
112         /// Removes files from the databases
113         void RemoveFiles(const std::vector<tree::Node*>& nodes);
114         /// Synchronizes the DB and disk by repeating the operations the user has done and returns a report
115         std::string Synchronize(bool repair, bool checkAttributes);
116         ///Recursively checks if the directory is synchronized and optionally the state of the attributes
117         void CheckSyncDirectory(const std::string &dirpath, 
118                                                         bool recursive, 
119                                                         bool repair,
120                                                         bool checkAttributes,
121                                                         std::vector<std::string> &i_ignorefiles,
122                                                         std::vector<std::string> & attsModified,
123                                                         std::vector<std::string> & newfiles);
124         ///Finds the node that matches the specified parameters
125         void FindNode(tree::Node* parent, int level, 
126                 const std::string& searchParam, 
127                 const std::string& searchVal, 
128                 tree::Node*& node);
129         ///Checks the attributes of the database against the ones in disk
130         void CheckAttributes(bool repair, std::string& file, std::vector<std::string>& attsModified);
131  
132     //====================================================================
133
134   private:
135
136     /// Adds a single file to the TreeHandler 
137     /// **WITHOUT** testing wether it is handled or not 
138     /// hence you have to call IsHandledFile before using AddFile!
139     void AddFile( const std::string& filename );
140
141     /// Recursive method which does the main job for AddDirectory
142     void AddDirectoryRecursor( const std::string& directory, 
143                                bool recurse,
144                            const std::string &addKey);
145
146     TreeHandler* mTreeHandler;
147         TimestampDatabaseHandler* mTimestampHandler;
148         Synchronizer* mSynchronizer;
149     ImageReader mReader;
150     
151     Progress mProgress;
152     ProgressSignalType mProgressSignal;
153
154
155   };
156   // EO class TreeHandlerImageAdder
157   //=======================================================================
158
159
160  
161
162
163 } // EO namespace creaImageIO
164
165 #include <iostream>
166 inline std::ostream& operator << ( std::ostream& o, 
167                             const creaImageIO::TreeHandlerImageAdder::Progress& p)
168 {
169   o << p.GetNumberScannedFiles() << " files - "
170     << p.GetNumberScannedDirs() << " dirs - "
171     << p.GetNumberHandledFiles() << " handled -"
172     << p.GetNumberAddedFiles() << " added";
173   return o;
174 }
175
176 // EOF
177 #endif  
178