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>
24 #if defined(BUILD_BRUKER)
25 #include "bruker2dicom.h"
31 //======================================================================
32 // The ids of the different tools
38 TOOL_ADDDATABASE_ID = 4,
40 TOOL_SYNCHRONIZE_ID = 6,
45 //======================================================================
47 //================================================================
49 const int icon_number = 11;
66 //================================================================
68 //================================================================
70 const icon_id Icon[5] = { Icon_Database,
76 //================================================================
79 //======================================================================
81 WxGimmickView::WxGimmickView(Gimmick* gimmick,
84 const wxPoint& pos, const wxSize& size,
87 int number_of_threads)
88 : wxPanel(parent,id,pos,size),
89 GimmickView(gimmick, number_of_threads),
93 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
95 // Sets the current directory to the home dir
96 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
98 // Connect the AddProgress callback
99 gimmick->ConnectAddProgressObserver
100 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
102 // Create the list of icons (mIcon)
106 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
108 // Create the tool bar
110 sizer->Add( mToolBar ,0, wxGROW ,0);
112 // Split part below toolbar into notebook for views and panel
113 // for preview, messages...
114 mSplitter = new wxSplitterWindow( this , -1);
118 mNotebook = new wxNotebook(mSplitter,
119 -1,wxDefaultPosition, wxDefaultSize, 0);
125 mSelectionMaxDimension= max_dim;
126 mSelectionMinDimension= min_dim;
132 mBottomPanel = new wxPanel(mSplitter,-1);
134 wxBoxSizer *bottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
138 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
139 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
140 mViewer->SetImageVector(pointers);
141 mViewer->StartPlayer();
144 bottom_sizer->Add(mViewer,1,wxGROW,1);
147 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
148 bottom_sizer->Add(mText,0,wxGROW,0);
152 mBottomPanel->SetSizer(bottom_sizer);
155 int hsize = size.GetHeight();
157 int top_minsize = 450;
158 int bottom_minsize = 50;
160 mSplitter->SetMinimumPaneSize( bottom_minsize );
161 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
164 sizer->Add( mSplitter,1,wxGROW ,0);
170 mListener=new Listener();
171 mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount , this, _1 ) );
178 //======================================================================
180 //======================================================================
182 WxGimmickView::~WxGimmickView()
184 // stop the viewer before application exit.
185 mViewer->StopPlayer();
186 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
188 if(mListener->IsAlive())
193 //======================================================================
195 //======================================================================
196 /// Creates the tool bar
197 void WxGimmickView::CreateToolBar()
199 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
200 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
203 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
204 _T("Create database"),
205 mIcon->GetBitmap(Icon_create_database),
206 _T("Create DB from an Attributes Descriptor file")
208 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
210 mIcon->GetBitmap(Icon_page_down),
211 _T("Add one or more file to database")
213 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
215 mIcon->GetBitmap(Icon_folder_down),
216 _T("Add the content of a folder to database")
218 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
220 mIcon->GetBitmap(Icon_database_add),
221 _T("Open a local or distant database")
223 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
225 mIcon->GetBitmap(Icon_remove),
226 _T("Remove selected items")
228 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
230 mIcon->GetBitmap(Icon_synchronize),
231 _T("Synchronizes the database with disk")
233 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
235 mIcon->GetBitmap(Icon_help),
236 _T("Open help window")
238 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
239 _T("System settings"),
240 mIcon->GetBitmap(Icon_settings),
241 _T("Allows the modification of various system settings")
243 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
245 mIcon->GetBitmap(Icon_tools),
246 _T("Applies tools to images")
248 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
252 //======================================================================
255 //======================================================================
256 /// Create the tree view for TreeHandler provided
257 void WxGimmickView::CreateTreeView( TreeHandler* h)
259 std::string name(h->GetTree().GetAttribute("Name"));
260 GimmickMessage(2,"Creating the tree view for '"<<
261 name<<"'"<<std::endl);
262 // Create the WxTreeView
263 WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
265 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
266 // ALREADY IN THE MAP
267 GetTreeViewMap()[name] = view;
270 mNotebook->AddPage( view, crea::std2wx(name) );
274 //======================================================================
275 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
277 std::vector<std::string> files;
278 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
279 ReadImagesNotThreaded(s,files,dim);
281 //======================================================================
283 //======================================================================
284 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
286 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
288 //======================================================================
290 //======================================================================
291 void WxGimmickView::GetImages(int dim,
292 const std::vector<std::string>& files,
293 std::vector<vtkImageData*>& s)
295 ReadImagesNotThreaded(s,files,dim);
297 //======================================================================
300 //=================================================
301 void WxGimmickView::CreateIconList()
303 // Size of the icons;
307 // should correspond to Icon_xxx enum
308 icons[Icon_accept] = wxIcon(accept_xpm);
309 icons[Icon_add] = wxIcon(add_xpm);
310 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
311 icons[Icon_page_down] = wxIcon(page_down_xpm);
312 icons[Icon_remove] = wxIcon(remove_xpm);
313 icons[Icon_database_add] = wxIcon(database_add_xpm);
314 icons[Icon_help] = wxIcon(help_xpm);
315 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
316 icons[Icon_create_database] = wxIcon(create_database_xpm);
317 icons[Icon_settings] = wxIcon(settings_xpm);
318 icons[Icon_tools] = wxIcon(tools_xpm);
320 // unsigned int NbIcons = 8;
321 // Make an image list containing small icons
322 mIcon = new wxImageList(size,size,true);
324 // Make all icons the same size = size of the first one
325 int sizeOrig = icons[0].GetWidth();
326 for ( size_t i = 0; i < icon_number; i++ )
328 if ( size == sizeOrig )
330 mIcon->Add(icons[i]);
334 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
338 //=================================================
341 //=================================================
342 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
344 mViewer->StopPlayer();
345 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
346 std::string wc("*.*");
347 wxFileDialog* FD = new wxFileDialog( 0,
355 if (FD->ShowModal()==wxID_OK)
362 std::vector<std::string> filenames;
363 for (i=0;i<files.GetCount();++i)
365 filenames.push_back(wx2std(files[i]));
366 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
370 new wxProgressDialog(_T("Adding file(s)"),
375 // wxPD_ESTIMATED_TIME |
376 // wxPD_REMAINING_TIME |
379 // TO DO : select the current tree handler
380 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
382 mProgressDialog->Pulse(_T("Updating view..."));
384 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
385 delete mProgressDialog;
389 mViewer->StartPlayer();
391 //=================================================
393 //=================================================
394 void WxGimmickView::OnAddDir(wxCommandEvent& event)
396 mViewer->StopPlayer();
397 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
398 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
401 _T("Select directory"),
405 if (FD->ShowModal()==wxID_OK)
409 std::string dirname = wx2std (FD->GetPath());
410 bool recurse = isNeedRecursive(dirname);
413 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
417 wxString title(_T("Adding directory"));
419 title = _T("Adding directory (recursive)");
421 new wxProgressDialog(_T("Adding directory"),
426 // wxPD_ESTIMATED_TIME |
427 // wxPD_REMAINING_TIME |
430 mCurrentDirectory = FD->GetPath();
431 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
432 mProgressDialog->Pulse(_T("Updating view..."));
434 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
435 delete mProgressDialog;
439 mViewer->StartPlayer();
442 //=================================================
443 // Test a directory to know if contains sub-directory to analyze
444 bool WxGimmickView::isNeedRecursive(std::string i_name)
446 boost::filesystem::directory_iterator iter(i_name), end_iter;
447 bool bfindir = false;
448 for(; iter != end_iter; ++iter)
450 if(boost::filesystem::is_directory(*iter))
457 //=================================================
459 //=================================================
460 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
462 GimmickDebugMessage(5,
463 "WxGimmickView::OnSelectionChange"
470 valid= ValidateSelected(NULL,
471 mSelectionMinDimension,
472 mSelectionMaxDimension );
477 std::vector<tree::Node*>::const_iterator i;
478 for(i=sel.begin();i!=sel.end()&&valid;++i)
480 valid= ValidateSelected((*i),
481 mSelectionMinDimension,
482 mSelectionMaxDimension );
487 valid= ValidateSelected(sel.front(),
488 mSelectionMinDimension,
489 mSelectionMaxDimension );
494 std::vector<tree::Node*>::const_iterator i;
495 for(i=sel.begin();i!=sel.end()&&valid;++i)
497 valid= ValidateSelected((*i),
498 mSelectionMinDimension,
499 mSelectionMaxDimension );
502 mText->SetLabel(crea::std2wx(GetMessage()));
505 ReadImageThreaded(sel);
511 ReadImageThreaded(sel);
516 //==================================================
518 //==================================================
519 ///Reads Images (Threaded)
520 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
522 GimmickDebugMessage(5,
525 int maxprio = GetMaximalPriority();
526 int prio = maxprio + 2000;
530 //First load the selected images
531 mCurImageItemToShow = sel.front();
534 std::vector<tree::Node*>::const_iterator selected;
535 for(selected=sel.begin();selected!=sel.end();++selected)
537 GimmickDebugMessage(5,
538 "Requesting image from selected "
539 <<(*selected)->GetAttribute("FullFileName")
541 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
542 pointers.push_back(ph);
543 RequestReading(*selected,prio,index,ph);
544 // AddEntryToMap(*selected);
548 mViewer->SetImageVector(pointers);
551 std::vector<tree::Node*> up;
552 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
553 std::vector<tree::Node*>::iterator iterUp;
554 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
556 GimmickDebugMessage(5,
557 "Requesting image from neighbors up "
558 <<(*iterUp)->GetAttribute("FullFileName")
560 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
561 RequestReading(*iterUp,prio,-1,ph);
562 // AddEntryToMap(*iterUp);
564 if (prio == maxprio) break;
569 std::vector<tree::Node*> down;
570 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
571 std::vector<tree::Node*>::iterator iterDown;
572 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
574 GimmickDebugMessage(5,
575 "Requesting image from neighbors down "
576 <<(*iterDown)->GetAttribute("FullFileName")
578 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
579 RequestReading(*iterDown,prio,-1,ph);
580 // AddEntryToMap(*iterDown);
582 if (prio == maxprio) break;
588 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
589 pointers.push_back(ph);
590 mViewer->SetImageVector(pointers);
594 //==================================================
596 //==================================================
598 //==================================================
599 void WxGimmickView::OnInternalIdle()
601 if (!mConstructed) return;
602 static bool first_time = true;
607 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
608 // mViewer->StartPlayer();
611 mViewer->RefreshIfNecessary();
615 //==================================================
617 //==================================================
618 void WxGimmickView::ClearSelection()
621 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
622 mViewer->SetImageVector(pointers);
623 mViewer->RefreshIfNecessary();
627 //=================================================
629 //=================================================
630 void WxGimmickView::OnRemove(wxCommandEvent& event)
632 //TODO Select current tree handler
634 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected();
637 //=================================================
640 //=================================================
641 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
643 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
644 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
647 //=================================================
648 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
650 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
651 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
654 //=================================================
655 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
658 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
659 _T("Check database for files deletion, addition and attributes change. Then give a report."),
660 _T("Repair database (remove deleted files and add new files)."),
661 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
663 wxSingleChoiceDialog dialog(this,
664 _T("Select one of the following synchronization actions:\n")
665 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
666 _T("Synchronization Settings"),
667 WXSIZEOF(choices), choices);
669 //dialog.SetSelection(0);
671 if (dialog.ShowModal() == wxID_OK)
673 int sel=dialog.GetSelection();
675 bool checkAttributes=false;
676 if(sel==2 || sel==3){repair=true;}
677 if(sel==1 || sel==3){checkAttributes=true;}
678 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
679 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
680 if(sel==2 || sel==3){
681 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
686 //=================================================
688 //=================================================
689 void WxGimmickView::OnSettings(wxCommandEvent& event)
691 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
692 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
694 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
696 siz->Add( nb,1,wxGROW ,0);
697 CreateSettingsDialog(nb,dial);
701 //=================================================
703 //=================================================
705 void WxGimmickView::OnTools(wxCommandEvent& event)
707 mViewer->StopPlayer();
709 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(300,250));
711 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
712 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
714 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
715 dialSizer->Add(nb,1,wxGROW,0);
716 dialSizer->Add(buttonsSizer,0,wxGROW);
718 #if defined(BUILD_BRUKER)
719 //First page: Bruker Image Reader
720 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
721 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
724 dial->SetSizer(dialSizer, true);
728 if (dial->GetReturnCode() == wxID_OK)
730 #if defined(BUILD_BRUKER)
731 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
733 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
734 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
735 bool addToDB = gimmickTools->getCheckBoxValue();
737 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
739 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
740 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
743 b2d.SetInputDirectory(inputDir);
744 b2d.SetOutputDirectory(outputDir);
745 b2d.SetConvertModeToDicom();
750 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
751 mCurrentDirectory = gimmickTools->getOutputDir(); // Try // JPRx
752 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
753 mProgressDialog->Pulse(_T("Updating view..."));
755 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
756 delete mProgressDialog;
764 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
770 mViewer->StartPlayer();
772 //=================================================
774 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
776 //First page: Customization of configurations
779 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
780 //Database Path String
782 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
783 //Syncronization Event String
785 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
786 //Syncronization Frequency String
788 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
790 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
792 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
794 //Second page: Creation of Databases
795 wxPanel* databaseCreation=new wxPanel(nb);
796 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );
798 //Third page: CD/DVD Watch
799 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
800 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
802 //Fourth page: Selection of attributes to show (edit)
803 wxPanel* attSelection=new wxPanel(nb);
804 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
807 //===================================================================
808 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
809 const std::string& dbPath,
810 const std::string& syncEvent,
811 const std::string& syncFreq)
813 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
814 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
815 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
816 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
819 //===================================================================
820 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
822 mListener->SetMonitoredDrive(drive);
823 mListener->SetAddFilesState(addFiles);
824 mListener->SetRemoveFilesState(removeFiles);
827 //========================================================================
829 void WxGimmickView::OnDriveMount(bool mount)
831 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
833 mListener->GetMonitoredDrive(drive);
837 mViewer->StopPlayer();
839 wxString title(_T("Adding drive"));
841 new wxProgressDialog(_T("Adding drive"),
846 // wxPD_ESTIMATED_TIME |
847 // wxPD_REMAINING_TIME |
849 mCurrentDirectory = crea::std2wx(drive);
850 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
851 mProgressDialog->Pulse(_T("Updating view..."));
853 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
854 delete mProgressDialog;
856 mViewer->StartPlayer();
861 mGimmick->DeleteDrive(drive);
862 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
867 //========================================================================
869 void WxGimmickView::StartListeningThread()
874 //========================================================================
876 void WxGimmickView::StopListeningThread()
882 //=================================================
883 /// AddProgress Gimmick callback
884 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
889 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
890 p.GetNumberScannedDirs(),
891 p.GetNumberScannedFiles(),
892 p.GetNumberHandledFiles(),
893 p.GetNumberAddedFiles());
894 // std::cout << "OnAddProgress "<<mess<<std::endl;
895 wxString s(wxString::From8BitData(mess));
896 // std::cout << "Pulse"<<std::endl;
897 if (!mProgressDialog->Pulse(s))
901 // std::cout << "OnAddProgress ok"<<std::endl;
903 //=================================================
905 //=================================================
906 void WxGimmickView::DisplayAddSummary()
908 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
909 std::stringstream mess;
910 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
911 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
912 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
913 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
916 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",
918 (int)( summary.parse_time*100./summary.total_time),
919 summary.file_scan_time,
920 (int)(summary.file_scan_time*100./summary.total_time),
921 summary.update_structs_time,
922 (int)(summary.update_structs_time*100./summary.total_time),
923 summary.update_database_time,
924 (int)(summary.update_database_time*100./summary.total_time),
925 summary.total_time );
929 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
932 //////////////////////////////////////////////////
933 // Add a DB to application //
934 // @param event : WxEvent //
936 //////////////////////////////////////////////////
937 void WxGimmickView::OnAddDB(wxCommandEvent& event)
941 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
942 std::string wc("*.sqlite3*");
943 wxFileDialog* FD = new wxFileDialog( 0,
951 if (FD->ShowModal()==wxID_OK)
956 std::stringstream st;
957 for(int i = 0; i< files.size(); i++)
959 //get name of DB (file name)
960 size_t pos = files[i].find_last_of(_T("\\"));
961 std::string name = crea::wx2std(files[i].substr(pos+1));
962 pos = name.find_last_of(".");
963 name = name.substr(0,pos);
965 mGimmick->addDB(name, crea::wx2std(files[i]));
967 CreateSingleTreeView(name);
971 ////////////////////////////////////////////////////
972 // Create a DB from an Attributes Descriptor files //
973 // @param event : WxEvent //
975 //////////////////////////////////////////////////
976 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
980 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
981 std::string wc("*.txt");
982 wxFileDialog* FD = new wxFileDialog( 0,
990 if (FD->ShowModal()==wxID_OK)
995 //get name of DB (file name)
996 std::string file = crea::wx2std(afile[0]);
997 size_t pos = file.find_last_of("\\");
998 std::string name = file.substr(pos+1);
999 std::string directory = file.substr(0,pos);
1000 pos = name.find_last_of(".");
1001 name = name.substr(0,pos);
1002 //get directory to store DB
1003 directory += "\\" + name + ".sqlite3";
1005 mGimmick->createDB(name, file,directory);
1006 //create TreeHandler
1007 mGimmick->addDB(name, directory);
1009 CreateSingleTreeView(name);
1013 //=================================================
1015 //=================================================
1016 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1017 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1018 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1019 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1020 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1021 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1022 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1023 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1024 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1026 //=================================================
1028 } // EO namespace creaImageIO