1 #include <creaImageIOTreeHandlerImageAdder.h>
4 #include <wx/filename.h>
10 //====================================================================
12 TreeHandlerImageAdder::TreeHandlerImageAdder(TreeHandler* tree)
17 TreeHandlerImageAdder::~TreeHandlerImageAdder()
20 //====================================================================
22 //====================================================================
23 void TreeHandlerImageAdder::ConnectProgressObserver(ProgressCallbackType callback)
25 mProgressSignal.connect(callback);
27 //====================================================================
29 //=====================================================================
30 bool TreeHandlerImageAdder::IsHandledFile( const std::string& filename)
32 return (mReader.CanRead(filename,""));
34 //=====================================================================
36 //=====================================================================
37 void TreeHandlerImageAdder::AddFiles( const std::vector<std::string>& filenames)
41 unsigned int nbf = filenames.size();
42 std::vector<std::string>::const_iterator i;
43 for (i=filenames.begin();i!=filenames.end();++i)
45 mProgress.IncNumberScannedFiles();
46 if (IsHandledFile(*i))
48 mProgress.IncNumberHandledFiles();
55 std::string mess("Adding ");
57 if (!progress->Update( (int)(summary.added_images*999./nbf),
60 // Some file was added hence we must return true !
61 summary.cancelled_by_user = true;
67 mProgressSignal(mProgress);
70 //=====================================================================
72 //=====================================================================
73 void TreeHandlerImageAdder::AddDirectory( const std::string& directory,
77 AddDirectoryRecursor( directory, recurse );
79 //=====================================================================
84 //=====================================================================
85 void TreeHandlerImageAdder::AddFile( const std::string& filename )
88 std::map< std::string, std::string> attr;
89 mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
91 mReader.ReadAttributes(filename,attr);
93 int lev = mTreeHandler->AddBranch(attr);
95 // update the progress according to lev
96 if (lev<mTreeHandler->GetTree().GetNumberOfLevels())
97 mProgress.IncNumberAddedFiles();
99 //=====================================================================
101 //=====================================================================
102 void TreeHandlerImageAdder::AddDirectoryRecursor(const std::string &dirpath,
105 // std::cout << "dir : "<<dirpath << std::endl;
106 mProgress.IncNumberScannedDirs();
110 std::string mess("Parsing ");
112 progress->Pulse(std2wx(mess));
115 std::string fileName;
116 std::string dirName = dirpath;
118 wxDir dir( std2wx(dirpath) );
120 if ( !dir.IsOpened() )
122 // deal with the error here - wxDir would already log an error message
123 // explaining the exact reason of the failure
129 bool cont = dir.GetFirst(&filename, wxEmptyString,
130 wxDIR_FILES | wxDIR_HIDDEN );
133 mProgress.IncNumberScannedFiles();
135 wxFileName wxffn(dir.GetName(),filename);
136 std::string ffn = wx2std(wxffn.GetFullPath());
137 // std::cout << "file : "<<ffn << std::endl;
138 if (IsHandledFile(ffn))
140 mProgress.IncNumberHandledFiles();
141 // std::cout << "handled : "<<ffn << std::endl;
144 // std::cout << "signal " << std::endl;
145 mProgressSignal(mProgress);
146 // std::cout << "cont " << std::endl;
147 cont = ( dir.GetNext(&filename) && (!mProgress.GetStop()) );
148 // std::cout << "next" << std::endl;
151 // Recurse into subdirs
154 // std::cout << "recurse " << std::endl;
155 cont = dir.GetFirst(&filename, wxEmptyString,
156 wxDIR_DIRS | wxDIR_HIDDEN );
159 wxFileName wxffn(dir.GetName(),filename);
160 std::string ffn = wx2std(wxffn.GetFullPath());
161 // std::cout << "goto "<<ffn << std::endl;
162 AddDirectoryRecursor( ffn, recursive);
163 cont = dir.GetNext(&filename);
168 //=======================================================================