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 # ------------------------------------------------------------------------
30 #include <creaImageIOWxPACSConnectionPanel.h>
31 #include <creaImageIOWxTreeView.h>
32 #include <creaImageIOWxCustomizeConfigPanel.h>
33 #include <creaImageIOWxListenerPanel.h>
34 #include <creaImageIOWxEditFieldsPanel.h>
35 #include <creaImageIOWxAttributeSelectionPanel.h>
36 #include <creaImageIOWxDescriptorPanel.h>
37 #include <creaImageIOWxDumpPanel.h>
38 #include <creaImageIOWxExportDlg.h>
39 #include <creaImageIOWxOutputDlg.h>
40 #include <creaImageIOOutputModel.h>
43 #pragma warning(disable: 4996)
48 #include "icons/accept.xpm"
49 #include "icons/add.xpm"
50 #include "icons/folder-down.xpm"
51 #include "icons/page-down.xpm"
52 #include "icons/remove.xpm"
53 #include "icons/database-add.xpm"
54 #include "icons/create-database.xpm"
55 #include "icons/help.xpm"
56 #include "icons/synchronize.xpm"
57 #include "icons/settings.xpm"
58 #include "icons/tools.xpm"
59 //#include "icons/import.xpm"
61 #include <wx/imaglist.h>
62 #include <wx/popupwin.h>
63 #include<boost/filesystem/operations.hpp>
64 #if defined(BUILD_BRUKER)
65 #include "bruker2dicom.h"
69 #include <creaImageIOGimmick.h>
77 //======================================================================
78 // The ids of the different tools
83 TOOL_ADDDATABASE_ID = 3,
85 TOOL_SYNCHRONIZE_ID = 5,
92 //======================================================================
94 //================================================================
96 const int icon_number = 11;
100 Icon_create_database,
113 //================================================================
115 //================================================================
117 const icon_id Icon[5] = { Icon_Database,
123 //================================================================
126 //======================================================================
128 WxGimmickView::WxGimmickView(boost::shared_ptr<Gimmick> gimmick,
135 int number_of_threads)
136 : wxPanel(parent,id,pos,size),
137 GimmickView(gimmick, number_of_threads),
141 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
143 // Sets the current directory to the home dir
144 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
147 // Connect the AddProgress callback
148 gimmick->ConnectAddProgressObserver
149 ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
151 // Create the list of icons (mIcon)
155 msizer = new wxBoxSizer(wxVERTICAL);
157 // Create the tool bar
159 msizer->Add( mToolBar, 0, wxGROW, 0);
161 // Split part below toolbar into notebook for views and panel
162 // for preview, messages...
163 mSplitter = new wxSplitterWindow( this , -1);
166 mNotebook = new wxNotebook(mSplitter,
167 -1, wxDefaultPosition, wxDefaultSize, 0);
172 mSelectionMaxDimension = max_dim;
173 mSelectionMinDimension = min_dim;
179 mBottomPanel = new wxPanel(mSplitter,-1);
181 mbottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
185 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
186 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
187 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
189 mViewer->SetImageVector(pointers);
190 mViewer->StartPlayer();
193 mbottom_sizer->Add(mViewer,1,wxGROW,1);
196 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
197 mbottom_sizer->Add(mText,0,wxGROW,0);
201 mBottomPanel->SetSizer(mbottom_sizer);
204 /// \TODO fix warning: unused variable hsize
205 int hsize = size.GetHeight();
207 int top_minsize = 450;
208 int bottom_minsize = 50;
210 mSplitter->SetMinimumPaneSize( bottom_minsize );
211 mSplitter->SplitHorizontally( mNotebook, mBottomPanel,
214 msizer->Add( mSplitter, 1, wxGROW, 0);
220 //mListener=new Listener();
221 //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
222 //mListener->Create();
224 // mListener->Pause();
228 //======================================================================
230 //======================================================================
232 WxGimmickView::~WxGimmickView()
234 // stop the viewer before application exit.
235 mViewer->StopPlayer();
236 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
240 //if(mListener->IsAlive()) { mListener->Delete(); }
242 //======================================================================
244 //======================================================================
245 /// Creates the tool bar
246 void WxGimmickView::CreateToolBar()
248 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
249 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
252 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
254 mIcon->GetBitmap(Icon_page_down),
255 _T("Add one or more file to database")
257 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
259 mIcon->GetBitmap(Icon_folder_down),
260 _T("Add the content of a folder to database")
262 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
264 mIcon->GetBitmap(Icon_database_add),
265 _T("Open a local or distant database")
267 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
269 mIcon->GetBitmap(Icon_remove),
270 _T("Remove selected items")
272 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
274 mIcon->GetBitmap(Icon_synchronize),
275 _T("Synchronizes the database with disk")
277 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
279 mIcon->GetBitmap(Icon_help),
280 _T("Open help window")
282 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
283 _T("System settings"),
284 mIcon->GetBitmap(Icon_settings),
285 _T("Allows the modification of various system settings")
287 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
289 mIcon->GetBitmap(Icon_tools),
290 _T("Applies tools to images")
292 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
293 _T("Create database"),
294 mIcon->GetBitmap(Icon_create_database),
295 _T("Create DB from an Attributes Descriptor file")
297 #if defined(BUILD_PACS)
298 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
299 _T("PACS Connection,"),
300 mIcon->GetBitmap(Icon_create_database),
301 _T("Echo, Find and Get to a PACS")
304 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
308 //======================================================================
311 //======================================================================
312 /// Create the tree view for TreeHandler provided
313 void WxGimmickView::CreateTreeView( TreeHandler* h)
315 std::string name(h->GetTree().GetAttribute("Name"));
316 GimmickMessage(2,"Creating the tree view for '"<<
317 name<<"'"<<std::endl);
318 // Create the WxTreeView
319 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
321 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
322 // ALREADY IN THE MAP
323 GetTreeViewMap()[name] = view;
326 mNotebook->AddPage( view, crea::std2wx(name) );
330 //======================================================================
331 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
333 std::vector<std::string> files;
334 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
335 //ReadImagesNotThreaded(s, files, dim);
338 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
339 // ReadImagesNotThreadedInfosInVector(db_name,output, files,dim,1);
344 //======================================================================
345 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
347 std::vector<std::string> files;
348 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
349 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
351 ReadImagesNotThreadedInVector(s, files, dim);
355 /// By default if out_infos is empty, we dont' provide informations, we return only vtkImageData
356 /// if out_infos has only one entry "all" we provide all database informations
357 void WxGimmickView::getSelectedFiles(std::vector<OutStrGimmick> &outG, std::vector< std::string> i_attr,
358 bool mult, const std::string out_model)
360 // First we select the files
361 std::vector<std::string> files;
362 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
363 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
367 bool bsingle = isSingle(files.front());
369 mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking);
370 mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim);
373 if (asking == "true")
375 // display the output dialog box
378 sscanf(dim.c_str(),"%d",&idim);
379 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
380 if (dlg->ShowModal() == wxID_OK)
383 mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
384 mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
390 sscanf(dim.c_str(),"%d",&i_dim_out);
392 // Next we create the structure for dicom output infos
401 Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
404 // We don't send informations!
405 } else if( i_attr.size() == 1 && i_attr.front() == "ALL")
407 // we send all database
408 Oattr.inside.push_back("ALL");
409 } else if( (i_attr.size() == 1 && i_attr.front() != "ALL")
410 || (i_attr.size() >1) )
412 mGimmick->fillVectInfos(i_attr, Oattr);
417 // Next we create model and sort files
418 std::vector<std::string> sort_files(files);
420 if( !out_model.empty() )
422 /* OutputModel mod(out_model);
423 mGimmick->isAttributeExist(db_name, mod);
424 mod.sort(files, sort_files);
427 if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
429 OutputModel *mod = new OutputModel();
430 zspacing = mod->orderFilesWithZspacing(sort_files);
433 // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
434 readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
440 //======================================================================
442 //======================================================================
445 //======================================================================
446 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
448 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
450 //======================================================================
452 //======================================================================
453 void WxGimmickView::GetImages(int dim,
454 const std::vector<std::string>& files,
455 std::vector<vtkImageData*>& s)
457 ReadImagesNotThreaded(s,files,dim);
459 //======================================================================
462 //=================================================
463 void WxGimmickView::CreateIconList()
465 // Size of the icons;
469 // should correspond to Icon_xxx enum
470 icons[Icon_accept] = wxIcon(accept_xpm);
471 icons[Icon_add] = wxIcon(add_xpm);
472 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
473 icons[Icon_page_down] = wxIcon(page_down_xpm);
474 icons[Icon_remove] = wxIcon(remove_xpm);
475 icons[Icon_database_add] = wxIcon(database_add_xpm);
476 icons[Icon_help] = wxIcon(help_xpm);
477 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
478 icons[Icon_create_database] = wxIcon(create_database_xpm);
479 icons[Icon_settings] = wxIcon(settings_xpm);
480 icons[Icon_tools] = wxIcon(tools_xpm);
482 // unsigned int NbIcons = 8;
483 // Make an image list containing small icons
484 mIcon = new wxImageList(size,size,true);
486 // Make all icons the same size = size of the first one
487 int sizeOrig = icons[0].GetWidth();
488 for ( size_t i = 0; i < icon_number; i++ )
490 if ( size == sizeOrig )
492 mIcon->Add(icons[i]);
496 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
500 //=================================================
503 //=================================================
504 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
506 mViewer->StopPlayer();
508 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
509 #if wxMAJOR_VERSION <= 2
510 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
512 long style = wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE;
517 wxFileDialog* FD = new wxFileDialog( 0,
525 if (FD->ShowModal()==wxID_OK)
532 std::vector<std::string> filenames;
533 for (i=0;i<files.GetCount();++i)
535 filenames.push_back(wx2std(files[i]));
536 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
540 new wxProgressDialog(_T("Adding file(s)"),
546 // wxPD_ESTIMATED_TIME |
547 // wxPD_REMAINING_TIME |
550 // TO DO : select the current tree handler
551 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
553 mProgressDialog->Pulse(_T("Updating view..."));
555 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
560 mViewer->StartPlayer();
562 //=================================================
564 //=================================================
565 void WxGimmickView::OnAddDir(wxCommandEvent& event)
567 mViewer->StopPlayer();
568 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
569 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
572 _T("Select directory"),
576 if (FD->ShowModal()==wxID_OK)
579 std::string dirname = wx2std (FD->GetPath());
580 bool recurse = isNeedRecursive(dirname);
583 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
587 wxString title(_T("Adding directory"));
589 title = _T("Adding directory (recursive)");
591 new wxProgressDialog(_T("Adding directory"),
593 NumberFilesToAdd(dirname,recurse),
600 // wxPD_ESTIMATED_TIME |
601 // wxPD_REMAINING_TIME |
604 mCurrentDirectory = FD->GetPath();
605 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
606 mProgressDialog->Pulse(_T("Updating view..."));
608 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
612 mViewer->StartPlayer();
617 //=================================================
618 // Determines number of files potentially to add to database
619 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
622 if ( !boost::filesystem::exists( dirpath ) ) return nb;
623 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
624 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
626 // If is directory & recurse : do recurse
627 if ( boost::filesystem::is_directory(itr->status()) )
631 nb += NumberFilesToAdd(itr->path().string(), recursive);
642 //=================================================
643 // Test a directory to know if contains sub-directory to analyze
644 bool WxGimmickView::isNeedRecursive(std::string i_name)
646 boost::filesystem::directory_iterator iter(i_name), end_iter;
647 //bool bfindir = false;
648 for(; iter != end_iter; ++iter)
650 if(boost::filesystem::is_directory(*iter))
657 //=================================================
659 //=================================================
660 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
662 GimmickDebugMessage(5,"WxGimmickView::OnSelectionChange"<<std::endl);
668 valid= ValidateSelected(NULL,
669 mSelectionMinDimension,
670 mSelectionMaxDimension );
671 } else if(needProcess) {
673 std::vector<tree::Node*>::const_iterator i;
674 for(i=sel.begin();i!=sel.end()&&valid;++i)
676 valid= ValidateSelected((*i),
677 mSelectionMinDimension,
678 mSelectionMaxDimension );
680 } else if(isSelection) {
681 valid= ValidateSelected(sel.front(),
682 mSelectionMinDimension,
683 mSelectionMaxDimension );
686 std::vector<tree::Node*>::const_iterator i;
687 for(i=sel.begin();i!=sel.end()&&valid;++i)
689 valid= ValidateSelected((*i),
690 mSelectionMinDimension,
691 mSelectionMaxDimension );
694 mText->SetLabel(crea::std2wx(GetMessage()));
698 ReadImageThreaded(sel);
706 //EED1 ReadImageThreaded(sel);
710 //==================================================
712 //==================================================
713 ///Reads Images (Threaded)
714 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
716 GimmickDebugMessage(5,
719 int maxprio = GetMaximalPriority();
720 int prio = maxprio + 2000;
724 //First load the selected images
725 mCurImageItemToShow = sel.front();
728 std::vector<tree::Node*>::const_iterator selected;
729 for(selected=sel.begin();selected!=sel.end();++selected)
731 GimmickDebugMessage(5,
732 "Requesting image from selected "
733 <<(*selected)->GetAttribute("FullFileName")
735 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
736 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
737 pointers.push_back(ph);
738 RequestReading(*selected,prio,index,ph);
739 // AddEntryToMap(*selected);
743 mViewer->SetImageVector(pointers);
746 std::vector<tree::Node*> up;
747 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
748 std::vector<tree::Node*>::iterator iterUp;
749 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
751 GimmickDebugMessage(5,
752 "Requesting image from neighbors up "
753 <<(*iterUp)->GetAttribute("FullFileName")
755 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
756 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
757 RequestReading(*iterUp,prio,-1,ph);
758 // AddEntryToMap(*iterUp);
760 if (prio == maxprio) break;
765 std::vector<tree::Node*> down;
766 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
767 std::vector<tree::Node*>::iterator iterDown;
768 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
770 GimmickDebugMessage(5,
771 "Requesting image from neighbors down "
772 <<(*iterDown)->GetAttribute("FullFileName")
774 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
775 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
776 RequestReading(*iterDown,prio,-1,ph);
777 // AddEntryToMap(*iterDown);
779 if (prio == maxprio) { break; }
783 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
784 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
785 pointers.push_back(ph);
786 mViewer->SetImageVector(pointers);
790 //==================================================
792 //==================================================
795 //==================================================
796 void WxGimmickView::OnInternalIdle()
798 if (!mConstructed) return;
799 static bool first_time = true;
804 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
805 // mViewer->StartPlayer();
808 mViewer->RefreshIfNecessary();
812 void WxGimmickView::UpdateWindowUI(long flags)
816 mViewer->RefreshIfNecessary();
820 //==================================================
822 //==================================================
823 void WxGimmickView::ClearSelection()
825 printf("EED WxGimmickView::ClearSelection Start\n");
827 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
828 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
829 mViewer->SetImageVector(pointers);
830 mViewer->RefreshIfNecessary();
832 printf("EED WxGimmickView::ClearSelection End\n");
835 //=================================================
837 //=================================================
838 void WxGimmickView::OnRemove(wxCommandEvent& event)
840 //TODO Select current tree handler
843 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
844 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
845 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
848 //=================================================
851 //=================================================
852 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
854 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
855 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
858 //=================================================
859 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
861 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
862 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
865 //=================================================
866 void WxGimmickView::AddDir(std::string dirName)
868 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
873 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
874 mCurrentDirectory = crea::std2wx(dirName);
875 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
876 mProgressDialog->Pulse(_T("Updating view..."));
878 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
883 //=================================================
884 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
887 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
888 _T("Check database for files deletion, addition and attributes change. Then give a report."),
889 _T("Repair database (remove deleted files and add new files)."),
890 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
892 wxSingleChoiceDialog dialog(this,
893 _T("Select one of the following synchronization actions:\n")
894 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
895 _T("Synchronization Settings"),
896 WXSIZEOF(choices), choices);
898 //dialog.SetSelection(0);
900 if (dialog.ShowModal() == wxID_OK)
903 int sel=dialog.GetSelection();
905 bool checkAttributes=false;
906 if(sel==2 || sel==3){repair=true;}
907 if(sel==1 || sel==3){checkAttributes=true;}
908 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
909 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
910 if(sel==2 || sel==3){
911 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
916 //=================================================
918 //=================================================
919 void WxGimmickView::OnSettings(wxCommandEvent& event)
921 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
922 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
924 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
926 siz->Add( nb,1,wxGROW ,0);
927 CreateSettingsDialog(nb,dial);
932 //=================================================
933 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
936 // Test if one image is selected => export
938 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
948 void WxGimmickView::ExportImages()
950 //Archive selection: name, emplacement
951 //same process than copy local but to a zip
952 // if settings are yes "always ask for descriptor addition", ask
953 // if settings are yes, adding descriptor
956 void WxGimmickView::ImportImages()
960 // Contain a descriptor.text
961 // create a new database, and add to database
962 // if not, add to current database
966 //=================================================
968 void WxGimmickView::OnTools(wxCommandEvent& event)
970 mViewer->StopPlayer();
972 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
974 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
975 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
976 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
977 dialSizer->Add(nb,1,wxGROW,0);
978 dialSizer->Add(buttonsSizer,0,wxGROW);
980 #if defined(BUILD_BRUKER)
981 //First page: Bruker Image Reader
982 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
983 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
986 dial->SetSizer(dialSizer, true);
990 if (dial->GetReturnCode() == wxID_OK)
992 #if defined(BUILD_BRUKER)
993 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
995 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
996 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
998 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
1000 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
1002 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
1003 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
1006 b2d.SetInputDirectory(inputDir);
1007 b2d.SetOutputDirectory(outputDir);
1008 b2d.SetConvertModeToDicom();
1013 std::cout <<"after addToDB" << std::endl;
1014 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
1019 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
1020 std::cout <<"after new wxProgressDialog" << std::endl;
1021 mCurrentDirectory = gimmickTools->getOutputDir();
1022 std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;
1023 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
1024 std::cout <<"after mGimmick->AddDir" << std::endl;
1025 mProgressDialog->Pulse(_T("Updating view..."));
1026 std::cout <<"after mProgressDialog->Pulse" << std::endl;
1027 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1028 std::cout <<"after UpdateTreeViewLevel" << std::endl;
1030 std::cout <<"after delete mProgressDialog" << std::endl;
1031 DisplayAddSummary();
1032 std::cout <<"after dDisplayAddSummary" << std::endl;
1038 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
1041 delete gimmickTools;
1044 mViewer->StartPlayer();
1047 //=================================================
1049 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1051 //First page: Customization of configurations
1054 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1055 //Database Path String
1057 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1058 //Syncronization Event String
1060 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1061 //Syncronization Frequency String
1063 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1065 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1067 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1069 //Second page: Creation of Databases
1070 /*wxPanel* databaseCreation=new wxPanel(nb);
1071 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1073 //Second page (temporary): Connection to PACS
1074 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1075 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1077 //Third page: CD/DVD Watch
1078 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1079 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1081 //Fourth page: Selection of attributes to show
1082 std::vector<std::string> shown;
1083 std::vector<std::string> nShown;
1084 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1085 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1086 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1087 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1090 //===================================================================
1091 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1092 std::vector<std::string>& nShown, int level)
1094 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1097 //===================================================================
1098 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1100 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1101 std::vector<std::string> n=nShown;
1102 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1104 //===================================================================
1105 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1106 const std::string& dbPath,
1107 const std::string& syncEvent,
1108 const std::string& syncFreq)
1110 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1111 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1112 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1113 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1116 //===================================================================
1117 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1119 mListener->SetMonitoredDrive(drive);
1120 mListener->SetAddFilesState(addFiles);
1121 mListener->SetRemoveFilesState(removeFiles);
1124 //========================================================================
1126 void WxGimmickView::OnDriveMount(bool mount)
1128 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1130 mListener->GetMonitoredDrive(drive);
1134 mViewer->StopPlayer();
1136 wxString title(_T("Adding drive"));
1138 new wxProgressDialog(_T("Adding drive"),
1146 // wxPD_ESTIMATED_TIME |
1147 // wxPD_REMAINING_TIME |
1149 mCurrentDirectory = crea::std2wx(drive);
1150 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1151 mProgressDialog->Pulse(_T("Updating view..."));
1153 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1155 DisplayAddSummary();
1156 mViewer->StartPlayer();
1160 mGimmick->DeleteDrive(drive);
1161 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1165 //========================================================================
1167 void WxGimmickView::StartListeningThread()
1169 mListener->Resume();
1172 //========================================================================
1174 void WxGimmickView::StopListeningThread()
1179 //========================================================================
1180 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1182 wxDialog *dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1183 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1184 WxEditFieldsPanel *ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1186 siz->Add( ef,1,wxGROW ,0);
1187 dial->SetSizer(siz);
1193 //========================================================================
1194 void WxGimmickView::DumpTags(std::string i_filename)
1196 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1200 //========================================================================
1201 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1203 std::vector<std::string> storages;
1204 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1205 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1207 storages.push_back(it->first);
1210 WxExportDlg* exp= new WxExportDlg(this,storages);
1211 if ( exp->ShowModal() ==ID_EXPORT_OK)
1213 std::string storage = exp->GetStorage();
1215 new wxProgressDialog(_T("Adding file(s)"),
1223 // wxPD_ESTIMATED_TIME |
1224 // wxPD_REMAINING_TIME |
1226 mGimmick->AddFiles(storage,i_filenames);
1227 mProgressDialog->Pulse(_T("Updating view..."));
1228 UpdateTreeViewLevel(storage,1);
1230 DisplayAddSummary();
1236 //========================================================================
1237 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1239 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1240 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1243 //=================================================
1244 /// AddProgress Gimmick callback
1245 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1248 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1249 p.GetNumberScannedDirs(),
1250 p.GetNumberScannedFiles(),
1251 p.GetNumberHandledFiles(),
1252 p.GetNumberAddedFiles());
1253 // std::cout << "OnAddProgress "<<mess<<std::endl;
1254 wxString s(wxString::From8BitData(mess));
1255 // std::cout << "Pulse"<<std::endl;
1257 if(mProgressDialog != 0)
1259 if (!mProgressDialog->Pulse(s))
1264 // std::cout << "OnAddProgress ok"<<std::endl;
1266 //=================================================
1268 //=================================================
1269 void WxGimmickView::DisplayAddSummary()
1271 std::stringstream mess(mGimmick->getSummary());
1274 mess << "time to scan :" << difftime(end,mstart) << "sec";
1275 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1278 ////////////////////////////////////////////////
1279 // Add a DB to application //
1280 // @param event : WxEvent //
1282 ////////////////////////////////////////////////
1283 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1286 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1287 std::string wc("*.sqlite3*");
1288 wxFileDialog* FD = new wxFileDialog( 0,
1296 if (FD->ShowModal()==wxID_OK)
1299 wxArrayString files;
1300 FD->GetPaths(files);
1301 std::stringstream st;
1302 for(int i = 0; i< files.size(); i++)
1304 //get name of DB (file name)
1305 size_t pos = files[i].find_last_of(_T("\\"));
1306 std::string name = crea::wx2std(files[i].substr(pos+1));
1307 pos = name.find_last_of(".");
1308 name = name.substr(0,pos);
1309 //create TreeHandler
1310 mGimmick->addDB(name, crea::wx2std(files[i]));
1312 CreateSingleTreeView(name);
1316 ////////////////////////////////////////////////////
1317 // Create a DB from an Attributes Descriptor files //
1318 // @param event : WxEvent //
1320 //////////////////////////////////////////////////
1321 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1323 // PACSConnection("");
1324 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1325 DescriptorPan->Layout();
1326 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1329 std::string file(DescriptorPan->GetDescriptor());
1332 size_t pos = file.find_last_of("\\");
1333 std::string name = file.substr(pos+1);
1334 std::string directory = file.substr(0,pos);
1335 pos = name.find_last_of(".");
1336 name = name.substr(0,pos);
1337 //get directory to store DB
1338 directory += "\\" + name + ".sqlite3";
1340 mGimmick->createDB(name, file,directory);
1341 //create TreeHandler
1342 mGimmick->addDB(name, directory);
1344 CreateSingleTreeView(name);
1349 void WxGimmickView::killProgress()
1351 mProgressDialog->Resume();
1352 mProgressDialog->Destroy();
1353 mProgressDialog = 0;
1356 //=================================================
1358 //=================================================
1359 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1360 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1361 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1362 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1363 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1364 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1365 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1366 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1367 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1369 //=================================================
1371 } // EO namespace creaImageIO