#endif
wxInitAllImageHandlers();
+ /*
creaImageIO::SetGimmickMessageLevel(9);
creaImageIO::SetGimmickDebugMessageLevel(9);
+ */
int image_type = GIMMICK_3D_IMAGE_SELECTION;
int threads = 1;
if (args.file_given)
{
- g.AddFile(handler,args.file_arg);
+ std::vector<std::string> files;
+ // TO DO : multiple files given
+ files.push_back(args.file_arg);
+ g.AddFiles(handler,files);
}
if (args.dir_given)
{
creaImageIOSQLiteTreeHandler
#
- creaImageIOImageFinder
+ creaImageIOTreeHandlerImageAdder
#
creaImageIOGimmick
#include <creaImageIOGimmick.h>
#include <creaImageIOSystem.h>
-#include <creaImageIOImageFinder.h>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
//==============================================================
Gimmick::Gimmick()
+ : mImageAdder(0)
{
RegisterGimmickMessageTypes();
}
//========================================================================
- /// Add a file to the local database
- void Gimmick::AddFile(const std::string& d, const std::string& f)
+ /// Add the files to the tree handler
+ void Gimmick::AddFiles(const std::string& d,
+ const std::vector<std::string>& filenames)
{
- GimmickMessage(2,"Adding file '"<<f<<"' to '"<<d<<"'"<<std::endl);
+ GimmickMessage(2,"Adding files to '"<<d<<"'"<<std::endl);
- ImageFinder finder(GetTreeHandler(d));
- if (finder.IsHandledFile(f))
- {
- finder.AddFile(f);
- }
- else
- {
- GimmickError("File '"<<f<<"' does not exist or is not handled");
- }
+ mImageAdder.SetTreeHandler(GetTreeHandler(d));
+ mImageAdder.AddFiles(filenames);
+
}
//========================================================================
GimmickMessage(2,"Adding dir '"<<f<<"' to '"<<d<<"' recurse:"
<<recurse<<std::endl);
- ImageFinder finder(GetTreeHandler(d));
-
- finder.AddDirectory(f,recurse);
+ mImageAdder.SetTreeHandler(GetTreeHandler(d));
+ mImageAdder.AddDirectory(f,recurse);
}
//========================================================================
#define __creaImageIOGimmick_h_INCLUDED__
#include <creaImageIOSQLiteTreeHandler.h>
+#include <creaImageIOTreeHandlerImageAdder.h>
namespace creaImageIO
{
/// Dtor
~Gimmick();
+ ///
+ typedef TreeHandlerImageAdder::Progress AddProgress;
+ typedef TreeHandlerImageAdder::ProgressCallbackType AddProgressCallbackType;
+
+ /// Adds the function f to the list of functions to call
+ /// when addition operations progres.
+ /// f is of type AddProgressCallbackType which is:
+ /// void (*AddProgressCallbackType)(AddProgress&)
+ /// To pass a member function 'f' of an instance 'c' of a class 'C'
+ /// as callback you have to 'bind' it, i.e. call:
+ /// ConnectAddProgressObserver ( boost::bind( &C::f , c, _1 ) );
+ void ConnectAddProgressObserver( AddProgressCallbackType callback )
+ { mImageAdder.ConnectProgressObserver(callback); }
+
+
+ ///
+ const AddProgress& GetAddProgress() const { return mImageAdder.GetProgress(); }
+
/// Initialize (read/creates databases, etc.)
void Initialize();
{ return mTreeHandlerMap; }
- /// Add a file to the given TreeHandler
- void AddFile(const std::string& handler, const std::string& filename);
+ /// Add the files to the given TreeHandler
+ void AddFiles(const std::string& handler,
+ const std::vector<std::string>& filenames);
+
/// Add a dir to the given TreeHandler
void AddDir(const std::string& handler, const std::string& path,
bool recurse);
void CreateUserSettingsDirectory();
const std::string& GetLocalDatabasePath();
+
+ //=============================================
private:
SQLiteTreeHandler* mLocalDatabase;
TreeHandlerMapType mTreeHandlerMap;
std::string mHomeDirectory;
std::string mUserSettingsDirectory;
std::string mLocalDatabasePath;
-
+
+ TreeHandlerImageAdder mImageAdder;
};
// EO class Gimmick
//=======================================================================
namespace creaImageIO
{
+ //======================================================================
// CTor
GimmickView::GimmickView(Gimmick* gimmick)
: mGimmick(gimmick)
GimmickDebugMessage(1,"GimmickView::GimmickView"
<<std::endl);
}
+ //======================================================================
+ //======================================================================
/// Destructor
GimmickView::~GimmickView()
{
GimmickDebugMessage(1,"GimmickView::~GimmickView"
<<std::endl);
}
-
-
+ //======================================================================
+
+ //======================================================================
/// Initializes the view :
/// Creates the TreeViews for all the TreeHandler of the Controller
///
void GimmickView::Initialize()
{
}
+ //======================================================================
+ //======================================================================
/// Finalize
void GimmickView::Finalize()
{
}
+ //======================================================================
+ //======================================================================
/// Create the tree views
void GimmickView::CreateTreeViews()
{
this->CreateTreeView(i->second);
}
}
+ //======================================================================
+ //======================================================================
+ /// Updates the TreeView of given name from level l to bottom
+ /// (calls the virtual method TreeView::Update())
+ void GimmickView::UpdateTreeViewLevel(const std::string& t, int l)
+ {
+ TreeViewMapType::iterator i;
+ i = GetTreeViewMap().find(t);
+ if ( i == GetTreeViewMap().end() )
+ {
+ GimmickError("INTERNAL ERROR : GimmickView::UpdateTreeView : '"
+ <<t<<"' is not in TreeViewMap");
+ }
+ i->second->UpdateLevel(l);
+ }
+ //======================================================================
} // EO namespace creaImageIO
void CreateTreeViews();
/// Create the tree view for TreeHandler provided
- virtual void CreateTreeView( TreeHandler* h) { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
+ virtual void CreateTreeView( TreeHandler*)
+ { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
+
+ /// Updates the TreeView of given name from level l to bottom
+ /// (calls the virtual method TreeView::UpdateLevel(l))
+ virtual void UpdateTreeViewLevel(const std::string&, int l);
private:
/// Controller which manages the interaction with the model
+++ /dev/null
-#include <creaImageIOImageFinder.h>
-#include <creaWx.h>
-#include <wx/dir.h>
-#include <wx/filename.h>
-
-using namespace crea;
-
-namespace creaImageIO
-{
- //====================================================================
- // Ctor
- ImageFinder::ImageFinder(TreeHandler* tree)
- : mTreeHandler(tree)
- {
- }
- // Dtor
- ImageFinder::~ImageFinder()
- {
- }
- //====================================================================
-
- //=====================================================================
- bool ImageFinder::IsHandledFile( const std::string& filename)
- {
- return (mReader.CanRead(filename,""));
- }
- //=====================================================================
-
- //=====================================================================
- bool ImageFinder::AddFiles( const std::vector<std::string>& filenames)
- // wxProgressDialog* progress,
- // UpdateSummary& summary)
- {
-
- unsigned int nbf = filenames.size();
- std::vector<std::string>::const_iterator i;
- for (i=filenames.begin();i!=filenames.end();++i)
- {
- // summary.scanned_files++;
- if (IsHandledFile(*i))
- {
- // summary.handled_images++;
- AddFile(*i);//,summary);
- /*
- 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;
- }
- }
- */
- }
- }
-
- return true;
- }
- //=====================================================================
-
- //=====================================================================
- bool ImageFinder::AddFile( const std::string& filename )
- // UpdateSummary& summary)
- {
-
- std::map< std::string, std::string> attr;
- mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
-
- mReader.ReadAttributes(filename,attr);
-
- // image->SetFieldValue("FullFileName",filename);
-
- int lev = mTreeHandler->AddBranch(attr);
-
- // TO DO : update the summary according to lev
-
- return true;
- }
- //=====================================================================
-
- //=====================================================================
- /**
- * \brief Explore a directory with possibility of recursion
- * return number of files read
- * @param dirpath directory to explore
- * @param recursive whether we want recursion or not
- */
- void ImageFinder::ParseDirectory( const std::string &dirpath,
- std::vector<std::string> &Filenames,
- bool recursive)
- // wxProgressDialog* progress,
- // UpdateSummary& summary)
-
- {
- /*
- if (progress)
- {
- std::string mess("Parsing ");
- mess += dirpath;
- progress->Pulse(std2wx(mess));
- }
- */
- std::string fileName;
- std::string dirName = dirpath;
-
- // summary.scanned_dirs++;
-
- wxDir dir( std2wx(dirpath) );
-
- if ( !dir.IsOpened() )
- {
- // deal with the error here - wxDir would already log an error message
- // explaining the exact reason of the failure
- return;
- }
-
- wxString filename;
-
- bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN );
- while ( cont )
- {
- /*
- if ((progress)&&( sw.Time() >= 250 ))
- {
- // std::cout << "PULSE"<<std::endl;
- sw.Start(0);
- if (!progress->Pulse())
- {
- summary.cancelled_by_user = true;
- break;
- }
- }
- */
- // summary.scanned_files++;
- wxFileName wxffn(dir.GetName(),filename);
- std::string ffn = wx2std(wxffn.GetFullPath());
- // std::cout << ffn << std::endl;
- if (mReader.CanRead(ffn,""))
- {
- Filenames.push_back( ffn );
- // summary.handled_images++;
- }
- cont = dir.GetNext(&filename);
- }
-
- // Recurse into subdirs
- if ( recursive )
- {
- cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS | wxDIR_HIDDEN );
- while ( cont )
- {
-
- wxFileName wxffn(dir.GetName(),filename);
- std::string ffn = wx2std(wxffn.GetFullPath());
-
- // std::cout << "dir="<< ffn<< std::endl;
-
- ParseDirectory( ffn,
- Filenames,
- recursive);
- // progress,
- // summary);
- // if (summary.cancelled_by_user) break;
-
- cont = dir.GetNext(&filename);
- }
- }
-
- }
- //=======================================================================
-
-
- //=====================================================================
- bool ImageFinder::AddDirectory( const std::string& directory,
- bool recurse)
- // wxProgressDialog* progress,
- // UpdateSummary& summary
- // )
- {
- // std::cout << "** ImageFinder::AddDirectory"
- // << " '"<<directory<<"'"<<std::endl;
- // std::cout << "------ Parsing directory ------"<<std::endl;
- /*
- if (progress)
- {
- progress->Pulse();
- }
-
- for (int swi=0;swi<10;swi++)
- {
- msw[swi].Start(0);
- msw[swi].Pause();
- }
-
- // Parse directory
- wxStopWatch sw;
-
- bool was_canceled_by_user(false);
- */
- std::vector<std::string> filenames;
- ParseDirectory( directory,
- filenames,
- recurse );
- //,
- // progress,
- // summary);
- /*
- if ( summary.cancelled_by_user )
- {
- return false;
- }
-
- summary.parse_time = sw.Time();
-
-
- summary.added_images = 0;
- */
- unsigned int nbf = filenames.size(); // , nf = 0;
- std::vector<std::string>::iterator i;
- for (i=filenames.begin();i!=filenames.end();++i)
- {
- AddFile(*i); //,summary);
- /*
- 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;
- }
- }
- */
- }
-
- /*
- sw.Pause();
- msw[0].Pause();
- msw[1].Pause();
- msw[2].Pause();
-
- summary.total_time = sw.Time();
- summary.file_scan_time = msw[1].Time();
- summary.update_database_time = msw[2].Time();
- summary.update_structs_time =
- summary.total_time -
- summary.parse_time -
- summary.file_scan_time -
- summary.update_database_time;
- */
- return true;
- }
- //=====================================================================
-
-
-
-}
+++ /dev/null
-#ifndef __creaImageIOImageFinder_h_INCLUDED__
-#define __creaImageIOImageFinder_h_INCLUDED__
-
-#include <creaImageIOTreeHandler.h>
-#include <creaImageIOImageReader.h>
-#include <wx/wx.h>
-#include <wx/progdlg.h>
-
-namespace creaImageIO
-{
- /**
- * \ingroup Model
- */
-
- //=======================================================================
- /// Parses (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)
-
- class ImageFinder
- {
- public:
- //====================================================================
- /// Ctor
- ImageFinder(TreeHandler* tree);
- /// Dtor
- ~ImageFinder();
- //====================================================================
- /*
- struct UpdateSummary
- {
- int scanned_dirs;
- int scanned_files;
- int handled_images;
- int added_images;
-
- int added_patients;
- int added_studies;
- int added_series;
-
- long parse_time;
- long file_scan_time;
- long update_structs_time;
- long update_database_time;
- long total_time;
- bool cancelled_by_user;
-
- UpdateSummary() :
- scanned_dirs(0),
- scanned_files(0),
- handled_images(0),
- added_images(0),
- added_patients(0),
- added_studies(0),
- added_series(0),
- parse_time(0),
- file_scan_time(0),
- update_structs_time(0),
- update_database_time(0),
- total_time(0),
- cancelled_by_user(false)
- {}
- };
- */
-
- ///Returns if the file can be read or not
- bool IsHandledFile( const std::string& filename);
- bool AddFile( const std::string& filename );
- // UpdateSummary& summary );
- bool AddFiles( const std::vector<std::string>& filename );
- // wxProgressDialog* progress,
- // UpdateSummary& summary);
- bool AddDirectory( const std::string& directory,
- bool recurse );
- // wxProgressDialog* progress,
- // UpdateSummary& summary
- // );
-
- void ParseDirectory( const std::string& directory,
- std::vector<std::string> &Filenames,
- bool recurse );
- // wxProgressDialog* progress,
- // UpdateSummary& summary);
- private:
- TreeHandler* mTreeHandler;
- ImageReader mReader;
- // wxStopWatch msw[10];
-
- };
- // EO class ImageFinder
- //=======================================================================
-
-
-} // EO namespace creaImageIO
-
-// EOF
-#endif
-
--- /dev/null
+#include <creaImageIOTreeHandlerImageAdder.h>
+#include <creaWx.h>
+#include <wx/dir.h>
+#include <wx/filename.h>
+
+using namespace crea;
+
+namespace creaImageIO
+{
+ //====================================================================
+ // Ctor
+ TreeHandlerImageAdder::TreeHandlerImageAdder(TreeHandler* tree)
+ : mTreeHandler(tree)
+ {
+ }
+ // Dtor
+ TreeHandlerImageAdder::~TreeHandlerImageAdder()
+ {
+ }
+ //====================================================================
+
+ //====================================================================
+ void TreeHandlerImageAdder::ConnectProgressObserver(ProgressCallbackType callback)
+ {
+ mProgressSignal.connect(callback);
+ }
+ //====================================================================
+
+ //=====================================================================
+ bool TreeHandlerImageAdder::IsHandledFile( const std::string& filename)
+ {
+ return (mReader.CanRead(filename,""));
+ }
+ //=====================================================================
+
+ //=====================================================================
+ void TreeHandlerImageAdder::AddFiles( const std::vector<std::string>& filenames)
+ {
+ mProgress.Reset();
+
+ unsigned int nbf = filenames.size();
+ 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);
+ }
+ }
+ //=====================================================================
+
+ //=====================================================================
+ void TreeHandlerImageAdder::AddDirectory( const std::string& directory,
+ bool recurse)
+ {
+ mProgress.Reset();
+ AddDirectoryRecursor( directory, recurse );
+ }
+ //=====================================================================
+
+
+
+
+ //=====================================================================
+ void TreeHandlerImageAdder::AddFile( const std::string& filename )
+ {
+
+ std::map< std::string, std::string> attr;
+ mTreeHandler->GetTree().GetDescriptor().BuildAttributeMap(attr);
+
+ mReader.ReadAttributes(filename,attr);
+
+ int lev = mTreeHandler->AddBranch(attr);
+
+ // update the progress according to lev
+ if (lev<mTreeHandler->GetTree().GetNumberOfLevels())
+ mProgress.IncNumberAddedFiles();
+ }
+ //=====================================================================
+
+ //=====================================================================
+ void TreeHandlerImageAdder::AddDirectoryRecursor(const std::string &dirpath,
+ bool recursive)
+ {
+ // std::cout << "dir : "<<dirpath << std::endl;
+ mProgress.IncNumberScannedDirs();
+ /*
+ if (progress)
+ {
+ std::string mess("Parsing ");
+ mess += dirpath;
+ progress->Pulse(std2wx(mess));
+ }
+ */
+ std::string fileName;
+ std::string dirName = dirpath;
+
+ wxDir dir( std2wx(dirpath) );
+
+ if ( !dir.IsOpened() )
+ {
+ // deal with the error here - wxDir would already log an error message
+ // explaining the exact reason of the failure
+ return;
+ }
+
+ wxString filename;
+
+ bool cont = dir.GetFirst(&filename, wxEmptyString,
+ wxDIR_FILES | wxDIR_HIDDEN );
+ while ( cont )
+ {
+ mProgress.IncNumberScannedFiles();
+
+ 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);
+ }
+ }
+
+ }
+ //=======================================================================
+
+
+
+}
--- /dev/null
+#ifndef __creaImageIOTreeHandlerImageAdder_h_INCLUDED__
+#define __creaImageIOTreeHandlerImageAdder_h_INCLUDED__
+
+#include <creaImageIOTreeHandler.h>
+#include <creaImageIOImageReader.h>
+#include <wx/wx.h>
+#include <wx/progdlg.h>
+// Signal/slot mechanism for progress events
+#include <boost/signal.hpp>
+#include <boost/bind.hpp>
+
+
+namespace creaImageIO
+{
+ /**
+ * \ingroup Model
+ */
+
+ //=======================================================================
+ /// 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)
+
+ class TreeHandlerImageAdder
+ {
+ public:
+ //====================================================================
+ /// Ctor
+ TreeHandlerImageAdder(TreeHandler* tree);
+ /// Dtor
+ ~TreeHandlerImageAdder();
+ /// Sets the TreeHandler
+ void SetTreeHandler(TreeHandler* tree) { mTreeHandler = tree;}
+ //====================================================================
+
+ //====================================================================
+ /// Structure which holds progress information
+ /// To stop the image adder use SetStop()
+ class Progress
+ {
+ public:
+ Progress() { Reset(); }
+ ~Progress() {}
+
+ void Reset()
+ {
+ mStop = false;
+ mNumberScannedFiles = 0;
+ mNumberScannedDirs = 0;
+ mNumberHandledFiles = 0;
+ mNumberAddedFiles = 0;
+ }
+
+ int GetNumberScannedFiles() { return mNumberScannedFiles; }
+ int GetNumberScannedDirs() { return mNumberScannedDirs; }
+ int GetNumberHandledFiles() { return mNumberHandledFiles; }
+ int GetNumberAddedFiles() { return mNumberAddedFiles; }
+
+ void IncNumberScannedFiles() { mNumberScannedFiles++; }
+ void IncNumberScannedDirs() { mNumberScannedDirs++; }
+ void IncNumberHandledFiles() { mNumberHandledFiles++; }
+ void IncNumberAddedFiles() { mNumberAddedFiles++; }
+
+ void SetStop() { mStop = true; }
+ bool GetStop() { return mStop; }
+
+ private:
+ bool mStop;
+ int mNumberScannedFiles;
+ int mNumberScannedDirs;
+ int mNumberHandledFiles;
+ int mNumberAddedFiles;
+ };
+ //=============================================
+
+ //=============================================
+ const Progress& GetProgress() const { return mProgress; }
+ //=============================================
+
+ //=============================================
+ // typedef boost::signals::trackable ProgressObserverType;
+ typedef boost::signal<void (Progress&)> ProgressSignalType;
+ typedef ProgressSignalType::slot_function_type ProgressCallbackType;
+ //=============================================
+
+ //==================================================================
+ /// Adds the function f to the list of functions to call
+ /// when the addition progresses.
+ /// f is of type ProgressCallbackType which is:
+ /// void (*ProgressCallbackType)(Progress&)
+ /// To pass a member function 'f' of an instance 'c' of a class 'C'
+ /// as callback you have to 'bind' it, i.e. call:
+ /// ConnectProgressObserver ( boost::bind( &C::f , c, _1 ) );
+ void ConnectProgressObserver(ProgressCallbackType callback);
+ //==================================================================
+
+ //====================================================================
+ /// Returns if the file can be read or not
+ bool IsHandledFile( const std::string& filename);
+ /// Adds a list of files to the TreeHandler
+ void AddFiles( const std::vector<std::string>& filename );
+ /// (Recursively) adds the files of a directory to the TreeHandler
+ void AddDirectory( const std::string& directory,
+ bool recurse );
+ //====================================================================
+
+ private:
+
+ /// Adds a single file to the TreeHandler
+ /// **WITHOUT** testing werther it is handled or not
+ /// hence you have to call IsHandledFile before using AddFile!
+ void AddFile( const std::string& filename );
+
+ /// Recursive method which does the main job for AddDirectory
+ void AddDirectoryRecursor( const std::string& directory,
+ bool recurse );
+
+
+ TreeHandler* mTreeHandler;
+ ImageReader mReader;
+
+ Progress mProgress;
+ ProgressSignalType mProgressSignal;
+ };
+ // EO class TreeHandlerImageAdder
+ //=======================================================================
+
+
+} // EO namespace creaImageIO
+
+// EOF
+#endif
+
#define __creaImageIOTreeView_h_INCLUDED__
#include <creaImageIOTreeHandler.h>
-
+#include <creaImageIOSystem.h>
namespace creaImageIO
{
/**
/// Updates the view of a level given the selected items of upper level
- virtual void UpdateLevel( int ) {}
+ virtual void UpdateLevel( int )
+ { GimmickError("INTERNAL ERROR : TreeView::UpdateLevel not overloaded");}
protected:
TreeHandler* GetTreeHandler() { return mTreeHandler; }
// The ids of the different tools
enum
{
- TOOL_ADDFILE_ID = 1,
+ TOOL_ADDFILES_ID = 1,
TOOL_ADDDIR_ID = 2,
TOOL_REMOVE_ID = 3,
TOOL_ADDDATABASE_ID = 4,
int image_type,
int number_of_threads)
: wxPanel(parent,id,pos,size),
- GimmickView(gimmick)
+ GimmickView(gimmick),
+ mProgressDialog(0)
{
GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
<<std::endl);
+ // Sets the current directory to the home dir
+ mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
+
+ // Connect the AddProgress callback
+ gimmick->ConnectAddProgressObserver
+ ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
+
// Create the list of icons (mIcon)
CreateIconList();
mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
style);
- mToolAddFile = mToolBar->AddTool( TOOL_ADDFILE_ID,
+ mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
_T("Add file(s)"),
mIcon->GetBitmap(Icon_page_down),
- _T("Add some file(s) to database")
+ _T("Add one or more file to database")
);
mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
_T("Add folder"),
}
}
}
+ //=================================================
//=================================================
- void WxGimmickView::OnAddFile(wxCommandEvent& event)
+ void WxGimmickView::OnAddFiles(wxCommandEvent& event)
{
long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
std::string wc("*.*");
wxFileDialog* FD = new wxFileDialog( 0,
_T("Select file"),
- "",
_T(""),
- std2wx(wc),
+ _T(""),
+ crea::std2wx(wc),
style,
wxDefaultPosition);
if (FD->ShowModal()==wxID_OK)
{
+ wxBusyCursor busy;
wxArrayString files;
FD->GetPaths(files);
GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
}
+ mProgressDialog =
+ new wxProgressDialog(_T("Adding file(s)"),
+ _T(""),
+ 1000,
+ this,
+ wxPD_ELAPSED_TIME |
+ wxPD_ESTIMATED_TIME |
+ wxPD_REMAINING_TIME |
+ wxPD_CAN_ABORT );
+
+ // TO DO : select the current tree handler
+ mGimmick->AddFiles("Local database",filenames);
+
+ mProgressDialog->Pulse(_T("Updating view..."));
+
+ UpdateTreeViewLevel("Local database",1);
+ delete mProgressDialog;
/*
TreeItemData *data =
}
//=================================================
+ //=================================================
+ void WxGimmickView::OnAddDir(wxCommandEvent& event)
+ {
+ long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
+ wxDirDialog* FD =
+ new wxDirDialog( 0,
+ _T("Select directory"),
+ mCurrentDirectory,
+ style);
+
+ if (FD->ShowModal()==wxID_OK)
+ {
+
+ bool recurse = false;
+ if (wxMessageBox(_T("Recurse into sub-directories ?"),
+ _T("Scan directory"),
+ wxYES_NO,this ) == wxYES)
+ {
+ recurse = true;
+ }
+
+ wxBusyCursor busy;
+ wxString title(_T("Adding directory"));
+ if (recurse)
+ title = _T("Adding directory (recursive)");
+ mProgressDialog =
+ new wxProgressDialog(_T("Adding directory"),
+ _T(""),
+ 1000,
+ this,
+ wxPD_ELAPSED_TIME |
+ wxPD_ESTIMATED_TIME |
+ wxPD_REMAINING_TIME |
+ wxPD_CAN_ABORT );
+ std::string dirname = wx2std (FD->GetPath()) ;
+ mCurrentDirectory = FD->GetPath();
+
+ // TO DO : select the current tree handler
+ mGimmick->AddDir("Local database",dirname,recurse);
+
+ mProgressDialog->Pulse(_T("Updating view..."));
+
+ UpdateTreeViewLevel("Local database",1);
+ delete mProgressDialog;
+
+ }
+ }
+ //=================================================
+
+ //=================================================
+ /// AddProgress Gimmick callback
+ void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
+ {
+
+ char mess[200];
+ sprintf(mess,"%i dirs - %i files - %i handled - %i added",
+ p.GetNumberScannedDirs(),
+ p.GetNumberScannedFiles(),
+ p.GetNumberHandledFiles(),
+ p.GetNumberAddedFiles());
+ std::cout << "OnAddProgress "<<mess<<std::endl;
+ wxString s(wxString::From8BitData(mess));
+ // std::cout << "Pulse"<<std::endl;
+ if (!mProgressDialog->Pulse(s))
+ {
+ p.SetStop();
+ }
+ // std::cout << "OnAddProgress ok"<<std::endl;
+ }
+ //=================================================
+
+ //=================================================
BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
- EVT_TOOL(TOOL_ADDFILE_ID, WxGimmickView::OnAddFile)
- END_EVENT_TABLE()
+ EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
+ EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
+ END_EVENT_TABLE()
+ //=================================================
} // EO namespace creaImageIO
wxImageList * mIcon;
void CreateIconList();
- Gimmick * mGimmick;
- /// Callback for adding a file
- void OnAddFile(wxCommandEvent& event);
+ Gimmick * mGimmick;
+ /// Callback for adding files
+ void OnAddFiles(wxCommandEvent& event);
+ /// Callback for adding dir
+ void OnAddDir(wxCommandEvent& event);
- DECLARE_EVENT_TABLE()
+ /// AddProgress Gimmick callback
+ void OnAddProgress( Gimmick::AddProgress& );
+ /// Progress dialog
+ wxProgressDialog* mProgressDialog;
+
+
+ wxString mCurrentDirectory;
+
+ DECLARE_EVENT_TABLE()
};
// EO class WxGimmickView
//=====================================================================