2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
29 #include <creaImageIOPACSConnection.h>
30 #include <creaImageIOWxPACSConnectionPanel.h>
31 #include <creaImageIOWxGimmickView.h>
32 #include <creaImageIOWxTreeView.h>
33 #include <creaImageIOSystem.h>
34 #include <creaImageIOWxCustomizeConfigPanel.h>
35 #include <creaImageIOWxListenerPanel.h>
36 #include <creaImageIOWxEditFieldsPanel.h>
37 #include <creaImageIOWxAttributeSelectionPanel.h>
38 #include <creaImageIOWxDescriptorPanel.h>
39 #include <creaImageIOWxDumpPanel.h>
40 #include <creaImageIOWxExportDlg.h>
41 #include <creaImageIOWxOutputDlg.h>
42 #include <creaImageIOOutputModel.h>
46 #include "icons/accept.xpm"
47 #include "icons/add.xpm"
48 #include "icons/folder-down.xpm"
49 #include "icons/page-down.xpm"
50 #include "icons/remove.xpm"
51 #include "icons/database-add.xpm"
52 #include "icons/create-database.xpm"
53 #include "icons/help.xpm"
54 #include "icons/synchronize.xpm"
55 #include "icons/settings.xpm"
56 #include "icons/tools.xpm"
57 //#include "icons/import.xpm"
59 #include <wx/imaglist.h>
60 #include <wx/popupwin.h>
61 #include<boost/filesystem/operations.hpp>
62 #if defined(BUILD_BRUKER)
63 #include "bruker2dicom.h"
67 #include <creaImageIOGimmick.h>
75 //======================================================================
76 // The ids of the different tools
81 TOOL_ADDDATABASE_ID = 3,
83 TOOL_SYNCHRONIZE_ID = 5,
90 //======================================================================
92 //================================================================
94 const int icon_number = 11;
111 //================================================================
113 //================================================================
115 const icon_id Icon[5] = { Icon_Database,
121 //================================================================
124 //======================================================================
126 WxGimmickView::WxGimmickView(boost::shared_ptr<Gimmick> gimmick,
133 int number_of_threads)
134 : wxPanel(parent,id,pos,size),
135 GimmickView(gimmick, number_of_threads),
139 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
141 // Sets the current directory to the home dir
142 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
145 // Connect the AddProgress callback
146 gimmick->ConnectAddProgressObserver
147 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
149 // Create the list of icons (mIcon)
153 msizer = new wxBoxSizer(wxVERTICAL);
155 // Create the tool bar
157 msizer->Add( mToolBar, 0, wxGROW, 0);
159 // Split part below toolbar into notebook for views and panel
160 // for preview, messages...
161 mSplitter = new wxSplitterWindow( this , -1);
164 mNotebook = new wxNotebook(mSplitter,
165 -1, wxDefaultPosition, wxDefaultSize, 0);
170 mSelectionMaxDimension = max_dim;
171 mSelectionMinDimension = min_dim;
177 mBottomPanel = new wxPanel(mSplitter,-1);
179 mbottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
183 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
184 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
185 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
187 mViewer->SetImageVector(pointers);
188 mViewer->StartPlayer();
191 mbottom_sizer->Add(mViewer,1,wxGROW,1);
194 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
195 mbottom_sizer->Add(mText,0,wxGROW,0);
199 mBottomPanel->SetSizer(mbottom_sizer);
202 /// \TODO fix warning: unused variable hsize
203 int hsize = size.GetHeight();
205 int top_minsize = 450;
206 int bottom_minsize = 50;
208 mSplitter->SetMinimumPaneSize( bottom_minsize );
209 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
212 msizer->Add( mSplitter, 1, wxGROW, 0);
218 //mListener=new Listener();
219 //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
220 //mListener->Create();
222 // mListener->Pause();
226 //======================================================================
228 //======================================================================
230 WxGimmickView::~WxGimmickView()
232 // stop the viewer before application exit.
233 mViewer->StopPlayer();
234 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
238 //if(mListener->IsAlive()) { mListener->Delete(); }
240 //======================================================================
242 //======================================================================
243 /// Creates the tool bar
244 void WxGimmickView::CreateToolBar()
246 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
247 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
250 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
252 mIcon->GetBitmap(Icon_page_down),
253 _T("Add one or more file to database")
255 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
257 mIcon->GetBitmap(Icon_folder_down),
258 _T("Add the content of a folder to database")
260 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
262 mIcon->GetBitmap(Icon_database_add),
263 _T("Open a local or distant database")
265 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
267 mIcon->GetBitmap(Icon_remove),
268 _T("Remove selected items")
270 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
272 mIcon->GetBitmap(Icon_synchronize),
273 _T("Synchronizes the database with disk")
275 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
277 mIcon->GetBitmap(Icon_help),
278 _T("Open help window")
280 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
281 _T("System settings"),
282 mIcon->GetBitmap(Icon_settings),
283 _T("Allows the modification of various system settings")
285 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
287 mIcon->GetBitmap(Icon_tools),
288 _T("Applies tools to images")
290 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
291 _T("Create database"),
292 mIcon->GetBitmap(Icon_create_database),
293 _T("Create DB from an Attributes Descriptor file")
295 #if defined(BUILD_PACS)
296 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
297 _T("PACS Connection,"),
298 mIcon->GetBitmap(Icon_create_database),
299 _T("Echo, Find and Get to a PACS")
302 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
306 //======================================================================
309 //======================================================================
310 /// Create the tree view for TreeHandler provided
311 void WxGimmickView::CreateTreeView( TreeHandler* h)
313 std::string name(h->GetTree().GetAttribute("Name"));
314 GimmickMessage(2,"Creating the tree view for '"<<
315 name<<"'"<<std::endl);
316 // Create the WxTreeView
317 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
319 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
320 // ALREADY IN THE MAP
321 GetTreeViewMap()[name] = view;
324 mNotebook->AddPage( view, crea::std2wx(name) );
328 //======================================================================
329 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
331 std::vector<std::string> files;
332 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
333 //ReadImagesNotThreaded(s, files, dim);
336 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
337 // ReadImagesNotThreadedInfosInVector(db_name,output, files,dim,1);
342 //======================================================================
343 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
345 std::vector<std::string> files;
346 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
347 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
349 ReadImagesNotThreadedInVector(s, files, dim);
353 /// By default if out_infos is empty, we dont' provide informations, we return only vtkImageData
354 /// if out_infos has only one entry "all" we provide all database informations
355 void WxGimmickView::getSelectedFiles(std::vector<OutStrGimmick> &outG, std::vector< std::string> i_attr,
356 bool mult, const std::string out_model)
358 // First we select the files
359 std::vector<std::string> files;
360 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
361 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
365 bool bsingle = isSingle(files.front());
367 mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking);
368 mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim);
370 if (asking == "true")
372 // display the output dialog box
375 sscanf(dim.c_str(),"%d",&idim);
376 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
377 if (dlg->ShowModal() == wxID_OK)
380 mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
381 mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
391 sscanf(dim.c_str(),"%d",&i_dim_out);
394 // Next we create the structure for dicom output infos
396 Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
399 // We don't send informations!
401 else if( i_attr.size() == 1 && i_attr.front() == "ALL")
403 // we send all database
404 Oattr.inside.push_back("ALL");
406 else if( (i_attr.size() == 1 && i_attr.front() != "ALL")
407 || (i_attr.size() >1) )
409 mGimmick->fillVectInfos(i_attr, Oattr);
416 // Next we create model and sort files
417 std::vector<std::string> sort_files(files);
419 if( !out_model.empty() )
421 /* OutputModel mod(out_model);
422 mGimmick->isAttributeExist(db_name, mod);
423 mod.sort(files, sort_files);
426 if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
428 OutputModel *mod = new OutputModel();
429 zspacing = mod->orderFilesWithZspacing(sort_files);
432 // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
433 readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
439 //======================================================================
441 //======================================================================
444 //======================================================================
445 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
447 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
449 //======================================================================
451 //======================================================================
452 void WxGimmickView::GetImages(int dim,
453 const std::vector<std::string>& files,
454 std::vector<vtkImageData*>& s)
456 ReadImagesNotThreaded(s,files,dim);
458 //======================================================================
461 //=================================================
462 void WxGimmickView::CreateIconList()
464 // Size of the icons;
468 // should correspond to Icon_xxx enum
469 icons[Icon_accept] = wxIcon(accept_xpm);
470 icons[Icon_add] = wxIcon(add_xpm);
471 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
472 icons[Icon_page_down] = wxIcon(page_down_xpm);
473 icons[Icon_remove] = wxIcon(remove_xpm);
474 icons[Icon_database_add] = wxIcon(database_add_xpm);
475 icons[Icon_help] = wxIcon(help_xpm);
476 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
477 icons[Icon_create_database] = wxIcon(create_database_xpm);
478 icons[Icon_settings] = wxIcon(settings_xpm);
479 icons[Icon_tools] = wxIcon(tools_xpm);
481 // unsigned int NbIcons = 8;
482 // Make an image list containing small icons
483 mIcon = new wxImageList(size,size,true);
485 // Make all icons the same size = size of the first one
486 int sizeOrig = icons[0].GetWidth();
487 for ( size_t i = 0; i < icon_number; i++ )
489 if ( size == sizeOrig )
491 mIcon->Add(icons[i]);
495 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
499 //=================================================
502 //=================================================
503 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
505 mViewer->StopPlayer();
506 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
508 wxFileDialog* FD = new wxFileDialog( 0,
516 if (FD->ShowModal()==wxID_OK)
523 std::vector<std::string> filenames;
524 for (i=0;i<files.GetCount();++i)
526 filenames.push_back(wx2std(files[i]));
527 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
531 new wxProgressDialog(_T("Adding file(s)"),
537 // wxPD_ESTIMATED_TIME |
538 // wxPD_REMAINING_TIME |
541 // TO DO : select the current tree handler
542 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
544 mProgressDialog->Pulse(_T("Updating view..."));
546 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
551 mViewer->StartPlayer();
553 //=================================================
555 //=================================================
556 void WxGimmickView::OnAddDir(wxCommandEvent& event)
558 mViewer->StopPlayer();
559 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
560 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
563 _T("Select directory"),
567 if (FD->ShowModal()==wxID_OK)
570 std::string dirname = wx2std (FD->GetPath());
571 bool recurse = isNeedRecursive(dirname);
574 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
578 wxString title(_T("Adding directory"));
580 title = _T("Adding directory (recursive)");
582 new wxProgressDialog(_T("Adding directory"),
584 NumberFilesToAdd(dirname,recurse),
591 // wxPD_ESTIMATED_TIME |
592 // wxPD_REMAINING_TIME |
595 mCurrentDirectory = FD->GetPath();
596 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
597 mProgressDialog->Pulse(_T("Updating view..."));
599 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
603 mViewer->StartPlayer();
608 //=================================================
609 // Determines number of files potentially to add to database
610 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
613 if ( !boost::filesystem::exists( dirpath ) ) return nb;
614 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
615 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
617 // If is directory & recurse : do recurse
618 if ( boost::filesystem::is_directory(itr->status()) )
622 nb += NumberFilesToAdd(itr->path().string(), recursive);
633 //=================================================
634 // Test a directory to know if contains sub-directory to analyze
635 bool WxGimmickView::isNeedRecursive(std::string i_name)
637 boost::filesystem::directory_iterator iter(i_name), end_iter;
638 //bool bfindir = false;
639 for(; iter != end_iter; ++iter)
641 if(boost::filesystem::is_directory(*iter))
648 //=================================================
650 //=================================================
651 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
653 GimmickDebugMessage(5,
654 "WxGimmickView::OnSelectionChange"
661 valid= ValidateSelected(NULL,
662 mSelectionMinDimension,
663 mSelectionMaxDimension );
668 std::vector<tree::Node*>::const_iterator i;
669 for(i=sel.begin();i!=sel.end()&&valid;++i)
671 valid= ValidateSelected((*i),
672 mSelectionMinDimension,
673 mSelectionMaxDimension );
678 valid= ValidateSelected(sel.front(),
679 mSelectionMinDimension,
680 mSelectionMaxDimension );
685 std::vector<tree::Node*>::const_iterator i;
686 for(i=sel.begin();i!=sel.end()&&valid;++i)
688 valid= ValidateSelected((*i),
689 mSelectionMinDimension,
690 mSelectionMaxDimension );
693 mText->SetLabel(crea::std2wx(GetMessage()));
696 ReadImageThreaded(sel);
702 ReadImageThreaded(sel);
705 //==================================================
707 //==================================================
708 ///Reads Images (Threaded)
709 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
711 GimmickDebugMessage(5,
714 int maxprio = GetMaximalPriority();
715 int prio = maxprio + 2000;
719 //First load the selected images
720 mCurImageItemToShow = sel.front();
723 std::vector<tree::Node*>::const_iterator selected;
724 for(selected=sel.begin();selected!=sel.end();++selected)
726 GimmickDebugMessage(5,
727 "Requesting image from selected "
728 <<(*selected)->GetAttribute("FullFileName")
730 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
731 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
732 pointers.push_back(ph);
733 RequestReading(*selected,prio,index,ph);
734 // AddEntryToMap(*selected);
738 mViewer->SetImageVector(pointers);
741 std::vector<tree::Node*> up;
742 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
743 std::vector<tree::Node*>::iterator iterUp;
744 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
746 GimmickDebugMessage(5,
747 "Requesting image from neighbors up "
748 <<(*iterUp)->GetAttribute("FullFileName")
750 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
751 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
752 RequestReading(*iterUp,prio,-1,ph);
753 // AddEntryToMap(*iterUp);
755 if (prio == maxprio) break;
760 std::vector<tree::Node*> down;
761 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
762 std::vector<tree::Node*>::iterator iterDown;
763 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
765 GimmickDebugMessage(5,
766 "Requesting image from neighbors down "
767 <<(*iterDown)->GetAttribute("FullFileName")
769 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
770 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
771 RequestReading(*iterDown,prio,-1,ph);
772 // AddEntryToMap(*iterDown);
774 if (prio == maxprio) break;
780 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
781 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
782 pointers.push_back(ph);
783 mViewer->SetImageVector(pointers);
787 //==================================================
789 //==================================================
792 //==================================================
793 void WxGimmickView::OnInternalIdle()
795 if (!mConstructed) return;
796 static bool first_time = true;
801 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
802 // mViewer->StartPlayer();
805 mViewer->RefreshIfNecessary();
809 void WxGimmickView::UpdateWindowUI(long flags)
813 mViewer->RefreshIfNecessary();
817 //==================================================
819 //==================================================
820 void WxGimmickView::ClearSelection()
823 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
824 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
825 mViewer->SetImageVector(pointers);
826 mViewer->RefreshIfNecessary();
830 //=================================================
832 //=================================================
833 void WxGimmickView::OnRemove(wxCommandEvent& event)
835 //TODO Select current tree handler
838 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
839 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
840 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
843 //=================================================
846 //=================================================
847 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
849 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
850 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
853 //=================================================
854 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
856 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
857 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
860 //=================================================
861 void WxGimmickView::AddDir(std::string dirName)
863 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
868 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
869 mCurrentDirectory = crea::std2wx(dirName);
870 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
871 mProgressDialog->Pulse(_T("Updating view..."));
873 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
878 //=================================================
879 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
882 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
883 _T("Check database for files deletion, addition and attributes change. Then give a report."),
884 _T("Repair database (remove deleted files and add new files)."),
885 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
887 wxSingleChoiceDialog dialog(this,
888 _T("Select one of the following synchronization actions:\n")
889 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
890 _T("Synchronization Settings"),
891 WXSIZEOF(choices), choices);
893 //dialog.SetSelection(0);
895 if (dialog.ShowModal() == wxID_OK)
898 int sel=dialog.GetSelection();
900 bool checkAttributes=false;
901 if(sel==2 || sel==3){repair=true;}
902 if(sel==1 || sel==3){checkAttributes=true;}
903 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
904 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
905 if(sel==2 || sel==3){
906 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
911 //=================================================
913 //=================================================
914 void WxGimmickView::OnSettings(wxCommandEvent& event)
916 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
917 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
919 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
921 siz->Add( nb,1,wxGROW ,0);
922 CreateSettingsDialog(nb,dial);
927 //=================================================
928 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
931 // Test if one image is selected => export
933 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
943 void WxGimmickView::ExportImages()
945 //Archive selection: name, emplacement
946 //same process than copy local but to a zip
947 // if settings are yes "always ask for descriptor addition", ask
948 // if settings are yes, adding descriptor
951 void WxGimmickView::ImportImages()
955 // Contain a descriptor.text
956 // create a new database, and add to database
957 // if not, add to current database
961 //=================================================
963 void WxGimmickView::OnTools(wxCommandEvent& event)
965 mViewer->StopPlayer();
967 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
969 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
970 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
971 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
972 dialSizer->Add(nb,1,wxGROW,0);
973 dialSizer->Add(buttonsSizer,0,wxGROW);
975 #if defined(BUILD_BRUKER)
976 //First page: Bruker Image Reader
977 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
978 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
981 dial->SetSizer(dialSizer, true);
985 if (dial->GetReturnCode() == wxID_OK)
987 #if defined(BUILD_BRUKER)
988 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
990 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
991 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
993 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
995 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
997 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
998 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
1001 b2d.SetInputDirectory(inputDir);
1002 b2d.SetOutputDirectory(outputDir);
1003 b2d.SetConvertModeToDicom();
1008 std::cout <<"after addToDB" << std::endl;
1009 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
1014 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
1015 std::cout <<"after new wxProgressDialog" << std::endl;
1016 mCurrentDirectory = gimmickTools->getOutputDir();
1017 std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;
1018 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
1019 std::cout <<"after mGimmick->AddDir" << std::endl;
1020 mProgressDialog->Pulse(_T("Updating view..."));
1021 std::cout <<"after mProgressDialog->Pulse" << std::endl;
1022 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1023 std::cout <<"after UpdateTreeViewLevel" << std::endl;
1025 std::cout <<"after delete mProgressDialog" << std::endl;
1026 DisplayAddSummary();
1027 std::cout <<"after dDisplayAddSummary" << std::endl;
1033 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
1036 delete gimmickTools;
1039 mViewer->StartPlayer();
1042 //=================================================
1044 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1046 //First page: Customization of configurations
1049 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1050 //Database Path String
1052 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1053 //Syncronization Event String
1055 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1056 //Syncronization Frequency String
1058 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1060 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1062 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1064 //Second page: Creation of Databases
1065 /*wxPanel* databaseCreation=new wxPanel(nb);
1066 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1068 //Second page (temporary): Connection to PACS
1069 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1070 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1072 //Third page: CD/DVD Watch
1073 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1074 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1076 //Fourth page: Selection of attributes to show
1077 std::vector<std::string> shown;
1078 std::vector<std::string> nShown;
1079 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1080 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1081 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1082 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1085 //===================================================================
1086 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1087 std::vector<std::string>& nShown, int level)
1089 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1092 //===================================================================
1093 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1095 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1096 std::vector<std::string> n=nShown;
1097 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1099 //===================================================================
1100 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1101 const std::string& dbPath,
1102 const std::string& syncEvent,
1103 const std::string& syncFreq)
1105 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1106 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1107 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1108 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1111 //===================================================================
1112 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1114 mListener->SetMonitoredDrive(drive);
1115 mListener->SetAddFilesState(addFiles);
1116 mListener->SetRemoveFilesState(removeFiles);
1119 //========================================================================
1121 void WxGimmickView::OnDriveMount(bool mount)
1123 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1125 mListener->GetMonitoredDrive(drive);
1129 mViewer->StopPlayer();
1131 wxString title(_T("Adding drive"));
1133 new wxProgressDialog(_T("Adding drive"),
1141 // wxPD_ESTIMATED_TIME |
1142 // wxPD_REMAINING_TIME |
1144 mCurrentDirectory = crea::std2wx(drive);
1145 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1146 mProgressDialog->Pulse(_T("Updating view..."));
1148 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1150 DisplayAddSummary();
1151 mViewer->StartPlayer();
1155 mGimmick->DeleteDrive(drive);
1156 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1160 //========================================================================
1162 void WxGimmickView::StartListeningThread()
1164 mListener->Resume();
1167 //========================================================================
1169 void WxGimmickView::StopListeningThread()
1174 //========================================================================
1175 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1177 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1178 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1179 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1181 siz->Add( ef,1,wxGROW ,0);
1182 dial->SetSizer(siz);
1188 //========================================================================
1189 void WxGimmickView::DumpTags(std::string i_filename)
1191 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1195 //========================================================================
1196 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1198 std::vector<std::string> storages;
1199 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1200 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1202 storages.push_back(it->first);
1205 WxExportDlg* exp= new WxExportDlg(this,storages);
1206 if ( exp->ShowModal() ==ID_EXPORT_OK)
1208 std::string storage = exp->GetStorage();
1210 new wxProgressDialog(_T("Adding file(s)"),
1218 // wxPD_ESTIMATED_TIME |
1219 // wxPD_REMAINING_TIME |
1221 mGimmick->AddFiles(storage,i_filenames);
1222 mProgressDialog->Pulse(_T("Updating view..."));
1223 UpdateTreeViewLevel(storage,1);
1225 DisplayAddSummary();
1231 //========================================================================
1232 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1234 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1235 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1238 //=================================================
1239 /// AddProgress Gimmick callback
1240 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1243 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1244 p.GetNumberScannedDirs(),
1245 p.GetNumberScannedFiles(),
1246 p.GetNumberHandledFiles(),
1247 p.GetNumberAddedFiles());
1248 // std::cout << "OnAddProgress "<<mess<<std::endl;
1249 wxString s(wxString::From8BitData(mess));
1250 // std::cout << "Pulse"<<std::endl;
1252 if(mProgressDialog != 0)
1254 if (!mProgressDialog->Pulse(s))
1259 // std::cout << "OnAddProgress ok"<<std::endl;
1261 //=================================================
1263 //=================================================
1264 void WxGimmickView::DisplayAddSummary()
1266 std::stringstream mess(mGimmick->getSummary());
1269 mess << "time to scan :" << difftime(end,mstart) << "sec";
1270 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1273 ////////////////////////////////////////////////
1274 // Add a DB to application //
1275 // @param event : WxEvent //
1277 ////////////////////////////////////////////////
1278 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1281 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1282 std::string wc("*.sqlite3*");
1283 wxFileDialog* FD = new wxFileDialog( 0,
1291 if (FD->ShowModal()==wxID_OK)
1294 wxArrayString files;
1295 FD->GetPaths(files);
1296 std::stringstream st;
1297 for(int i = 0; i< files.size(); i++)
1299 //get name of DB (file name)
1300 size_t pos = files[i].find_last_of(_T("\\"));
1301 std::string name = crea::wx2std(files[i].substr(pos+1));
1302 pos = name.find_last_of(".");
1303 name = name.substr(0,pos);
1304 //create TreeHandler
1305 mGimmick->addDB(name, crea::wx2std(files[i]));
1307 CreateSingleTreeView(name);
1311 ////////////////////////////////////////////////////
1312 // Create a DB from an Attributes Descriptor files //
1313 // @param event : WxEvent //
1315 //////////////////////////////////////////////////
1316 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1318 // PACSConnection("");
1319 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1320 DescriptorPan->Layout();
1321 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1324 std::string file(DescriptorPan->GetDescriptor());
1327 size_t pos = file.find_last_of("\\");
1328 std::string name = file.substr(pos+1);
1329 std::string directory = file.substr(0,pos);
1330 pos = name.find_last_of(".");
1331 name = name.substr(0,pos);
1332 //get directory to store DB
1333 directory += "\\" + name + ".sqlite3";
1335 mGimmick->createDB(name, file,directory);
1336 //create TreeHandler
1337 mGimmick->addDB(name, directory);
1339 CreateSingleTreeView(name);
1344 void WxGimmickView::killProgress()
1346 mProgressDialog->Resume();
1347 mProgressDialog->Destroy();
1348 mProgressDialog = 0;
1351 //=================================================
1353 //=================================================
1354 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1355 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1356 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1357 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1358 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1359 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1360 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1361 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1362 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1364 //=================================================
1366 } // EO namespace creaImageIO