#include <creaImageIOTreeHandlerImageAdder.h>
-#include <creaWx.h>
-#include <wx/dir.h>
-#include <wx/filename.h>
+#include <creaImageIOSystem.h>
+//#include <wx/dir.h>
+//#include <wx/filename.h>
-using namespace crea;
+#include "boost/filesystem.hpp"
+
+namespace fs = boost::filesystem;
+
+//using namespace crea;
namespace creaImageIO
{
//=====================================================================
bool TreeHandlerImageAdder::IsHandledFile( const std::string& filename)
{
- return (mReader.CanRead(filename,""));
+ return (mReader.CanRead(filename));
}
//=====================================================================
std::vector<std::string>::const_iterator i;
for (i=filenames.begin();i!=filenames.end();++i)
{
+
mProgress.IncNumberScannedFiles();
if (IsHandledFile(*i))
{
mProgress.IncNumberHandledFiles();
AddFile(*i);
-
-
- /*
- if (progress)
- {
- std::string mess("Adding ");
- mess += *i;
- if (!progress->Update( (int)(summary.added_images*999./nbf),
- std2wx(mess)))
- {
- // Some file was added hence we must return true !
- summary.cancelled_by_user = true;
- break;
- }
- }
- */
}
mProgressSignal(mProgress);
+ if (mProgress.GetStop()) break;
}
+ SetNumberOfChildren();
}
//=====================================================================
{
mProgress.Reset();
AddDirectoryRecursor( directory, recurse );
+ SetNumberOfChildren();
+ GimmickDebugMessage(3,mProgress<<std::endl);
}
- //=====================================================================
+ //=====================================================================
+ void TreeHandlerImageAdder::SetNumberOfChildren()
+ {
+ std::vector<tree::Node*> children = mTreeHandler->GetTree().GetChildrenList();
+ std::vector<tree::Node*>::iterator it;
+ for(it=children.begin();it!=children.end();++it)
+ {
+ SetNumberOfChildrenRecursor(*it);
+ }
+ }
+ //=====================================================================
+ void TreeHandlerImageAdder::SetNumberOfChildrenRecursor(tree::Node* node)
+ {
+ std::stringstream out;
+ out << node->GetChildrenList().size();
+ mTreeHandler->SetAttribute(node,"D1111_0011",out.str());
+ if(node->GetLevel()<mTreeHandler->GetTree().GetNumberOfLevels()-2)
+ {
+ std::vector<tree::Node*> children = node->GetChildrenList();
+ std::vector<tree::Node*>::iterator it;
+ for(it=children.begin();it!=children.end();++it)
+ {
+ SetNumberOfChildrenRecursor(*it);
+ }
+ }
+ }
//=====================================================================
void TreeHandlerImageAdder::AddFile( const std::string& filename )
{
-
+ GimmickDebugMessage(4,"Adding '"<<filename<<"'"<<std::endl);
std::map< std::string, std::string> attr;
mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
void TreeHandlerImageAdder::AddDirectoryRecursor(const std::string &dirpath,
bool recursive)
{
- // std::cout << "dir : "<<dirpath << std::endl;
- mProgress.IncNumberScannedDirs();
- /*
- if (progress)
+ GimmickDebugMessage(4,"Scanning '"<<dirpath<<"'"<<std::endl);
+ mProgress.IncNumberScannedDirs();
+
+ if ( !fs::exists( dirpath ) ) return;
+
+ fs::directory_iterator end_itr; // default construction yields past-the-end
+ for ( fs::directory_iterator itr( dirpath );
+ itr != end_itr;
+ ++itr )
{
- std::string mess("Parsing ");
- mess += dirpath;
- progress->Pulse(std2wx(mess));
+ // If is directory & recurse : do recurse
+ if ( fs::is_directory(itr->status()) )
+ {
+ if (recursive) AddDirectoryRecursor( itr->string(), recursive);
+ }
+ else
+ {
+ mProgress.IncNumberScannedFiles();
+ if (IsHandledFile(itr->string()))
+ {
+ mProgress.IncNumberHandledFiles();
+ AddFile( itr->string() );
+ }
+ mProgressSignal(mProgress);
+ if (mProgress.GetStop()) break;
+ }
}
- */
+
+ }
+
+ /*
+
std::string fileName;
std::string dirName = dirpath;
wxFileName wxffn(dir.GetName(),filename);
std::string ffn = wx2std(wxffn.GetFullPath());
- // std::cout << "file : "<<ffn << std::endl;
if (IsHandledFile(ffn))
{
mProgress.IncNumberHandledFiles();
- // std::cout << "handled : "<<ffn << std::endl;
AddFile( ffn );
}
- // std::cout << "signal " << std::endl;
mProgressSignal(mProgress);
- // std::cout << "cont " << std::endl;
cont = ( dir.GetNext(&filename) && (!mProgress.GetStop()) );
- // std::cout << "next" << std::endl;
}
// Recurse into subdirs
if ( recursive )
{
- // std::cout << "recurse " << std::endl;
cont = dir.GetFirst(&filename, wxEmptyString,
wxDIR_DIRS | wxDIR_HIDDEN );
while ( cont )
{
wxFileName wxffn(dir.GetName(),filename);
std::string ffn = wx2std(wxffn.GetFullPath());
- // std::cout << "goto "<<ffn << std::endl;
AddDirectoryRecursor( ffn, recursive);
cont = dir.GetNext(&filename);
}
}
-
- }
+
+ */
+
//=======================================================================