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 ) );
182 //mListener->Create();
184 // mListener->Pause();
188 //======================================================================
190 //======================================================================
192 WxGimmickView::~WxGimmickView()
194 // stop the viewer before application exit.
195 mViewer->StopPlayer();
196 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
199 //if(mListener->IsAlive()) { mListener->Delete(); }
201 //======================================================================
203 //======================================================================
204 /// Creates the tool bar
205 void WxGimmickView::CreateToolBar()
207 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
208 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
211 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
213 mIcon->GetBitmap(Icon_page_down),
214 _T("Add one or more file to database")
216 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
218 mIcon->GetBitmap(Icon_folder_down),
219 _T("Add the content of a folder to database")
221 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
223 mIcon->GetBitmap(Icon_database_add),
224 _T("Open a local or distant database")
226 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
228 mIcon->GetBitmap(Icon_remove),
229 _T("Remove selected items")
231 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
233 mIcon->GetBitmap(Icon_synchronize),
234 _T("Synchronizes the database with disk")
236 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
238 mIcon->GetBitmap(Icon_help),
239 _T("Open help window")
241 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
242 _T("System settings"),
243 mIcon->GetBitmap(Icon_settings),
244 _T("Allows the modification of various system settings")
246 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
248 mIcon->GetBitmap(Icon_tools),
249 _T("Applies tools to images")
251 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
252 _T("Create database"),
253 mIcon->GetBitmap(Icon_create_database),
254 _T("Create DB from an Attributes Descriptor file")
256 #if defined(BUILD_PACS)
257 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
258 _T("PACS Connection,"),
259 mIcon->GetBitmap(Icon_create_database),
260 _T("Echo, Find and Get to a PACS")
263 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
267 //======================================================================
270 //======================================================================
271 /// Create the tree view for TreeHandler provided
272 void WxGimmickView::CreateTreeView( TreeHandler* h)
274 std::string name(h->GetTree().GetAttribute("Name"));
275 GimmickMessage(2,"Creating the tree view for '"<<
276 name<<"'"<<std::endl);
277 // Create the WxTreeView
278 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
280 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
281 // ALREADY IN THE MAP
282 GetTreeViewMap()[name] = view;
285 mNotebook->AddPage( view, crea::std2wx(name) );
289 //======================================================================
290 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
292 std::vector<std::string> files;
293 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
294 ReadImagesNotThreaded(s, files, dim);
297 //======================================================================
298 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
300 std::vector<std::string> files;
301 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
302 ReadImagesNotThreadedInVector(s, files, dim);
304 //======================================================================
306 //======================================================================
307 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
309 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
311 //======================================================================
313 //======================================================================
314 void WxGimmickView::GetImages(int dim,
315 const std::vector<std::string>& files,
316 std::vector<vtkImageData*>& s)
318 ReadImagesNotThreaded(s,files,dim);
320 //======================================================================
323 //=================================================
324 void WxGimmickView::CreateIconList()
326 // Size of the icons;
330 // should correspond to Icon_xxx enum
331 icons[Icon_accept] = wxIcon(accept_xpm);
332 icons[Icon_add] = wxIcon(add_xpm);
333 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
334 icons[Icon_page_down] = wxIcon(page_down_xpm);
335 icons[Icon_remove] = wxIcon(remove_xpm);
336 icons[Icon_database_add] = wxIcon(database_add_xpm);
337 icons[Icon_help] = wxIcon(help_xpm);
338 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
339 icons[Icon_create_database] = wxIcon(create_database_xpm);
340 icons[Icon_settings] = wxIcon(settings_xpm);
341 icons[Icon_tools] = wxIcon(tools_xpm);
343 // unsigned int NbIcons = 8;
344 // Make an image list containing small icons
345 mIcon = new wxImageList(size,size,true);
347 // Make all icons the same size = size of the first one
348 int sizeOrig = icons[0].GetWidth();
349 for ( size_t i = 0; i < icon_number; i++ )
351 if ( size == sizeOrig )
353 mIcon->Add(icons[i]);
357 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
361 //=================================================
364 //=================================================
365 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
367 mViewer->StopPlayer();
368 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
370 wxFileDialog* FD = new wxFileDialog( 0,
378 if (FD->ShowModal()==wxID_OK)
385 std::vector<std::string> filenames;
386 for (i=0;i<files.GetCount();++i)
388 filenames.push_back(wx2std(files[i]));
389 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
393 new wxProgressDialog(_T("Adding file(s)"),
398 // wxPD_ESTIMATED_TIME |
399 // wxPD_REMAINING_TIME |
402 // TO DO : select the current tree handler
403 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
405 mProgressDialog->Pulse(_T("Updating view..."));
407 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
408 delete mProgressDialog;
412 mViewer->StartPlayer();
414 //=================================================
416 //=================================================
417 void WxGimmickView::OnAddDir(wxCommandEvent& event)
419 mViewer->StopPlayer();
420 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
421 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
424 _T("Select directory"),
428 if (FD->ShowModal()==wxID_OK)
430 std::string dirname = wx2std (FD->GetPath());
431 bool recurse = isNeedRecursive(dirname);
434 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
438 wxString title(_T("Adding directory"));
440 title = _T("Adding directory (recursive)");
442 new wxProgressDialog(_T("Adding directory"),
444 NumberFilesToAdd(dirname,recurse),
448 // wxPD_ESTIMATED_TIME |
449 // wxPD_REMAINING_TIME |
452 mCurrentDirectory = FD->GetPath();
453 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
454 mProgressDialog->Pulse(_T("Updating view..."));
456 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
457 delete mProgressDialog;
460 mViewer->StartPlayer();
464 //=================================================
465 // Determines number of files potentially to add to database
466 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
469 if ( !boost::filesystem::exists( dirpath ) ) return nb;
470 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
471 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
473 // If is directory & recurse : do recurse
474 if ( boost::filesystem::is_directory(itr->status()) )
478 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);
561 //==================================================
563 //==================================================
564 ///Reads Images (Threaded)
565 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
567 GimmickDebugMessage(5,
570 int maxprio = GetMaximalPriority();
571 int prio = maxprio + 2000;
575 //First load the selected images
576 mCurImageItemToShow = sel.front();
579 std::vector<tree::Node*>::const_iterator selected;
580 for(selected=sel.begin();selected!=sel.end();++selected)
582 GimmickDebugMessage(5,
583 "Requesting image from selected "
584 <<(*selected)->GetAttribute("FullFileName")
586 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
587 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
588 pointers.push_back(ph);
589 RequestReading(*selected,prio,index,ph);
590 // AddEntryToMap(*selected);
594 mViewer->SetImageVector(pointers);
597 std::vector<tree::Node*> up;
598 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
599 std::vector<tree::Node*>::iterator iterUp;
600 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
602 GimmickDebugMessage(5,
603 "Requesting image from neighbors up "
604 <<(*iterUp)->GetAttribute("FullFileName")
606 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
607 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
608 RequestReading(*iterUp,prio,-1,ph);
609 // AddEntryToMap(*iterUp);
611 if (prio == maxprio) break;
616 std::vector<tree::Node*> down;
617 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
618 std::vector<tree::Node*>::iterator iterDown;
619 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
621 GimmickDebugMessage(5,
622 "Requesting image from neighbors down "
623 <<(*iterDown)->GetAttribute("FullFileName")
625 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
626 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
627 RequestReading(*iterDown,prio,-1,ph);
628 // AddEntryToMap(*iterDown);
630 if (prio == maxprio) break;
636 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
637 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
638 pointers.push_back(ph);
639 mViewer->SetImageVector(pointers);
643 //==================================================
645 //==================================================
647 //==================================================
648 void WxGimmickView::OnInternalIdle()
650 if (!mConstructed) return;
651 static bool first_time = true;
656 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
657 // mViewer->StartPlayer();
660 mViewer->RefreshIfNecessary();
664 //==================================================
666 //==================================================
667 void WxGimmickView::ClearSelection()
670 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
671 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
672 mViewer->SetImageVector(pointers);
673 mViewer->RefreshIfNecessary();
677 //=================================================
679 //=================================================
680 void WxGimmickView::OnRemove(wxCommandEvent& event)
682 //TODO Select current tree handler
685 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
686 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
687 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
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)
740 int sel=dialog.GetSelection();
742 bool checkAttributes=false;
743 if(sel==2 || sel==3){repair=true;}
744 if(sel==1 || sel==3){checkAttributes=true;}
745 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
746 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
747 if(sel==2 || sel==3){
748 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
753 //=================================================
755 //=================================================
756 void WxGimmickView::OnSettings(wxCommandEvent& event)
758 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
759 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
761 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
763 siz->Add( nb,1,wxGROW ,0);
764 CreateSettingsDialog(nb,dial);
769 //=================================================
770 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
773 // Test if one image is selected => export
775 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
785 void WxGimmickView::ExportImages()
787 //Archive selection: name, emplacement
788 //same process than copy local but to a zip
789 // if settings are yes "always ask for descriptor addition", ask
790 // if settings are yes, adding descriptor
793 void WxGimmickView::ImportImages()
797 // Contain a descriptor.text
798 // create a new database, and add to database
799 // if not, add to current database
803 //=================================================
805 void WxGimmickView::OnTools(wxCommandEvent& event)
807 mViewer->StopPlayer();
809 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
811 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
812 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
813 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
814 dialSizer->Add(nb,1,wxGROW,0);
815 dialSizer->Add(buttonsSizer,0,wxGROW);
817 #if defined(BUILD_BRUKER)
818 //First page: Bruker Image Reader
819 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
820 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
823 dial->SetSizer(dialSizer, true);
827 if (dial->GetReturnCode() == wxID_OK)
829 #if defined(BUILD_BRUKER)
830 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
832 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
833 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
835 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
837 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
839 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
840 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
843 b2d.SetInputDirectory(inputDir);
844 b2d.SetOutputDirectory(outputDir);
845 b2d.SetConvertModeToDicom();
851 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
852 mCurrentDirectory = gimmickTools->getOutputDir();
853 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
854 mProgressDialog->Pulse(_T("Updating view..."));
856 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
857 delete mProgressDialog;
864 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
870 mViewer->StartPlayer();
873 //=================================================
875 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
877 //First page: Customization of configurations
880 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
881 //Database Path String
883 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
884 //Syncronization Event String
886 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
887 //Syncronization Frequency String
889 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
891 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
893 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
895 //Second page: Creation of Databases
896 /*wxPanel* databaseCreation=new wxPanel(nb);
897 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
899 //Second page (temporary): Connection to PACS
900 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
901 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
903 //Third page: CD/DVD Watch
904 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this, mListener->IsPaused());
905 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
907 //Fourth page: Selection of attributes to show
908 std::vector<std::string> shown;
909 std::vector<std::string> nShown;
910 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
911 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
912 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
913 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
916 //===================================================================
917 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
918 std::vector<std::string>& nShown, int level)
920 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
923 //===================================================================
924 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
926 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
927 std::vector<std::string> n=nShown;
928 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
930 //===================================================================
931 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
932 const std::string& dbPath,
933 const std::string& syncEvent,
934 const std::string& syncFreq)
936 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
937 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
938 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
939 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
942 //===================================================================
943 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
945 mListener->SetMonitoredDrive(drive);
946 mListener->SetAddFilesState(addFiles);
947 mListener->SetRemoveFilesState(removeFiles);
950 //========================================================================
952 void WxGimmickView::OnDriveMount(bool mount)
954 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
956 mListener->GetMonitoredDrive(drive);
960 mViewer->StopPlayer();
962 wxString title(_T("Adding drive"));
964 new wxProgressDialog(_T("Adding drive"),
969 // wxPD_ESTIMATED_TIME |
970 // wxPD_REMAINING_TIME |
972 mCurrentDirectory = crea::std2wx(drive);
973 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
974 mProgressDialog->Pulse(_T("Updating view..."));
976 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
977 delete mProgressDialog;
979 mViewer->StartPlayer();
983 mGimmick->DeleteDrive(drive);
984 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
988 //========================================================================
990 void WxGimmickView::StartListeningThread()
995 //========================================================================
997 void WxGimmickView::StopListeningThread()
1002 //========================================================================
1003 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1005 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1006 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1007 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1009 siz->Add( ef,1,wxGROW ,0);
1010 dial->SetSizer(siz);
1014 //========================================================================
1015 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1017 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1018 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1021 //=================================================
1022 /// AddProgress Gimmick callback
1023 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1026 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1027 p.GetNumberScannedDirs(),
1028 p.GetNumberScannedFiles(),
1029 p.GetNumberHandledFiles(),
1030 p.GetNumberAddedFiles());
1031 // std::cout << "OnAddProgress "<<mess<<std::endl;
1032 wxString s(wxString::From8BitData(mess));
1033 // std::cout << "Pulse"<<std::endl;
1034 if (!mProgressDialog->Pulse(s))
1038 // std::cout << "OnAddProgress ok"<<std::endl;
1040 //=================================================
1042 //=================================================
1043 void WxGimmickView::DisplayAddSummary()
1045 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
1046 std::stringstream mess;
1047 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
1048 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
1049 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
1050 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
1051 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1054 ////////////////////////////////////////////////
1055 // Add a DB to application //
1056 // @param event : WxEvent //
1058 ////////////////////////////////////////////////
1059 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1062 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1063 std::string wc("*.sqlite3*");
1064 wxFileDialog* FD = new wxFileDialog( 0,
1072 if (FD->ShowModal()==wxID_OK)
1075 wxArrayString files;
1076 FD->GetPaths(files);
1077 std::stringstream st;
1078 for(int i = 0; i< files.size(); i++)
1080 //get name of DB (file name)
1081 size_t pos = files[i].find_last_of(_T("\\"));
1082 std::string name = crea::wx2std(files[i].substr(pos+1));
1083 pos = name.find_last_of(".");
1084 name = name.substr(0,pos);
1085 //create TreeHandler
1086 mGimmick->addDB(name, crea::wx2std(files[i]));
1088 CreateSingleTreeView(name);
1092 ////////////////////////////////////////////////////
1093 // Create a DB from an Attributes Descriptor files //
1094 // @param event : WxEvent //
1096 //////////////////////////////////////////////////
1097 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1099 // PACSConnection("");
1100 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1101 DescriptorPan->Layout();
1102 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1105 std::string file(DescriptorPan->GetDescriptor());
1108 size_t pos = file.find_last_of("\\");
1109 std::string name = file.substr(pos+1);
1110 std::string directory = file.substr(0,pos);
1111 pos = name.find_last_of(".");
1112 name = name.substr(0,pos);
1113 //get directory to store DB
1114 directory += "\\" + name + ".sqlite3";
1116 mGimmick->createDB(name, file,directory);
1117 //create TreeHandler
1118 mGimmick->addDB(name, directory);
1120 CreateSingleTreeView(name);
1125 //=================================================
1127 //=================================================
1128 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1129 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1130 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1131 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1132 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1133 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1134 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1135 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1136 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1138 //=================================================
1140 } // EO namespace creaImageIO