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),
138 mProgressDialog(NULL),
143 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView" <<std::endl);
144 // Sets the current directory to the home dir
145 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
147 // Connect the AddProgress callback
148 gimmick->ConnectAddProgressObserver( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
151 // Create the list of icons (mIcon)
156 msizer = new wxBoxSizer(wxVERTICAL);
159 // Create the tool bar
161 msizer->Add( mToolBar, 0, wxGROW, 0);
164 // Split part below toolbar into notebook for views and panel
165 // for preview, messages...
166 mSplitter = new wxSplitterWindow( this , -1);
169 mNotebook = new wxNotebook(mSplitter, -1, wxDefaultPosition, wxDefaultSize, 0);
174 mSelectionMaxDimension = max_dim;
175 mSelectionMinDimension = min_dim;
182 mBottomPanel = new wxPanel(mSplitter,-1);
184 mbottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
188 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
189 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
190 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
192 mViewer->SetImageVector(pointers);
193 mViewer->StartPlayer();
196 mbottom_sizer->Add(mViewer,1,wxGROW,1);
201 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
202 mbottom_sizer->Add(mText,0,wxGROW,0);
204 mBottomPanel->SetSizer(mbottom_sizer);
207 /// \TODO fix warning: unused variable hsize
208 int hsize = size.GetHeight();
210 int top_minsize = 450;
211 int bottom_minsize = 50;
213 mSplitter->SetMinimumPaneSize( bottom_minsize );
214 mSplitter->SplitHorizontally( mNotebook, mBottomPanel, top_minsize);
216 msizer->Add( mSplitter, 1, wxGROW, 0);
218 mProgressDialog=NULL;
223 //mListener=new Listener();
224 //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
225 //mListener->Create();
227 // mListener->Pause();
231 //======================================================================
233 //======================================================================
235 WxGimmickView::~WxGimmickView()
237 // stop the viewer before application exit.
238 mViewer->StopPlayer();
239 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView" <<std::endl);
244 //if(mListener->IsAlive()) { mListener->Delete(); }
246 //======================================================================
250 void WxGimmickView::AddBtnTool(wxPanel *panel, wxBoxSizer *sizerH, int id, wxString label, int idBitmap, wxString tooltip )
256 bitmap = mIcon->GetBitmap(idBitmap);
257 btn = new wxBitmapButton(mToolBar, id, bitmap, wxDefaultPosition, wxSize(50,50) , wxBU_BOTTOM );
258 btn->SetToolTip( tooltip );
259 sizer = new wxBoxSizer(wxVERTICAL);
260 sizer->Add(btn,1,wxGROW,0);
261 sizer->Add(new wxStaticText(mToolBar,-1,label) , 0, wxALL | wxALIGN_CENTER, 3);
262 sizerH->Add( sizer ,1,wxGROW,0);
265 //======================================================================
266 /// Creates the tool bar
267 void WxGimmickView::CreateToolBar()
269 mToolBar = new wxPanel(this,-1, wxDefaultPosition, wxSize(80,80) );
270 wxBoxSizer *sizerH = new wxBoxSizer(wxHORIZONTAL);
272 AddBtnTool(mToolBar, sizerH, TOOL_ADDFILES_ID , _T("Add file(s)") , Icon_page_down , _T("Add one or more file to database") );
273 AddBtnTool(mToolBar, sizerH, TOOL_ADDDIR_ID , _T("Add folder") , Icon_folder_down , _T("Add the content of a folder to database") );
274 AddBtnTool(mToolBar, sizerH, TOOL_ADDDATABASE_ID , _T("Open database") , Icon_database_add , _T("Open a local or distant database") );
275 AddBtnTool(mToolBar, sizerH, TOOL_REMOVE_ID , _T("Remove") , Icon_remove , _T("Remove selected items") );
276 AddBtnTool(mToolBar, sizerH, TOOL_SYNCHRONIZE_ID , _T("Synchronize") , Icon_synchronize , _T("Synchronizes the database with disk") );
277 AddBtnTool(mToolBar, sizerH, TOOL_HELP_ID , _T("Help") , Icon_help , _T("Open help window") );
278 AddBtnTool(mToolBar, sizerH, TOOL_SETTINGS_ID , _T("System settings") , Icon_settings , _T("Allows the modification of various system settings") );
279 AddBtnTool(mToolBar, sizerH, TOOL_TOOLS_ID , _T("Tools") , Icon_tools , _T("Applies tools to images") );
280 AddBtnTool(mToolBar, sizerH, TOOL_CREATEDB_ID , _T("Create database") , Icon_create_database , _T("Create DB from an Attributes Descriptor file") );
281 #if defined(BUILD_PACS)
282 AddBtnTool(mToolBar, sizerH, TOOL_PACS_ID , _T("PACS Connection,"), Icon_create_database , _T("Echo, Find and Get to a PACS") );
284 mToolBar->SetSizer( sizerH );
288 The wxToolBar depends from wxFrame, in this code it is not the case. In Mac Os is not working !
289 Change the mechanisme from wcToolBar to normal Buttons
290 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
291 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,style);
293 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
295 mIcon->GetBitmap(Icon_page_down),
296 _T("Add one or more file to database")
298 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
300 mIcon->GetBitmap(Icon_folder_down),
301 _T("Add the content of a folder to database")
303 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
305 mIcon->GetBitmap(Icon_database_add),
306 _T("Open a local or distant database")
308 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
310 mIcon->GetBitmap(Icon_remove),
311 _T("Remove selected items")
313 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
315 mIcon->GetBitmap(Icon_synchronize),
316 _T("Synchronizes the database with disk")
318 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
320 mIcon->GetBitmap(Icon_help),
321 _T("Open help window")
323 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
324 _T("System settings"),
325 mIcon->GetBitmap(Icon_settings),
326 _T("Allows the modification of various system settings")
328 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
330 mIcon->GetBitmap(Icon_tools),
331 _T("Applies tools to images")
333 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
334 _T("Create database"),
335 mIcon->GetBitmap(Icon_create_database),
336 _T("Create DB from an Attributes Descriptor file")
338 #if defined(BUILD_PACS)
339 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
340 _T("PACS Connection,"),
341 mIcon->GetBitmap(Icon_create_database),
342 _T("Echo, Find and Get to a PACS")
345 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
350 //======================================================================
353 //======================================================================
354 /// Create the tree view for TreeHandler provided
355 void WxGimmickView::CreateTreeView( TreeHandler* h)
357 std::string name(h->GetTree().GetAttribute("Name"));
358 GimmickMessage(2,"Creating the tree view for '"<< name<<"'"<<std::endl);
359 // Create the WxTreeView
360 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
362 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
363 // ALREADY IN THE MAP
364 GetTreeViewMap()[name] = view;
367 mNotebook->AddPage( view, crea::std2wx(name) );
371 //======================================================================
372 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
374 std::vector<std::string> files;
375 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
376 //ReadImagesNotThreaded(s, files, dim);
379 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
380 // ReadImagesNotThreadedInfosInVector(db_name,output, files,dim,1);
385 //======================================================================
386 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
388 std::vector<std::string> files;
389 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
390 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
392 ReadImagesNotThreadedInVector(s, files, dim);
396 /// By default if out_infos is empty, we dont' provide informations, we return only vtkImageData
397 /// if out_infos has only one entry "all" we provide all database informations
398 void WxGimmickView::getSelectedFiles(std::vector<OutStrGimmick> &outG, std::vector< std::string> i_attr, std::vector<std::string> &outFileNames,
399 bool mult, const std::string out_model)
401 // First we select the files
402 std::vector<std::string> files;
403 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
404 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
408 bool bsingle = isSingle( files.front() );
410 mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking);
411 mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim);
413 if (asking == "true")
415 // display the output dialog box
418 sscanf(dim.c_str(),"%d",&idim);
419 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
420 if (dlg->ShowModal() == wxID_OK)
423 mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
424 mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
430 sscanf(dim.c_str(),"%d",&i_dim_out);
432 // Next we create the structure for dicom output infos
441 Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
444 // We don't send informations!
445 } else if( i_attr.size() == 1 && i_attr.front() == "ALL")
447 // we send all database
448 Oattr.inside.push_back("ALL");
449 } else if( (i_attr.size() == 1 && i_attr.front() != "ALL")
450 || (i_attr.size() >1) )
452 mGimmick->fillVectInfos(i_attr, Oattr);
457 // Next we create model and sort files
458 std::vector<std::string> sort_files(files);
460 if( !out_model.empty() )
462 /* OutputModel mod(out_model);
463 mGimmick->isAttributeExist(db_name, mod);
464 mod.sort(files, sort_files);
467 if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
469 OutputModel *mod = new OutputModel();
470 zspacing = mod->orderFilesWithZspacing(sort_files);
473 // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
474 readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
475 outFileNames = sort_files;
481 //======================================================================
483 //======================================================================
486 //======================================================================
487 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
489 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
491 //======================================================================
493 //======================================================================
494 void WxGimmickView::GetImages(int dim,
495 const std::vector<std::string>& files,
496 std::vector<vtkImageData*>& s)
498 ReadImagesNotThreaded(s,files,dim);
500 //======================================================================
503 //=================================================
504 void WxGimmickView::CreateIconList()
506 // Size of the icons;
510 // should correspond to Icon_xxx enum
511 icons[Icon_accept] = wxIcon(accept_xpm);
512 icons[Icon_add] = wxIcon(add_xpm);
513 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
514 icons[Icon_page_down] = wxIcon(page_down_xpm);
515 icons[Icon_remove] = wxIcon(remove_xpm);
516 icons[Icon_database_add] = wxIcon(database_add_xpm);
517 icons[Icon_help] = wxIcon(help_xpm);
518 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
519 icons[Icon_create_database] = wxIcon(create_database_xpm);
520 icons[Icon_settings] = wxIcon(settings_xpm);
521 icons[Icon_tools] = wxIcon(tools_xpm);
523 // unsigned int NbIcons = 8;
524 // Make an image list containing small icons
525 mIcon = new wxImageList(size,size,true);
527 // Make all icons the same size = size of the first one
528 int sizeOrig = icons[0].GetWidth();
529 for ( size_t i = 0; i < icon_number; i++ )
531 if ( size == sizeOrig )
533 mIcon->Add(icons[i]);
537 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
541 //=================================================
544 //=================================================
545 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
547 mViewer->StopPlayer();
549 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
550 #if wxMAJOR_VERSION <= 2
551 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
553 long style = wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE;
558 wxFileDialog* FD = new wxFileDialog( 0,
566 if (FD->ShowModal()==wxID_OK)
573 std::vector<std::string> filenames;
574 for (i=0;i<files.GetCount();++i)
576 filenames.push_back(wx2std(files[i]));
577 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
581 new wxProgressDialog(_T("Adding file(s)"),
587 // wxPD_ESTIMATED_TIME |
588 // wxPD_REMAINING_TIME |
591 // TO DO : select the current tree handler
592 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
594 mProgressDialog->Pulse(_T("Updating view..."));
596 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
601 mViewer->StartPlayer();
603 //=================================================
605 //=================================================
606 void WxGimmickView::OnAddDir(wxCommandEvent& event)
608 mViewer->StopPlayer();
609 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
610 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
613 _T("Select directory"),
617 if (FD->ShowModal()==wxID_OK)
620 std::string dirname = wx2std (FD->GetPath());
621 bool recurse = isNeedRecursive(dirname);
624 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
628 wxString title(_T("Adding directory"));
630 title = _T("Adding directory (recursive)");
632 new wxProgressDialog(_T("Adding directory"),
634 NumberFilesToAdd(dirname,recurse),
641 // wxPD_ESTIMATED_TIME |
642 // wxPD_REMAINING_TIME |
645 mCurrentDirectory = FD->GetPath();
646 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
647 mProgressDialog->Pulse(_T("Updating view..."));
649 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
653 mViewer->StartPlayer();
658 //=================================================
659 // Determines number of files potentially to add to database
660 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
663 if ( !boost::filesystem::exists( dirpath ) ) return nb;
664 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
665 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
667 // If is directory & recurse : do recurse
668 if ( boost::filesystem::is_directory(itr->status()) )
672 nb += NumberFilesToAdd(itr->path().string(), recursive);
683 //=================================================
684 // Test a directory to know if contains sub-directory to analyze
685 bool WxGimmickView::isNeedRecursive(std::string i_name)
687 boost::filesystem::directory_iterator iter(i_name), end_iter;
688 //bool bfindir = false;
689 for(; iter != end_iter; ++iter)
691 if(boost::filesystem::is_directory(*iter))
698 //=================================================
700 //=================================================
701 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
703 GimmickDebugMessage(5,"WxGimmickView::OnSelectionChange"<<std::endl);
709 valid= ValidateSelected(NULL,
710 mSelectionMinDimension,
711 mSelectionMaxDimension );
712 } else if(needProcess) {
714 std::vector<tree::Node*>::const_iterator i;
715 for(i=sel.begin();i!=sel.end()&&valid;++i)
717 valid= ValidateSelected((*i),
718 mSelectionMinDimension,
719 mSelectionMaxDimension );
721 } else if(isSelection) {
722 valid= ValidateSelected(sel.front(),
723 mSelectionMinDimension,
724 mSelectionMaxDimension );
727 std::vector<tree::Node*>::const_iterator i;
728 for(i=sel.begin();i!=sel.end()&&valid;++i)
730 valid= ValidateSelected((*i),
731 mSelectionMinDimension,
732 mSelectionMaxDimension );
735 mText->SetLabel(crea::std2wx(GetMessage()));
739 ReadImageThreaded(sel);
747 // ReadImageThreaded(sel);
751 //==================================================
753 //==================================================
754 ///Reads Images (Threaded)
755 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
757 GimmickDebugMessage(5, "ReadImageThreaded" <<std::endl);
758 int maxprio = GetMaximalPriority();
759 int prio = maxprio + 2000;
763 //First load the selected images
764 mCurImageItemToShow = sel.front();
767 std::vector<tree::Node*>::const_iterator selected;
768 for(selected=sel.begin();selected!=sel.end();++selected)
770 GimmickDebugMessage(5,
771 "Requesting image from selected "
772 <<(*selected)->GetAttribute("FullFileName")
774 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
775 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
776 pointers.push_back(ph);
777 RequestReading(*selected,prio,index,ph);
778 // AddEntryToMap(*selected);
782 mViewer->SetImageVector(pointers);
785 std::vector<tree::Node*> up;
786 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
787 std::vector<tree::Node*>::iterator iterUp;
788 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
790 GimmickDebugMessage(5,
791 "Requesting image from neighbors up "
792 <<(*iterUp)->GetAttribute("FullFileName")
794 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
795 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
796 RequestReading(*iterUp,prio,-1,ph);
797 // AddEntryToMap(*iterUp);
799 if (prio == maxprio) break;
804 std::vector<tree::Node*> down;
805 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
806 std::vector<tree::Node*>::iterator iterDown;
807 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
809 GimmickDebugMessage(5,
810 "Requesting image from neighbors down "
811 <<(*iterDown)->GetAttribute("FullFileName")
813 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
814 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
815 RequestReading(*iterDown,prio,-1,ph);
816 // AddEntryToMap(*iterDown);
818 if (prio == maxprio) { break; }
822 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
823 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
824 pointers.push_back(ph);
825 mViewer->SetImageVector(pointers);
829 //==================================================
831 //==================================================
834 //==================================================
835 void WxGimmickView::OnInternalIdle()
837 if (!mConstructed) return;
838 static bool first_time = true;
844 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
845 // mViewer->StartPlayer();
848 mViewer->RefreshIfNecessary();
852 void WxGimmickView::UpdateWindowUI(long flags)
857 // GL Conflict because window is not showing the fist time
858 //EED mViewer->RefreshIfNecessary();
862 //==================================================
864 //==================================================
865 void WxGimmickView::ClearSelection()
868 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
869 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
870 mViewer->SetImageVector(pointers);
871 mViewer->RefreshIfNecessary();
875 //=================================================
877 //=================================================
878 void WxGimmickView::OnRemove(wxCommandEvent& event)
880 //TODO Select current tree handler
883 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
884 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
885 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
888 //=================================================
891 //=================================================
892 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
894 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
895 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
898 //=================================================
899 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
901 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
902 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
905 //=================================================
906 void WxGimmickView::AddDir(std::string dirName)
908 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
913 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
914 mCurrentDirectory = crea::std2wx(dirName);
915 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
916 mProgressDialog->Pulse(_T("Updating view..."));
918 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
923 //=================================================
924 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
927 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
928 _T("Check database for files deletion, addition and attributes change. Then give a report."),
929 _T("Repair database (remove deleted files and add new files)."),
930 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
932 wxSingleChoiceDialog dialog(this,
933 _T("Select one of the following synchronization actions:\n")
934 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
935 _T("Synchronization Settings"),
936 WXSIZEOF(choices), choices);
938 //dialog.SetSelection(0);
940 if (dialog.ShowModal() == wxID_OK)
943 int sel=dialog.GetSelection();
945 bool checkAttributes=false;
946 if(sel==2 || sel==3){repair=true;}
947 if(sel==1 || sel==3){checkAttributes=true;}
948 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
949 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
950 if(sel==2 || sel==3){
951 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
956 //=================================================
958 //=================================================
959 void WxGimmickView::OnSettings(wxCommandEvent& event)
961 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
962 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
964 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
966 siz->Add( nb,1,wxGROW ,0);
967 CreateSettingsDialog(nb,dial);
972 //=================================================
973 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
976 // Test if one image is selected => export
978 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
988 void WxGimmickView::ExportImages()
990 //Archive selection: name, emplacement
991 //same process than copy local but to a zip
992 // if settings are yes "always ask for descriptor addition", ask
993 // if settings are yes, adding descriptor
996 void WxGimmickView::ImportImages()
1000 // Contain a descriptor.text
1001 // create a new database, and add to database
1002 // if not, add to current database
1006 //=================================================
1008 void WxGimmickView::OnTools(wxCommandEvent& event)
1010 mViewer->StopPlayer();
1012 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
1014 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1015 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
1016 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1017 dialSizer->Add(nb,1,wxGROW,0);
1018 dialSizer->Add(buttonsSizer,0,wxGROW);
1020 #if defined(BUILD_BRUKER)
1021 //First page: Bruker Image Reader
1022 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
1023 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
1026 dial->SetSizer(dialSizer, true);
1030 if (dial->GetReturnCode() == wxID_OK)
1032 #if defined(BUILD_BRUKER)
1033 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
1035 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
1036 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
1038 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
1040 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
1042 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
1043 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
1046 b2d.SetInputDirectory(inputDir);
1047 b2d.SetOutputDirectory(outputDir);
1048 b2d.SetConvertModeToDicom();
1053 std::cout <<"after addToDB" << std::endl;
1054 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
1059 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
1060 std::cout <<"after new wxProgressDialog" << std::endl;
1061 mCurrentDirectory = gimmickTools->getOutputDir();
1062 std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;
1063 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
1064 std::cout <<"after mGimmick->AddDir" << std::endl;
1065 mProgressDialog->Pulse(_T("Updating view..."));
1066 std::cout <<"after mProgressDialog->Pulse" << std::endl;
1067 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1068 std::cout <<"after UpdateTreeViewLevel" << std::endl;
1070 std::cout <<"after delete mProgressDialog" << std::endl;
1071 DisplayAddSummary();
1072 std::cout <<"after dDisplayAddSummary" << std::endl;
1078 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
1081 delete gimmickTools;
1084 mViewer->StartPlayer();
1087 //=================================================
1089 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1091 //First page: Customization of configurations
1094 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1095 //Database Path String
1097 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1098 //Syncronization Event String
1100 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1101 //Syncronization Frequency String
1103 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1105 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1107 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1109 //Second page: Creation of Databases
1110 /*wxPanel* databaseCreation=new wxPanel(nb);
1111 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1113 //Second page (temporary): Connection to PACS
1114 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1115 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1117 //Third page: CD/DVD Watch
1118 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1119 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1121 //Fourth page: Selection of attributes to show
1122 std::vector<std::string> shown;
1123 std::vector<std::string> nShown;
1124 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1125 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1126 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1127 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1130 //===================================================================
1131 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1132 std::vector<std::string>& nShown, int level)
1134 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1137 //===================================================================
1138 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1140 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1141 std::vector<std::string> n=nShown;
1142 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1144 //===================================================================
1145 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1146 const std::string& dbPath,
1147 const std::string& syncEvent,
1148 const std::string& syncFreq)
1150 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1151 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1152 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1153 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1156 //===================================================================
1157 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1159 mListener->SetMonitoredDrive(drive);
1160 mListener->SetAddFilesState(addFiles);
1161 mListener->SetRemoveFilesState(removeFiles);
1164 //========================================================================
1166 void WxGimmickView::OnDriveMount(bool mount)
1168 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1170 mListener->GetMonitoredDrive(drive);
1174 mViewer->StopPlayer();
1176 wxString title(_T("Adding drive"));
1178 new wxProgressDialog(_T("Adding drive"),
1186 // wxPD_ESTIMATED_TIME |
1187 // wxPD_REMAINING_TIME |
1189 mCurrentDirectory = crea::std2wx(drive);
1190 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1191 mProgressDialog->Pulse(_T("Updating view..."));
1193 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1195 DisplayAddSummary();
1196 mViewer->StartPlayer();
1200 mGimmick->DeleteDrive(drive);
1201 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1205 //========================================================================
1207 void WxGimmickView::StartListeningThread()
1209 mListener->Resume();
1212 //========================================================================
1214 void WxGimmickView::StopListeningThread()
1219 //========================================================================
1220 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1222 wxDialog *dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1223 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1224 WxEditFieldsPanel *ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1226 siz->Add( ef,1,wxGROW ,0);
1227 dial->SetSizer(siz);
1233 //========================================================================
1234 void WxGimmickView::DumpTags(std::string i_filename)
1236 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1240 //========================================================================
1241 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1243 std::vector<std::string> storages;
1244 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1245 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1247 storages.push_back(it->first);
1250 WxExportDlg* exp= new WxExportDlg(this,storages);
1251 if ( exp->ShowModal() ==ID_EXPORT_OK)
1253 std::string storage = exp->GetStorage();
1255 new wxProgressDialog(_T("Adding file(s)"),
1263 // wxPD_ESTIMATED_TIME |
1264 // wxPD_REMAINING_TIME |
1266 mGimmick->AddFiles(storage,i_filenames);
1267 mProgressDialog->Pulse(_T("Updating view..."));
1268 UpdateTreeViewLevel(storage,1);
1270 DisplayAddSummary();
1276 //========================================================================
1277 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1279 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1280 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1283 //=================================================
1284 /// AddProgress Gimmick callback
1285 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1288 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1289 p.GetNumberScannedDirs(),
1290 p.GetNumberScannedFiles(),
1291 p.GetNumberHandledFiles(),
1292 p.GetNumberAddedFiles());
1293 // std::cout << "OnAddProgress "<<mess<<std::endl;
1294 wxString s(wxString::From8BitData(mess));
1295 // std::cout << "Pulse"<<std::endl;
1297 if(mProgressDialog != NULL)
1299 if (!mProgressDialog->Pulse(s))
1304 // std::cout << "OnAddProgress ok"<<std::endl;
1306 //=================================================
1308 //=================================================
1309 void WxGimmickView::DisplayAddSummary()
1311 std::stringstream mess(mGimmick->getSummary());
1314 mess << "time to scan :" << difftime(end,mstart) << "sec";
1315 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1318 ////////////////////////////////////////////////
1319 // Add a DB to application //
1320 // @param event : WxEvent //
1322 ////////////////////////////////////////////////
1323 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1326 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1327 std::string wc("*.sqlite3*");
1328 wxFileDialog* FD = new wxFileDialog( 0,
1336 if (FD->ShowModal()==wxID_OK)
1339 wxArrayString files;
1340 FD->GetPaths(files);
1341 std::stringstream st;
1342 for(int i = 0; i< files.size(); i++)
1344 //get name of DB (file name)
1345 size_t pos = files[i].find_last_of(_T("\\"));
1346 std::string name = crea::wx2std(files[i].substr(pos+1));
1347 pos = name.find_last_of(".");
1348 name = name.substr(0,pos);
1349 //create TreeHandler
1350 mGimmick->addDB(name, crea::wx2std(files[i]));
1352 CreateSingleTreeView(name);
1356 ////////////////////////////////////////////////////
1357 // Create a DB from an Attributes Descriptor files //
1358 // @param event : WxEvent //
1360 //////////////////////////////////////////////////
1361 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1363 // PACSConnection("");
1364 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1365 DescriptorPan->Layout();
1366 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1369 std::string file(DescriptorPan->GetDescriptor());
1372 size_t pos = file.find_last_of("\\");
1373 std::string name = file.substr(pos+1);
1374 std::string directory = file.substr(0,pos);
1375 pos = name.find_last_of(".");
1376 name = name.substr(0,pos);
1377 //get directory to store DB
1378 directory += "\\" + name + ".sqlite3";
1380 mGimmick->createDB(name, file,directory);
1381 //create TreeHandler
1382 mGimmick->addDB(name, directory);
1384 CreateSingleTreeView(name);
1389 void WxGimmickView::killProgress()
1391 mProgressDialog->Resume();
1392 mProgressDialog->Destroy();
1393 mProgressDialog = NULL;
1396 //=================================================
1398 //=================================================
1400 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1401 EVT_BUTTON(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1402 EVT_BUTTON(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1403 EVT_BUTTON(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1404 EVT_BUTTON(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1405 EVT_BUTTON(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1406 EVT_BUTTON(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1407 EVT_BUTTON(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1408 EVT_BUTTON(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1413 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1414 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1415 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1416 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1417 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1418 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1419 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1420 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1421 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1424 //=================================================
1426 } // EO namespace creaImageIO