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);
372 if (asking == "true")
374 // display the output dialog box
377 sscanf(dim.c_str(),"%d",&idim);
378 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
379 if (dlg->ShowModal() == wxID_OK)
382 mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
383 mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
393 sscanf(dim.c_str(),"%d",&i_dim_out);
396 // Next we create the structure for dicom output infos
398 Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
401 // We don't send informations!
403 else if( i_attr.size() == 1 && i_attr.front() == "ALL")
405 // we send all database
406 Oattr.inside.push_back("ALL");
408 else if( (i_attr.size() == 1 && i_attr.front() != "ALL")
409 || (i_attr.size() >1) )
411 mGimmick->fillVectInfos(i_attr, Oattr);
418 // Next we create model and sort files
419 std::vector<std::string> sort_files(files);
421 if( !out_model.empty() )
423 /* OutputModel mod(out_model);
424 mGimmick->isAttributeExist(db_name, mod);
425 mod.sort(files, sort_files);
428 if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
430 OutputModel *mod = new OutputModel();
431 zspacing = mod->orderFilesWithZspacing(sort_files);
434 // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
435 readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
441 //======================================================================
443 //======================================================================
446 //======================================================================
447 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
449 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
451 //======================================================================
453 //======================================================================
454 void WxGimmickView::GetImages(int dim,
455 const std::vector<std::string>& files,
456 std::vector<vtkImageData*>& s)
458 ReadImagesNotThreaded(s,files,dim);
460 //======================================================================
463 //=================================================
464 void WxGimmickView::CreateIconList()
466 // Size of the icons;
470 // should correspond to Icon_xxx enum
471 icons[Icon_accept] = wxIcon(accept_xpm);
472 icons[Icon_add] = wxIcon(add_xpm);
473 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
474 icons[Icon_page_down] = wxIcon(page_down_xpm);
475 icons[Icon_remove] = wxIcon(remove_xpm);
476 icons[Icon_database_add] = wxIcon(database_add_xpm);
477 icons[Icon_help] = wxIcon(help_xpm);
478 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
479 icons[Icon_create_database] = wxIcon(create_database_xpm);
480 icons[Icon_settings] = wxIcon(settings_xpm);
481 icons[Icon_tools] = wxIcon(tools_xpm);
483 // unsigned int NbIcons = 8;
484 // Make an image list containing small icons
485 mIcon = new wxImageList(size,size,true);
487 // Make all icons the same size = size of the first one
488 int sizeOrig = icons[0].GetWidth();
489 for ( size_t i = 0; i < icon_number; i++ )
491 if ( size == sizeOrig )
493 mIcon->Add(icons[i]);
497 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
501 //=================================================
504 //=================================================
505 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
507 mViewer->StopPlayer();
508 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
510 wxFileDialog* FD = new wxFileDialog( 0,
518 if (FD->ShowModal()==wxID_OK)
525 std::vector<std::string> filenames;
526 for (i=0;i<files.GetCount();++i)
528 filenames.push_back(wx2std(files[i]));
529 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
533 new wxProgressDialog(_T("Adding file(s)"),
539 // wxPD_ESTIMATED_TIME |
540 // wxPD_REMAINING_TIME |
543 // TO DO : select the current tree handler
544 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
546 mProgressDialog->Pulse(_T("Updating view..."));
548 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
553 mViewer->StartPlayer();
555 //=================================================
557 //=================================================
558 void WxGimmickView::OnAddDir(wxCommandEvent& event)
560 mViewer->StopPlayer();
561 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
562 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
565 _T("Select directory"),
569 if (FD->ShowModal()==wxID_OK)
572 std::string dirname = wx2std (FD->GetPath());
573 bool recurse = isNeedRecursive(dirname);
576 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
580 wxString title(_T("Adding directory"));
582 title = _T("Adding directory (recursive)");
584 new wxProgressDialog(_T("Adding directory"),
586 NumberFilesToAdd(dirname,recurse),
593 // wxPD_ESTIMATED_TIME |
594 // wxPD_REMAINING_TIME |
597 mCurrentDirectory = FD->GetPath();
598 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
599 mProgressDialog->Pulse(_T("Updating view..."));
601 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
605 mViewer->StartPlayer();
610 //=================================================
611 // Determines number of files potentially to add to database
612 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
615 if ( !boost::filesystem::exists( dirpath ) ) return nb;
616 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
617 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
619 // If is directory & recurse : do recurse
620 if ( boost::filesystem::is_directory(itr->status()) )
624 nb += NumberFilesToAdd(itr->path().string(), recursive);
635 //=================================================
636 // Test a directory to know if contains sub-directory to analyze
637 bool WxGimmickView::isNeedRecursive(std::string i_name)
639 boost::filesystem::directory_iterator iter(i_name), end_iter;
640 //bool bfindir = false;
641 for(; iter != end_iter; ++iter)
643 if(boost::filesystem::is_directory(*iter))
650 //=================================================
652 //=================================================
653 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
655 GimmickDebugMessage(5,
656 "WxGimmickView::OnSelectionChange"
663 valid= ValidateSelected(NULL,
664 mSelectionMinDimension,
665 mSelectionMaxDimension );
670 std::vector<tree::Node*>::const_iterator i;
671 for(i=sel.begin();i!=sel.end()&&valid;++i)
673 valid= ValidateSelected((*i),
674 mSelectionMinDimension,
675 mSelectionMaxDimension );
680 valid= ValidateSelected(sel.front(),
681 mSelectionMinDimension,
682 mSelectionMaxDimension );
687 std::vector<tree::Node*>::const_iterator i;
688 for(i=sel.begin();i!=sel.end()&&valid;++i)
690 valid= ValidateSelected((*i),
691 mSelectionMinDimension,
692 mSelectionMaxDimension );
695 mText->SetLabel(crea::std2wx(GetMessage()));
698 ReadImageThreaded(sel);
704 ReadImageThreaded(sel);
707 //==================================================
709 //==================================================
710 ///Reads Images (Threaded)
711 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
713 GimmickDebugMessage(5,
716 int maxprio = GetMaximalPriority();
717 int prio = maxprio + 2000;
721 //First load the selected images
722 mCurImageItemToShow = sel.front();
725 std::vector<tree::Node*>::const_iterator selected;
726 for(selected=sel.begin();selected!=sel.end();++selected)
728 GimmickDebugMessage(5,
729 "Requesting image from selected "
730 <<(*selected)->GetAttribute("FullFileName")
732 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
733 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
734 pointers.push_back(ph);
735 RequestReading(*selected,prio,index,ph);
736 // AddEntryToMap(*selected);
740 mViewer->SetImageVector(pointers);
743 std::vector<tree::Node*> up;
744 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
745 std::vector<tree::Node*>::iterator iterUp;
746 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
748 GimmickDebugMessage(5,
749 "Requesting image from neighbors up "
750 <<(*iterUp)->GetAttribute("FullFileName")
752 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
753 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
754 RequestReading(*iterUp,prio,-1,ph);
755 // AddEntryToMap(*iterUp);
757 if (prio == maxprio) break;
762 std::vector<tree::Node*> down;
763 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
764 std::vector<tree::Node*>::iterator iterDown;
765 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
767 GimmickDebugMessage(5,
768 "Requesting image from neighbors down "
769 <<(*iterDown)->GetAttribute("FullFileName")
771 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
772 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
773 RequestReading(*iterDown,prio,-1,ph);
774 // AddEntryToMap(*iterDown);
776 if (prio == maxprio) break;
782 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
783 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
784 pointers.push_back(ph);
785 mViewer->SetImageVector(pointers);
789 //==================================================
791 //==================================================
794 //==================================================
795 void WxGimmickView::OnInternalIdle()
797 if (!mConstructed) return;
798 static bool first_time = true;
803 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
804 // mViewer->StartPlayer();
807 mViewer->RefreshIfNecessary();
811 void WxGimmickView::UpdateWindowUI(long flags)
815 mViewer->RefreshIfNecessary();
819 //==================================================
821 //==================================================
822 void WxGimmickView::ClearSelection()
825 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
826 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
827 mViewer->SetImageVector(pointers);
828 mViewer->RefreshIfNecessary();
832 //=================================================
834 //=================================================
835 void WxGimmickView::OnRemove(wxCommandEvent& event)
837 //TODO Select current tree handler
840 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
841 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
842 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
845 //=================================================
848 //=================================================
849 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
851 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
852 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
855 //=================================================
856 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
858 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
859 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
862 //=================================================
863 void WxGimmickView::AddDir(std::string dirName)
865 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
870 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
871 mCurrentDirectory = crea::std2wx(dirName);
872 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
873 mProgressDialog->Pulse(_T("Updating view..."));
875 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
880 //=================================================
881 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
884 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
885 _T("Check database for files deletion, addition and attributes change. Then give a report."),
886 _T("Repair database (remove deleted files and add new files)."),
887 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
889 wxSingleChoiceDialog dialog(this,
890 _T("Select one of the following synchronization actions:\n")
891 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
892 _T("Synchronization Settings"),
893 WXSIZEOF(choices), choices);
895 //dialog.SetSelection(0);
897 if (dialog.ShowModal() == wxID_OK)
900 int sel=dialog.GetSelection();
902 bool checkAttributes=false;
903 if(sel==2 || sel==3){repair=true;}
904 if(sel==1 || sel==3){checkAttributes=true;}
905 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
906 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
907 if(sel==2 || sel==3){
908 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
913 //=================================================
915 //=================================================
916 void WxGimmickView::OnSettings(wxCommandEvent& event)
918 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
919 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
921 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
923 siz->Add( nb,1,wxGROW ,0);
924 CreateSettingsDialog(nb,dial);
929 //=================================================
930 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
933 // Test if one image is selected => export
935 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
945 void WxGimmickView::ExportImages()
947 //Archive selection: name, emplacement
948 //same process than copy local but to a zip
949 // if settings are yes "always ask for descriptor addition", ask
950 // if settings are yes, adding descriptor
953 void WxGimmickView::ImportImages()
957 // Contain a descriptor.text
958 // create a new database, and add to database
959 // if not, add to current database
963 //=================================================
965 void WxGimmickView::OnTools(wxCommandEvent& event)
967 mViewer->StopPlayer();
969 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
971 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
972 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
973 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
974 dialSizer->Add(nb,1,wxGROW,0);
975 dialSizer->Add(buttonsSizer,0,wxGROW);
977 #if defined(BUILD_BRUKER)
978 //First page: Bruker Image Reader
979 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
980 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
983 dial->SetSizer(dialSizer, true);
987 if (dial->GetReturnCode() == wxID_OK)
989 #if defined(BUILD_BRUKER)
990 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
992 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
993 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
995 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
997 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
999 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
1000 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
1003 b2d.SetInputDirectory(inputDir);
1004 b2d.SetOutputDirectory(outputDir);
1005 b2d.SetConvertModeToDicom();
1010 std::cout <<"after addToDB" << std::endl;
1011 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
1016 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
1017 std::cout <<"after new wxProgressDialog" << std::endl;
1018 mCurrentDirectory = gimmickTools->getOutputDir();
1019 std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;
1020 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
1021 std::cout <<"after mGimmick->AddDir" << std::endl;
1022 mProgressDialog->Pulse(_T("Updating view..."));
1023 std::cout <<"after mProgressDialog->Pulse" << std::endl;
1024 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1025 std::cout <<"after UpdateTreeViewLevel" << std::endl;
1027 std::cout <<"after delete mProgressDialog" << std::endl;
1028 DisplayAddSummary();
1029 std::cout <<"after dDisplayAddSummary" << std::endl;
1035 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
1038 delete gimmickTools;
1041 mViewer->StartPlayer();
1044 //=================================================
1046 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1048 //First page: Customization of configurations
1051 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1052 //Database Path String
1054 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1055 //Syncronization Event String
1057 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1058 //Syncronization Frequency String
1060 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1062 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1064 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1066 //Second page: Creation of Databases
1067 /*wxPanel* databaseCreation=new wxPanel(nb);
1068 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1070 //Second page (temporary): Connection to PACS
1071 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1072 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1074 //Third page: CD/DVD Watch
1075 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1076 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1078 //Fourth page: Selection of attributes to show
1079 std::vector<std::string> shown;
1080 std::vector<std::string> nShown;
1081 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1082 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1083 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1084 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1087 //===================================================================
1088 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1089 std::vector<std::string>& nShown, int level)
1091 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1094 //===================================================================
1095 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1097 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1098 std::vector<std::string> n=nShown;
1099 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1101 //===================================================================
1102 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1103 const std::string& dbPath,
1104 const std::string& syncEvent,
1105 const std::string& syncFreq)
1107 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1108 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1109 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1110 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1113 //===================================================================
1114 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1116 mListener->SetMonitoredDrive(drive);
1117 mListener->SetAddFilesState(addFiles);
1118 mListener->SetRemoveFilesState(removeFiles);
1121 //========================================================================
1123 void WxGimmickView::OnDriveMount(bool mount)
1125 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1127 mListener->GetMonitoredDrive(drive);
1131 mViewer->StopPlayer();
1133 wxString title(_T("Adding drive"));
1135 new wxProgressDialog(_T("Adding drive"),
1143 // wxPD_ESTIMATED_TIME |
1144 // wxPD_REMAINING_TIME |
1146 mCurrentDirectory = crea::std2wx(drive);
1147 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1148 mProgressDialog->Pulse(_T("Updating view..."));
1150 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1152 DisplayAddSummary();
1153 mViewer->StartPlayer();
1157 mGimmick->DeleteDrive(drive);
1158 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1162 //========================================================================
1164 void WxGimmickView::StartListeningThread()
1166 mListener->Resume();
1169 //========================================================================
1171 void WxGimmickView::StopListeningThread()
1176 //========================================================================
1177 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1179 wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1180 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1181 WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1183 siz->Add( ef,1,wxGROW ,0);
1184 dial->SetSizer(siz);
1190 //========================================================================
1191 void WxGimmickView::DumpTags(std::string i_filename)
1193 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1197 //========================================================================
1198 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1200 std::vector<std::string> storages;
1201 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1202 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1204 storages.push_back(it->first);
1207 WxExportDlg* exp= new WxExportDlg(this,storages);
1208 if ( exp->ShowModal() ==ID_EXPORT_OK)
1210 std::string storage = exp->GetStorage();
1212 new wxProgressDialog(_T("Adding file(s)"),
1220 // wxPD_ESTIMATED_TIME |
1221 // wxPD_REMAINING_TIME |
1223 mGimmick->AddFiles(storage,i_filenames);
1224 mProgressDialog->Pulse(_T("Updating view..."));
1225 UpdateTreeViewLevel(storage,1);
1227 DisplayAddSummary();
1233 //========================================================================
1234 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1236 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1237 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1240 //=================================================
1241 /// AddProgress Gimmick callback
1242 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1245 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1246 p.GetNumberScannedDirs(),
1247 p.GetNumberScannedFiles(),
1248 p.GetNumberHandledFiles(),
1249 p.GetNumberAddedFiles());
1250 // std::cout << "OnAddProgress "<<mess<<std::endl;
1251 wxString s(wxString::From8BitData(mess));
1252 // std::cout << "Pulse"<<std::endl;
1254 if(mProgressDialog != 0)
1256 if (!mProgressDialog->Pulse(s))
1261 // std::cout << "OnAddProgress ok"<<std::endl;
1263 //=================================================
1265 //=================================================
1266 void WxGimmickView::DisplayAddSummary()
1268 std::stringstream mess(mGimmick->getSummary());
1271 mess << "time to scan :" << difftime(end,mstart) << "sec";
1272 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1275 ////////////////////////////////////////////////
1276 // Add a DB to application //
1277 // @param event : WxEvent //
1279 ////////////////////////////////////////////////
1280 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1283 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1284 std::string wc("*.sqlite3*");
1285 wxFileDialog* FD = new wxFileDialog( 0,
1293 if (FD->ShowModal()==wxID_OK)
1296 wxArrayString files;
1297 FD->GetPaths(files);
1298 std::stringstream st;
1299 for(int i = 0; i< files.size(); i++)
1301 //get name of DB (file name)
1302 size_t pos = files[i].find_last_of(_T("\\"));
1303 std::string name = crea::wx2std(files[i].substr(pos+1));
1304 pos = name.find_last_of(".");
1305 name = name.substr(0,pos);
1306 //create TreeHandler
1307 mGimmick->addDB(name, crea::wx2std(files[i]));
1309 CreateSingleTreeView(name);
1313 ////////////////////////////////////////////////////
1314 // Create a DB from an Attributes Descriptor files //
1315 // @param event : WxEvent //
1317 //////////////////////////////////////////////////
1318 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1320 // PACSConnection("");
1321 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1322 DescriptorPan->Layout();
1323 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1326 std::string file(DescriptorPan->GetDescriptor());
1329 size_t pos = file.find_last_of("\\");
1330 std::string name = file.substr(pos+1);
1331 std::string directory = file.substr(0,pos);
1332 pos = name.find_last_of(".");
1333 name = name.substr(0,pos);
1334 //get directory to store DB
1335 directory += "\\" + name + ".sqlite3";
1337 mGimmick->createDB(name, file,directory);
1338 //create TreeHandler
1339 mGimmick->addDB(name, directory);
1341 CreateSingleTreeView(name);
1346 void WxGimmickView::killProgress()
1348 mProgressDialog->Resume();
1349 mProgressDialog->Destroy();
1350 mProgressDialog = 0;
1353 //=================================================
1355 //=================================================
1356 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1357 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1358 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1359 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1360 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1361 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1362 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1363 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1364 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1366 //=================================================
1368 } // EO namespace creaImageIO