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::AddDir(std::string dirName)
659 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
660 mCurrentDirectory = crea::std2wx(dirName);
661 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
662 mProgressDialog->Pulse(_T("Updating view..."));
664 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
665 delete mProgressDialog;
669 //=================================================
670 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
673 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
674 _T("Check database for files deletion, addition and attributes change. Then give a report."),
675 _T("Repair database (remove deleted files and add new files)."),
676 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
678 wxSingleChoiceDialog dialog(this,
679 _T("Select one of the following synchronization actions:\n")
680 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
681 _T("Synchronization Settings"),
682 WXSIZEOF(choices), choices);
684 //dialog.SetSelection(0);
686 if (dialog.ShowModal() == wxID_OK)
688 int sel=dialog.GetSelection();
690 bool checkAttributes=false;
691 if(sel==2 || sel==3){repair=true;}
692 if(sel==1 || sel==3){checkAttributes=true;}
693 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
694 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
695 if(sel==2 || sel==3){
696 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
701 //=================================================
703 //=================================================
704 void WxGimmickView::OnSettings(wxCommandEvent& event)
706 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
707 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
709 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
711 siz->Add( nb,1,wxGROW ,0);
712 CreateSettingsDialog(nb,dial);
716 //=================================================
718 //=================================================
720 void WxGimmickView::OnTools(wxCommandEvent& event)
722 mViewer->StopPlayer();
724 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(300,250));
726 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
727 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
729 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
730 dialSizer->Add(nb,1,wxGROW,0);
731 dialSizer->Add(buttonsSizer,0,wxGROW);
733 #if defined(BUILD_BRUKER)
734 //First page: Bruker Image Reader
735 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
736 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
739 dial->SetSizer(dialSizer, true);
743 if (dial->GetReturnCode() == wxID_OK)
745 #if defined(BUILD_BRUKER)
746 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
748 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
749 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
750 bool addToDB = gimmickTools->getCheckBoxValue();
752 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
754 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
755 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
758 b2d.SetInputDirectory(inputDir);
759 b2d.SetOutputDirectory(outputDir);
760 b2d.SetConvertModeToDicom();
765 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
766 mCurrentDirectory = gimmickTools->getOutputDir();
767 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
768 mProgressDialog->Pulse(_T("Updating view..."));
770 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
771 delete mProgressDialog;
779 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
786 mViewer->StartPlayer();
788 //=================================================
790 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
792 //First page: Customization of configurations
795 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
796 //Database Path String
798 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
799 //Syncronization Event String
801 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
802 //Syncronization Frequency String
804 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
806 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
808 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
810 //Second page: Creation of Databases
811 wxPanel* databaseCreation=new wxPanel(nb);
812 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );
814 //Third page: CD/DVD Watch
815 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
816 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
818 //Fourth page: Selection of attributes to show
819 std::vector<std::string> shown;
820 std::vector<std::string> nShown;
821 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
822 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
823 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
824 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
827 //===================================================================
828 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
829 std::vector<std::string>& nShown, int level)
831 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
834 //===================================================================
835 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
837 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
838 std::vector<std::string> n=nShown;
839 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
841 //===================================================================
842 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
843 const std::string& dbPath,
844 const std::string& syncEvent,
845 const std::string& syncFreq)
847 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
848 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
849 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
850 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
853 //===================================================================
854 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
856 mListener->SetMonitoredDrive(drive);
857 mListener->SetAddFilesState(addFiles);
858 mListener->SetRemoveFilesState(removeFiles);
861 //========================================================================
863 void WxGimmickView::OnDriveMount(bool mount)
865 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
867 mListener->GetMonitoredDrive(drive);
871 mViewer->StopPlayer();
873 wxString title(_T("Adding drive"));
875 new wxProgressDialog(_T("Adding drive"),
880 // wxPD_ESTIMATED_TIME |
881 // wxPD_REMAINING_TIME |
883 mCurrentDirectory = crea::std2wx(drive);
884 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
885 mProgressDialog->Pulse(_T("Updating view..."));
887 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
888 delete mProgressDialog;
890 mViewer->StartPlayer();
895 mGimmick->DeleteDrive(drive);
896 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
901 //========================================================================
903 void WxGimmickView::StartListeningThread()
908 //========================================================================
910 void WxGimmickView::StopListeningThread()
915 //========================================================================
916 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
918 wxDialog* dial= new wxDialog (this,-1,_T("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
919 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
920 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
922 siz->Add( ef,1,wxGROW ,0);
927 //========================================================================
928 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
930 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
931 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
934 //=================================================
935 /// AddProgress Gimmick callback
936 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
939 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
940 p.GetNumberScannedDirs(),
941 p.GetNumberScannedFiles(),
942 p.GetNumberHandledFiles(),
943 p.GetNumberAddedFiles());
944 // std::cout << "OnAddProgress "<<mess<<std::endl;
945 wxString s(wxString::From8BitData(mess));
946 // std::cout << "Pulse"<<std::endl;
947 if (!mProgressDialog->Pulse(s))
951 // std::cout << "OnAddProgress ok"<<std::endl;
953 //=================================================
955 //=================================================
956 void WxGimmickView::DisplayAddSummary()
958 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
959 std::stringstream mess;
960 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
961 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
962 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
963 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
966 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",
968 (int)( summary.parse_time*100./summary.total_time),
969 summary.file_scan_time,
970 (int)(summary.file_scan_time*100./summary.total_time),
971 summary.update_structs_time,
972 (int)(summary.update_structs_time*100./summary.total_time),
973 summary.update_database_time,
974 (int)(summary.update_database_time*100./summary.total_time),
975 summary.total_time );
979 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
982 //////////////////////////////////////////////////
983 // Add a DB to application //
984 // @param event : WxEvent //
986 //////////////////////////////////////////////////
987 void WxGimmickView::OnAddDB(wxCommandEvent& event)
991 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
992 std::string wc("*.sqlite3*");
993 wxFileDialog* FD = new wxFileDialog( 0,
1001 if (FD->ShowModal()==wxID_OK)
1004 wxArrayString files;
1005 FD->GetPaths(files);
1006 std::stringstream st;
1007 for(int i = 0; i< files.size(); i++)
1009 //get name of DB (file name)
1010 size_t pos = files[i].find_last_of(_T("\\"));
1011 std::string name = crea::wx2std(files[i].substr(pos+1));
1012 pos = name.find_last_of(".");
1013 name = name.substr(0,pos);
1014 //create TreeHandler
1015 mGimmick->addDB(name, crea::wx2std(files[i]));
1017 CreateSingleTreeView(name);
1021 ////////////////////////////////////////////////////
1022 // Create a DB from an Attributes Descriptor files //
1023 // @param event : WxEvent //
1025 //////////////////////////////////////////////////
1026 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1030 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1031 std::string wc("*.txt");
1032 wxFileDialog* FD = new wxFileDialog( 0,
1040 if (FD->ShowModal()==wxID_OK)
1043 wxArrayString afile;
1044 FD->GetPaths(afile);
1045 //get name of DB (file name)
1046 std::string file = crea::wx2std(afile[0]);
1047 size_t pos = file.find_last_of("\\");
1048 std::string name = file.substr(pos+1);
1049 std::string directory = file.substr(0,pos);
1050 pos = name.find_last_of(".");
1051 name = name.substr(0,pos);
1052 //get directory to store DB
1053 directory += "\\" + name + ".sqlite3";
1055 mGimmick->createDB(name, file,directory);
1056 //create TreeHandler
1057 mGimmick->addDB(name, directory);
1059 CreateSingleTreeView(name);
1063 //=================================================
1065 //=================================================
1066 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1067 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1068 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1069 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1070 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1071 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1072 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1073 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1074 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1076 //=================================================
1078 } // EO namespace creaImageIO