1 #include <creaImageIOPACSConnection.h>
2 #include <creaImageIOWxPACSConnectionPanel.h>
3 #include <creaImageIOWxGimmickView.h>
4 #include <creaImageIOWxTreeView.h>
5 #include <creaImageIOSystem.h>
6 #include <creaImageIOWxCustomizeConfigPanel.h>
7 #include <creaImageIOWxListenerPanel.h>
8 #include <creaImageIOWxEditFieldsPanel.h>
9 #include <creaImageIOWxAttributeSelectionPanel.h>
10 #include <creaImageIOWxDescriptorPanel.h>
14 #include "icons/accept.xpm"
15 #include "icons/add.xpm"
16 #include "icons/folder-down.xpm"
17 #include "icons/page-down.xpm"
18 #include "icons/remove.xpm"
19 #include "icons/database-add.xpm"
20 #include "icons/create-database.xpm"
21 #include "icons/help.xpm"
22 #include "icons/synchronize.xpm"
23 #include "icons/settings.xpm"
24 #include "icons/tools.xpm"
25 //#include "icons/import.xpm"
27 #include <wx/imaglist.h>
28 #include <wx/popupwin.h>
29 #include<boost/filesystem/operations.hpp>
30 #if defined(BUILD_BRUKER)
31 #include "bruker2dicom.h"
39 //======================================================================
40 // The ids of the different tools
45 TOOL_ADDDATABASE_ID = 3,
47 TOOL_SYNCHRONIZE_ID = 5,
54 //======================================================================
56 //================================================================
58 const int icon_number = 11;
75 //================================================================
77 //================================================================
79 const icon_id Icon[5] = { Icon_Database,
85 //================================================================
88 //======================================================================
90 WxGimmickView::WxGimmickView(Gimmick* gimmick,
97 int number_of_threads)
98 : wxPanel(parent,id,pos,size),
99 GimmickView(gimmick, number_of_threads),
103 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
105 // Sets the current directory to the home dir
106 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
108 // Connect the AddProgress callback
109 gimmick->ConnectAddProgressObserver
110 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
112 // Create the list of icons (mIcon)
116 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
118 // Create the tool bar
120 sizer->Add( mToolBar ,0, wxGROW ,0);
122 // Split part below toolbar into notebook for views and panel
123 // for preview, messages...
124 mSplitter = new wxSplitterWindow( this , -1);
128 mNotebook = new wxNotebook(mSplitter,
129 -1,wxDefaultPosition, wxDefaultSize, 0);
135 mSelectionMaxDimension= max_dim;
136 mSelectionMinDimension= min_dim;
142 mBottomPanel = new wxPanel(mSplitter,-1);
144 wxBoxSizer *bottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
148 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
149 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
150 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
152 mViewer->SetImageVector(pointers);
153 mViewer->StartPlayer();
156 bottom_sizer->Add(mViewer,1,wxGROW,1);
159 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
160 bottom_sizer->Add(mText,0,wxGROW,0);
164 mBottomPanel->SetSizer(bottom_sizer);
167 int hsize = size.GetHeight();
169 int top_minsize = 450;
170 int bottom_minsize = 50;
172 mSplitter->SetMinimumPaneSize( bottom_minsize );
173 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
176 sizer->Add( mSplitter,1,wxGROW ,0);
182 mListener=new Listener();
183 mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount , this, _1 ) );
190 //======================================================================
192 //======================================================================
194 WxGimmickView::~WxGimmickView()
196 // stop the viewer before application exit.
197 mViewer->StopPlayer();
198 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
200 if(mListener->IsAlive())
205 //======================================================================
207 //======================================================================
208 /// Creates the tool bar
209 void WxGimmickView::CreateToolBar()
211 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
212 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
215 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
217 mIcon->GetBitmap(Icon_page_down),
218 _T("Add one or more file to database")
220 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
222 mIcon->GetBitmap(Icon_folder_down),
223 _T("Add the content of a folder to database")
225 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
227 mIcon->GetBitmap(Icon_database_add),
228 _T("Open a local or distant database")
230 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
232 mIcon->GetBitmap(Icon_remove),
233 _T("Remove selected items")
235 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
237 mIcon->GetBitmap(Icon_synchronize),
238 _T("Synchronizes the database with disk")
240 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
242 mIcon->GetBitmap(Icon_help),
243 _T("Open help window")
245 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
246 _T("System settings"),
247 mIcon->GetBitmap(Icon_settings),
248 _T("Allows the modification of various system settings")
250 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
252 mIcon->GetBitmap(Icon_tools),
253 _T("Applies tools to images")
255 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
256 _T("Create database"),
257 mIcon->GetBitmap(Icon_create_database),
258 _T("Create DB from an Attributes Descriptor file")
260 #if defined(BUILD_PACS)
261 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
262 _T("PACS Connection,"),
263 mIcon->GetBitmap(Icon_create_database),
264 _T("Echo, Find and Get to a PACS")
267 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
271 //======================================================================
274 //======================================================================
275 /// Create the tree view for TreeHandler provided
276 void WxGimmickView::CreateTreeView( TreeHandler* h)
278 std::string name(h->GetTree().GetAttribute("Name"));
279 GimmickMessage(2,"Creating the tree view for '"<<
280 name<<"'"<<std::endl);
281 // Create the WxTreeView
282 WxTreeView* view = new WxTreeView(h,this,mNotebook,-1);
284 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
285 // ALREADY IN THE MAP
286 GetTreeViewMap()[name] = view;
289 mNotebook->AddPage( view, crea::std2wx(name) );
293 //======================================================================
294 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
296 std::vector<std::string> files;
297 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
298 ReadImagesNotThreaded(s,files,dim);
300 //======================================================================
302 //======================================================================
303 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
305 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
307 //======================================================================
309 //======================================================================
310 void WxGimmickView::GetImages(int dim,
311 const std::vector<std::string>& files,
312 std::vector<vtkImageData*>& s)
314 ReadImagesNotThreaded(s,files,dim);
316 //======================================================================
319 //=================================================
320 void WxGimmickView::CreateIconList()
322 // Size of the icons;
326 // should correspond to Icon_xxx enum
327 icons[Icon_accept] = wxIcon(accept_xpm);
328 icons[Icon_add] = wxIcon(add_xpm);
329 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
330 icons[Icon_page_down] = wxIcon(page_down_xpm);
331 icons[Icon_remove] = wxIcon(remove_xpm);
332 icons[Icon_database_add] = wxIcon(database_add_xpm);
333 icons[Icon_help] = wxIcon(help_xpm);
334 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
335 icons[Icon_create_database] = wxIcon(create_database_xpm);
336 icons[Icon_settings] = wxIcon(settings_xpm);
337 icons[Icon_tools] = wxIcon(tools_xpm);
339 // unsigned int NbIcons = 8;
340 // Make an image list containing small icons
341 mIcon = new wxImageList(size,size,true);
343 // Make all icons the same size = size of the first one
344 int sizeOrig = icons[0].GetWidth();
345 for ( size_t i = 0; i < icon_number; i++ )
347 if ( size == sizeOrig )
349 mIcon->Add(icons[i]);
353 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
357 //=================================================
360 //=================================================
361 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
363 mViewer->StopPlayer();
364 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
366 wxFileDialog* FD = new wxFileDialog( 0,
374 if (FD->ShowModal()==wxID_OK)
381 std::vector<std::string> filenames;
382 for (i=0;i<files.GetCount();++i)
384 filenames.push_back(wx2std(files[i]));
385 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
389 new wxProgressDialog(_T("Adding file(s)"),
394 // wxPD_ESTIMATED_TIME |
395 // wxPD_REMAINING_TIME |
398 // TO DO : select the current tree handler
399 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
401 mProgressDialog->Pulse(_T("Updating view..."));
403 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
404 delete mProgressDialog;
408 mViewer->StartPlayer();
410 //=================================================
412 //=================================================
413 void WxGimmickView::OnAddDir(wxCommandEvent& event)
415 mViewer->StopPlayer();
416 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
417 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
420 _T("Select directory"),
424 if (FD->ShowModal()==wxID_OK)
428 std::string dirname = wx2std (FD->GetPath());
429 bool recurse = isNeedRecursive(dirname);
432 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
436 wxString title(_T("Adding directory"));
438 title = _T("Adding directory (recursive)");
440 new wxProgressDialog(_T("Adding directory"),
442 NumberFilesToAdd(dirname,recurse),
446 // wxPD_ESTIMATED_TIME |
447 // wxPD_REMAINING_TIME |
450 mCurrentDirectory = FD->GetPath();
451 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
452 mProgressDialog->Pulse(_T("Updating view..."));
454 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
455 delete mProgressDialog;
459 mViewer->StartPlayer();
463 //=================================================
464 // Determines number of files potentially to add to database
465 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
468 if ( !boost::filesystem::exists( dirpath ) ) return nb;
469 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
470 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
472 // If is directory & recurse : do recurse
473 if ( boost::filesystem::is_directory(itr->status()) )
477 nb += NumberFilesToAdd(itr->string(), recursive);
489 //=================================================
490 // Test a directory to know if contains sub-directory to analyze
491 bool WxGimmickView::isNeedRecursive(std::string i_name)
493 boost::filesystem::directory_iterator iter(i_name), end_iter;
494 bool bfindir = false;
495 for(; iter != end_iter; ++iter)
497 if(boost::filesystem::is_directory(*iter))
504 //=================================================
506 //=================================================
507 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
509 GimmickDebugMessage(5,
510 "WxGimmickView::OnSelectionChange"
517 valid= ValidateSelected(NULL,
518 mSelectionMinDimension,
519 mSelectionMaxDimension );
524 std::vector<tree::Node*>::const_iterator i;
525 for(i=sel.begin();i!=sel.end()&&valid;++i)
527 valid= ValidateSelected((*i),
528 mSelectionMinDimension,
529 mSelectionMaxDimension );
534 valid= ValidateSelected(sel.front(),
535 mSelectionMinDimension,
536 mSelectionMaxDimension );
541 std::vector<tree::Node*>::const_iterator i;
542 for(i=sel.begin();i!=sel.end()&&valid;++i)
544 valid= ValidateSelected((*i),
545 mSelectionMinDimension,
546 mSelectionMaxDimension );
549 mText->SetLabel(crea::std2wx(GetMessage()));
552 ReadImageThreaded(sel);
558 ReadImageThreaded(sel);
563 //==================================================
565 //==================================================
566 ///Reads Images (Threaded)
567 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
569 GimmickDebugMessage(5,
572 int maxprio = GetMaximalPriority();
573 int prio = maxprio + 2000;
577 //First load the selected images
578 mCurImageItemToShow = sel.front();
581 std::vector<tree::Node*>::const_iterator selected;
582 for(selected=sel.begin();selected!=sel.end();++selected)
584 GimmickDebugMessage(5,
585 "Requesting image from selected "
586 <<(*selected)->GetAttribute("FullFileName")
588 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
589 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
590 pointers.push_back(ph);
591 RequestReading(*selected,prio,index,ph);
592 // AddEntryToMap(*selected);
596 mViewer->SetImageVector(pointers);
599 std::vector<tree::Node*> up;
600 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
601 std::vector<tree::Node*>::iterator iterUp;
602 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
604 GimmickDebugMessage(5,
605 "Requesting image from neighbors up "
606 <<(*iterUp)->GetAttribute("FullFileName")
608 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
609 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
610 RequestReading(*iterUp,prio,-1,ph);
611 // AddEntryToMap(*iterUp);
613 if (prio == maxprio) break;
618 std::vector<tree::Node*> down;
619 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
620 std::vector<tree::Node*>::iterator iterDown;
621 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
623 GimmickDebugMessage(5,
624 "Requesting image from neighbors down "
625 <<(*iterDown)->GetAttribute("FullFileName")
627 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
628 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
629 RequestReading(*iterDown,prio,-1,ph);
630 // AddEntryToMap(*iterDown);
632 if (prio == maxprio) break;
638 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
639 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
640 pointers.push_back(ph);
641 mViewer->SetImageVector(pointers);
645 //==================================================
647 //==================================================
649 //==================================================
650 void WxGimmickView::OnInternalIdle()
652 if (!mConstructed) return;
653 static bool first_time = true;
658 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
659 // mViewer->StartPlayer();
662 mViewer->RefreshIfNecessary();
666 //==================================================
668 //==================================================
669 void WxGimmickView::ClearSelection()
672 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
673 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
674 mViewer->SetImageVector(pointers);
675 mViewer->RefreshIfNecessary();
679 //=================================================
681 //=================================================
682 void WxGimmickView::OnRemove(wxCommandEvent& event)
684 //TODO Select current tree handler
686 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected();
689 //=================================================
692 //=================================================
693 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
695 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
696 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
699 //=================================================
700 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
702 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
703 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
706 //=================================================
707 void WxGimmickView::AddDir(std::string dirName)
709 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
710 mCurrentDirectory = crea::std2wx(dirName);
711 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
712 mProgressDialog->Pulse(_T("Updating view..."));
714 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
715 delete mProgressDialog;
719 //=================================================
720 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
723 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
724 _T("Check database for files deletion, addition and attributes change. Then give a report."),
725 _T("Repair database (remove deleted files and add new files)."),
726 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
728 wxSingleChoiceDialog dialog(this,
729 _T("Select one of the following synchronization actions:\n")
730 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
731 _T("Synchronization Settings"),
732 WXSIZEOF(choices), choices);
734 //dialog.SetSelection(0);
736 if (dialog.ShowModal() == wxID_OK)
738 int sel=dialog.GetSelection();
740 bool checkAttributes=false;
741 if(sel==2 || sel==3){repair=true;}
742 if(sel==1 || sel==3){checkAttributes=true;}
743 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
744 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
745 if(sel==2 || sel==3){
746 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
751 //=================================================
753 //=================================================
754 void WxGimmickView::OnSettings(wxCommandEvent& event)
756 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
757 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
759 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
761 siz->Add( nb,1,wxGROW ,0);
762 CreateSettingsDialog(nb,dial);
766 //=================================================
767 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
770 // Test if one image is selected => export
772 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
782 void WxGimmickView::ExportImages()
784 //Archive selection: name, emplacement
785 //same process than copy local but to a zip
786 // if settings are yes "always ask for descriptor addition", ask
787 // if settings are yes, adding descriptor
790 void WxGimmickView::ImportImages()
794 // Contain a descriptor.text
795 // create a new database, and add to database
796 // if not, add to current database
800 //=================================================
802 void WxGimmickView::OnTools(wxCommandEvent& event)
804 mViewer->StopPlayer();
806 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
808 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
809 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
810 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
811 dialSizer->Add(nb,1,wxGROW,0);
812 dialSizer->Add(buttonsSizer,0,wxGROW);
814 #if defined(BUILD_BRUKER)
815 //First page: Bruker Image Reader
816 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
817 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
820 dial->SetSizer(dialSizer, true);
824 if (dial->GetReturnCode() == wxID_OK)
826 #if defined(BUILD_BRUKER)
827 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
829 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
830 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
832 bool addToDB = gimmickTools->getCheckBoxValue();
834 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
836 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
837 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
840 b2d.SetInputDirectory(inputDir);
841 b2d.SetOutputDirectory(outputDir);
842 b2d.SetConvertModeToDicom();
848 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
849 mCurrentDirectory = gimmickTools->getOutputDir();
850 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
851 mProgressDialog->Pulse(_T("Updating view..."));
853 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
854 delete mProgressDialog;
862 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
869 mViewer->StartPlayer();
871 //=================================================
873 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
875 //First page: Customization of configurations
878 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
879 //Database Path String
881 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
882 //Syncronization Event String
884 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
885 //Syncronization Frequency String
887 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
889 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
891 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
893 //Second page: Creation of Databases
894 /*wxPanel* databaseCreation=new wxPanel(nb);
895 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
897 //Second page (temporary): Connection to PACS
898 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
899 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
901 //Third page: CD/DVD Watch
902 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
903 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
905 //Fourth page: Selection of attributes to show
906 std::vector<std::string> shown;
907 std::vector<std::string> nShown;
908 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
909 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
910 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
911 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
914 //===================================================================
915 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
916 std::vector<std::string>& nShown, int level)
918 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
921 //===================================================================
922 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
924 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
925 std::vector<std::string> n=nShown;
926 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
928 //===================================================================
929 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
930 const std::string& dbPath,
931 const std::string& syncEvent,
932 const std::string& syncFreq)
934 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
935 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
936 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
937 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
940 //===================================================================
941 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
943 mListener->SetMonitoredDrive(drive);
944 mListener->SetAddFilesState(addFiles);
945 mListener->SetRemoveFilesState(removeFiles);
948 //========================================================================
950 void WxGimmickView::OnDriveMount(bool mount)
952 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
954 mListener->GetMonitoredDrive(drive);
958 mViewer->StopPlayer();
960 wxString title(_T("Adding drive"));
962 new wxProgressDialog(_T("Adding drive"),
967 // wxPD_ESTIMATED_TIME |
968 // wxPD_REMAINING_TIME |
970 mCurrentDirectory = crea::std2wx(drive);
971 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
972 mProgressDialog->Pulse(_T("Updating view..."));
974 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
975 delete mProgressDialog;
977 mViewer->StartPlayer();
981 mGimmick->DeleteDrive(drive);
982 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
986 //========================================================================
988 void WxGimmickView::StartListeningThread()
993 //========================================================================
995 void WxGimmickView::StopListeningThread()
1000 //========================================================================
1001 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1003 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1004 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1005 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1007 siz->Add( ef,1,wxGROW ,0);
1008 dial->SetSizer(siz);
1012 //========================================================================
1013 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1015 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1016 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1019 //=================================================
1020 /// AddProgress Gimmick callback
1021 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1024 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1025 p.GetNumberScannedDirs(),
1026 p.GetNumberScannedFiles(),
1027 p.GetNumberHandledFiles(),
1028 p.GetNumberAddedFiles());
1029 // std::cout << "OnAddProgress "<<mess<<std::endl;
1030 wxString s(wxString::From8BitData(mess));
1031 // std::cout << "Pulse"<<std::endl;
1032 if (!mProgressDialog->Pulse(s))
1036 // std::cout << "OnAddProgress ok"<<std::endl;
1038 //=================================================
1040 //=================================================
1041 void WxGimmickView::DisplayAddSummary()
1043 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
1044 std::stringstream mess;
1045 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
1046 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
1047 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
1048 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
1049 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1052 ////////////////////////////////////////////////
1053 // Add a DB to application //
1054 // @param event : WxEvent //
1056 ////////////////////////////////////////////////
1057 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1060 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1061 std::string wc("*.sqlite3*");
1062 wxFileDialog* FD = new wxFileDialog( 0,
1070 if (FD->ShowModal()==wxID_OK)
1073 wxArrayString files;
1074 FD->GetPaths(files);
1075 std::stringstream st;
1076 for(int i = 0; i< files.size(); i++)
1078 //get name of DB (file name)
1079 size_t pos = files[i].find_last_of(_T("\\"));
1080 std::string name = crea::wx2std(files[i].substr(pos+1));
1081 pos = name.find_last_of(".");
1082 name = name.substr(0,pos);
1083 //create TreeHandler
1084 mGimmick->addDB(name, crea::wx2std(files[i]));
1086 CreateSingleTreeView(name);
1090 ////////////////////////////////////////////////////
1091 // Create a DB from an Attributes Descriptor files //
1092 // @param event : WxEvent //
1094 //////////////////////////////////////////////////
1095 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1097 // PACSConnection("");
1098 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1099 DescriptorPan->Layout();
1100 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1103 std::string file(DescriptorPan->GetDescriptor());
1106 size_t pos = file.find_last_of("\\");
1107 std::string name = file.substr(pos+1);
1108 std::string directory = file.substr(0,pos);
1109 pos = name.find_last_of(".");
1110 name = name.substr(0,pos);
1111 //get directory to store DB
1112 directory += "\\" + name + ".sqlite3";
1114 mGimmick->createDB(name, file,directory);
1115 //create TreeHandler
1116 mGimmick->addDB(name, directory);
1118 CreateSingleTreeView(name);
1123 //=================================================
1125 //=================================================
1126 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1127 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1128 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1129 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1130 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1131 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1132 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1133 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1134 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1136 //=================================================
1138 } // EO namespace creaImageIO