1 #include <creaImageIOWxGimmickView.h>
2 #include <creaImageIOWxTreeView.h>
3 #include <creaImageIOSystem.h>
4 #include <creaImageIOWxCustomizeConfigPanel.h>
5 #include <creaImageIOWxListenerPanel.h>
6 #include <creaImageIOWxEditFieldsPanel.h>
7 #include <creaImageIOWxAttributeSelectionPanel.h>
11 #include "icons/accept.xpm"
12 #include "icons/add.xpm"
13 #include "icons/folder-down.xpm"
14 #include "icons/page-down.xpm"
15 #include "icons/remove.xpm"
16 #include "icons/database-add.xpm"
17 #include "icons/create-database.xpm"
18 #include "icons/help.xpm"
19 #include "icons/synchronize.xpm"
20 #include "icons/settings.xpm"
21 #include "icons/tools.xpm"
23 #include <wx/imaglist.h>
24 #include <wx/popupwin.h>
25 #include<boost/filesystem/operations.hpp>
26 #if defined(BUILD_BRUKER)
27 #include "bruker2dicom.h"
33 //======================================================================
34 // The ids of the different tools
40 TOOL_ADDDATABASE_ID = 4,
42 TOOL_SYNCHRONIZE_ID = 6,
47 //======================================================================
49 //================================================================
51 const int icon_number = 11;
68 //================================================================
70 //================================================================
72 const icon_id Icon[5] = { Icon_Database,
78 //================================================================
81 //======================================================================
83 WxGimmickView::WxGimmickView(Gimmick* gimmick,
86 const wxPoint& pos, const wxSize& size,
89 int number_of_threads)
90 : wxPanel(parent,id,pos,size),
91 GimmickView(gimmick, number_of_threads),
95 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
97 // Sets the current directory to the home dir
98 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
100 // Connect the AddProgress callback
101 gimmick->ConnectAddProgressObserver
102 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
104 // Create the list of icons (mIcon)
108 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
110 // Create the tool bar
112 sizer->Add( mToolBar ,0, wxGROW ,0);
114 // Split part below toolbar into notebook for views and panel
115 // for preview, messages...
116 mSplitter = new wxSplitterWindow( this , -1);
120 mNotebook = new wxNotebook(mSplitter,
121 -1,wxDefaultPosition, wxDefaultSize, 0);
127 mSelectionMaxDimension= max_dim;
128 mSelectionMinDimension= min_dim;
134 mBottomPanel = new wxPanel(mSplitter,-1);
136 wxBoxSizer *bottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
140 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
141 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
142 mViewer->SetImageVector(pointers);
143 mViewer->StartPlayer();
146 bottom_sizer->Add(mViewer,1,wxGROW,1);
149 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
150 bottom_sizer->Add(mText,0,wxGROW,0);
154 mBottomPanel->SetSizer(bottom_sizer);
157 int hsize = size.GetHeight();
159 int top_minsize = 450;
160 int bottom_minsize = 50;
162 mSplitter->SetMinimumPaneSize( bottom_minsize );
163 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
166 sizer->Add( mSplitter,1,wxGROW ,0);
172 mListener=new Listener();
173 mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount , this, _1 ) );
180 //======================================================================
182 //======================================================================
184 WxGimmickView::~WxGimmickView()
186 // stop the viewer before application exit.
187 mViewer->StopPlayer();
188 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
190 if(mListener->IsAlive())
195 //======================================================================
197 //======================================================================
198 /// Creates the tool bar
199 void WxGimmickView::CreateToolBar()
201 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
202 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
205 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
206 _T("Create database"),
207 mIcon->GetBitmap(Icon_create_database),
208 _T("Create DB from an Attributes Descriptor file")
210 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
212 mIcon->GetBitmap(Icon_page_down),
213 _T("Add one or more file to database")
215 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
217 mIcon->GetBitmap(Icon_folder_down),
218 _T("Add the content of a folder to database")
220 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
222 mIcon->GetBitmap(Icon_database_add),
223 _T("Open a local or distant database")
225 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
227 mIcon->GetBitmap(Icon_remove),
228 _T("Remove selected items")
230 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
232 mIcon->GetBitmap(Icon_synchronize),
233 _T("Synchronizes the database with disk")
235 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
237 mIcon->GetBitmap(Icon_help),
238 _T("Open help window")
240 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
241 _T("System settings"),
242 mIcon->GetBitmap(Icon_settings),
243 _T("Allows the modification of various system settings")
245 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
247 mIcon->GetBitmap(Icon_tools),
248 _T("Applies tools to images")
250 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
254 //======================================================================
257 //======================================================================
258 /// Create the tree view for TreeHandler provided
259 void WxGimmickView::CreateTreeView( TreeHandler* h)
261 std::string name(h->GetTree().GetAttribute("Name"));
262 GimmickMessage(2,"Creating the tree view for '"<<
263 name<<"'"<<std::endl);
264 // Create the WxTreeView
265 WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
267 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
268 // ALREADY IN THE MAP
269 GetTreeViewMap()[name] = view;
272 mNotebook->AddPage( view, crea::std2wx(name) );
276 //======================================================================
277 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
279 std::vector<std::string> files;
280 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
281 ReadImagesNotThreaded(s,files,dim);
283 //======================================================================
285 //======================================================================
286 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
288 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
290 //======================================================================
292 //======================================================================
293 void WxGimmickView::GetImages(int dim,
294 const std::vector<std::string>& files,
295 std::vector<vtkImageData*>& s)
297 ReadImagesNotThreaded(s,files,dim);
299 //======================================================================
302 //=================================================
303 void WxGimmickView::CreateIconList()
305 // Size of the icons;
309 // should correspond to Icon_xxx enum
310 icons[Icon_accept] = wxIcon(accept_xpm);
311 icons[Icon_add] = wxIcon(add_xpm);
312 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
313 icons[Icon_page_down] = wxIcon(page_down_xpm);
314 icons[Icon_remove] = wxIcon(remove_xpm);
315 icons[Icon_database_add] = wxIcon(database_add_xpm);
316 icons[Icon_help] = wxIcon(help_xpm);
317 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
318 icons[Icon_create_database] = wxIcon(create_database_xpm);
319 icons[Icon_settings] = wxIcon(settings_xpm);
320 icons[Icon_tools] = wxIcon(tools_xpm);
322 // unsigned int NbIcons = 8;
323 // Make an image list containing small icons
324 mIcon = new wxImageList(size,size,true);
326 // Make all icons the same size = size of the first one
327 int sizeOrig = icons[0].GetWidth();
328 for ( size_t i = 0; i < icon_number; i++ )
330 if ( size == sizeOrig )
332 mIcon->Add(icons[i]);
336 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
340 //=================================================
343 //=================================================
344 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
346 mViewer->StopPlayer();
347 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
348 std::string wc("*.*");
349 wxFileDialog* FD = new wxFileDialog( 0,
357 if (FD->ShowModal()==wxID_OK)
364 std::vector<std::string> filenames;
365 for (i=0;i<files.GetCount();++i)
367 filenames.push_back(wx2std(files[i]));
368 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
372 new wxProgressDialog(_T("Adding file(s)"),
377 // wxPD_ESTIMATED_TIME |
378 // wxPD_REMAINING_TIME |
381 // TO DO : select the current tree handler
382 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
384 mProgressDialog->Pulse(_T("Updating view..."));
386 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
387 delete mProgressDialog;
391 mViewer->StartPlayer();
393 //=================================================
395 //=================================================
396 void WxGimmickView::OnAddDir(wxCommandEvent& event)
398 mViewer->StopPlayer();
399 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
400 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
403 _T("Select directory"),
407 if (FD->ShowModal()==wxID_OK)
411 std::string dirname = wx2std (FD->GetPath());
412 bool recurse = isNeedRecursive(dirname);
415 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
419 wxString title(_T("Adding directory"));
421 title = _T("Adding directory (recursive)");
423 new wxProgressDialog(_T("Adding directory"),
428 // wxPD_ESTIMATED_TIME |
429 // wxPD_REMAINING_TIME |
432 mCurrentDirectory = FD->GetPath();
433 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
434 mProgressDialog->Pulse(_T("Updating view..."));
436 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
437 delete mProgressDialog;
441 mViewer->StartPlayer();
444 //=================================================
445 // Test a directory to know if contains sub-directory to analyze
446 bool WxGimmickView::isNeedRecursive(std::string i_name)
448 boost::filesystem::directory_iterator iter(i_name), end_iter;
449 bool bfindir = false;
450 for(; iter != end_iter; ++iter)
452 if(boost::filesystem::is_directory(*iter))
459 //=================================================
461 //=================================================
462 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
464 GimmickDebugMessage(5,
465 "WxGimmickView::OnSelectionChange"
472 valid= ValidateSelected(NULL,
473 mSelectionMinDimension,
474 mSelectionMaxDimension );
479 std::vector<tree::Node*>::const_iterator i;
480 for(i=sel.begin();i!=sel.end()&&valid;++i)
482 valid= ValidateSelected((*i),
483 mSelectionMinDimension,
484 mSelectionMaxDimension );
489 valid= ValidateSelected(sel.front(),
490 mSelectionMinDimension,
491 mSelectionMaxDimension );
496 std::vector<tree::Node*>::const_iterator i;
497 for(i=sel.begin();i!=sel.end()&&valid;++i)
499 valid= ValidateSelected((*i),
500 mSelectionMinDimension,
501 mSelectionMaxDimension );
504 mText->SetLabel(crea::std2wx(GetMessage()));
507 ReadImageThreaded(sel);
513 ReadImageThreaded(sel);
518 //==================================================
520 //==================================================
521 ///Reads Images (Threaded)
522 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
524 GimmickDebugMessage(5,
527 int maxprio = GetMaximalPriority();
528 int prio = maxprio + 2000;
532 //First load the selected images
533 mCurImageItemToShow = sel.front();
536 std::vector<tree::Node*>::const_iterator selected;
537 for(selected=sel.begin();selected!=sel.end();++selected)
539 GimmickDebugMessage(5,
540 "Requesting image from selected "
541 <<(*selected)->GetAttribute("FullFileName")
543 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
544 pointers.push_back(ph);
545 RequestReading(*selected,prio,index,ph);
546 // AddEntryToMap(*selected);
550 mViewer->SetImageVector(pointers);
553 std::vector<tree::Node*> up;
554 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
555 std::vector<tree::Node*>::iterator iterUp;
556 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
558 GimmickDebugMessage(5,
559 "Requesting image from neighbors up "
560 <<(*iterUp)->GetAttribute("FullFileName")
562 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
563 RequestReading(*iterUp,prio,-1,ph);
564 // AddEntryToMap(*iterUp);
566 if (prio == maxprio) break;
571 std::vector<tree::Node*> down;
572 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
573 std::vector<tree::Node*>::iterator iterDown;
574 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
576 GimmickDebugMessage(5,
577 "Requesting image from neighbors down "
578 <<(*iterDown)->GetAttribute("FullFileName")
580 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
581 RequestReading(*iterDown,prio,-1,ph);
582 // AddEntryToMap(*iterDown);
584 if (prio == maxprio) break;
590 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
591 pointers.push_back(ph);
592 mViewer->SetImageVector(pointers);
596 //==================================================
598 //==================================================
600 //==================================================
601 void WxGimmickView::OnInternalIdle()
603 if (!mConstructed) return;
604 static bool first_time = true;
609 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
610 // mViewer->StartPlayer();
613 mViewer->RefreshIfNecessary();
617 //==================================================
619 //==================================================
620 void WxGimmickView::ClearSelection()
623 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
624 mViewer->SetImageVector(pointers);
625 mViewer->RefreshIfNecessary();
629 //=================================================
631 //=================================================
632 void WxGimmickView::OnRemove(wxCommandEvent& event)
634 //TODO Select current tree handler
636 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected();
639 //=================================================
642 //=================================================
643 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
645 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
646 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
649 //=================================================
650 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
652 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
653 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
656 //=================================================
657 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
660 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
661 _T("Check database for files deletion, addition and attributes change. Then give a report."),
662 _T("Repair database (remove deleted files and add new files)."),
663 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
665 wxSingleChoiceDialog dialog(this,
666 _T("Select one of the following synchronization actions:\n")
667 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
668 _T("Synchronization Settings"),
669 WXSIZEOF(choices), choices);
671 //dialog.SetSelection(0);
673 if (dialog.ShowModal() == wxID_OK)
675 int sel=dialog.GetSelection();
677 bool checkAttributes=false;
678 if(sel==2 || sel==3){repair=true;}
679 if(sel==1 || sel==3){checkAttributes=true;}
680 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
681 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
682 if(sel==2 || sel==3){
683 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
688 //=================================================
690 //=================================================
691 void WxGimmickView::OnSettings(wxCommandEvent& event)
693 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
694 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
696 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
698 siz->Add( nb,1,wxGROW ,0);
699 CreateSettingsDialog(nb,dial);
703 //=================================================
705 //=================================================
707 void WxGimmickView::OnTools(wxCommandEvent& event)
709 mViewer->StopPlayer();
711 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(300,250));
713 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
714 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
716 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
717 dialSizer->Add(nb,1,wxGROW,0);
718 dialSizer->Add(buttonsSizer,0,wxGROW);
720 #if defined(BUILD_BRUKER)
721 //First page: Bruker Image Reader
722 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
723 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
726 dial->SetSizer(dialSizer, true);
730 if (dial->GetReturnCode() == wxID_OK)
732 #if defined(BUILD_BRUKER)
733 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
735 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
736 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
737 bool addToDB = gimmickTools->getCheckBoxValue();
739 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
741 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
742 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
745 b2d.SetInputDirectory(inputDir);
746 b2d.SetOutputDirectory(outputDir);
747 b2d.SetConvertModeToDicom();
752 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
753 mCurrentDirectory = gimmickTools->getOutputDir(); // Try // JPRx
754 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
755 mProgressDialog->Pulse(_T("Updating view..."));
757 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
758 delete mProgressDialog;
766 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
772 mViewer->StartPlayer();
774 //=================================================
776 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
778 //First page: Customization of configurations
781 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
782 //Database Path String
784 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
785 //Syncronization Event String
787 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
788 //Syncronization Frequency String
790 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
792 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
794 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
796 //Second page: Creation of Databases
797 wxPanel* databaseCreation=new wxPanel(nb);
798 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );
800 //Third page: CD/DVD Watch
801 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
802 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
804 //Fourth page: Selection of attributes to show
805 std::vector<std::string> shown;
806 std::vector<std::string> nShown;
807 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
808 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
809 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
810 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
813 //===================================================================
814 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
815 std::vector<std::string>& nShown, int level)
817 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
819 //===================================================================
820 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
821 const std::string& dbPath,
822 const std::string& syncEvent,
823 const std::string& syncFreq)
825 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
826 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
827 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
828 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
831 //===================================================================
832 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
834 mListener->SetMonitoredDrive(drive);
835 mListener->SetAddFilesState(addFiles);
836 mListener->SetRemoveFilesState(removeFiles);
839 //========================================================================
841 void WxGimmickView::OnDriveMount(bool mount)
843 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
845 mListener->GetMonitoredDrive(drive);
849 mViewer->StopPlayer();
851 wxString title(_T("Adding drive"));
853 new wxProgressDialog(_T("Adding drive"),
858 // wxPD_ESTIMATED_TIME |
859 // wxPD_REMAINING_TIME |
861 mCurrentDirectory = crea::std2wx(drive);
862 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
863 mProgressDialog->Pulse(_T("Updating view..."));
865 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
866 delete mProgressDialog;
868 mViewer->StartPlayer();
873 mGimmick->DeleteDrive(drive);
874 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
879 //========================================================================
881 void WxGimmickView::StartListeningThread()
886 //========================================================================
888 void WxGimmickView::StopListeningThread()
893 //========================================================================
894 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
896 wxDialog* dial= new wxDialog (this,-1,_T("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
897 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
898 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
900 siz->Add( ef,1,wxGROW ,0);
905 //========================================================================
906 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
908 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
909 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
912 //=================================================
913 /// AddProgress Gimmick callback
914 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
917 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
918 p.GetNumberScannedDirs(),
919 p.GetNumberScannedFiles(),
920 p.GetNumberHandledFiles(),
921 p.GetNumberAddedFiles());
922 // std::cout << "OnAddProgress "<<mess<<std::endl;
923 wxString s(wxString::From8BitData(mess));
924 // std::cout << "Pulse"<<std::endl;
925 if (!mProgressDialog->Pulse(s))
929 // std::cout << "OnAddProgress ok"<<std::endl;
931 //=================================================
933 //=================================================
934 void WxGimmickView::DisplayAddSummary()
936 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
937 std::stringstream mess;
938 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
939 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
940 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
941 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
944 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",
946 (int)( summary.parse_time*100./summary.total_time),
947 summary.file_scan_time,
948 (int)(summary.file_scan_time*100./summary.total_time),
949 summary.update_structs_time,
950 (int)(summary.update_structs_time*100./summary.total_time),
951 summary.update_database_time,
952 (int)(summary.update_database_time*100./summary.total_time),
953 summary.total_time );
957 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
960 //////////////////////////////////////////////////
961 // Add a DB to application //
962 // @param event : WxEvent //
964 //////////////////////////////////////////////////
965 void WxGimmickView::OnAddDB(wxCommandEvent& event)
969 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
970 std::string wc("*.sqlite3*");
971 wxFileDialog* FD = new wxFileDialog( 0,
979 if (FD->ShowModal()==wxID_OK)
984 std::stringstream st;
985 for(int i = 0; i< files.size(); i++)
987 //get name of DB (file name)
988 size_t pos = files[i].find_last_of(_T("\\"));
989 std::string name = crea::wx2std(files[i].substr(pos+1));
990 pos = name.find_last_of(".");
991 name = name.substr(0,pos);
993 mGimmick->addDB(name, crea::wx2std(files[i]));
995 CreateSingleTreeView(name);
999 ////////////////////////////////////////////////////
1000 // Create a DB from an Attributes Descriptor files //
1001 // @param event : WxEvent //
1003 //////////////////////////////////////////////////
1004 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1008 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1009 std::string wc("*.txt");
1010 wxFileDialog* FD = new wxFileDialog( 0,
1018 if (FD->ShowModal()==wxID_OK)
1021 wxArrayString afile;
1022 FD->GetPaths(afile);
1023 //get name of DB (file name)
1024 std::string file = crea::wx2std(afile[0]);
1025 size_t pos = file.find_last_of("\\");
1026 std::string name = file.substr(pos+1);
1027 std::string directory = file.substr(0,pos);
1028 pos = name.find_last_of(".");
1029 name = name.substr(0,pos);
1030 //get directory to store DB
1031 directory += "\\" + name + ".sqlite3";
1033 mGimmick->createDB(name, file,directory);
1034 //create TreeHandler
1035 mGimmick->addDB(name, directory);
1037 CreateSingleTreeView(name);
1041 //=================================================
1043 //=================================================
1044 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1045 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1046 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1047 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1048 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1049 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1050 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1051 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1052 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1054 //=================================================
1056 } // EO namespace creaImageIO