1 #include <creaImageIOWxGimmickView.h>
2 #include <creaImageIOWxTreeView.h>
3 #include <creaImageIOSystem.h>
4 #include <creaImageIOWxCustomizeConfigPanel.h>
5 #include <creaImageIOWxListenerPanel.h>
9 #include "icons/accept.xpm"
10 #include "icons/add.xpm"
11 #include "icons/folder-down.xpm"
12 #include "icons/page-down.xpm"
13 #include "icons/remove.xpm"
14 #include "icons/database-add.xpm"
15 #include "icons/create-database.xpm"
16 #include "icons/help.xpm"
17 #include "icons/synchronize.xpm"
18 #include "icons/settings.xpm"
19 #include "icons/tools.xpm"
21 #include <wx/imaglist.h>
22 #include <wx/popupwin.h>
23 #include<boost/filesystem/operations.hpp>
28 //======================================================================
29 // The ids of the different tools
35 TOOL_ADDDATABASE_ID = 4,
37 TOOL_SYNCHRONIZE_ID = 6,
42 //======================================================================
44 //================================================================
46 const int icon_number = 11;
63 //================================================================
65 //================================================================
67 const icon_id Icon[5] = { Icon_Database,
73 //================================================================
76 //======================================================================
78 WxGimmickView::WxGimmickView(Gimmick* gimmick,
81 const wxPoint& pos, const wxSize& size,
84 int number_of_threads)
85 : wxPanel(parent,id,pos,size),
86 GimmickView(gimmick, number_of_threads),
90 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
92 // Sets the current directory to the home dir
93 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
95 // Connect the AddProgress callback
96 gimmick->ConnectAddProgressObserver
97 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
99 // Create the list of icons (mIcon)
103 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
105 // Create the tool bar
107 sizer->Add( mToolBar ,0, wxGROW ,0);
109 // Split part below toolbar into notebook for views and panel
110 // for preview, messages...
111 mSplitter = new wxSplitterWindow( this , -1);
115 mNotebook = new wxNotebook(mSplitter,
116 -1,wxDefaultPosition, wxDefaultSize, 0);
122 mSelectionMaxDimension= max_dim;
123 mSelectionMinDimension= min_dim;
129 mBottomPanel = new wxPanel(mSplitter,-1);
131 wxBoxSizer *bottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
135 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
136 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
137 mViewer->SetImageVector(pointers);
138 mViewer->StartPlayer();
141 bottom_sizer->Add(mViewer,1,wxGROW,1);
144 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
145 bottom_sizer->Add(mText,0,wxGROW,0);
149 mBottomPanel->SetSizer(bottom_sizer);
152 int hsize = size.GetHeight();
154 int top_minsize = 450;
155 int bottom_minsize = 50;
157 mSplitter->SetMinimumPaneSize( bottom_minsize );
158 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
161 sizer->Add( mSplitter,1,wxGROW ,0);
167 mListener=new Listener();
168 mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount , this, _1 ) );
175 //======================================================================
177 //======================================================================
179 WxGimmickView::~WxGimmickView()
181 // stop the viewer before application exit.
182 mViewer->StopPlayer();
183 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
185 if(mListener->IsAlive())
190 //======================================================================
192 //======================================================================
193 /// Creates the tool bar
194 void WxGimmickView::CreateToolBar()
196 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
197 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
200 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
201 _T("Create database"),
202 mIcon->GetBitmap(Icon_create_database),
203 _T("Create DB from an Attributes Descriptor file")
205 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
207 mIcon->GetBitmap(Icon_page_down),
208 _T("Add one or more file to database")
210 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
212 mIcon->GetBitmap(Icon_folder_down),
213 _T("Add the content of a folder to database")
215 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
217 mIcon->GetBitmap(Icon_database_add),
218 _T("Open a local or distant database")
220 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
222 mIcon->GetBitmap(Icon_remove),
223 _T("Remove selected items")
225 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
227 mIcon->GetBitmap(Icon_synchronize),
228 _T("Synchronizes the database with disk")
230 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
232 mIcon->GetBitmap(Icon_help),
233 _T("Open help window")
235 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
236 _T("System settings"),
237 mIcon->GetBitmap(Icon_settings),
238 _T("Allows the modification of various system settings")
240 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
242 mIcon->GetBitmap(Icon_tools),
243 _T("Applies tools to images")
245 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
249 //======================================================================
252 //======================================================================
253 /// Create the tree view for TreeHandler provided
254 void WxGimmickView::CreateTreeView( TreeHandler* h)
256 std::string name(h->GetTree().GetAttribute("Name"));
257 GimmickMessage(2,"Creating the tree view for '"<<
258 name<<"'"<<std::endl);
259 // Create the WxTreeView
260 WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
262 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
263 // ALREADY IN THE MAP
264 GetTreeViewMap()[name] = view;
267 mNotebook->AddPage( view, crea::std2wx(name) );
271 //======================================================================
272 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
274 std::vector<std::string> files;
275 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
276 ReadImagesNotThreaded(s,files,dim);
278 //======================================================================
280 //======================================================================
281 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
283 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
285 //======================================================================
287 //======================================================================
288 void WxGimmickView::GetImages(int dim,
289 const std::vector<std::string>& files,
290 std::vector<vtkImageData*>& s)
292 ReadImagesNotThreaded(s,files,dim);
294 //======================================================================
297 //=================================================
298 void WxGimmickView::CreateIconList()
300 // Size of the icons;
304 // should correspond to Icon_xxx enum
305 icons[Icon_accept] = wxIcon(accept_xpm);
306 icons[Icon_add] = wxIcon(add_xpm);
307 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
308 icons[Icon_page_down] = wxIcon(page_down_xpm);
309 icons[Icon_remove] = wxIcon(remove_xpm);
310 icons[Icon_database_add] = wxIcon(database_add_xpm);
311 icons[Icon_help] = wxIcon(help_xpm);
312 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
313 icons[Icon_create_database] = wxIcon(create_database_xpm);
314 icons[Icon_settings] = wxIcon(settings_xpm);
315 icons[Icon_tools] = wxIcon(tools_xpm);
317 // unsigned int NbIcons = 8;
318 // Make an image list containing small icons
319 mIcon = new wxImageList(size,size,true);
321 // Make all icons the same size = size of the first one
322 int sizeOrig = icons[0].GetWidth();
323 for ( size_t i = 0; i < icon_number; i++ )
325 if ( size == sizeOrig )
327 mIcon->Add(icons[i]);
331 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
335 //=================================================
338 //=================================================
339 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
341 mViewer->StopPlayer();
342 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
343 std::string wc("*.*");
344 wxFileDialog* FD = new wxFileDialog( 0,
352 if (FD->ShowModal()==wxID_OK)
359 std::vector<std::string> filenames;
360 for (i=0;i<files.GetCount();++i)
362 filenames.push_back(wx2std(files[i]));
363 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
367 new wxProgressDialog(_T("Adding file(s)"),
372 // wxPD_ESTIMATED_TIME |
373 // wxPD_REMAINING_TIME |
376 // TO DO : select the current tree handler
377 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
379 mProgressDialog->Pulse(_T("Updating view..."));
381 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
382 delete mProgressDialog;
386 mViewer->StartPlayer();
388 //=================================================
390 //=================================================
391 void WxGimmickView::OnAddDir(wxCommandEvent& event)
393 mViewer->StopPlayer();
394 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
395 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
398 _T("Select directory"),
402 if (FD->ShowModal()==wxID_OK)
406 std::string dirname = wx2std (FD->GetPath());
407 bool recurse = isNeedRecursive(dirname);
410 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
414 wxString title(_T("Adding directory"));
416 title = _T("Adding directory (recursive)");
418 new wxProgressDialog(_T("Adding directory"),
423 // wxPD_ESTIMATED_TIME |
424 // wxPD_REMAINING_TIME |
427 mCurrentDirectory = FD->GetPath();
428 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
429 mProgressDialog->Pulse(_T("Updating view..."));
431 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
432 delete mProgressDialog;
436 mViewer->StartPlayer();
439 //=================================================
440 // Test a directory to know if contains sub-directory to analyze
441 bool WxGimmickView::isNeedRecursive(std::string i_name)
443 boost::filesystem::directory_iterator iter(i_name), end_iter;
444 bool bfindir = false;
445 for(; iter != end_iter; ++iter)
447 if(boost::filesystem::is_directory(*iter))
454 //=================================================
456 //=================================================
457 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
459 GimmickDebugMessage(5,
460 "WxGimmickView::OnSelectionChange"
467 valid= ValidateSelected(NULL,
468 mSelectionMinDimension,
469 mSelectionMaxDimension );
474 std::vector<tree::Node*>::const_iterator i;
475 for(i=sel.begin();i!=sel.end()&&valid;++i)
477 valid= ValidateSelected((*i),
478 mSelectionMinDimension,
479 mSelectionMaxDimension );
484 valid= ValidateSelected(sel.front(),
485 mSelectionMinDimension,
486 mSelectionMaxDimension );
491 std::vector<tree::Node*>::const_iterator i;
492 for(i=sel.begin();i!=sel.end()&&valid;++i)
494 valid= ValidateSelected((*i),
495 mSelectionMinDimension,
496 mSelectionMaxDimension );
499 mText->SetLabel(crea::std2wx(GetMessage()));
502 ReadImageThreaded(sel);
508 ReadImageThreaded(sel);
513 //==================================================
515 //==================================================
516 ///Reads Images (Threaded)
517 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
519 GimmickDebugMessage(5,
522 int maxprio = GetMaximalPriority();
523 int prio = maxprio + 2000;
527 //First load the selected images
528 mCurImageItemToShow = sel.front();
531 std::vector<tree::Node*>::const_iterator selected;
532 for(selected=sel.begin();selected!=sel.end();++selected)
534 GimmickDebugMessage(5,
535 "Requesting image from selected "
536 <<(*selected)->GetAttribute("FullFileName")
538 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
539 pointers.push_back(ph);
540 RequestReading(*selected,prio,index,ph);
541 // AddEntryToMap(*selected);
545 mViewer->SetImageVector(pointers);
548 std::vector<tree::Node*> up;
549 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
550 std::vector<tree::Node*>::iterator iterUp;
551 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
553 GimmickDebugMessage(5,
554 "Requesting image from neighbors up "
555 <<(*iterUp)->GetAttribute("FullFileName")
557 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
558 RequestReading(*iterUp,prio,-1,ph);
559 // AddEntryToMap(*iterUp);
561 if (prio == maxprio) break;
566 std::vector<tree::Node*> down;
567 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
568 std::vector<tree::Node*>::iterator iterDown;
569 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
571 GimmickDebugMessage(5,
572 "Requesting image from neighbors down "
573 <<(*iterDown)->GetAttribute("FullFileName")
575 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
576 RequestReading(*iterDown,prio,-1,ph);
577 // AddEntryToMap(*iterDown);
579 if (prio == maxprio) break;
585 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
586 pointers.push_back(ph);
587 mViewer->SetImageVector(pointers);
591 //==================================================
593 //==================================================
595 //==================================================
596 void WxGimmickView::OnInternalIdle()
598 if (!mConstructed) return;
599 static bool first_time = true;
604 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
605 // mViewer->StartPlayer();
608 mViewer->RefreshIfNecessary();
612 //==================================================
614 //==================================================
615 void WxGimmickView::ClearSelection()
618 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
619 mViewer->SetImageVector(pointers);
620 mViewer->RefreshIfNecessary();
624 //=================================================
626 //=================================================
627 void WxGimmickView::OnRemove(wxCommandEvent& event)
629 //TODO Select current tree handler
631 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected();
634 //=================================================
637 //=================================================
638 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
640 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
641 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
644 //=================================================
645 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
647 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
648 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
651 //=================================================
652 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
655 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
656 _T("Check database for files deletion, addition and attributes change. Then give a report."),
657 _T("Repair database (remove deleted files and add new files)."),
658 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
660 wxSingleChoiceDialog dialog(this,
661 _T("Select one of the following synchronization actions:\n")
662 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
663 _T("Synchronization Settings"),
664 WXSIZEOF(choices), choices);
666 //dialog.SetSelection(0);
668 if (dialog.ShowModal() == wxID_OK)
670 int sel=dialog.GetSelection();
672 bool checkAttributes=false;
673 if(sel==2 || sel==3){repair=true;}
674 if(sel==1 || sel==3){checkAttributes=true;}
675 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
676 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
677 if(sel==2 || sel==3){
678 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
683 //=================================================
685 //=================================================
686 void WxGimmickView::OnSettings(wxCommandEvent& event)
688 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
689 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
691 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
693 siz->Add( nb,1,wxGROW ,0);
694 CreateSettingsDialog(nb,dial);
698 //=================================================
700 //=================================================
702 void WxGimmickView::OnTools(wxCommandEvent& event)
704 mViewer->StopPlayer();
706 wxDialog* dial = new wxDialog (this,-1,"Tools",wxDefaultPosition, wxSize(300,250));
708 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
709 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
711 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
712 dialSizer->Add(nb,1,wxGROW,0);
713 dialSizer->Add(buttonsSizer,0,wxGROW);
715 //First page: Bruker Image Reader
716 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
717 nb->AddPage( gimmickTools, crea::std2wx("Bruker Image Reader") );
719 dial->SetSizer(dialSizer, true);
723 if (dial->GetReturnCode() == wxID_OK)
725 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
727 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
728 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
729 bool addToDB = gimmickTools->getCheckBoxValue();
731 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
735 b2d.SetInputDirectory(crea::wx2std(inputDir));
736 b2d.SetOutputDirectory(crea::wx2std(outputDir));
737 b2d.SetConvertModeToDicom();
743 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
744 mCurrentDirectory = outputDir;
745 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),crea::wx2std(outputDir),true);
746 mProgressDialog->Pulse(_T("Updating view..."));
748 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
749 delete mProgressDialog;
756 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
761 mViewer->StartPlayer();
763 //=================================================
765 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
767 //First page: Customization of configurations
770 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
771 //Database Path String
773 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
774 //Syncronization Event String
776 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
777 //Syncronization Frequency String
779 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
781 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
783 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
785 //Second page: Creation of Databases
786 wxPanel* databaseCreation=new wxPanel(nb);
787 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );
789 //Third page: CD/DVD Watch
790 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
791 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
793 //Fourth page: Selection of attributes to show (edit)
794 wxPanel* attSelection=new wxPanel(nb);
795 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
798 //===================================================================
799 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
800 const std::string& dbPath,
801 const std::string& syncEvent,
802 const std::string& syncFreq)
804 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
805 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
806 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
807 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
810 //===================================================================
811 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
813 mListener->SetMonitoredDrive(drive);
814 mListener->SetAddFilesState(addFiles);
815 mListener->SetRemoveFilesState(removeFiles);
818 //========================================================================
820 void WxGimmickView::OnDriveMount(bool mount)
822 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
824 mListener->GetMonitoredDrive(drive);
828 mViewer->StopPlayer();
830 wxString title(_T("Adding drive"));
832 new wxProgressDialog(_T("Adding drive"),
837 // wxPD_ESTIMATED_TIME |
838 // wxPD_REMAINING_TIME |
840 mCurrentDirectory = crea::std2wx(drive);
841 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
842 mProgressDialog->Pulse(_T("Updating view..."));
844 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
845 delete mProgressDialog;
847 mViewer->StartPlayer();
852 mGimmick->DeleteDrive(drive);
853 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
858 //========================================================================
860 void WxGimmickView::StartListeningThread()
865 //========================================================================
867 void WxGimmickView::StopListeningThread()
873 //=================================================
874 /// AddProgress Gimmick callback
875 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
880 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
881 p.GetNumberScannedDirs(),
882 p.GetNumberScannedFiles(),
883 p.GetNumberHandledFiles(),
884 p.GetNumberAddedFiles());
885 // std::cout << "OnAddProgress "<<mess<<std::endl;
886 wxString s(wxString::From8BitData(mess));
887 // std::cout << "Pulse"<<std::endl;
888 if (!mProgressDialog->Pulse(s))
892 // std::cout << "OnAddProgress ok"<<std::endl;
894 //=================================================
896 //=================================================
897 void WxGimmickView::DisplayAddSummary()
899 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
900 std::stringstream mess;
901 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
902 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
903 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
904 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
907 sprintf(times,"Time to parse dir \t\t: %ld ms \t%d°/o\nTime to read files info \t: %ld ms \t%d°/o\nTime to update structs \t: %ld ms \t%d°/o\nTime to update database \t: %ld ms \t%d°/o\nTotal time \t\t\t: %ld ms",
909 (int)( summary.parse_time*100./summary.total_time),
910 summary.file_scan_time,
911 (int)(summary.file_scan_time*100./summary.total_time),
912 summary.update_structs_time,
913 (int)(summary.update_structs_time*100./summary.total_time),
914 summary.update_database_time,
915 (int)(summary.update_database_time*100./summary.total_time),
916 summary.total_time );
920 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
923 //////////////////////////////////////////////////
924 // Add a DB to application //
925 // @param event : WxEvent //
927 //////////////////////////////////////////////////
928 void WxGimmickView::OnAddDB(wxCommandEvent& event)
932 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
933 std::string wc("*.sqlite3*");
934 wxFileDialog* FD = new wxFileDialog( 0,
942 if (FD->ShowModal()==wxID_OK)
947 std::stringstream st;
948 for(int i = 0; i< files.size(); i++)
950 //get name of DB (file name)
951 size_t pos = files[i].find_last_of(_T("\\"));
952 std::string name = crea::wx2std(files[i].substr(pos+1));
953 pos = name.find_last_of(".");
954 name = name.substr(0,pos);
956 mGimmick->addDB(name, crea::wx2std(files[i]));
958 CreateSingleTreeView(name);
962 ////////////////////////////////////////////////////
963 // Create a DB from an Attributes Descriptor files //
964 // @param event : WxEvent //
966 //////////////////////////////////////////////////
967 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
971 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
972 std::string wc("*.txt");
973 wxFileDialog* FD = new wxFileDialog( 0,
981 if (FD->ShowModal()==wxID_OK)
986 //get name of DB (file name)
987 std::string file = crea::wx2std(afile[0]);
988 size_t pos = file.find_last_of("\\");
989 std::string name = file.substr(pos+1);
990 std::string directory = file.substr(0,pos);
991 pos = name.find_last_of(".");
992 name = name.substr(0,pos);
993 //get directory to store DB
994 directory += "\\" + name + ".sqlite3";
996 mGimmick->createDB(name, file,directory);
998 mGimmick->addDB(name, directory);
1000 CreateSingleTreeView(name);
1004 //=================================================
1006 //=================================================
1007 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1008 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1009 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1010 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1011 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1012 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1013 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1014 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1015 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1017 //=================================================
1019 } // EO namespace creaImageIO