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(boost::shared_ptr<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);
127 mNotebook = new wxNotebook(mSplitter,
128 -1, wxDefaultPosition, wxDefaultSize, 0);
133 mSelectionMaxDimension = max_dim;
134 mSelectionMinDimension = min_dim;
140 mBottomPanel = new wxPanel(mSplitter,-1);
142 wxBoxSizer *bottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
146 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
147 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
148 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
150 mViewer->SetImageVector(pointers);
151 mViewer->StartPlayer();
154 bottom_sizer->Add(mViewer,1,wxGROW,1);
157 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
158 bottom_sizer->Add(mText,0,wxGROW,0);
162 mBottomPanel->SetSizer(bottom_sizer);
165 int hsize = size.GetHeight();
167 int top_minsize = 450;
168 int bottom_minsize = 50;
170 mSplitter->SetMinimumPaneSize( bottom_minsize );
171 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
174 sizer->Add( mSplitter, 1, wxGROW, 0);
180 mListener=new Listener();
181 mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
188 //======================================================================
190 //======================================================================
192 WxGimmickView::~WxGimmickView()
194 // stop the viewer before application exit.
195 mViewer->StopPlayer();
196 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
199 if(mListener->IsAlive())
204 //======================================================================
206 //======================================================================
207 /// Creates the tool bar
208 void WxGimmickView::CreateToolBar()
210 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
211 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
214 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
216 mIcon->GetBitmap(Icon_page_down),
217 _T("Add one or more file to database")
219 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
221 mIcon->GetBitmap(Icon_folder_down),
222 _T("Add the content of a folder to database")
224 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
226 mIcon->GetBitmap(Icon_database_add),
227 _T("Open a local or distant database")
229 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
231 mIcon->GetBitmap(Icon_remove),
232 _T("Remove selected items")
234 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
236 mIcon->GetBitmap(Icon_synchronize),
237 _T("Synchronizes the database with disk")
239 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
241 mIcon->GetBitmap(Icon_help),
242 _T("Open help window")
244 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
245 _T("System settings"),
246 mIcon->GetBitmap(Icon_settings),
247 _T("Allows the modification of various system settings")
249 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
251 mIcon->GetBitmap(Icon_tools),
252 _T("Applies tools to images")
254 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
255 _T("Create database"),
256 mIcon->GetBitmap(Icon_create_database),
257 _T("Create DB from an Attributes Descriptor file")
259 #if defined(BUILD_PACS)
260 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
261 _T("PACS Connection,"),
262 mIcon->GetBitmap(Icon_create_database),
263 _T("Echo, Find and Get to a PACS")
266 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
270 //======================================================================
273 //======================================================================
274 /// Create the tree view for TreeHandler provided
275 void WxGimmickView::CreateTreeView( TreeHandler* h)
277 std::string name(h->GetTree().GetAttribute("Name"));
278 GimmickMessage(2,"Creating the tree view for '"<<
279 name<<"'"<<std::endl);
280 // Create the WxTreeView
281 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
283 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
284 // ALREADY IN THE MAP
285 GetTreeViewMap()[name] = view;
288 mNotebook->AddPage( view, crea::std2wx(name) );
292 //======================================================================
293 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
295 std::vector<std::string> files;
296 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
297 ReadImagesNotThreaded(s, files, dim);
300 //======================================================================
301 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
303 std::vector<std::string> files;
304 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
305 ReadImagesNotThreadedInVector(s, files, dim);
307 //======================================================================
309 //======================================================================
310 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
312 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
314 //======================================================================
316 //======================================================================
317 void WxGimmickView::GetImages(int dim,
318 const std::vector<std::string>& files,
319 std::vector<vtkImageData*>& s)
321 ReadImagesNotThreaded(s,files,dim);
323 //======================================================================
326 //=================================================
327 void WxGimmickView::CreateIconList()
329 // Size of the icons;
333 // should correspond to Icon_xxx enum
334 icons[Icon_accept] = wxIcon(accept_xpm);
335 icons[Icon_add] = wxIcon(add_xpm);
336 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
337 icons[Icon_page_down] = wxIcon(page_down_xpm);
338 icons[Icon_remove] = wxIcon(remove_xpm);
339 icons[Icon_database_add] = wxIcon(database_add_xpm);
340 icons[Icon_help] = wxIcon(help_xpm);
341 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
342 icons[Icon_create_database] = wxIcon(create_database_xpm);
343 icons[Icon_settings] = wxIcon(settings_xpm);
344 icons[Icon_tools] = wxIcon(tools_xpm);
346 // unsigned int NbIcons = 8;
347 // Make an image list containing small icons
348 mIcon = new wxImageList(size,size,true);
350 // Make all icons the same size = size of the first one
351 int sizeOrig = icons[0].GetWidth();
352 for ( size_t i = 0; i < icon_number; i++ )
354 if ( size == sizeOrig )
356 mIcon->Add(icons[i]);
360 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
364 //=================================================
367 //=================================================
368 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
370 mViewer->StopPlayer();
371 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
373 wxFileDialog* FD = new wxFileDialog( 0,
381 if (FD->ShowModal()==wxID_OK)
388 std::vector<std::string> filenames;
389 for (i=0;i<files.GetCount();++i)
391 filenames.push_back(wx2std(files[i]));
392 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
396 new wxProgressDialog(_T("Adding file(s)"),
401 // wxPD_ESTIMATED_TIME |
402 // wxPD_REMAINING_TIME |
405 // TO DO : select the current tree handler
406 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
408 mProgressDialog->Pulse(_T("Updating view..."));
410 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
411 delete mProgressDialog;
415 mViewer->StartPlayer();
417 //=================================================
419 //=================================================
420 void WxGimmickView::OnAddDir(wxCommandEvent& event)
422 mViewer->StopPlayer();
423 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
424 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
427 _T("Select directory"),
431 if (FD->ShowModal()==wxID_OK)
433 std::string dirname = wx2std (FD->GetPath());
434 bool recurse = isNeedRecursive(dirname);
437 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
441 wxString title(_T("Adding directory"));
443 title = _T("Adding directory (recursive)");
445 new wxProgressDialog(_T("Adding directory"),
447 NumberFilesToAdd(dirname,recurse),
451 // wxPD_ESTIMATED_TIME |
452 // wxPD_REMAINING_TIME |
455 mCurrentDirectory = FD->GetPath();
456 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
457 mProgressDialog->Pulse(_T("Updating view..."));
459 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
460 delete mProgressDialog;
463 mViewer->StartPlayer();
467 //=================================================
468 // Determines number of files potentially to add to database
469 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
472 if ( !boost::filesystem::exists( dirpath ) ) return nb;
473 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
474 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
476 // If is directory & recurse : do recurse
477 if ( boost::filesystem::is_directory(itr->status()) )
481 nb += NumberFilesToAdd(itr->string(), recursive);
492 //=================================================
493 // Test a directory to know if contains sub-directory to analyze
494 bool WxGimmickView::isNeedRecursive(std::string i_name)
496 boost::filesystem::directory_iterator iter(i_name), end_iter;
497 bool bfindir = false;
498 for(; iter != end_iter; ++iter)
500 if(boost::filesystem::is_directory(*iter))
507 //=================================================
509 //=================================================
510 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
512 GimmickDebugMessage(5,
513 "WxGimmickView::OnSelectionChange"
520 valid= ValidateSelected(NULL,
521 mSelectionMinDimension,
522 mSelectionMaxDimension );
527 std::vector<tree::Node*>::const_iterator i;
528 for(i=sel.begin();i!=sel.end()&&valid;++i)
530 valid= ValidateSelected((*i),
531 mSelectionMinDimension,
532 mSelectionMaxDimension );
537 valid= ValidateSelected(sel.front(),
538 mSelectionMinDimension,
539 mSelectionMaxDimension );
544 std::vector<tree::Node*>::const_iterator i;
545 for(i=sel.begin();i!=sel.end()&&valid;++i)
547 valid= ValidateSelected((*i),
548 mSelectionMinDimension,
549 mSelectionMaxDimension );
552 mText->SetLabel(crea::std2wx(GetMessage()));
555 ReadImageThreaded(sel);
561 ReadImageThreaded(sel);
564 //==================================================
566 //==================================================
567 ///Reads Images (Threaded)
568 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
570 GimmickDebugMessage(5,
573 int maxprio = GetMaximalPriority();
574 int prio = maxprio + 2000;
578 //First load the selected images
579 mCurImageItemToShow = sel.front();
582 std::vector<tree::Node*>::const_iterator selected;
583 for(selected=sel.begin();selected!=sel.end();++selected)
585 GimmickDebugMessage(5,
586 "Requesting image from selected "
587 <<(*selected)->GetAttribute("FullFileName")
589 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
590 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
591 pointers.push_back(ph);
592 RequestReading(*selected,prio,index,ph);
593 // AddEntryToMap(*selected);
597 mViewer->SetImageVector(pointers);
600 std::vector<tree::Node*> up;
601 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
602 std::vector<tree::Node*>::iterator iterUp;
603 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
605 GimmickDebugMessage(5,
606 "Requesting image from neighbors up "
607 <<(*iterUp)->GetAttribute("FullFileName")
609 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
610 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
611 RequestReading(*iterUp,prio,-1,ph);
612 // AddEntryToMap(*iterUp);
614 if (prio == maxprio) break;
619 std::vector<tree::Node*> down;
620 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
621 std::vector<tree::Node*>::iterator iterDown;
622 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
624 GimmickDebugMessage(5,
625 "Requesting image from neighbors down "
626 <<(*iterDown)->GetAttribute("FullFileName")
628 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
629 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
630 RequestReading(*iterDown,prio,-1,ph);
631 // AddEntryToMap(*iterDown);
633 if (prio == maxprio) break;
639 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
640 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
641 pointers.push_back(ph);
642 mViewer->SetImageVector(pointers);
646 //==================================================
648 //==================================================
650 //==================================================
651 void WxGimmickView::OnInternalIdle()
653 if (!mConstructed) return;
654 static bool first_time = true;
659 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
660 // mViewer->StartPlayer();
663 mViewer->RefreshIfNecessary();
667 //==================================================
669 //==================================================
670 void WxGimmickView::ClearSelection()
673 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
674 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
675 mViewer->SetImageVector(pointers);
676 mViewer->RefreshIfNecessary();
680 //=================================================
682 //=================================================
683 void WxGimmickView::OnRemove(wxCommandEvent& event)
685 //TODO Select current tree handler
687 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected();
690 //=================================================
693 //=================================================
694 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
696 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
697 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
700 //=================================================
701 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
703 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
704 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
707 //=================================================
708 void WxGimmickView::AddDir(std::string dirName)
710 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
711 mCurrentDirectory = crea::std2wx(dirName);
712 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
713 mProgressDialog->Pulse(_T("Updating view..."));
715 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
716 delete mProgressDialog;
720 //=================================================
721 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
724 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
725 _T("Check database for files deletion, addition and attributes change. Then give a report."),
726 _T("Repair database (remove deleted files and add new files)."),
727 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
729 wxSingleChoiceDialog dialog(this,
730 _T("Select one of the following synchronization actions:\n")
731 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
732 _T("Synchronization Settings"),
733 WXSIZEOF(choices), choices);
735 //dialog.SetSelection(0);
737 if (dialog.ShowModal() == wxID_OK)
739 int sel=dialog.GetSelection();
741 bool checkAttributes=false;
742 if(sel==2 || sel==3){repair=true;}
743 if(sel==1 || sel==3){checkAttributes=true;}
744 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
745 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
746 if(sel==2 || sel==3){
747 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
752 //=================================================
754 //=================================================
755 void WxGimmickView::OnSettings(wxCommandEvent& event)
757 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
758 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
760 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
762 siz->Add( nb,1,wxGROW ,0);
763 CreateSettingsDialog(nb,dial);
768 //=================================================
769 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
772 // Test if one image is selected => export
774 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
784 void WxGimmickView::ExportImages()
786 //Archive selection: name, emplacement
787 //same process than copy local but to a zip
788 // if settings are yes "always ask for descriptor addition", ask
789 // if settings are yes, adding descriptor
792 void WxGimmickView::ImportImages()
796 // Contain a descriptor.text
797 // create a new database, and add to database
798 // if not, add to current database
802 //=================================================
804 void WxGimmickView::OnTools(wxCommandEvent& event)
806 mViewer->StopPlayer();
808 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
810 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
811 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
812 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
813 dialSizer->Add(nb,1,wxGROW,0);
814 dialSizer->Add(buttonsSizer,0,wxGROW);
816 #if defined(BUILD_BRUKER)
817 //First page: Bruker Image Reader
818 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
819 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
822 dial->SetSizer(dialSizer, true);
826 if (dial->GetReturnCode() == wxID_OK)
828 #if defined(BUILD_BRUKER)
829 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
831 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
832 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
834 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
836 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
838 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
839 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
842 b2d.SetInputDirectory(inputDir);
843 b2d.SetOutputDirectory(outputDir);
844 b2d.SetConvertModeToDicom();
850 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
851 mCurrentDirectory = gimmickTools->getOutputDir();
852 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
853 mProgressDialog->Pulse(_T("Updating view..."));
855 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
856 delete mProgressDialog;
863 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
869 mViewer->StartPlayer();
872 //=================================================
874 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
876 //First page: Customization of configurations
879 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
880 //Database Path String
882 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
883 //Syncronization Event String
885 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
886 //Syncronization Frequency String
888 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
890 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
892 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
894 //Second page: Creation of Databases
895 /*wxPanel* databaseCreation=new wxPanel(nb);
896 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
898 //Second page (temporary): Connection to PACS
899 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
900 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
902 //Third page: CD/DVD Watch
903 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
904 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
906 //Fourth page: Selection of attributes to show
907 std::vector<std::string> shown;
908 std::vector<std::string> nShown;
909 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
910 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
911 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
912 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
915 //===================================================================
916 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
917 std::vector<std::string>& nShown, int level)
919 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
922 //===================================================================
923 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
925 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
926 std::vector<std::string> n=nShown;
927 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
929 //===================================================================
930 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
931 const std::string& dbPath,
932 const std::string& syncEvent,
933 const std::string& syncFreq)
935 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
936 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
937 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
938 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
941 //===================================================================
942 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
944 mListener->SetMonitoredDrive(drive);
945 mListener->SetAddFilesState(addFiles);
946 mListener->SetRemoveFilesState(removeFiles);
949 //========================================================================
951 void WxGimmickView::OnDriveMount(bool mount)
953 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
955 mListener->GetMonitoredDrive(drive);
959 mViewer->StopPlayer();
961 wxString title(_T("Adding drive"));
963 new wxProgressDialog(_T("Adding drive"),
968 // wxPD_ESTIMATED_TIME |
969 // wxPD_REMAINING_TIME |
971 mCurrentDirectory = crea::std2wx(drive);
972 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
973 mProgressDialog->Pulse(_T("Updating view..."));
975 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
976 delete mProgressDialog;
978 mViewer->StartPlayer();
982 mGimmick->DeleteDrive(drive);
983 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
987 //========================================================================
989 void WxGimmickView::StartListeningThread()
994 //========================================================================
996 void WxGimmickView::StopListeningThread()
1001 //========================================================================
1002 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1004 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1005 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1006 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1008 siz->Add( ef,1,wxGROW ,0);
1009 dial->SetSizer(siz);
1013 //========================================================================
1014 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1016 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1017 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1020 //=================================================
1021 /// AddProgress Gimmick callback
1022 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1025 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1026 p.GetNumberScannedDirs(),
1027 p.GetNumberScannedFiles(),
1028 p.GetNumberHandledFiles(),
1029 p.GetNumberAddedFiles());
1030 // std::cout << "OnAddProgress "<<mess<<std::endl;
1031 wxString s(wxString::From8BitData(mess));
1032 // std::cout << "Pulse"<<std::endl;
1033 if (!mProgressDialog->Pulse(s))
1037 // std::cout << "OnAddProgress ok"<<std::endl;
1039 //=================================================
1041 //=================================================
1042 void WxGimmickView::DisplayAddSummary()
1044 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
1045 std::stringstream mess;
1046 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
1047 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
1048 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
1049 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
1050 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1053 ////////////////////////////////////////////////
1054 // Add a DB to application //
1055 // @param event : WxEvent //
1057 ////////////////////////////////////////////////
1058 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1061 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1062 std::string wc("*.sqlite3*");
1063 wxFileDialog* FD = new wxFileDialog( 0,
1071 if (FD->ShowModal()==wxID_OK)
1074 wxArrayString files;
1075 FD->GetPaths(files);
1076 std::stringstream st;
1077 for(int i = 0; i< files.size(); i++)
1079 //get name of DB (file name)
1080 size_t pos = files[i].find_last_of(_T("\\"));
1081 std::string name = crea::wx2std(files[i].substr(pos+1));
1082 pos = name.find_last_of(".");
1083 name = name.substr(0,pos);
1084 //create TreeHandler
1085 mGimmick->addDB(name, crea::wx2std(files[i]));
1087 CreateSingleTreeView(name);
1091 ////////////////////////////////////////////////////
1092 // Create a DB from an Attributes Descriptor files //
1093 // @param event : WxEvent //
1095 //////////////////////////////////////////////////
1096 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1098 // PACSConnection("");
1099 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1100 DescriptorPan->Layout();
1101 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1104 std::string file(DescriptorPan->GetDescriptor());
1107 size_t pos = file.find_last_of("\\");
1108 std::string name = file.substr(pos+1);
1109 std::string directory = file.substr(0,pos);
1110 pos = name.find_last_of(".");
1111 name = name.substr(0,pos);
1112 //get directory to store DB
1113 directory += "\\" + name + ".sqlite3";
1115 mGimmick->createDB(name, file,directory);
1116 //create TreeHandler
1117 mGimmick->addDB(name, directory);
1119 CreateSingleTreeView(name);
1124 //=================================================
1126 //=================================================
1127 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1128 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1129 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1130 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1131 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1132 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1133 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1134 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1135 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1137 //=================================================
1139 } // EO namespace creaImageIO