1 #include <creaImageIOImageFinder.h>
4 #include <wx/filename.h>
10 //====================================================================
12 ImageFinder::ImageFinder(TreeHandler* tree)
17 ImageFinder::~ImageFinder()
20 //====================================================================
22 //=====================================================================
23 bool ImageFinder::IsHandledFile( const std::string& filename)
25 return (mReader.CanRead(filename,""));
27 //=====================================================================
29 //=====================================================================
30 bool ImageFinder::AddFiles( const std::vector<std::string>& filenames,
31 wxProgressDialog* progress,
32 UpdateSummary& summary)
34 for (int swi=0;swi<10;swi++)
44 summary.added_images = 0;
45 unsigned int nbf = filenames.size();
46 std::vector<std::string>::const_iterator i;
47 for (i=filenames.begin();i!=filenames.end();++i)
49 summary.scanned_files++;
50 if (IsHandledFile(*i))
52 summary.handled_images++;
57 std::string mess("Adding ");
59 if (!progress->Update( (int)(summary.added_images*999./nbf),
62 // Some file was added hence we must return true !
63 summary.cancelled_by_user = true;
76 summary.total_time = sw.Time();
77 summary.file_scan_time = msw[1].Time();
78 summary.update_database_time = msw[2].Time();
79 summary.update_structs_time =
82 summary.file_scan_time -
83 summary.update_database_time;
87 //=====================================================================
89 //=====================================================================
90 bool ImageFinder::AddFile( const std::string& filename,
91 UpdateSummary& summary)
94 std::map< std::string, std::string> attr;
95 mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
98 mReader.ReadAttributes(filename,attr);
99 // mReader.ReadDicomInfo(filename,image);
102 // image->SetFieldValue("FullFileName",filename);
104 int lev = mTreeHandler->AddBranch(attr);
106 // TO DO : update the summary according to lev
110 //=====================================================================
112 //=====================================================================
114 * \brief Explore a directory with possibility of recursion
115 * return number of files read
116 * @param dirpath directory to explore
117 * @param recursive whether we want recursion or not
119 void ImageFinder::ParseDirectory( const std::string &dirpath,
120 std::vector<std::string> &Filenames,
122 wxProgressDialog* progress,
123 UpdateSummary& summary)
128 std::string mess("Parsing ");
130 progress->Pulse(std2wx(mess));
136 std::string fileName;
137 std::string dirName = dirpath;
139 summary.scanned_dirs++;
141 wxDir dir( std2wx(dirpath) );
143 if ( !dir.IsOpened() )
145 // deal with the error here - wxDir would already log an error message
146 // explaining the exact reason of the failure
152 bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN );
155 if ((progress)&&( sw.Time() >= 250 ))
157 // std::cout << "PULSE"<<std::endl;
159 if (!progress->Pulse())
161 summary.cancelled_by_user = true;
166 summary.scanned_files++;
167 wxFileName wxffn(dir.GetName(),filename);
168 std::string ffn = wx2std(wxffn.GetFullPath());
169 // std::cout << ffn << std::endl;
170 if (mReader.CanRead(ffn,""))
172 Filenames.push_back( ffn );
173 summary.handled_images++;
175 cont = dir.GetNext(&filename);
178 // Recurse into subdirs
181 cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN );
185 wxFileName wxffn(dir.GetName(),filename);
186 std::string ffn = wx2std(wxffn.GetFullPath());
188 // std::cout << "dir="<< ffn<< std::endl;
195 if (summary.cancelled_by_user) break;
197 cont = dir.GetNext(&filename);
202 //=======================================================================
205 //=====================================================================
206 bool ImageFinder::AddDirectory( const std::string& directory,
208 wxProgressDialog* progress,
209 UpdateSummary& summary
212 // std::cout << "** ImageFinder::AddDirectory"
213 // << " '"<<directory<<"'"<<std::endl;
214 // std::cout << "------ Parsing directory ------"<<std::endl;
221 for (int swi=0;swi<10;swi++)
230 bool was_canceled_by_user(false);
231 std::vector<std::string> filenames;
232 ParseDirectory( directory,
238 if ( summary.cancelled_by_user )
243 summary.parse_time = sw.Time();
246 summary.added_images = 0;
247 unsigned int nbf = filenames.size(); // , nf = 0;
248 std::vector<std::string>::iterator i;
249 for (i=filenames.begin();i!=filenames.end();++i)
255 std::string mess("Adding ");
257 if (!progress->Update( (int)(summary.added_images*999./nbf),
260 // Some file was added hence we must return true !
261 summary.cancelled_by_user = true;
273 summary.total_time = sw.Time();
274 summary.file_scan_time = msw[1].Time();
275 summary.update_database_time = msw[2].Time();
276 summary.update_structs_time =
279 summary.file_scan_time -
280 summary.update_database_time;
284 //=====================================================================