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,
89 const wxPoint& pos, const wxSize& size,
92 int number_of_threads)
93 : wxPanel(parent,id,pos,size),
94 GimmickView(gimmick, number_of_threads),
98 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
100 // Sets the current directory to the home dir
101 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
103 // Connect the AddProgress callback
104 gimmick->ConnectAddProgressObserver
105 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
107 // Create the list of icons (mIcon)
111 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
113 // Create the tool bar
115 sizer->Add( mToolBar ,0, wxGROW ,0);
117 // Split part below toolbar into notebook for views and panel
118 // for preview, messages...
119 mSplitter = new wxSplitterWindow( this , -1);
123 mNotebook = new wxNotebook(mSplitter,
124 -1,wxDefaultPosition, wxDefaultSize, 0);
130 mSelectionMaxDimension= max_dim;
131 mSelectionMinDimension= min_dim;
137 mBottomPanel = new wxPanel(mSplitter,-1);
139 wxBoxSizer *bottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
143 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
144 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
145 mViewer->SetImageVector(pointers);
146 mViewer->StartPlayer();
149 bottom_sizer->Add(mViewer,1,wxGROW,1);
152 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
153 bottom_sizer->Add(mText,0,wxGROW,0);
157 mBottomPanel->SetSizer(bottom_sizer);
160 int hsize = size.GetHeight();
162 int top_minsize = 450;
163 int bottom_minsize = 50;
165 mSplitter->SetMinimumPaneSize( bottom_minsize );
166 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
169 sizer->Add( mSplitter,1,wxGROW ,0);
175 mListener=new Listener();
176 mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount , this, _1 ) );
183 //======================================================================
185 //======================================================================
187 WxGimmickView::~WxGimmickView()
189 // stop the viewer before application exit.
190 mViewer->StopPlayer();
191 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
193 if(mListener->IsAlive())
198 //======================================================================
200 //======================================================================
201 /// Creates the tool bar
202 void WxGimmickView::CreateToolBar()
204 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
205 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
208 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
210 mIcon->GetBitmap(Icon_page_down),
211 _T("Add one or more file to database")
213 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
215 mIcon->GetBitmap(Icon_folder_down),
216 _T("Add the content of a folder to database")
218 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
220 mIcon->GetBitmap(Icon_database_add),
221 _T("Open a local or distant database")
223 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
225 mIcon->GetBitmap(Icon_remove),
226 _T("Remove selected items")
228 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
230 mIcon->GetBitmap(Icon_synchronize),
231 _T("Synchronizes the database with disk")
233 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
235 mIcon->GetBitmap(Icon_help),
236 _T("Open help window")
238 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
239 _T("System settings"),
240 mIcon->GetBitmap(Icon_settings),
241 _T("Allows the modification of various system settings")
243 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
245 mIcon->GetBitmap(Icon_tools),
246 _T("Applies tools to images")
248 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
249 _T("Create database"),
250 mIcon->GetBitmap(Icon_create_database),
251 _T("Create DB from an Attributes Descriptor file")
254 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
258 //======================================================================
261 //======================================================================
262 /// Create the tree view for TreeHandler provided
263 void WxGimmickView::CreateTreeView( TreeHandler* h)
265 std::string name(h->GetTree().GetAttribute("Name"));
266 GimmickMessage(2,"Creating the tree view for '"<<
267 name<<"'"<<std::endl);
268 // Create the WxTreeView
269 WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
271 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
272 // ALREADY IN THE MAP
273 GetTreeViewMap()[name] = view;
276 mNotebook->AddPage( view, crea::std2wx(name) );
280 //======================================================================
281 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
283 std::vector<std::string> files;
284 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
285 ReadImagesNotThreaded(s,files,dim);
287 //======================================================================
289 //======================================================================
290 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
292 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
294 //======================================================================
296 //======================================================================
297 void WxGimmickView::GetImages(int dim,
298 const std::vector<std::string>& files,
299 std::vector<vtkImageData*>& s)
301 ReadImagesNotThreaded(s,files,dim);
303 //======================================================================
306 //=================================================
307 void WxGimmickView::CreateIconList()
309 // Size of the icons;
313 // should correspond to Icon_xxx enum
314 icons[Icon_accept] = wxIcon(accept_xpm);
315 icons[Icon_add] = wxIcon(add_xpm);
316 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
317 icons[Icon_page_down] = wxIcon(page_down_xpm);
318 icons[Icon_remove] = wxIcon(remove_xpm);
319 icons[Icon_database_add] = wxIcon(database_add_xpm);
320 icons[Icon_help] = wxIcon(help_xpm);
321 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
322 icons[Icon_create_database] = wxIcon(create_database_xpm);
323 icons[Icon_settings] = wxIcon(settings_xpm);
324 icons[Icon_tools] = wxIcon(tools_xpm);
326 // unsigned int NbIcons = 8;
327 // Make an image list containing small icons
328 mIcon = new wxImageList(size,size,true);
330 // Make all icons the same size = size of the first one
331 int sizeOrig = icons[0].GetWidth();
332 for ( size_t i = 0; i < icon_number; i++ )
334 if ( size == sizeOrig )
336 mIcon->Add(icons[i]);
340 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
344 //=================================================
347 //=================================================
348 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
350 mViewer->StopPlayer();
351 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
353 wxFileDialog* FD = new wxFileDialog( 0,
361 if (FD->ShowModal()==wxID_OK)
368 std::vector<std::string> filenames;
369 for (i=0;i<files.GetCount();++i)
371 filenames.push_back(wx2std(files[i]));
372 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
376 new wxProgressDialog(_T("Adding file(s)"),
381 // wxPD_ESTIMATED_TIME |
382 // wxPD_REMAINING_TIME |
385 // TO DO : select the current tree handler
386 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
388 mProgressDialog->Pulse(_T("Updating view..."));
390 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
391 delete mProgressDialog;
395 mViewer->StartPlayer();
397 //=================================================
399 //=================================================
400 void WxGimmickView::OnAddDir(wxCommandEvent& event)
402 mViewer->StopPlayer();
403 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
404 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
407 _T("Select directory"),
411 if (FD->ShowModal()==wxID_OK)
415 std::string dirname = wx2std (FD->GetPath());
416 bool recurse = isNeedRecursive(dirname);
419 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
423 wxString title(_T("Adding directory"));
425 title = _T("Adding directory (recursive)");
427 new wxProgressDialog(_T("Adding directory"),
429 NumberFilesToAdd(dirname,recurse),
433 // wxPD_ESTIMATED_TIME |
434 // wxPD_REMAINING_TIME |
437 mCurrentDirectory = FD->GetPath();
438 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
439 mProgressDialog->Pulse(_T("Updating view..."));
441 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
442 delete mProgressDialog;
446 mViewer->StartPlayer();
450 //=================================================
451 // Determines number of files potentially to add to database
452 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
455 if ( !boost::filesystem::exists( dirpath ) ) return nb;
456 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
457 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
459 // If is directory & recurse : do recurse
460 if ( boost::filesystem::is_directory(itr->status()) )
464 nb += NumberFilesToAdd(itr->string(), recursive);
476 //=================================================
477 // Test a directory to know if contains sub-directory to analyze
478 bool WxGimmickView::isNeedRecursive(std::string i_name)
480 boost::filesystem::directory_iterator iter(i_name), end_iter;
481 bool bfindir = false;
482 for(; iter != end_iter; ++iter)
484 if(boost::filesystem::is_directory(*iter))
491 //=================================================
493 //=================================================
494 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
496 GimmickDebugMessage(5,
497 "WxGimmickView::OnSelectionChange"
504 valid= ValidateSelected(NULL,
505 mSelectionMinDimension,
506 mSelectionMaxDimension );
511 std::vector<tree::Node*>::const_iterator i;
512 for(i=sel.begin();i!=sel.end()&&valid;++i)
514 valid= ValidateSelected((*i),
515 mSelectionMinDimension,
516 mSelectionMaxDimension );
521 valid= ValidateSelected(sel.front(),
522 mSelectionMinDimension,
523 mSelectionMaxDimension );
528 std::vector<tree::Node*>::const_iterator i;
529 for(i=sel.begin();i!=sel.end()&&valid;++i)
531 valid= ValidateSelected((*i),
532 mSelectionMinDimension,
533 mSelectionMaxDimension );
536 mText->SetLabel(crea::std2wx(GetMessage()));
539 ReadImageThreaded(sel);
545 ReadImageThreaded(sel);
550 //==================================================
552 //==================================================
553 ///Reads Images (Threaded)
554 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
556 GimmickDebugMessage(5,
559 int maxprio = GetMaximalPriority();
560 int prio = maxprio + 2000;
564 //First load the selected images
565 mCurImageItemToShow = sel.front();
568 std::vector<tree::Node*>::const_iterator selected;
569 for(selected=sel.begin();selected!=sel.end();++selected)
571 GimmickDebugMessage(5,
572 "Requesting image from selected "
573 <<(*selected)->GetAttribute("FullFileName")
575 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
576 pointers.push_back(ph);
577 RequestReading(*selected,prio,index,ph);
578 // AddEntryToMap(*selected);
582 mViewer->SetImageVector(pointers);
585 std::vector<tree::Node*> up;
586 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
587 std::vector<tree::Node*>::iterator iterUp;
588 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
590 GimmickDebugMessage(5,
591 "Requesting image from neighbors up "
592 <<(*iterUp)->GetAttribute("FullFileName")
594 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
595 RequestReading(*iterUp,prio,-1,ph);
596 // AddEntryToMap(*iterUp);
598 if (prio == maxprio) break;
603 std::vector<tree::Node*> down;
604 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
605 std::vector<tree::Node*>::iterator iterDown;
606 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
608 GimmickDebugMessage(5,
609 "Requesting image from neighbors down "
610 <<(*iterDown)->GetAttribute("FullFileName")
612 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
613 RequestReading(*iterDown,prio,-1,ph);
614 // AddEntryToMap(*iterDown);
616 if (prio == maxprio) break;
622 ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
623 pointers.push_back(ph);
624 mViewer->SetImageVector(pointers);
628 //==================================================
630 //==================================================
632 //==================================================
633 void WxGimmickView::OnInternalIdle()
635 if (!mConstructed) return;
636 static bool first_time = true;
641 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
642 // mViewer->StartPlayer();
645 mViewer->RefreshIfNecessary();
649 //==================================================
651 //==================================================
652 void WxGimmickView::ClearSelection()
655 pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
656 mViewer->SetImageVector(pointers);
657 mViewer->RefreshIfNecessary();
661 //=================================================
663 //=================================================
664 void WxGimmickView::OnRemove(wxCommandEvent& event)
666 //TODO Select current tree handler
668 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected();
671 //=================================================
674 //=================================================
675 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
677 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
678 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
681 //=================================================
682 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
684 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
685 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
688 //=================================================
689 void WxGimmickView::AddDir(std::string dirName)
691 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
692 mCurrentDirectory = crea::std2wx(dirName);
693 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
694 mProgressDialog->Pulse(_T("Updating view..."));
696 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
697 delete mProgressDialog;
701 //=================================================
702 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
705 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
706 _T("Check database for files deletion, addition and attributes change. Then give a report."),
707 _T("Repair database (remove deleted files and add new files)."),
708 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
710 wxSingleChoiceDialog dialog(this,
711 _T("Select one of the following synchronization actions:\n")
712 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
713 _T("Synchronization Settings"),
714 WXSIZEOF(choices), choices);
716 //dialog.SetSelection(0);
718 if (dialog.ShowModal() == wxID_OK)
720 int sel=dialog.GetSelection();
722 bool checkAttributes=false;
723 if(sel==2 || sel==3){repair=true;}
724 if(sel==1 || sel==3){checkAttributes=true;}
725 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
726 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
727 if(sel==2 || sel==3){
728 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
733 //=================================================
735 //=================================================
736 void WxGimmickView::OnSettings(wxCommandEvent& event)
738 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
739 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
741 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
743 siz->Add( nb,1,wxGROW ,0);
744 CreateSettingsDialog(nb,dial);
748 //=================================================
749 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
752 // Test if one image is selected => export
754 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
764 void WxGimmickView::ExportImages()
766 //Archive selection: name, emplacement
767 //same process than copy local but to a zip
768 // if settings are yes "always ask for descriptor addition", ask
769 // if settings are yes, adding descriptor
772 void WxGimmickView::ImportImages()
776 // Contain a descriptor.text
777 // create a new database, and add to database
778 // if not, add to current database
782 //=================================================
784 void WxGimmickView::OnTools(wxCommandEvent& event)
786 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);
794 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
795 dialSizer->Add(nb,1,wxGROW,0);
796 dialSizer->Add(buttonsSizer,0,wxGROW);
798 #if defined(BUILD_BRUKER)
799 //First page: Bruker Image Reader
800 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
801 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
805 dial->SetSizer(dialSizer, true);
809 if (dial->GetReturnCode() == wxID_OK)
811 #if defined(BUILD_BRUKER)
812 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
814 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
815 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
816 bool addToDB = gimmickTools->getCheckBoxValue();
818 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
820 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
821 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
824 b2d.SetInputDirectory(inputDir);
825 b2d.SetOutputDirectory(outputDir);
826 b2d.SetConvertModeToDicom();
832 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
833 mCurrentDirectory = gimmickTools->getOutputDir();
834 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
835 mProgressDialog->Pulse(_T("Updating view..."));
837 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
838 delete mProgressDialog;
846 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
853 mViewer->StartPlayer();
855 //=================================================
857 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
859 //First page: Customization of configurations
862 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
863 //Database Path String
865 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
866 //Syncronization Event String
868 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
869 //Syncronization Frequency String
871 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
873 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
875 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
877 //Second page: Creation of Databases
878 /*wxPanel* databaseCreation=new wxPanel(nb);
879 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
881 //Second page (temporary): Connection to PACS
882 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
883 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
885 //Third page: CD/DVD Watch
886 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
887 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
889 //Fourth page: Selection of attributes to show
890 std::vector<std::string> shown;
891 std::vector<std::string> nShown;
892 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
893 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
894 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
895 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
898 //===================================================================
899 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
900 std::vector<std::string>& nShown, int level)
902 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
905 //===================================================================
906 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
908 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
909 std::vector<std::string> n=nShown;
910 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
912 //===================================================================
913 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
914 const std::string& dbPath,
915 const std::string& syncEvent,
916 const std::string& syncFreq)
918 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
919 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
920 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
921 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
924 //===================================================================
925 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
927 mListener->SetMonitoredDrive(drive);
928 mListener->SetAddFilesState(addFiles);
929 mListener->SetRemoveFilesState(removeFiles);
932 //========================================================================
934 void WxGimmickView::OnDriveMount(bool mount)
936 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
938 mListener->GetMonitoredDrive(drive);
942 mViewer->StopPlayer();
944 wxString title(_T("Adding drive"));
946 new wxProgressDialog(_T("Adding drive"),
951 // wxPD_ESTIMATED_TIME |
952 // wxPD_REMAINING_TIME |
954 mCurrentDirectory = crea::std2wx(drive);
955 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
956 mProgressDialog->Pulse(_T("Updating view..."));
958 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
959 delete mProgressDialog;
961 mViewer->StartPlayer();
966 mGimmick->DeleteDrive(drive);
967 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
972 //========================================================================
974 void WxGimmickView::StartListeningThread()
979 //========================================================================
981 void WxGimmickView::StopListeningThread()
986 //========================================================================
987 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
989 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
990 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
991 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
993 siz->Add( ef,1,wxGROW ,0);
998 //========================================================================
999 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1001 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1002 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1005 //=================================================
1006 /// AddProgress Gimmick callback
1007 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1010 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1011 p.GetNumberScannedDirs(),
1012 p.GetNumberScannedFiles(),
1013 p.GetNumberHandledFiles(),
1014 p.GetNumberAddedFiles());
1015 // std::cout << "OnAddProgress "<<mess<<std::endl;
1016 wxString s(wxString::From8BitData(mess));
1017 // std::cout << "Pulse"<<std::endl;
1018 if (!mProgressDialog->Pulse(s))
1022 // std::cout << "OnAddProgress ok"<<std::endl;
1024 //=================================================
1026 //=================================================
1027 void WxGimmickView::DisplayAddSummary()
1029 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
1030 std::stringstream mess;
1031 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
1032 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
1033 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
1034 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
1035 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1038 //////////////////////////////////////////////////
1039 // Add a DB to application //
1040 // @param event : WxEvent //
1042 //////////////////////////////////////////////////
1043 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1047 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1048 std::string wc("*.sqlite3*");
1049 wxFileDialog* FD = new wxFileDialog( 0,
1057 if (FD->ShowModal()==wxID_OK)
1060 wxArrayString files;
1061 FD->GetPaths(files);
1062 std::stringstream st;
1063 for(int i = 0; i< files.size(); i++)
1065 //get name of DB (file name)
1066 size_t pos = files[i].find_last_of(_T("\\"));
1067 std::string name = crea::wx2std(files[i].substr(pos+1));
1068 pos = name.find_last_of(".");
1069 name = name.substr(0,pos);
1070 //create TreeHandler
1071 mGimmick->addDB(name, crea::wx2std(files[i]));
1073 CreateSingleTreeView(name);
1077 ////////////////////////////////////////////////////
1078 // Create a DB from an Attributes Descriptor files //
1079 // @param event : WxEvent //
1081 //////////////////////////////////////////////////
1082 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1085 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1086 DescriptorPan->Layout();
1087 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1090 std::string file(DescriptorPan->GetDescriptor());
1093 size_t pos = file.find_last_of("\\");
1094 std::string name = file.substr(pos+1);
1095 std::string directory = file.substr(0,pos);
1096 pos = name.find_last_of(".");
1097 name = name.substr(0,pos);
1098 //get directory to store DB
1099 directory += "\\" + name + ".sqlite3";
1101 mGimmick->createDB(name, file,directory);
1102 //create TreeHandler
1103 mGimmick->addDB(name, directory);
1105 CreateSingleTreeView(name);
1110 //=================================================
1112 //=================================================
1113 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1114 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1115 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1116 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1117 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1118 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1119 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1120 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1121 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1123 //=================================================
1125 } // EO namespace creaImageIO