1 #include <creaImageIOWxGimmickView.h>
2 #include <creaImageIOWxTreeView.h>
3 #include <creaImageIOSystem.h>
4 #include <creaImageIOWxCustomizeConfigPanel.h>
5 #include <creaImageIOWxListenerPanel.h>
6 #include <creaImageIOWxEditFieldsPanel.h>
10 #include "icons/accept.xpm"
11 #include "icons/add.xpm"
12 #include "icons/folder-down.xpm"
13 #include "icons/page-down.xpm"
14 #include "icons/remove.xpm"
15 #include "icons/database-add.xpm"
16 #include "icons/create-database.xpm"
17 #include "icons/help.xpm"
18 #include "icons/synchronize.xpm"
19 #include "icons/settings.xpm"
20 #include "icons/tools.xpm"
22 #include <wx/imaglist.h>
23 #include <wx/popupwin.h>
24 #include<boost/filesystem/operations.hpp>
25 #if defined(BUILD_BRUKER)
26 #include "bruker2dicom.h"
32 //======================================================================
33 // The ids of the different tools
39 TOOL_ADDDATABASE_ID = 4,
41 TOOL_SYNCHRONIZE_ID = 6,
46 //======================================================================
48 //================================================================
50 const int icon_number = 11;
67 //================================================================
69 //================================================================
71 const icon_id Icon[5] = { Icon_Database,
77 //================================================================
80 //======================================================================
82 WxGimmickView::WxGimmickView(Gimmick* gimmick,
85 const wxPoint& pos, const wxSize& size,
88 int number_of_threads)
89 : wxPanel(parent,id,pos,size),
90 GimmickView(gimmick, number_of_threads),
94 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
96 // Sets the current directory to the home dir
97 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
99 // Connect the AddProgress callback
100 gimmick->ConnectAddProgressObserver
101 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
103 // Create the list of icons (mIcon)
107 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
109 // Create the tool bar
111 sizer->Add( mToolBar ,0, wxGROW ,0);
113 // Split part below toolbar into notebook for views and panel
114 // for preview, messages...
115 mSplitter = new wxSplitterWindow( this , -1);
119 mNotebook = new wxNotebook(mSplitter,
120 -1,wxDefaultPosition, wxDefaultSize, 0);
126 mSelectionMaxDimension= max_dim;
127 mSelectionMinDimension= min_dim;
133 mBottomPanel = new wxPanel(mSplitter,-1);
135 wxBoxSizer *bottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
139 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
140 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
141 mViewer->SetImageVector(pointers);
142 mViewer->StartPlayer();
145 bottom_sizer->Add(mViewer,1,wxGROW,1);
148 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
149 bottom_sizer->Add(mText,0,wxGROW,0);
153 mBottomPanel->SetSizer(bottom_sizer);
156 int hsize = size.GetHeight();
158 int top_minsize = 450;
159 int bottom_minsize = 50;
161 mSplitter->SetMinimumPaneSize( bottom_minsize );
162 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
165 sizer->Add( mSplitter,1,wxGROW ,0);
171 mListener=new Listener();
172 mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount , this, _1 ) );
179 //======================================================================
181 //======================================================================
183 WxGimmickView::~WxGimmickView()
185 // stop the viewer before application exit.
186 mViewer->StopPlayer();
187 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
189 if(mListener->IsAlive())
194 //======================================================================
196 //======================================================================
197 /// Creates the tool bar
198 void WxGimmickView::CreateToolBar()
200 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
201 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
204 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
205 _T("Create database"),
206 mIcon->GetBitmap(Icon_create_database),
207 _T("Create DB from an Attributes Descriptor file")
209 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
211 mIcon->GetBitmap(Icon_page_down),
212 _T("Add one or more file to database")
214 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
216 mIcon->GetBitmap(Icon_folder_down),
217 _T("Add the content of a folder to database")
219 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
221 mIcon->GetBitmap(Icon_database_add),
222 _T("Open a local or distant database")
224 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
226 mIcon->GetBitmap(Icon_remove),
227 _T("Remove selected items")
229 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
231 mIcon->GetBitmap(Icon_synchronize),
232 _T("Synchronizes the database with disk")
234 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
236 mIcon->GetBitmap(Icon_help),
237 _T("Open help window")
239 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
240 _T("System settings"),
241 mIcon->GetBitmap(Icon_settings),
242 _T("Allows the modification of various system settings")
244 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
246 mIcon->GetBitmap(Icon_tools),
247 _T("Applies tools to images")
249 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
253 //======================================================================
256 //======================================================================
257 /// Create the tree view for TreeHandler provided
258 void WxGimmickView::CreateTreeView( TreeHandler* h)
260 std::string name(h->GetTree().GetAttribute("Name"));
261 GimmickMessage(2,"Creating the tree view for '"<<
262 name<<"'"<<std::endl);
263 // Create the WxTreeView
264 WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
266 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
267 // ALREADY IN THE MAP
268 GetTreeViewMap()[name] = view;
271 mNotebook->AddPage( view, crea::std2wx(name) );
275 //======================================================================
276 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
278 std::vector<std::string> files;
279 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
280 ReadImagesNotThreaded(s,files,dim);
282 //======================================================================
284 //======================================================================
285 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
287 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
289 //======================================================================
291 //======================================================================
292 void WxGimmickView::GetImages(int dim,
293 const std::vector<std::string>& files,
294 std::vector<vtkImageData*>& s)
296 ReadImagesNotThreaded(s,files,dim);
298 //======================================================================
301 //=================================================
302 void WxGimmickView::CreateIconList()
304 // Size of the icons;
308 // should correspond to Icon_xxx enum
309 icons[Icon_accept] = wxIcon(accept_xpm);
310 icons[Icon_add] = wxIcon(add_xpm);
311 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
312 icons[Icon_page_down] = wxIcon(page_down_xpm);
313 icons[Icon_remove] = wxIcon(remove_xpm);
314 icons[Icon_database_add] = wxIcon(database_add_xpm);
315 icons[Icon_help] = wxIcon(help_xpm);
316 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
317 icons[Icon_create_database] = wxIcon(create_database_xpm);
318 icons[Icon_settings] = wxIcon(settings_xpm);
319 icons[Icon_tools] = wxIcon(tools_xpm);
321 // unsigned int NbIcons = 8;
322 // Make an image list containing small icons
323 mIcon = new wxImageList(size,size,true);
325 // Make all icons the same size = size of the first one
326 int sizeOrig = icons[0].GetWidth();
327 for ( size_t i = 0; i < icon_number; i++ )
329 if ( size == sizeOrig )
331 mIcon->Add(icons[i]);
335 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
339 //=================================================
342 //=================================================
343 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
345 mViewer->StopPlayer();
346 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
347 std::string wc("*.*");
348 wxFileDialog* FD = new wxFileDialog( 0,
356 if (FD->ShowModal()==wxID_OK)
363 std::vector<std::string> filenames;
364 for (i=0;i<files.GetCount();++i)
366 filenames.push_back(wx2std(files[i]));
367 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
371 new wxProgressDialog(_T("Adding file(s)"),
376 // wxPD_ESTIMATED_TIME |
377 // wxPD_REMAINING_TIME |
380 // TO DO : select the current tree handler
381 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
383 mProgressDialog->Pulse(_T("Updating view..."));
385 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
386 delete mProgressDialog;
390 mViewer->StartPlayer();
392 //=================================================
394 //=================================================
395 void WxGimmickView::OnAddDir(wxCommandEvent& event)
397 mViewer->StopPlayer();
398 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
399 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
402 _T("Select directory"),
406 if (FD->ShowModal()==wxID_OK)
410 std::string dirname = wx2std (FD->GetPath());
411 bool recurse = isNeedRecursive(dirname);
414 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
418 wxString title(_T("Adding directory"));
420 title = _T("Adding directory (recursive)");
422 new wxProgressDialog(_T("Adding directory"),
427 // wxPD_ESTIMATED_TIME |
428 // wxPD_REMAINING_TIME |
431 mCurrentDirectory = FD->GetPath();
432 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
433 mProgressDialog->Pulse(_T("Updating view..."));
435 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
436 delete mProgressDialog;
440 mViewer->StartPlayer();
443 //=================================================
444 // Test a directory to know if contains sub-directory to analyze
445 bool WxGimmickView::isNeedRecursive(std::string i_name)
447 boost::filesystem::directory_iterator iter(i_name), end_iter;
448 bool bfindir = false;
449 for(; iter != end_iter; ++iter)
451 if(boost::filesystem::is_directory(*iter))
458 //=================================================
460 //=================================================
461 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
463 GimmickDebugMessage(5,
464 "WxGimmickView::OnSelectionChange"
471 valid= ValidateSelected(NULL,
472 mSelectionMinDimension,
473 mSelectionMaxDimension );
478 std::vector<tree::Node*>::const_iterator i;
479 for(i=sel.begin();i!=sel.end()&&valid;++i)
481 valid= ValidateSelected((*i),
482 mSelectionMinDimension,
483 mSelectionMaxDimension );
488 valid= ValidateSelected(sel.front(),
489 mSelectionMinDimension,
490 mSelectionMaxDimension );
495 std::vector<tree::Node*>::const_iterator i;
496 for(i=sel.begin();i!=sel.end()&&valid;++i)
498 valid= ValidateSelected((*i),
499 mSelectionMinDimension,
500 mSelectionMaxDimension );
503 mText->SetLabel(crea::std2wx(GetMessage()));
506 ReadImageThreaded(sel);
512 ReadImageThreaded(sel);
517 //==================================================
519 //==================================================
520 ///Reads Images (Threaded)
521 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
523 GimmickDebugMessage(5,
526 int maxprio = GetMaximalPriority();
527 int prio = maxprio + 2000;
531 //First load the selected images
532 mCurImageItemToShow = sel.front();
535 std::vector<tree::Node*>::const_iterator selected;
536 for(selected=sel.begin();selected!=sel.end();++selected)
538 GimmickDebugMessage(5,
539 "Requesting image from selected "
540 <<(*selected)->GetAttribute("FullFileName")
542 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
543 pointers.push_back(ph);
544 RequestReading(*selected,prio,index,ph);
545 // AddEntryToMap(*selected);
549 mViewer->SetImageVector(pointers);
552 std::vector<tree::Node*> up;
553 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
554 std::vector<tree::Node*>::iterator iterUp;
555 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
557 GimmickDebugMessage(5,
558 "Requesting image from neighbors up "
559 <<(*iterUp)->GetAttribute("FullFileName")
561 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
562 RequestReading(*iterUp,prio,-1,ph);
563 // AddEntryToMap(*iterUp);
565 if (prio == maxprio) break;
570 std::vector<tree::Node*> down;
571 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
572 std::vector<tree::Node*>::iterator iterDown;
573 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
575 GimmickDebugMessage(5,
576 "Requesting image from neighbors down "
577 <<(*iterDown)->GetAttribute("FullFileName")
579 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
580 RequestReading(*iterDown,prio,-1,ph);
581 // AddEntryToMap(*iterDown);
583 if (prio == maxprio) break;
589 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
590 pointers.push_back(ph);
591 mViewer->SetImageVector(pointers);
595 //==================================================
597 //==================================================
599 //==================================================
600 void WxGimmickView::OnInternalIdle()
602 if (!mConstructed) return;
603 static bool first_time = true;
608 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
609 // mViewer->StartPlayer();
612 mViewer->RefreshIfNecessary();
616 //==================================================
618 //==================================================
619 void WxGimmickView::ClearSelection()
622 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
623 mViewer->SetImageVector(pointers);
624 mViewer->RefreshIfNecessary();
628 //=================================================
630 //=================================================
631 void WxGimmickView::OnRemove(wxCommandEvent& event)
633 //TODO Select current tree handler
635 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected();
638 //=================================================
641 //=================================================
642 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
644 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
645 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
648 //=================================================
649 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
651 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
652 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
655 //=================================================
656 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
659 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
660 _T("Check database for files deletion, addition and attributes change. Then give a report."),
661 _T("Repair database (remove deleted files and add new files)."),
662 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
664 wxSingleChoiceDialog dialog(this,
665 _T("Select one of the following synchronization actions:\n")
666 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
667 _T("Synchronization Settings"),
668 WXSIZEOF(choices), choices);
670 //dialog.SetSelection(0);
672 if (dialog.ShowModal() == wxID_OK)
674 int sel=dialog.GetSelection();
676 bool checkAttributes=false;
677 if(sel==2 || sel==3){repair=true;}
678 if(sel==1 || sel==3){checkAttributes=true;}
679 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
680 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
681 if(sel==2 || sel==3){
682 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
687 //=================================================
689 //=================================================
690 void WxGimmickView::OnSettings(wxCommandEvent& event)
692 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
693 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
695 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
697 siz->Add( nb,1,wxGROW ,0);
698 CreateSettingsDialog(nb,dial);
702 //=================================================
704 //=================================================
706 void WxGimmickView::OnTools(wxCommandEvent& event)
708 mViewer->StopPlayer();
710 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(300,250));
712 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
713 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
715 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
716 dialSizer->Add(nb,1,wxGROW,0);
717 dialSizer->Add(buttonsSizer,0,wxGROW);
719 #if defined(BUILD_BRUKER)
720 //First page: Bruker Image Reader
721 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
722 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
725 dial->SetSizer(dialSizer, true);
729 if (dial->GetReturnCode() == wxID_OK)
731 #if defined(BUILD_BRUKER)
732 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
734 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
735 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
736 bool addToDB = gimmickTools->getCheckBoxValue();
738 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
740 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
741 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
744 b2d.SetInputDirectory(inputDir);
745 b2d.SetOutputDirectory(outputDir);
746 b2d.SetConvertModeToDicom();
751 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
752 mCurrentDirectory = gimmickTools->getOutputDir(); // Try // JPRx
753 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
754 mProgressDialog->Pulse(_T("Updating view..."));
756 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
757 delete mProgressDialog;
765 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
771 mViewer->StartPlayer();
773 //=================================================
775 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
777 //First page: Customization of configurations
780 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
781 //Database Path String
783 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
784 //Syncronization Event String
786 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
787 //Syncronization Frequency String
789 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
791 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
793 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
795 //Second page: Creation of Databases
796 wxPanel* databaseCreation=new wxPanel(nb);
797 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );
799 //Third page: CD/DVD Watch
800 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
801 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
803 //Fourth page: Selection of attributes to show (edit)
804 wxPanel* attSelection=new wxPanel(nb);
805 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
808 //===================================================================
809 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
810 const std::string& dbPath,
811 const std::string& syncEvent,
812 const std::string& syncFreq)
814 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
815 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
816 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
817 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
820 //===================================================================
821 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
823 mListener->SetMonitoredDrive(drive);
824 mListener->SetAddFilesState(addFiles);
825 mListener->SetRemoveFilesState(removeFiles);
828 //========================================================================
830 void WxGimmickView::OnDriveMount(bool mount)
832 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
834 mListener->GetMonitoredDrive(drive);
838 mViewer->StopPlayer();
840 wxString title(_T("Adding drive"));
842 new wxProgressDialog(_T("Adding drive"),
847 // wxPD_ESTIMATED_TIME |
848 // wxPD_REMAINING_TIME |
850 mCurrentDirectory = crea::std2wx(drive);
851 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
852 mProgressDialog->Pulse(_T("Updating view..."));
854 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
855 delete mProgressDialog;
857 mViewer->StartPlayer();
862 mGimmick->DeleteDrive(drive);
863 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
868 //========================================================================
870 void WxGimmickView::StartListeningThread()
875 //========================================================================
877 void WxGimmickView::StopListeningThread()
882 //========================================================================
883 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
885 wxDialog* dial= new wxDialog (this,-1,_T("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
886 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
887 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
889 siz->Add( ef,1,wxGROW ,0);
894 //========================================================================
895 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
897 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
898 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
901 //=================================================
902 /// AddProgress Gimmick callback
903 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
908 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
909 p.GetNumberScannedDirs(),
910 p.GetNumberScannedFiles(),
911 p.GetNumberHandledFiles(),
912 p.GetNumberAddedFiles());
913 // std::cout << "OnAddProgress "<<mess<<std::endl;
914 wxString s(wxString::From8BitData(mess));
915 // std::cout << "Pulse"<<std::endl;
916 if (!mProgressDialog->Pulse(s))
920 // std::cout << "OnAddProgress ok"<<std::endl;
922 //=================================================
924 //=================================================
925 void WxGimmickView::DisplayAddSummary()
927 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
928 std::stringstream mess;
929 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
930 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
931 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
932 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
935 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",
937 (int)( summary.parse_time*100./summary.total_time),
938 summary.file_scan_time,
939 (int)(summary.file_scan_time*100./summary.total_time),
940 summary.update_structs_time,
941 (int)(summary.update_structs_time*100./summary.total_time),
942 summary.update_database_time,
943 (int)(summary.update_database_time*100./summary.total_time),
944 summary.total_time );
948 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
951 //////////////////////////////////////////////////
952 // Add a DB to application //
953 // @param event : WxEvent //
955 //////////////////////////////////////////////////
956 void WxGimmickView::OnAddDB(wxCommandEvent& event)
960 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
961 std::string wc("*.sqlite3*");
962 wxFileDialog* FD = new wxFileDialog( 0,
970 if (FD->ShowModal()==wxID_OK)
975 std::stringstream st;
976 for(int i = 0; i< files.size(); i++)
978 //get name of DB (file name)
979 size_t pos = files[i].find_last_of(_T("\\"));
980 std::string name = crea::wx2std(files[i].substr(pos+1));
981 pos = name.find_last_of(".");
982 name = name.substr(0,pos);
984 mGimmick->addDB(name, crea::wx2std(files[i]));
986 CreateSingleTreeView(name);
990 ////////////////////////////////////////////////////
991 // Create a DB from an Attributes Descriptor files //
992 // @param event : WxEvent //
994 //////////////////////////////////////////////////
995 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
999 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1000 std::string wc("*.txt");
1001 wxFileDialog* FD = new wxFileDialog( 0,
1009 if (FD->ShowModal()==wxID_OK)
1012 wxArrayString afile;
1013 FD->GetPaths(afile);
1014 //get name of DB (file name)
1015 std::string file = crea::wx2std(afile[0]);
1016 size_t pos = file.find_last_of("\\");
1017 std::string name = file.substr(pos+1);
1018 std::string directory = file.substr(0,pos);
1019 pos = name.find_last_of(".");
1020 name = name.substr(0,pos);
1021 //get directory to store DB
1022 directory += "\\" + name + ".sqlite3";
1024 mGimmick->createDB(name, file,directory);
1025 //create TreeHandler
1026 mGimmick->addDB(name, directory);
1028 CreateSingleTreeView(name);
1032 //=================================================
1034 //=================================================
1035 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1036 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1037 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1038 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1039 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1040 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1041 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1042 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1043 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1045 //=================================================
1047 } // EO namespace creaImageIO