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),
141 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView" <<std::endl);
142 // Sets the current directory to the home dir
143 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
145 // Connect the AddProgress callback
146 gimmick->ConnectAddProgressObserver( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
148 // Create the list of icons (mIcon)
152 msizer = new wxBoxSizer(wxVERTICAL);
154 // Create the tool bar
156 msizer->Add( mToolBar, 0, wxGROW, 0);
158 // Split part below toolbar into notebook for views and panel
159 // for preview, messages...
160 mSplitter = new wxSplitterWindow( this , -1);
163 mNotebook = new wxNotebook(mSplitter, -1, wxDefaultPosition, wxDefaultSize, 0);
168 mSelectionMaxDimension = max_dim;
169 mSelectionMinDimension = min_dim;
175 mBottomPanel = new wxPanel(mSplitter,-1);
177 mbottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
181 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
182 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
183 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
185 mViewer->SetImageVector(pointers);
186 mViewer->StartPlayer();
189 mbottom_sizer->Add(mViewer,1,wxGROW,1);
192 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
193 mbottom_sizer->Add(mText,0,wxGROW,0);
195 mBottomPanel->SetSizer(mbottom_sizer);
198 /// \TODO fix warning: unused variable hsize
199 int hsize = size.GetHeight();
201 int top_minsize = 450;
202 int bottom_minsize = 50;
204 mSplitter->SetMinimumPaneSize( bottom_minsize );
205 mSplitter->SplitHorizontally( mNotebook, mBottomPanel, top_minsize);
207 msizer->Add( mSplitter, 1, wxGROW, 0);
209 mProgressDialog=NULL;
213 //mListener=new Listener();
214 //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
215 //mListener->Create();
217 // mListener->Pause();
221 //======================================================================
223 //======================================================================
225 WxGimmickView::~WxGimmickView()
227 // stop the viewer before application exit.
228 mViewer->StopPlayer();
229 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView" <<std::endl);
232 //if(mListener->IsAlive()) { mListener->Delete(); }
234 //======================================================================
236 //======================================================================
237 /// Creates the tool bar
238 void WxGimmickView::CreateToolBar()
240 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
241 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
244 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
246 mIcon->GetBitmap(Icon_page_down),
247 _T("Add one or more file to database")
249 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
251 mIcon->GetBitmap(Icon_folder_down),
252 _T("Add the content of a folder to database")
254 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
256 mIcon->GetBitmap(Icon_database_add),
257 _T("Open a local or distant database")
259 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
261 mIcon->GetBitmap(Icon_remove),
262 _T("Remove selected items")
264 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
266 mIcon->GetBitmap(Icon_synchronize),
267 _T("Synchronizes the database with disk")
269 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
271 mIcon->GetBitmap(Icon_help),
272 _T("Open help window")
274 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
275 _T("System settings"),
276 mIcon->GetBitmap(Icon_settings),
277 _T("Allows the modification of various system settings")
279 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
281 mIcon->GetBitmap(Icon_tools),
282 _T("Applies tools to images")
284 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
285 _T("Create database"),
286 mIcon->GetBitmap(Icon_create_database),
287 _T("Create DB from an Attributes Descriptor file")
289 #if defined(BUILD_PACS)
290 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
291 _T("PACS Connection,"),
292 mIcon->GetBitmap(Icon_create_database),
293 _T("Echo, Find and Get to a PACS")
296 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
300 //======================================================================
303 //======================================================================
304 /// Create the tree view for TreeHandler provided
305 void WxGimmickView::CreateTreeView( TreeHandler* h)
307 std::string name(h->GetTree().GetAttribute("Name"));
308 GimmickMessage(2,"Creating the tree view for '"<< name<<"'"<<std::endl);
309 // Create the WxTreeView
310 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
312 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
313 // ALREADY IN THE MAP
314 GetTreeViewMap()[name] = view;
317 mNotebook->AddPage( view, crea::std2wx(name) );
321 //======================================================================
322 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
324 std::vector<std::string> files;
325 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
326 //ReadImagesNotThreaded(s, files, dim);
329 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
330 // ReadImagesNotThreadedInfosInVector(db_name,output, files,dim,1);
335 //======================================================================
336 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
338 std::vector<std::string> files;
339 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
340 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
342 ReadImagesNotThreadedInVector(s, files, dim);
346 /// By default if out_infos is empty, we dont' provide informations, we return only vtkImageData
347 /// if out_infos has only one entry "all" we provide all database informations
348 void WxGimmickView::getSelectedFiles(std::vector<OutStrGimmick> &outG, std::vector< std::string> i_attr,
349 bool mult, const std::string out_model)
351 // First we select the files
352 std::vector<std::string> files;
353 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
354 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
358 bool bsingle = isSingle(files.front());
360 mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking);
361 mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim);
364 if (asking == "true")
366 // display the output dialog box
369 sscanf(dim.c_str(),"%d",&idim);
370 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
371 if (dlg->ShowModal() == wxID_OK)
374 mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
375 mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
381 sscanf(dim.c_str(),"%d",&i_dim_out);
383 // Next we create the structure for dicom output infos
392 Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
395 // We don't send informations!
396 } else if( i_attr.size() == 1 && i_attr.front() == "ALL")
398 // we send all database
399 Oattr.inside.push_back("ALL");
400 } else if( (i_attr.size() == 1 && i_attr.front() != "ALL")
401 || (i_attr.size() >1) )
403 mGimmick->fillVectInfos(i_attr, Oattr);
408 // Next we create model and sort files
409 std::vector<std::string> sort_files(files);
411 if( !out_model.empty() )
413 /* OutputModel mod(out_model);
414 mGimmick->isAttributeExist(db_name, mod);
415 mod.sort(files, sort_files);
418 if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
420 OutputModel *mod = new OutputModel();
421 zspacing = mod->orderFilesWithZspacing(sort_files);
424 // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
425 readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
431 //======================================================================
433 //======================================================================
436 //======================================================================
437 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
439 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
441 //======================================================================
443 //======================================================================
444 void WxGimmickView::GetImages(int dim,
445 const std::vector<std::string>& files,
446 std::vector<vtkImageData*>& s)
448 ReadImagesNotThreaded(s,files,dim);
450 //======================================================================
453 //=================================================
454 void WxGimmickView::CreateIconList()
456 // Size of the icons;
460 // should correspond to Icon_xxx enum
461 icons[Icon_accept] = wxIcon(accept_xpm);
462 icons[Icon_add] = wxIcon(add_xpm);
463 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
464 icons[Icon_page_down] = wxIcon(page_down_xpm);
465 icons[Icon_remove] = wxIcon(remove_xpm);
466 icons[Icon_database_add] = wxIcon(database_add_xpm);
467 icons[Icon_help] = wxIcon(help_xpm);
468 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
469 icons[Icon_create_database] = wxIcon(create_database_xpm);
470 icons[Icon_settings] = wxIcon(settings_xpm);
471 icons[Icon_tools] = wxIcon(tools_xpm);
473 // unsigned int NbIcons = 8;
474 // Make an image list containing small icons
475 mIcon = new wxImageList(size,size,true);
477 // Make all icons the same size = size of the first one
478 int sizeOrig = icons[0].GetWidth();
479 for ( size_t i = 0; i < icon_number; i++ )
481 if ( size == sizeOrig )
483 mIcon->Add(icons[i]);
487 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
491 //=================================================
494 //=================================================
495 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
497 mViewer->StopPlayer();
499 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
500 #if wxMAJOR_VERSION <= 2
501 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
503 long style = wxFD_OPEN | wxFD_FILE_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,"WxGimmickView::OnSelectionChange"<<std::endl);
659 valid= ValidateSelected(NULL,
660 mSelectionMinDimension,
661 mSelectionMaxDimension );
662 } else if(needProcess) {
664 std::vector<tree::Node*>::const_iterator i;
665 for(i=sel.begin();i!=sel.end()&&valid;++i)
667 valid= ValidateSelected((*i),
668 mSelectionMinDimension,
669 mSelectionMaxDimension );
671 } else if(isSelection) {
672 valid= ValidateSelected(sel.front(),
673 mSelectionMinDimension,
674 mSelectionMaxDimension );
677 std::vector<tree::Node*>::const_iterator i;
678 for(i=sel.begin();i!=sel.end()&&valid;++i)
680 valid= ValidateSelected((*i),
681 mSelectionMinDimension,
682 mSelectionMaxDimension );
685 mText->SetLabel(crea::std2wx(GetMessage()));
689 ReadImageThreaded(sel);
697 // ReadImageThreaded(sel);
701 //==================================================
703 //==================================================
704 ///Reads Images (Threaded)
705 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
707 GimmickDebugMessage(5, "ReadImageThreaded" <<std::endl);
708 int maxprio = GetMaximalPriority();
709 int prio = maxprio + 2000;
713 //First load the selected images
714 mCurImageItemToShow = sel.front();
717 std::vector<tree::Node*>::const_iterator selected;
718 for(selected=sel.begin();selected!=sel.end();++selected)
720 GimmickDebugMessage(5,
721 "Requesting image from selected "
722 <<(*selected)->GetAttribute("FullFileName")
724 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
725 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
726 pointers.push_back(ph);
727 RequestReading(*selected,prio,index,ph);
728 // AddEntryToMap(*selected);
732 mViewer->SetImageVector(pointers);
735 std::vector<tree::Node*> up;
736 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
737 std::vector<tree::Node*>::iterator iterUp;
738 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
740 GimmickDebugMessage(5,
741 "Requesting image from neighbors up "
742 <<(*iterUp)->GetAttribute("FullFileName")
744 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
745 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
746 RequestReading(*iterUp,prio,-1,ph);
747 // AddEntryToMap(*iterUp);
749 if (prio == maxprio) break;
754 std::vector<tree::Node*> down;
755 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
756 std::vector<tree::Node*>::iterator iterDown;
757 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
759 GimmickDebugMessage(5,
760 "Requesting image from neighbors down "
761 <<(*iterDown)->GetAttribute("FullFileName")
763 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
764 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
765 RequestReading(*iterDown,prio,-1,ph);
766 // AddEntryToMap(*iterDown);
768 if (prio == maxprio) { break; }
772 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
773 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
774 pointers.push_back(ph);
775 mViewer->SetImageVector(pointers);
779 //==================================================
781 //==================================================
784 //==================================================
785 void WxGimmickView::OnInternalIdle()
787 if (!mConstructed) return;
788 static bool first_time = true;
793 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
794 // mViewer->StartPlayer();
797 mViewer->RefreshIfNecessary();
801 void WxGimmickView::UpdateWindowUI(long flags)
805 mViewer->RefreshIfNecessary();
809 //==================================================
811 //==================================================
812 void WxGimmickView::ClearSelection()
814 printf("EED WxGimmickView::ClearSelection Start\n");
816 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
817 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
818 mViewer->SetImageVector(pointers);
819 mViewer->RefreshIfNecessary();
821 printf("EED WxGimmickView::ClearSelection End\n");
824 //=================================================
826 //=================================================
827 void WxGimmickView::OnRemove(wxCommandEvent& event)
829 //TODO Select current tree handler
832 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
833 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
834 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
837 //=================================================
840 //=================================================
841 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
843 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
844 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
847 //=================================================
848 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
850 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
851 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
854 //=================================================
855 void WxGimmickView::AddDir(std::string dirName)
857 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
862 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
863 mCurrentDirectory = crea::std2wx(dirName);
864 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
865 mProgressDialog->Pulse(_T("Updating view..."));
867 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
872 //=================================================
873 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
876 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
877 _T("Check database for files deletion, addition and attributes change. Then give a report."),
878 _T("Repair database (remove deleted files and add new files)."),
879 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
881 wxSingleChoiceDialog dialog(this,
882 _T("Select one of the following synchronization actions:\n")
883 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
884 _T("Synchronization Settings"),
885 WXSIZEOF(choices), choices);
887 //dialog.SetSelection(0);
889 if (dialog.ShowModal() == wxID_OK)
892 int sel=dialog.GetSelection();
894 bool checkAttributes=false;
895 if(sel==2 || sel==3){repair=true;}
896 if(sel==1 || sel==3){checkAttributes=true;}
897 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
898 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
899 if(sel==2 || sel==3){
900 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
905 //=================================================
907 //=================================================
908 void WxGimmickView::OnSettings(wxCommandEvent& event)
910 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
911 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
913 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
915 siz->Add( nb,1,wxGROW ,0);
916 CreateSettingsDialog(nb,dial);
921 //=================================================
922 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
925 // Test if one image is selected => export
927 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
937 void WxGimmickView::ExportImages()
939 //Archive selection: name, emplacement
940 //same process than copy local but to a zip
941 // if settings are yes "always ask for descriptor addition", ask
942 // if settings are yes, adding descriptor
945 void WxGimmickView::ImportImages()
949 // Contain a descriptor.text
950 // create a new database, and add to database
951 // if not, add to current database
955 //=================================================
957 void WxGimmickView::OnTools(wxCommandEvent& event)
959 mViewer->StopPlayer();
961 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
963 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
964 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
965 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
966 dialSizer->Add(nb,1,wxGROW,0);
967 dialSizer->Add(buttonsSizer,0,wxGROW);
969 #if defined(BUILD_BRUKER)
970 //First page: Bruker Image Reader
971 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
972 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
975 dial->SetSizer(dialSizer, true);
979 if (dial->GetReturnCode() == wxID_OK)
981 #if defined(BUILD_BRUKER)
982 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
984 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
985 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
987 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
989 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
991 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
992 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
995 b2d.SetInputDirectory(inputDir);
996 b2d.SetOutputDirectory(outputDir);
997 b2d.SetConvertModeToDicom();
1002 std::cout <<"after addToDB" << std::endl;
1003 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
1008 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
1009 std::cout <<"after new wxProgressDialog" << std::endl;
1010 mCurrentDirectory = gimmickTools->getOutputDir();
1011 std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;
1012 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
1013 std::cout <<"after mGimmick->AddDir" << std::endl;
1014 mProgressDialog->Pulse(_T("Updating view..."));
1015 std::cout <<"after mProgressDialog->Pulse" << std::endl;
1016 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1017 std::cout <<"after UpdateTreeViewLevel" << std::endl;
1019 std::cout <<"after delete mProgressDialog" << std::endl;
1020 DisplayAddSummary();
1021 std::cout <<"after dDisplayAddSummary" << std::endl;
1027 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
1030 delete gimmickTools;
1033 mViewer->StartPlayer();
1036 //=================================================
1038 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1040 //First page: Customization of configurations
1043 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1044 //Database Path String
1046 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1047 //Syncronization Event String
1049 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1050 //Syncronization Frequency String
1052 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1054 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1056 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1058 //Second page: Creation of Databases
1059 /*wxPanel* databaseCreation=new wxPanel(nb);
1060 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1062 //Second page (temporary): Connection to PACS
1063 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1064 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1066 //Third page: CD/DVD Watch
1067 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1068 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1070 //Fourth page: Selection of attributes to show
1071 std::vector<std::string> shown;
1072 std::vector<std::string> nShown;
1073 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1074 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1075 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1076 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1079 //===================================================================
1080 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1081 std::vector<std::string>& nShown, int level)
1083 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1086 //===================================================================
1087 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1089 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1090 std::vector<std::string> n=nShown;
1091 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1093 //===================================================================
1094 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1095 const std::string& dbPath,
1096 const std::string& syncEvent,
1097 const std::string& syncFreq)
1099 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1100 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1101 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1102 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1105 //===================================================================
1106 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1108 mListener->SetMonitoredDrive(drive);
1109 mListener->SetAddFilesState(addFiles);
1110 mListener->SetRemoveFilesState(removeFiles);
1113 //========================================================================
1115 void WxGimmickView::OnDriveMount(bool mount)
1117 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1119 mListener->GetMonitoredDrive(drive);
1123 mViewer->StopPlayer();
1125 wxString title(_T("Adding drive"));
1127 new wxProgressDialog(_T("Adding drive"),
1135 // wxPD_ESTIMATED_TIME |
1136 // wxPD_REMAINING_TIME |
1138 mCurrentDirectory = crea::std2wx(drive);
1139 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1140 mProgressDialog->Pulse(_T("Updating view..."));
1142 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1144 DisplayAddSummary();
1145 mViewer->StartPlayer();
1149 mGimmick->DeleteDrive(drive);
1150 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1154 //========================================================================
1156 void WxGimmickView::StartListeningThread()
1158 mListener->Resume();
1161 //========================================================================
1163 void WxGimmickView::StopListeningThread()
1168 //========================================================================
1169 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1171 wxDialog *dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1172 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1173 WxEditFieldsPanel *ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1175 siz->Add( ef,1,wxGROW ,0);
1176 dial->SetSizer(siz);
1182 //========================================================================
1183 void WxGimmickView::DumpTags(std::string i_filename)
1185 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1189 //========================================================================
1190 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1192 std::vector<std::string> storages;
1193 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1194 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1196 storages.push_back(it->first);
1199 WxExportDlg* exp= new WxExportDlg(this,storages);
1200 if ( exp->ShowModal() ==ID_EXPORT_OK)
1202 std::string storage = exp->GetStorage();
1204 new wxProgressDialog(_T("Adding file(s)"),
1212 // wxPD_ESTIMATED_TIME |
1213 // wxPD_REMAINING_TIME |
1215 mGimmick->AddFiles(storage,i_filenames);
1216 mProgressDialog->Pulse(_T("Updating view..."));
1217 UpdateTreeViewLevel(storage,1);
1219 DisplayAddSummary();
1225 //========================================================================
1226 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1228 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1229 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1232 //=================================================
1233 /// AddProgress Gimmick callback
1234 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1237 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1238 p.GetNumberScannedDirs(),
1239 p.GetNumberScannedFiles(),
1240 p.GetNumberHandledFiles(),
1241 p.GetNumberAddedFiles());
1242 // std::cout << "OnAddProgress "<<mess<<std::endl;
1243 wxString s(wxString::From8BitData(mess));
1244 // std::cout << "Pulse"<<std::endl;
1246 if(mProgressDialog != NULL)
1248 if (!mProgressDialog->Pulse(s))
1253 // std::cout << "OnAddProgress ok"<<std::endl;
1255 //=================================================
1257 //=================================================
1258 void WxGimmickView::DisplayAddSummary()
1260 std::stringstream mess(mGimmick->getSummary());
1263 mess << "time to scan :" << difftime(end,mstart) << "sec";
1264 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1267 ////////////////////////////////////////////////
1268 // Add a DB to application //
1269 // @param event : WxEvent //
1271 ////////////////////////////////////////////////
1272 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1275 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1276 std::string wc("*.sqlite3*");
1277 wxFileDialog* FD = new wxFileDialog( 0,
1285 if (FD->ShowModal()==wxID_OK)
1288 wxArrayString files;
1289 FD->GetPaths(files);
1290 std::stringstream st;
1291 for(int i = 0; i< files.size(); i++)
1293 //get name of DB (file name)
1294 size_t pos = files[i].find_last_of(_T("\\"));
1295 std::string name = crea::wx2std(files[i].substr(pos+1));
1296 pos = name.find_last_of(".");
1297 name = name.substr(0,pos);
1298 //create TreeHandler
1299 mGimmick->addDB(name, crea::wx2std(files[i]));
1301 CreateSingleTreeView(name);
1305 ////////////////////////////////////////////////////
1306 // Create a DB from an Attributes Descriptor files //
1307 // @param event : WxEvent //
1309 //////////////////////////////////////////////////
1310 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1312 // PACSConnection("");
1313 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1314 DescriptorPan->Layout();
1315 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1318 std::string file(DescriptorPan->GetDescriptor());
1321 size_t pos = file.find_last_of("\\");
1322 std::string name = file.substr(pos+1);
1323 std::string directory = file.substr(0,pos);
1324 pos = name.find_last_of(".");
1325 name = name.substr(0,pos);
1326 //get directory to store DB
1327 directory += "\\" + name + ".sqlite3";
1329 mGimmick->createDB(name, file,directory);
1330 //create TreeHandler
1331 mGimmick->addDB(name, directory);
1333 CreateSingleTreeView(name);
1338 void WxGimmickView::killProgress()
1340 mProgressDialog->Resume();
1341 mProgressDialog->Destroy();
1342 mProgressDialog = NULL;
1345 //=================================================
1347 //=================================================
1348 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1349 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1350 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1351 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1352 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1353 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1354 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1355 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1356 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1358 //=================================================
1360 } // EO namespace creaImageIO