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>
11 #include <creaImageIOWxDumpPanel.h>
12 #include <creaImageIOWxExportDlg.h>
16 #include "icons/accept.xpm"
17 #include "icons/add.xpm"
18 #include "icons/folder-down.xpm"
19 #include "icons/page-down.xpm"
20 #include "icons/remove.xpm"
21 #include "icons/database-add.xpm"
22 #include "icons/create-database.xpm"
23 #include "icons/help.xpm"
24 #include "icons/synchronize.xpm"
25 #include "icons/settings.xpm"
26 #include "icons/tools.xpm"
27 //#include "icons/import.xpm"
29 #include <wx/imaglist.h>
30 #include <wx/popupwin.h>
31 #include<boost/filesystem/operations.hpp>
32 #if defined(BUILD_BRUKER)
33 #include "bruker2dicom.h"
37 #include <creaImageIOGimmick.h>
45 //======================================================================
46 // The ids of the different tools
51 TOOL_ADDDATABASE_ID = 3,
53 TOOL_SYNCHRONIZE_ID = 5,
60 //======================================================================
62 //================================================================
64 const int icon_number = 11;
81 //================================================================
83 //================================================================
85 const icon_id Icon[5] = { Icon_Database,
91 //================================================================
94 //======================================================================
96 WxGimmickView::WxGimmickView(boost::shared_ptr<Gimmick> gimmick,
103 int number_of_threads)
104 : wxPanel(parent,id,pos,size),
105 GimmickView(gimmick, number_of_threads),
109 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
111 // Sets the current directory to the home dir
112 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
114 // Connect the AddProgress callback
115 gimmick->ConnectAddProgressObserver
116 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
118 // Create the list of icons (mIcon)
122 msizer = new wxBoxSizer(wxVERTICAL);
124 // Create the tool bar
126 msizer->Add( mToolBar, 0, wxGROW, 0);
128 // Split part below toolbar into notebook for views and panel
129 // for preview, messages...
130 mSplitter = new wxSplitterWindow( this , -1);
133 mNotebook = new wxNotebook(mSplitter,
134 -1, wxDefaultPosition, wxDefaultSize, 0);
139 mSelectionMaxDimension = max_dim;
140 mSelectionMinDimension = min_dim;
146 mBottomPanel = new wxPanel(mSplitter,-1);
148 mbottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
152 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
153 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
154 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
156 mViewer->SetImageVector(pointers);
157 mViewer->StartPlayer();
160 mbottom_sizer->Add(mViewer,1,wxGROW,1);
163 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
164 mbottom_sizer->Add(mText,0,wxGROW,0);
168 mBottomPanel->SetSizer(mbottom_sizer);
171 int hsize = size.GetHeight();
173 int top_minsize = 450;
174 int bottom_minsize = 50;
176 mSplitter->SetMinimumPaneSize( bottom_minsize );
177 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
180 msizer->Add( mSplitter, 1, wxGROW, 0);
186 //mListener=new Listener();
187 //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
188 //mListener->Create();
190 // mListener->Pause();
194 //======================================================================
196 //======================================================================
198 WxGimmickView::~WxGimmickView()
200 // stop the viewer before application exit.
201 mViewer->StopPlayer();
202 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
206 //if(mListener->IsAlive()) { mListener->Delete(); }
208 //======================================================================
210 //======================================================================
211 /// Creates the tool bar
212 void WxGimmickView::CreateToolBar()
214 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
215 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
218 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
220 mIcon->GetBitmap(Icon_page_down),
221 _T("Add one or more file to database")
223 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
225 mIcon->GetBitmap(Icon_folder_down),
226 _T("Add the content of a folder to database")
228 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
230 mIcon->GetBitmap(Icon_database_add),
231 _T("Open a local or distant database")
233 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
235 mIcon->GetBitmap(Icon_remove),
236 _T("Remove selected items")
238 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
240 mIcon->GetBitmap(Icon_synchronize),
241 _T("Synchronizes the database with disk")
243 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
245 mIcon->GetBitmap(Icon_help),
246 _T("Open help window")
248 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
249 _T("System settings"),
250 mIcon->GetBitmap(Icon_settings),
251 _T("Allows the modification of various system settings")
253 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
255 mIcon->GetBitmap(Icon_tools),
256 _T("Applies tools to images")
258 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
259 _T("Create database"),
260 mIcon->GetBitmap(Icon_create_database),
261 _T("Create DB from an Attributes Descriptor file")
263 #if defined(BUILD_PACS)
264 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
265 _T("PACS Connection,"),
266 mIcon->GetBitmap(Icon_create_database),
267 _T("Echo, Find and Get to a PACS")
270 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
274 //======================================================================
277 //======================================================================
278 /// Create the tree view for TreeHandler provided
279 void WxGimmickView::CreateTreeView( TreeHandler* h)
281 std::string name(h->GetTree().GetAttribute("Name"));
282 GimmickMessage(2,"Creating the tree view for '"<<
283 name<<"'"<<std::endl);
284 // Create the WxTreeView
285 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
287 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
288 // ALREADY IN THE MAP
289 GetTreeViewMap()[name] = view;
292 mNotebook->AddPage( view, crea::std2wx(name) );
296 //======================================================================
297 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
299 std::vector<std::string> files;
300 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
301 ReadImagesNotThreaded(s, files, dim);
304 //======================================================================
305 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
307 std::vector<std::string> files;
308 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
309 ReadImagesNotThreadedInVector(s, files, dim);
311 //======================================================================
313 //======================================================================
314 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
316 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
318 //======================================================================
320 //======================================================================
321 void WxGimmickView::GetImages(int dim,
322 const std::vector<std::string>& files,
323 std::vector<vtkImageData*>& s)
325 ReadImagesNotThreaded(s,files,dim);
327 //======================================================================
330 //=================================================
331 void WxGimmickView::CreateIconList()
333 // Size of the icons;
337 // should correspond to Icon_xxx enum
338 icons[Icon_accept] = wxIcon(accept_xpm);
339 icons[Icon_add] = wxIcon(add_xpm);
340 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
341 icons[Icon_page_down] = wxIcon(page_down_xpm);
342 icons[Icon_remove] = wxIcon(remove_xpm);
343 icons[Icon_database_add] = wxIcon(database_add_xpm);
344 icons[Icon_help] = wxIcon(help_xpm);
345 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
346 icons[Icon_create_database] = wxIcon(create_database_xpm);
347 icons[Icon_settings] = wxIcon(settings_xpm);
348 icons[Icon_tools] = wxIcon(tools_xpm);
350 // unsigned int NbIcons = 8;
351 // Make an image list containing small icons
352 mIcon = new wxImageList(size,size,true);
354 // Make all icons the same size = size of the first one
355 int sizeOrig = icons[0].GetWidth();
356 for ( size_t i = 0; i < icon_number; i++ )
358 if ( size == sizeOrig )
360 mIcon->Add(icons[i]);
364 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
368 //=================================================
371 //=================================================
372 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
374 mViewer->StopPlayer();
375 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
377 wxFileDialog* FD = new wxFileDialog( 0,
385 if (FD->ShowModal()==wxID_OK)
392 std::vector<std::string> filenames;
393 for (i=0;i<files.GetCount();++i)
395 filenames.push_back(wx2std(files[i]));
396 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
400 new wxProgressDialog(_T("Adding file(s)"),
405 // wxPD_ESTIMATED_TIME |
406 // wxPD_REMAINING_TIME |
409 // TO DO : select the current tree handler
410 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
412 mProgressDialog->Pulse(_T("Updating view..."));
414 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
415 delete mProgressDialog;
419 mViewer->StartPlayer();
421 //=================================================
423 //=================================================
424 void WxGimmickView::OnAddDir(wxCommandEvent& event)
426 mViewer->StopPlayer();
427 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
428 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
431 _T("Select directory"),
435 if (FD->ShowModal()==wxID_OK)
437 std::string dirname = wx2std (FD->GetPath());
438 bool recurse = isNeedRecursive(dirname);
441 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
445 wxString title(_T("Adding directory"));
447 title = _T("Adding directory (recursive)");
449 new wxProgressDialog(_T("Adding directory"),
451 NumberFilesToAdd(dirname,recurse),
455 // wxPD_ESTIMATED_TIME |
456 // wxPD_REMAINING_TIME |
459 mCurrentDirectory = FD->GetPath();
460 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
461 mProgressDialog->Pulse(_T("Updating view..."));
463 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
464 delete mProgressDialog;
467 mViewer->StartPlayer();
472 //=================================================
473 // Determines number of files potentially to add to database
474 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
477 if ( !boost::filesystem::exists( dirpath ) ) return nb;
478 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
479 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
481 // If is directory & recurse : do recurse
482 if ( boost::filesystem::is_directory(itr->status()) )
486 nb += NumberFilesToAdd(itr->string(), recursive);
497 //=================================================
498 // Test a directory to know if contains sub-directory to analyze
499 bool WxGimmickView::isNeedRecursive(std::string i_name)
501 boost::filesystem::directory_iterator iter(i_name), end_iter;
502 bool bfindir = false;
503 for(; iter != end_iter; ++iter)
505 if(boost::filesystem::is_directory(*iter))
512 //=================================================
514 //=================================================
515 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
517 GimmickDebugMessage(5,
518 "WxGimmickView::OnSelectionChange"
525 valid= ValidateSelected(NULL,
526 mSelectionMinDimension,
527 mSelectionMaxDimension );
532 std::vector<tree::Node*>::const_iterator i;
533 for(i=sel.begin();i!=sel.end()&&valid;++i)
535 valid= ValidateSelected((*i),
536 mSelectionMinDimension,
537 mSelectionMaxDimension );
542 valid= ValidateSelected(sel.front(),
543 mSelectionMinDimension,
544 mSelectionMaxDimension );
549 std::vector<tree::Node*>::const_iterator i;
550 for(i=sel.begin();i!=sel.end()&&valid;++i)
552 valid= ValidateSelected((*i),
553 mSelectionMinDimension,
554 mSelectionMaxDimension );
557 mText->SetLabel(crea::std2wx(GetMessage()));
560 ReadImageThreaded(sel);
566 ReadImageThreaded(sel);
569 //==================================================
571 //==================================================
572 ///Reads Images (Threaded)
573 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
575 GimmickDebugMessage(5,
578 int maxprio = GetMaximalPriority();
579 int prio = maxprio + 2000;
583 //First load the selected images
584 mCurImageItemToShow = sel.front();
587 std::vector<tree::Node*>::const_iterator selected;
588 for(selected=sel.begin();selected!=sel.end();++selected)
590 GimmickDebugMessage(5,
591 "Requesting image from selected "
592 <<(*selected)->GetAttribute("FullFileName")
594 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
595 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
596 pointers.push_back(ph);
597 RequestReading(*selected,prio,index,ph);
598 // AddEntryToMap(*selected);
602 mViewer->SetImageVector(pointers);
605 std::vector<tree::Node*> up;
606 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
607 std::vector<tree::Node*>::iterator iterUp;
608 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
610 GimmickDebugMessage(5,
611 "Requesting image from neighbors up "
612 <<(*iterUp)->GetAttribute("FullFileName")
614 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
615 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
616 RequestReading(*iterUp,prio,-1,ph);
617 // AddEntryToMap(*iterUp);
619 if (prio == maxprio) break;
624 std::vector<tree::Node*> down;
625 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
626 std::vector<tree::Node*>::iterator iterDown;
627 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
629 GimmickDebugMessage(5,
630 "Requesting image from neighbors down "
631 <<(*iterDown)->GetAttribute("FullFileName")
633 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
634 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
635 RequestReading(*iterDown,prio,-1,ph);
636 // AddEntryToMap(*iterDown);
638 if (prio == maxprio) break;
644 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
645 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
646 pointers.push_back(ph);
647 mViewer->SetImageVector(pointers);
651 //==================================================
653 //==================================================
654 void WxGimmickView::UpdateWindowUI(long flags)
658 mViewer->RefreshIfNecessary();
661 //==================================================
662 void WxGimmickView::OnInternalIdle()
664 if (!mConstructed) return;
665 static bool first_time = true;
670 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
671 // mViewer->StartPlayer();
674 mViewer->RefreshIfNecessary();
678 //==================================================
680 //==================================================
681 void WxGimmickView::ClearSelection()
684 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
685 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
686 mViewer->SetImageVector(pointers);
687 mViewer->RefreshIfNecessary();
691 //=================================================
693 //=================================================
694 void WxGimmickView::OnRemove(wxCommandEvent& event)
696 //TODO Select current tree handler
699 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
700 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
701 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
704 //=================================================
707 //=================================================
708 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
710 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
711 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
714 //=================================================
715 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
717 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
718 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
721 //=================================================
722 void WxGimmickView::AddDir(std::string dirName)
724 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
725 mCurrentDirectory = crea::std2wx(dirName);
726 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
727 mProgressDialog->Pulse(_T("Updating view..."));
729 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
730 delete mProgressDialog;
734 //=================================================
735 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
738 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
739 _T("Check database for files deletion, addition and attributes change. Then give a report."),
740 _T("Repair database (remove deleted files and add new files)."),
741 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
743 wxSingleChoiceDialog dialog(this,
744 _T("Select one of the following synchronization actions:\n")
745 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
746 _T("Synchronization Settings"),
747 WXSIZEOF(choices), choices);
749 //dialog.SetSelection(0);
751 if (dialog.ShowModal() == wxID_OK)
754 int sel=dialog.GetSelection();
756 bool checkAttributes=false;
757 if(sel==2 || sel==3){repair=true;}
758 if(sel==1 || sel==3){checkAttributes=true;}
759 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
760 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
761 if(sel==2 || sel==3){
762 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
767 //=================================================
769 //=================================================
770 void WxGimmickView::OnSettings(wxCommandEvent& event)
772 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
773 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
775 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
777 siz->Add( nb,1,wxGROW ,0);
778 CreateSettingsDialog(nb,dial);
783 //=================================================
784 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
787 // Test if one image is selected => export
789 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
799 void WxGimmickView::ExportImages()
801 //Archive selection: name, emplacement
802 //same process than copy local but to a zip
803 // if settings are yes "always ask for descriptor addition", ask
804 // if settings are yes, adding descriptor
807 void WxGimmickView::ImportImages()
811 // Contain a descriptor.text
812 // create a new database, and add to database
813 // if not, add to current database
817 //=================================================
819 void WxGimmickView::OnTools(wxCommandEvent& event)
821 mViewer->StopPlayer();
823 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
825 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
826 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
827 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
828 dialSizer->Add(nb,1,wxGROW,0);
829 dialSizer->Add(buttonsSizer,0,wxGROW);
831 #if defined(BUILD_BRUKER)
832 //First page: Bruker Image Reader
833 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
834 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
837 dial->SetSizer(dialSizer, true);
841 if (dial->GetReturnCode() == wxID_OK)
843 #if defined(BUILD_BRUKER)
844 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
846 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
847 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
849 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
851 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
853 if ( wxMessageBox(_T("Depending on the amount of Data the process can take between 1 and 5 minutes. Do you want to continue?"),
854 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
857 b2d.SetInputDirectory(inputDir);
858 b2d.SetOutputDirectory(outputDir);
859 b2d.SetConvertModeToDicom();
865 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,this,wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
866 mCurrentDirectory = gimmickTools->getOutputDir();
867 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
868 mProgressDialog->Pulse(_T("Updating view..."));
870 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
871 delete mProgressDialog;
878 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
884 mViewer->StartPlayer();
887 //=================================================
889 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
891 //First page: Customization of configurations
894 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
895 //Database Path String
897 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
898 //Syncronization Event String
900 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
901 //Syncronization Frequency String
903 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
905 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
907 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
909 //Second page: Creation of Databases
910 /*wxPanel* databaseCreation=new wxPanel(nb);
911 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
913 //Second page (temporary): Connection to PACS
914 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
915 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
917 //Third page: CD/DVD Watch
918 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
919 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
921 //Fourth page: Selection of attributes to show
922 std::vector<std::string> shown;
923 std::vector<std::string> nShown;
924 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
925 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
926 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
927 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
930 //===================================================================
931 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
932 std::vector<std::string>& nShown, int level)
934 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
937 //===================================================================
938 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
940 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
941 std::vector<std::string> n=nShown;
942 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
944 //===================================================================
945 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
946 const std::string& dbPath,
947 const std::string& syncEvent,
948 const std::string& syncFreq)
950 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
951 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
952 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
953 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
956 //===================================================================
957 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
959 mListener->SetMonitoredDrive(drive);
960 mListener->SetAddFilesState(addFiles);
961 mListener->SetRemoveFilesState(removeFiles);
964 //========================================================================
966 void WxGimmickView::OnDriveMount(bool mount)
968 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
970 mListener->GetMonitoredDrive(drive);
974 mViewer->StopPlayer();
976 wxString title(_T("Adding drive"));
978 new wxProgressDialog(_T("Adding drive"),
983 // wxPD_ESTIMATED_TIME |
984 // wxPD_REMAINING_TIME |
986 mCurrentDirectory = crea::std2wx(drive);
987 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
988 mProgressDialog->Pulse(_T("Updating view..."));
990 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
991 delete mProgressDialog;
993 mViewer->StartPlayer();
997 mGimmick->DeleteDrive(drive);
998 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1002 //========================================================================
1004 void WxGimmickView::StartListeningThread()
1006 mListener->Resume();
1009 //========================================================================
1011 void WxGimmickView::StopListeningThread()
1016 //========================================================================
1017 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1019 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1020 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1021 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1023 siz->Add( ef,1,wxGROW ,0);
1024 dial->SetSizer(siz);
1028 //========================================================================
1029 void WxGimmickView::DumpTags(std::string i_filename)
1031 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1035 //========================================================================
1036 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1038 std::vector<std::string> storages;
1039 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1040 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1042 storages.push_back(it->first);
1045 WxExportDlg* exp= new WxExportDlg(this,storages);
1046 if ( exp->ShowModal() ==ID_EXPORT_OK)
1048 std::string storage = exp->GetStorage();
1050 new wxProgressDialog(_T("Adding file(s)"),
1055 // wxPD_ESTIMATED_TIME |
1056 // wxPD_REMAINING_TIME |
1058 mGimmick->AddFiles(storage,i_filenames);
1059 mProgressDialog->Pulse(_T("Updating view..."));
1060 UpdateTreeViewLevel(storage,1);
1061 delete mProgressDialog;
1062 DisplayAddSummary();
1068 //========================================================================
1069 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1071 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1072 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1075 //=================================================
1076 /// AddProgress Gimmick callback
1077 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1080 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1081 p.GetNumberScannedDirs(),
1082 p.GetNumberScannedFiles(),
1083 p.GetNumberHandledFiles(),
1084 p.GetNumberAddedFiles());
1085 // std::cout << "OnAddProgress "<<mess<<std::endl;
1086 wxString s(wxString::From8BitData(mess));
1087 // std::cout << "Pulse"<<std::endl;
1088 if (!mProgressDialog->Pulse(s))
1092 // std::cout << "OnAddProgress ok"<<std::endl;
1094 //=================================================
1096 //=================================================
1097 void WxGimmickView::DisplayAddSummary()
1099 const Gimmick::AddProgress& p = mGimmick->GetAddProgress();
1100 std::stringstream mess;
1101 mess << "Dirs \tscanned\t: " << p.GetNumberScannedDirs() << "\n";
1102 mess << "Files\tscanned\t: " << p.GetNumberScannedFiles() << "\n";
1103 mess << "Files\thandled\t: " << p.GetNumberHandledFiles() << "\n\n";
1104 mess << "Files\tadded \t: " << p.GetNumberAddedFiles() << "\n\n";
1105 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1108 ////////////////////////////////////////////////
1109 // Add a DB to application //
1110 // @param event : WxEvent //
1112 ////////////////////////////////////////////////
1113 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1116 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1117 std::string wc("*.sqlite3*");
1118 wxFileDialog* FD = new wxFileDialog( 0,
1126 if (FD->ShowModal()==wxID_OK)
1129 wxArrayString files;
1130 FD->GetPaths(files);
1131 std::stringstream st;
1132 for(int i = 0; i< files.size(); i++)
1134 //get name of DB (file name)
1135 size_t pos = files[i].find_last_of(_T("\\"));
1136 std::string name = crea::wx2std(files[i].substr(pos+1));
1137 pos = name.find_last_of(".");
1138 name = name.substr(0,pos);
1139 //create TreeHandler
1140 mGimmick->addDB(name, crea::wx2std(files[i]));
1142 CreateSingleTreeView(name);
1146 ////////////////////////////////////////////////////
1147 // Create a DB from an Attributes Descriptor files //
1148 // @param event : WxEvent //
1150 //////////////////////////////////////////////////
1151 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1153 // PACSConnection("");
1154 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1155 DescriptorPan->Layout();
1156 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1159 std::string file(DescriptorPan->GetDescriptor());
1162 size_t pos = file.find_last_of("\\");
1163 std::string name = file.substr(pos+1);
1164 std::string directory = file.substr(0,pos);
1165 pos = name.find_last_of(".");
1166 name = name.substr(0,pos);
1167 //get directory to store DB
1168 directory += "\\" + name + ".sqlite3";
1170 mGimmick->createDB(name, file,directory);
1171 //create TreeHandler
1172 mGimmick->addDB(name, directory);
1174 CreateSingleTreeView(name);
1179 //=================================================
1181 //=================================================
1182 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1183 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1184 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1185 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1186 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1187 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1188 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1189 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1190 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1192 //=================================================
1194 } // EO namespace creaImageIO