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>
8 #include <creaImageIOWxPACSConnectionPanel.h>
9 #include <creaImageIOWxDescriptorPanel.h>
13 #include "icons/accept.xpm"
14 #include "icons/add.xpm"
15 #include "icons/folder-down.xpm"
16 #include "icons/page-down.xpm"
17 #include "icons/remove.xpm"
18 #include "icons/database-add.xpm"
19 #include "icons/create-database.xpm"
20 #include "icons/help.xpm"
21 #include "icons/synchronize.xpm"
22 #include "icons/settings.xpm"
23 #include "icons/tools.xpm"
24 //#include "icons/import.xpm"
26 #include <wx/imaglist.h>
27 #include <wx/popupwin.h>
28 #include<boost/filesystem/operations.hpp>
29 #if defined(BUILD_BRUKER)
30 #include "bruker2dicom.h"
36 //======================================================================
37 // The ids of the different tools
42 TOOL_ADDDATABASE_ID = 3,
44 TOOL_SYNCHRONIZE_ID = 5,
50 //======================================================================
52 //================================================================
54 const int icon_number = 11;
71 //================================================================
73 //================================================================
75 const icon_id Icon[5] = { Icon_Database,
81 //================================================================
84 //======================================================================
86 WxGimmickView::WxGimmickView(Gimmick* gimmick,
93 int number_of_threads)
94 : wxPanel(parent,id,pos,size),
95 GimmickView(gimmick, number_of_threads),
99 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
101 // Sets the current directory to the home dir
102 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
104 // Connect the AddProgress callback
105 gimmick->ConnectAddProgressObserver
106 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
108 // Create the list of icons (mIcon)
112 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
114 // Create the tool bar
116 sizer->Add( mToolBar ,0, wxGROW ,0);
118 // Split part below toolbar into notebook for views and panel
119 // for preview, messages...
120 mSplitter = new wxSplitterWindow( this , -1);
124 mNotebook = new wxNotebook(mSplitter,
125 -1,wxDefaultPosition, wxDefaultSize, 0);
131 mSelectionMaxDimension= max_dim;
132 mSelectionMinDimension= min_dim;
138 mBottomPanel = new wxPanel(mSplitter,-1);
140 wxBoxSizer *bottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
144 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
145 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
146 mViewer->SetImageVector(pointers);
147 mViewer->StartPlayer();
150 bottom_sizer->Add(mViewer,1,wxGROW,1);
153 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
154 bottom_sizer->Add(mText,0,wxGROW,0);
158 mBottomPanel->SetSizer(bottom_sizer);
161 int hsize = size.GetHeight();
163 int top_minsize = 450;
164 int bottom_minsize = 50;
166 mSplitter->SetMinimumPaneSize( bottom_minsize );
167 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
170 sizer->Add( mSplitter,1,wxGROW ,0);
176 mListener=new Listener();
177 mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount , this, _1 ) );
184 //======================================================================
186 //======================================================================
188 WxGimmickView::~WxGimmickView()
190 // stop the viewer before application exit.
191 mViewer->StopPlayer();
192 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
194 if(mListener->IsAlive())
199 //======================================================================
201 //======================================================================
202 /// Creates the tool bar
203 void WxGimmickView::CreateToolBar()
205 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
206 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
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 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
250 _T("Create database"),
251 mIcon->GetBitmap(Icon_create_database),
252 _T("Create DB from an Attributes Descriptor file")
255 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
259 //======================================================================
262 //======================================================================
263 /// Create the tree view for TreeHandler provided
264 void WxGimmickView::CreateTreeView( TreeHandler* h)
266 std::string name(h->GetTree().GetAttribute("Name"));
267 GimmickMessage(2,"Creating the tree view for '"<<
268 name<<"'"<<std::endl);
269 // Create the WxTreeView
270 WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
272 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
273 // ALREADY IN THE MAP
274 GetTreeViewMap()[name] = view;
277 mNotebook->AddPage( view, crea::std2wx(name) );
281 //======================================================================
282 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
284 std::vector<std::string> files;
285 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
286 ReadImagesNotThreaded(s,files,dim);
288 //======================================================================
290 //======================================================================
291 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
293 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
295 //======================================================================
297 //======================================================================
298 void WxGimmickView::GetImages(int dim,
299 const std::vector<std::string>& files,
300 std::vector<vtkImageData*>& s)
302 ReadImagesNotThreaded(s,files,dim);
304 //======================================================================
307 //=================================================
308 void WxGimmickView::CreateIconList()
310 // Size of the icons;
314 // should correspond to Icon_xxx enum
315 icons[Icon_accept] = wxIcon(accept_xpm);
316 icons[Icon_add] = wxIcon(add_xpm);
317 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
318 icons[Icon_page_down] = wxIcon(page_down_xpm);
319 icons[Icon_remove] = wxIcon(remove_xpm);
320 icons[Icon_database_add] = wxIcon(database_add_xpm);
321 icons[Icon_help] = wxIcon(help_xpm);
322 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
323 icons[Icon_create_database] = wxIcon(create_database_xpm);
324 icons[Icon_settings] = wxIcon(settings_xpm);
325 icons[Icon_tools] = wxIcon(tools_xpm);
327 // unsigned int NbIcons = 8;
328 // Make an image list containing small icons
329 mIcon = new wxImageList(size,size,true);
331 // Make all icons the same size = size of the first one
332 int sizeOrig = icons[0].GetWidth();
333 for ( size_t i = 0; i < icon_number; i++ )
335 if ( size == sizeOrig )
337 mIcon->Add(icons[i]);
341 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
345 //=================================================
348 //=================================================
349 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
351 mViewer->StopPlayer();
352 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
354 wxFileDialog* FD = new wxFileDialog( 0,
362 if (FD->ShowModal()==wxID_OK)
369 std::vector<std::string> filenames;
370 for (i=0;i<files.GetCount();++i)
372 filenames.push_back(wx2std(files[i]));
373 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
377 new wxProgressDialog(_T("Adding file(s)"),
382 // wxPD_ESTIMATED_TIME |
383 // wxPD_REMAINING_TIME |
386 // TO DO : select the current tree handler
387 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
389 mProgressDialog->Pulse(_T("Updating view..."));
391 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
392 delete mProgressDialog;
396 mViewer->StartPlayer();
398 //=================================================
400 //=================================================
401 void WxGimmickView::OnAddDir(wxCommandEvent& event)
403 mViewer->StopPlayer();
404 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
405 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
408 _T("Select directory"),
412 if (FD->ShowModal()==wxID_OK)
416 std::string dirname = wx2std (FD->GetPath());
417 bool recurse = isNeedRecursive(dirname);
420 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
424 wxString title(_T("Adding directory"));
426 title = _T("Adding directory (recursive)");
428 new wxProgressDialog(_T("Adding directory"),
430 NumberFilesToAdd(dirname,recurse),
434 // wxPD_ESTIMATED_TIME |
435 // wxPD_REMAINING_TIME |
438 mCurrentDirectory = FD->GetPath();
439 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
440 mProgressDialog->Pulse(_T("Updating view..."));
442 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
443 delete mProgressDialog;
447 mViewer->StartPlayer();
451 //=================================================
452 // Determines number of files potentially to add to database
453 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
456 if ( !boost::filesystem::exists( dirpath ) ) return nb;
457 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
458 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
460 // If is directory & recurse : do recurse
461 if ( boost::filesystem::is_directory(itr->status()) )
465 nb += NumberFilesToAdd(itr->string(), recursive);
477 //=================================================
478 // Test a directory to know if contains sub-directory to analyze
479 bool WxGimmickView::isNeedRecursive(std::string i_name)
481 boost::filesystem::directory_iterator iter(i_name), end_iter;
482 bool bfindir = false;
483 for(; iter != end_iter; ++iter)
485 if(boost::filesystem::is_directory(*iter))
492 //=================================================
494 //=================================================
495 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
497 GimmickDebugMessage(5,
498 "WxGimmickView::OnSelectionChange"
505 valid= ValidateSelected(NULL,
506 mSelectionMinDimension,
507 mSelectionMaxDimension );
512 std::vector<tree::Node*>::const_iterator i;
513 for(i=sel.begin();i!=sel.end()&&valid;++i)
515 valid= ValidateSelected((*i),
516 mSelectionMinDimension,
517 mSelectionMaxDimension );
522 valid= ValidateSelected(sel.front(),
523 mSelectionMinDimension,
524 mSelectionMaxDimension );
529 std::vector<tree::Node*>::const_iterator i;
530 for(i=sel.begin();i!=sel.end()&&valid;++i)
532 valid= ValidateSelected((*i),
533 mSelectionMinDimension,
534 mSelectionMaxDimension );
537 mText->SetLabel(crea::std2wx(GetMessage()));
540 ReadImageThreaded(sel);
546 ReadImageThreaded(sel);
551 //==================================================
553 //==================================================
554 ///Reads Images (Threaded)
555 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
557 GimmickDebugMessage(5,
560 int maxprio = GetMaximalPriority();
561 int prio = maxprio + 2000;
565 //First load the selected images
566 mCurImageItemToShow = sel.front();
569 std::vector<tree::Node*>::const_iterator selected;
570 for(selected=sel.begin();selected!=sel.end();++selected)
572 GimmickDebugMessage(5,
573 "Requesting image from selected "
574 <<(*selected)->GetAttribute("FullFileName")
576 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
577 pointers.push_back(ph);
578 RequestReading(*selected,prio,index,ph);
579 // AddEntryToMap(*selected);
583 mViewer->SetImageVector(pointers);
586 std::vector<tree::Node*> up;
587 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
588 std::vector<tree::Node*>::iterator iterUp;
589 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
591 GimmickDebugMessage(5,
592 "Requesting image from neighbors up "
593 <<(*iterUp)->GetAttribute("FullFileName")
595 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
596 RequestReading(*iterUp,prio,-1,ph);
597 // AddEntryToMap(*iterUp);
599 if (prio == maxprio) break;
604 std::vector<tree::Node*> down;
605 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
606 std::vector<tree::Node*>::iterator iterDown;
607 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
609 GimmickDebugMessage(5,
610 "Requesting image from neighbors down "
611 <<(*iterDown)->GetAttribute("FullFileName")
613 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
614 RequestReading(*iterDown,prio,-1,ph);
615 // AddEntryToMap(*iterDown);
617 if (prio == maxprio) break;
623 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
624 pointers.push_back(ph);
625 mViewer->SetImageVector(pointers);
629 //==================================================
631 //==================================================
633 //==================================================
634 void WxGimmickView::OnInternalIdle()
636 if (!mConstructed) return;
637 static bool first_time = true;
642 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
643 // mViewer->StartPlayer();
646 mViewer->RefreshIfNecessary();
650 //==================================================
652 //==================================================
653 void WxGimmickView::ClearSelection()
656 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
657 mViewer->SetImageVector(pointers);
658 mViewer->RefreshIfNecessary();
662 //=================================================
664 //=================================================
665 void WxGimmickView::OnRemove(wxCommandEvent& event)
667 //TODO Select current tree handler
669 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected();
672 //=================================================
675 //=================================================
676 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
678 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
679 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
682 //=================================================
683 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
685 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
686 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
689 //=================================================
690 void WxGimmickView::AddDir(std::string dirName)
692 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
693 mCurrentDirectory = crea::std2wx(dirName);
694 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
695 mProgressDialog->Pulse(_T("Updating view..."));
697 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
698 delete mProgressDialog;
702 //=================================================
703 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
706 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
707 _T("Check database for files deletion, addition and attributes change. Then give a report."),
708 _T("Repair database (remove deleted files and add new files)."),
709 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
711 wxSingleChoiceDialog dialog(this,
712 _T("Select one of the following synchronization actions:\n")
713 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
714 _T("Synchronization Settings"),
715 WXSIZEOF(choices), choices);
717 //dialog.SetSelection(0);
719 if (dialog.ShowModal() == wxID_OK)
721 int sel=dialog.GetSelection();
723 bool checkAttributes=false;
724 if(sel==2 || sel==3){repair=true;}
725 if(sel==1 || sel==3){checkAttributes=true;}
726 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
727 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
728 if(sel==2 || sel==3){
729 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
734 //=================================================
736 //=================================================
737 void WxGimmickView::OnSettings(wxCommandEvent& event)
739 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
740 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
742 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
744 siz->Add( nb,1,wxGROW ,0);
745 CreateSettingsDialog(nb,dial);
749 //=================================================
750 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
753 // Test if one image is selected => export
755 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
765 void WxGimmickView::ExportImages()
767 //Archive selection: name, emplacement
768 //same process than copy local but to a zip
769 // if settings are yes "always ask for descriptor addition", ask
770 // if settings are yes, adding descriptor
773 void WxGimmickView::ImportImages()
777 // Contain a descriptor.text
778 // create a new database, and add to database
779 // if not, add to current database
783 //=================================================
785 void WxGimmickView::OnTools(wxCommandEvent& event)
787 mViewer->StopPlayer();
789 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
791 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
792 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
793 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
794 dialSizer->Add(nb,1,wxGROW,0);
795 dialSizer->Add(buttonsSizer,0,wxGROW);
797 #if defined(BUILD_BRUKER)
798 //First page: Bruker Image Reader
799 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
800 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
803 dial->SetSizer(dialSizer, true);
807 if (dial->GetReturnCode() == wxID_OK)
809 #if defined(BUILD_BRUKER)
810 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
812 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
813 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
815 bool addToDB = gimmickTools->getCheckBoxValue();
817 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
819 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
820 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
823 b2d.SetInputDirectory(inputDir);
824 b2d.SetOutputDirectory(outputDir);
825 b2d.SetConvertModeToDicom();
831 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
832 mCurrentDirectory = gimmickTools->getOutputDir();
833 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
834 mProgressDialog->Pulse(_T("Updating view..."));
836 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
837 delete mProgressDialog;
845 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
852 mViewer->StartPlayer();
854 //=================================================
856 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
858 //First page: Customization of configurations
861 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
862 //Database Path String
864 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
865 //Syncronization Event String
867 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
868 //Syncronization Frequency String
870 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
872 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
874 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
876 //Second page: Creation of Databases
877 /*wxPanel* databaseCreation=new wxPanel(nb);
878 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
880 //Second page (temporary): Connection to PACS
881 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
882 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
884 //Third page: CD/DVD Watch
885 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
886 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
888 //Fourth page: Selection of attributes to show
889 std::vector<std::string> shown;
890 std::vector<std::string> nShown;
891 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
892 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
893 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
894 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
897 //===================================================================
898 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
899 std::vector<std::string>& nShown, int level)
901 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
904 //===================================================================
905 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
907 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
908 std::vector<std::string> n=nShown;
909 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
911 //===================================================================
912 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
913 const std::string& dbPath,
914 const std::string& syncEvent,
915 const std::string& syncFreq)
917 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
918 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
919 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
920 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
923 //===================================================================
924 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
926 mListener->SetMonitoredDrive(drive);
927 mListener->SetAddFilesState(addFiles);
928 mListener->SetRemoveFilesState(removeFiles);
931 //========================================================================
933 void WxGimmickView::OnDriveMount(bool mount)
935 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
937 mListener->GetMonitoredDrive(drive);
941 mViewer->StopPlayer();
943 wxString title(_T("Adding drive"));
945 new wxProgressDialog(_T("Adding drive"),
950 // wxPD_ESTIMATED_TIME |
951 // wxPD_REMAINING_TIME |
953 mCurrentDirectory = crea::std2wx(drive);
954 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
955 mProgressDialog->Pulse(_T("Updating view..."));
957 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
958 delete mProgressDialog;
960 mViewer->StartPlayer();
964 mGimmick->DeleteDrive(drive);
965 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
969 //========================================================================
971 void WxGimmickView::StartListeningThread()
976 //========================================================================
978 void WxGimmickView::StopListeningThread()
983 //========================================================================
984 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
986 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
987 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
988 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
990 siz->Add( ef,1,wxGROW ,0);
995 //========================================================================
996 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
998 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
999 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1002 //=================================================
1003 /// AddProgress Gimmick callback
1004 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1007 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1008 p.GetNumberScannedDirs(),
1009 p.GetNumberScannedFiles(),
1010 p.GetNumberHandledFiles(),
1011 p.GetNumberAddedFiles());
1012 // std::cout << "OnAddProgress "<<mess<<std::endl;
1013 wxString s(wxString::From8BitData(mess));
1014 // std::cout << "Pulse"<<std::endl;
1015 if (!mProgressDialog->Pulse(s))
1019 // std::cout << "OnAddProgress ok"<<std::endl;
1021 //=================================================
1023 //=================================================
1024 void WxGimmickView::DisplayAddSummary()
1026 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
1027 std::stringstream mess;
1028 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
1029 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
1030 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
1031 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
1032 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1035 ////////////////////////////////////////////////
1036 // Add a DB to application //
1037 // @param event : WxEvent //
1039 ////////////////////////////////////////////////
1040 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1043 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1044 std::string wc("*.sqlite3*");
1045 wxFileDialog* FD = new wxFileDialog( 0,
1053 if (FD->ShowModal()==wxID_OK)
1056 wxArrayString files;
1057 FD->GetPaths(files);
1058 std::stringstream st;
1059 for(int i = 0; i< files.size(); i++)
1061 //get name of DB (file name)
1062 size_t pos = files[i].find_last_of(_T("\\"));
1063 std::string name = crea::wx2std(files[i].substr(pos+1));
1064 pos = name.find_last_of(".");
1065 name = name.substr(0,pos);
1066 //create TreeHandler
1067 mGimmick->addDB(name, crea::wx2std(files[i]));
1069 CreateSingleTreeView(name);
1073 ////////////////////////////////////////////////////
1074 // Create a DB from an Attributes Descriptor files //
1075 // @param event : WxEvent //
1077 //////////////////////////////////////////////////
1078 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1080 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1081 DescriptorPan->Layout();
1082 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1085 std::string file(DescriptorPan->GetDescriptor());
1088 size_t pos = file.find_last_of("\\");
1089 std::string name = file.substr(pos+1);
1090 std::string directory = file.substr(0,pos);
1091 pos = name.find_last_of(".");
1092 name = name.substr(0,pos);
1093 //get directory to store DB
1094 directory += "\\" + name + ".sqlite3";
1096 mGimmick->createDB(name, file,directory);
1097 //create TreeHandler
1098 mGimmick->addDB(name, directory);
1100 CreateSingleTreeView(name);
1105 //=================================================
1107 //=================================================
1108 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1109 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1110 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1111 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1112 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1113 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1114 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1115 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1116 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1118 //=================================================
1120 } // EO namespace creaImageIO