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),
142 GimmickDebugMessage(1,"WxGimmickView::WxGimmickView" <<std::endl);
143 // Sets the current directory to the home dir
144 mCurrentDirectory = std2wx(gimmick->GetHomeDirectory());
146 // Connect the AddProgress callback
147 gimmick->ConnectAddProgressObserver( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
149 // Create the list of icons (mIcon)
153 msizer = new wxBoxSizer(wxVERTICAL);
155 // Create the tool bar
157 msizer->Add( mToolBar, 0, wxGROW, 0);
159 // Split part below toolbar into notebook for views and panel
160 // for preview, messages...
161 mSplitter = new wxSplitterWindow( this , -1);
164 mNotebook = new wxNotebook(mSplitter, -1, wxDefaultPosition, wxDefaultSize, 0);
169 mSelectionMaxDimension = max_dim;
170 mSelectionMinDimension = min_dim;
176 mBottomPanel = new wxPanel(mSplitter,-1);
178 mbottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
182 mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
183 //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
184 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
186 mViewer->SetImageVector(pointers);
187 mViewer->StartPlayer();
190 mbottom_sizer->Add(mViewer,1,wxGROW,1);
193 mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
194 mbottom_sizer->Add(mText,0,wxGROW,0);
196 mBottomPanel->SetSizer(mbottom_sizer);
199 /// \TODO fix warning: unused variable hsize
200 int hsize = size.GetHeight();
202 int top_minsize = 450;
203 int bottom_minsize = 50;
205 mSplitter->SetMinimumPaneSize( bottom_minsize );
206 mSplitter->SplitHorizontally( mNotebook, mBottomPanel, top_minsize);
208 msizer->Add( mSplitter, 1, wxGROW, 0);
210 mProgressDialog=NULL;
214 //mListener=new Listener();
215 //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
216 //mListener->Create();
218 // mListener->Pause();
222 //======================================================================
224 //======================================================================
226 WxGimmickView::~WxGimmickView()
228 // stop the viewer before application exit.
229 mViewer->StopPlayer();
230 GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView" <<std::endl);
235 //if(mListener->IsAlive()) { mListener->Delete(); }
237 //======================================================================
239 //======================================================================
240 /// Creates the tool bar
241 void WxGimmickView::CreateToolBar()
243 long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
244 mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
247 mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID,
249 mIcon->GetBitmap(Icon_page_down),
250 _T("Add one or more file to database")
252 mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID,
254 mIcon->GetBitmap(Icon_folder_down),
255 _T("Add the content of a folder to database")
257 mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID,
259 mIcon->GetBitmap(Icon_database_add),
260 _T("Open a local or distant database")
262 mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID,
264 mIcon->GetBitmap(Icon_remove),
265 _T("Remove selected items")
267 mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID,
269 mIcon->GetBitmap(Icon_synchronize),
270 _T("Synchronizes the database with disk")
272 mToolHelp = mToolBar->AddTool( TOOL_HELP_ID,
274 mIcon->GetBitmap(Icon_help),
275 _T("Open help window")
277 mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID,
278 _T("System settings"),
279 mIcon->GetBitmap(Icon_settings),
280 _T("Allows the modification of various system settings")
282 mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID,
284 mIcon->GetBitmap(Icon_tools),
285 _T("Applies tools to images")
287 mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID,
288 _T("Create database"),
289 mIcon->GetBitmap(Icon_create_database),
290 _T("Create DB from an Attributes Descriptor file")
292 #if defined(BUILD_PACS)
293 mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID,
294 _T("PACS Connection,"),
295 mIcon->GetBitmap(Icon_create_database),
296 _T("Echo, Find and Get to a PACS")
299 //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
303 //======================================================================
306 //======================================================================
307 /// Create the tree view for TreeHandler provided
308 void WxGimmickView::CreateTreeView( TreeHandler* h)
310 std::string name(h->GetTree().GetAttribute("Name"));
311 GimmickMessage(2,"Creating the tree view for '"<< name<<"'"<<std::endl);
312 // Create the WxTreeView
313 WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
315 // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
316 // ALREADY IN THE MAP
317 GetTreeViewMap()[name] = view;
320 mNotebook->AddPage( view, crea::std2wx(name) );
324 //======================================================================
325 void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
327 std::vector<std::string> files;
328 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
329 //ReadImagesNotThreaded(s, files, dim);
332 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
333 // ReadImagesNotThreadedInfosInVector(db_name,output, files,dim,1);
338 //======================================================================
339 void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
341 std::vector<std::string> files;
342 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
343 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
345 ReadImagesNotThreadedInVector(s, files, dim);
349 /// By default if out_infos is empty, we dont' provide informations, we return only vtkImageData
350 /// if out_infos has only one entry "all" we provide all database informations
351 void WxGimmickView::getSelectedFiles(std::vector<OutStrGimmick> &outG, std::vector< std::string> i_attr,
352 bool mult, const std::string out_model)
354 // First we select the files
355 std::vector<std::string> files;
356 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
357 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
361 bool bsingle = isSingle(files.front());
363 mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking);
364 mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim);
367 if (asking == "true")
369 // display the output dialog box
372 sscanf(dim.c_str(),"%d",&idim);
373 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
374 if (dlg->ShowModal() == wxID_OK)
377 mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
378 mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
384 sscanf(dim.c_str(),"%d",&i_dim_out);
386 // Next we create the structure for dicom output infos
395 Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
398 // We don't send informations!
399 } else if( i_attr.size() == 1 && i_attr.front() == "ALL")
401 // we send all database
402 Oattr.inside.push_back("ALL");
403 } else if( (i_attr.size() == 1 && i_attr.front() != "ALL")
404 || (i_attr.size() >1) )
406 mGimmick->fillVectInfos(i_attr, Oattr);
411 // Next we create model and sort files
412 std::vector<std::string> sort_files(files);
414 if( !out_model.empty() )
416 /* OutputModel mod(out_model);
417 mGimmick->isAttributeExist(db_name, mod);
418 mod.sort(files, sort_files);
421 if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
423 OutputModel *mod = new OutputModel();
424 zspacing = mod->orderFilesWithZspacing(sort_files);
427 // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
428 readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
434 //======================================================================
436 //======================================================================
439 //======================================================================
440 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
442 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
444 //======================================================================
446 //======================================================================
447 void WxGimmickView::GetImages(int dim,
448 const std::vector<std::string>& files,
449 std::vector<vtkImageData*>& s)
451 ReadImagesNotThreaded(s,files,dim);
453 //======================================================================
456 //=================================================
457 void WxGimmickView::CreateIconList()
459 // Size of the icons;
463 // should correspond to Icon_xxx enum
464 icons[Icon_accept] = wxIcon(accept_xpm);
465 icons[Icon_add] = wxIcon(add_xpm);
466 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
467 icons[Icon_page_down] = wxIcon(page_down_xpm);
468 icons[Icon_remove] = wxIcon(remove_xpm);
469 icons[Icon_database_add] = wxIcon(database_add_xpm);
470 icons[Icon_help] = wxIcon(help_xpm);
471 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
472 icons[Icon_create_database] = wxIcon(create_database_xpm);
473 icons[Icon_settings] = wxIcon(settings_xpm);
474 icons[Icon_tools] = wxIcon(tools_xpm);
476 // unsigned int NbIcons = 8;
477 // Make an image list containing small icons
478 mIcon = new wxImageList(size,size,true);
480 // Make all icons the same size = size of the first one
481 int sizeOrig = icons[0].GetWidth();
482 for ( size_t i = 0; i < icon_number; i++ )
484 if ( size == sizeOrig )
486 mIcon->Add(icons[i]);
490 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
494 //=================================================
497 //=================================================
498 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
500 mViewer->StopPlayer();
502 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
503 #if wxMAJOR_VERSION <= 2
504 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
506 long style = wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE;
511 wxFileDialog* FD = new wxFileDialog( 0,
519 if (FD->ShowModal()==wxID_OK)
526 std::vector<std::string> filenames;
527 for (i=0;i<files.GetCount();++i)
529 filenames.push_back(wx2std(files[i]));
530 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
534 new wxProgressDialog(_T("Adding file(s)"),
540 // wxPD_ESTIMATED_TIME |
541 // wxPD_REMAINING_TIME |
544 // TO DO : select the current tree handler
545 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
547 mProgressDialog->Pulse(_T("Updating view..."));
549 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
554 mViewer->StartPlayer();
556 //=================================================
558 //=================================================
559 void WxGimmickView::OnAddDir(wxCommandEvent& event)
561 mViewer->StopPlayer();
562 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
563 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
566 _T("Select directory"),
570 if (FD->ShowModal()==wxID_OK)
573 std::string dirname = wx2std (FD->GetPath());
574 bool recurse = isNeedRecursive(dirname);
577 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
581 wxString title(_T("Adding directory"));
583 title = _T("Adding directory (recursive)");
585 new wxProgressDialog(_T("Adding directory"),
587 NumberFilesToAdd(dirname,recurse),
594 // wxPD_ESTIMATED_TIME |
595 // wxPD_REMAINING_TIME |
598 mCurrentDirectory = FD->GetPath();
599 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
600 mProgressDialog->Pulse(_T("Updating view..."));
602 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
606 mViewer->StartPlayer();
611 //=================================================
612 // Determines number of files potentially to add to database
613 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
616 if ( !boost::filesystem::exists( dirpath ) ) return nb;
617 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
618 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
620 // If is directory & recurse : do recurse
621 if ( boost::filesystem::is_directory(itr->status()) )
625 nb += NumberFilesToAdd(itr->path().string(), recursive);
636 //=================================================
637 // Test a directory to know if contains sub-directory to analyze
638 bool WxGimmickView::isNeedRecursive(std::string i_name)
640 boost::filesystem::directory_iterator iter(i_name), end_iter;
641 //bool bfindir = false;
642 for(; iter != end_iter; ++iter)
644 if(boost::filesystem::is_directory(*iter))
651 //=================================================
653 //=================================================
654 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
656 GimmickDebugMessage(5,"WxGimmickView::OnSelectionChange"<<std::endl);
662 valid= ValidateSelected(NULL,
663 mSelectionMinDimension,
664 mSelectionMaxDimension );
665 } else if(needProcess) {
667 std::vector<tree::Node*>::const_iterator i;
668 for(i=sel.begin();i!=sel.end()&&valid;++i)
670 valid= ValidateSelected((*i),
671 mSelectionMinDimension,
672 mSelectionMaxDimension );
674 } else if(isSelection) {
675 valid= ValidateSelected(sel.front(),
676 mSelectionMinDimension,
677 mSelectionMaxDimension );
680 std::vector<tree::Node*>::const_iterator i;
681 for(i=sel.begin();i!=sel.end()&&valid;++i)
683 valid= ValidateSelected((*i),
684 mSelectionMinDimension,
685 mSelectionMaxDimension );
688 mText->SetLabel(crea::std2wx(GetMessage()));
692 ReadImageThreaded(sel);
700 // ReadImageThreaded(sel);
704 //==================================================
706 //==================================================
707 ///Reads Images (Threaded)
708 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
710 GimmickDebugMessage(5, "ReadImageThreaded" <<std::endl);
711 int maxprio = GetMaximalPriority();
712 int prio = maxprio + 2000;
716 //First load the selected images
717 mCurImageItemToShow = sel.front();
720 std::vector<tree::Node*>::const_iterator selected;
721 for(selected=sel.begin();selected!=sel.end();++selected)
723 GimmickDebugMessage(5,
724 "Requesting image from selected "
725 <<(*selected)->GetAttribute("FullFileName")
727 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
728 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
729 pointers.push_back(ph);
730 RequestReading(*selected,prio,index,ph);
731 // AddEntryToMap(*selected);
735 mViewer->SetImageVector(pointers);
738 std::vector<tree::Node*> up;
739 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
740 std::vector<tree::Node*>::iterator iterUp;
741 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
743 GimmickDebugMessage(5,
744 "Requesting image from neighbors up "
745 <<(*iterUp)->GetAttribute("FullFileName")
747 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
748 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
749 RequestReading(*iterUp,prio,-1,ph);
750 // AddEntryToMap(*iterUp);
752 if (prio == maxprio) break;
757 std::vector<tree::Node*> down;
758 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
759 std::vector<tree::Node*>::iterator iterDown;
760 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
762 GimmickDebugMessage(5,
763 "Requesting image from neighbors down "
764 <<(*iterDown)->GetAttribute("FullFileName")
766 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
767 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
768 RequestReading(*iterDown,prio,-1,ph);
769 // AddEntryToMap(*iterDown);
771 if (prio == maxprio) { break; }
775 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
776 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
777 pointers.push_back(ph);
778 mViewer->SetImageVector(pointers);
782 //==================================================
784 //==================================================
787 //==================================================
788 void WxGimmickView::OnInternalIdle()
790 if (!mConstructed) return;
791 static bool first_time = true;
797 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
798 // mViewer->StartPlayer();
801 mViewer->RefreshIfNecessary();
805 void WxGimmickView::UpdateWindowUI(long flags)
810 // GL Conflict because window is not showing the fist time
811 //EED mViewer->RefreshIfNecessary();
815 //==================================================
817 //==================================================
818 void WxGimmickView::ClearSelection()
821 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
822 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
823 mViewer->SetImageVector(pointers);
824 mViewer->RefreshIfNecessary();
828 //=================================================
830 //=================================================
831 void WxGimmickView::OnRemove(wxCommandEvent& event)
833 //TODO Select current tree handler
836 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
837 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
838 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
841 //=================================================
844 //=================================================
845 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
847 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
848 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
851 //=================================================
852 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
854 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
855 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
858 //=================================================
859 void WxGimmickView::AddDir(std::string dirName)
861 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
866 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
867 mCurrentDirectory = crea::std2wx(dirName);
868 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
869 mProgressDialog->Pulse(_T("Updating view..."));
871 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
876 //=================================================
877 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
880 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
881 _T("Check database for files deletion, addition and attributes change. Then give a report."),
882 _T("Repair database (remove deleted files and add new files)."),
883 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
885 wxSingleChoiceDialog dialog(this,
886 _T("Select one of the following synchronization actions:\n")
887 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
888 _T("Synchronization Settings"),
889 WXSIZEOF(choices), choices);
891 //dialog.SetSelection(0);
893 if (dialog.ShowModal() == wxID_OK)
896 int sel=dialog.GetSelection();
898 bool checkAttributes=false;
899 if(sel==2 || sel==3){repair=true;}
900 if(sel==1 || sel==3){checkAttributes=true;}
901 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
902 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
903 if(sel==2 || sel==3){
904 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
909 //=================================================
911 //=================================================
912 void WxGimmickView::OnSettings(wxCommandEvent& event)
914 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
915 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
917 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
919 siz->Add( nb,1,wxGROW ,0);
920 CreateSettingsDialog(nb,dial);
925 //=================================================
926 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
929 // Test if one image is selected => export
931 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
941 void WxGimmickView::ExportImages()
943 //Archive selection: name, emplacement
944 //same process than copy local but to a zip
945 // if settings are yes "always ask for descriptor addition", ask
946 // if settings are yes, adding descriptor
949 void WxGimmickView::ImportImages()
953 // Contain a descriptor.text
954 // create a new database, and add to database
955 // if not, add to current database
959 //=================================================
961 void WxGimmickView::OnTools(wxCommandEvent& event)
963 mViewer->StopPlayer();
965 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
967 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
968 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
969 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
970 dialSizer->Add(nb,1,wxGROW,0);
971 dialSizer->Add(buttonsSizer,0,wxGROW);
973 #if defined(BUILD_BRUKER)
974 //First page: Bruker Image Reader
975 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
976 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
979 dial->SetSizer(dialSizer, true);
983 if (dial->GetReturnCode() == wxID_OK)
985 #if defined(BUILD_BRUKER)
986 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
988 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
989 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
991 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
993 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
995 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
996 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
999 b2d.SetInputDirectory(inputDir);
1000 b2d.SetOutputDirectory(outputDir);
1001 b2d.SetConvertModeToDicom();
1006 std::cout <<"after addToDB" << std::endl;
1007 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
1012 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
1013 std::cout <<"after new wxProgressDialog" << std::endl;
1014 mCurrentDirectory = gimmickTools->getOutputDir();
1015 std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;
1016 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
1017 std::cout <<"after mGimmick->AddDir" << std::endl;
1018 mProgressDialog->Pulse(_T("Updating view..."));
1019 std::cout <<"after mProgressDialog->Pulse" << std::endl;
1020 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1021 std::cout <<"after UpdateTreeViewLevel" << std::endl;
1023 std::cout <<"after delete mProgressDialog" << std::endl;
1024 DisplayAddSummary();
1025 std::cout <<"after dDisplayAddSummary" << std::endl;
1031 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
1034 delete gimmickTools;
1037 mViewer->StartPlayer();
1040 //=================================================
1042 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1044 //First page: Customization of configurations
1047 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1048 //Database Path String
1050 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1051 //Syncronization Event String
1053 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1054 //Syncronization Frequency String
1056 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1058 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1060 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1062 //Second page: Creation of Databases
1063 /*wxPanel* databaseCreation=new wxPanel(nb);
1064 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1066 //Second page (temporary): Connection to PACS
1067 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1068 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1070 //Third page: CD/DVD Watch
1071 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1072 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1074 //Fourth page: Selection of attributes to show
1075 std::vector<std::string> shown;
1076 std::vector<std::string> nShown;
1077 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1078 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1079 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1080 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1083 //===================================================================
1084 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1085 std::vector<std::string>& nShown, int level)
1087 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1090 //===================================================================
1091 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1093 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1094 std::vector<std::string> n=nShown;
1095 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1097 //===================================================================
1098 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1099 const std::string& dbPath,
1100 const std::string& syncEvent,
1101 const std::string& syncFreq)
1103 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1104 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1105 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1106 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1109 //===================================================================
1110 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1112 mListener->SetMonitoredDrive(drive);
1113 mListener->SetAddFilesState(addFiles);
1114 mListener->SetRemoveFilesState(removeFiles);
1117 //========================================================================
1119 void WxGimmickView::OnDriveMount(bool mount)
1121 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1123 mListener->GetMonitoredDrive(drive);
1127 mViewer->StopPlayer();
1129 wxString title(_T("Adding drive"));
1131 new wxProgressDialog(_T("Adding drive"),
1139 // wxPD_ESTIMATED_TIME |
1140 // wxPD_REMAINING_TIME |
1142 mCurrentDirectory = crea::std2wx(drive);
1143 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1144 mProgressDialog->Pulse(_T("Updating view..."));
1146 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1148 DisplayAddSummary();
1149 mViewer->StartPlayer();
1153 mGimmick->DeleteDrive(drive);
1154 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1158 //========================================================================
1160 void WxGimmickView::StartListeningThread()
1162 mListener->Resume();
1165 //========================================================================
1167 void WxGimmickView::StopListeningThread()
1172 //========================================================================
1173 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1175 wxDialog *dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1176 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1177 WxEditFieldsPanel *ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1179 siz->Add( ef,1,wxGROW ,0);
1180 dial->SetSizer(siz);
1186 //========================================================================
1187 void WxGimmickView::DumpTags(std::string i_filename)
1189 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1193 //========================================================================
1194 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1196 std::vector<std::string> storages;
1197 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1198 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1200 storages.push_back(it->first);
1203 WxExportDlg* exp= new WxExportDlg(this,storages);
1204 if ( exp->ShowModal() ==ID_EXPORT_OK)
1206 std::string storage = exp->GetStorage();
1208 new wxProgressDialog(_T("Adding file(s)"),
1216 // wxPD_ESTIMATED_TIME |
1217 // wxPD_REMAINING_TIME |
1219 mGimmick->AddFiles(storage,i_filenames);
1220 mProgressDialog->Pulse(_T("Updating view..."));
1221 UpdateTreeViewLevel(storage,1);
1223 DisplayAddSummary();
1229 //========================================================================
1230 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1232 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1233 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1236 //=================================================
1237 /// AddProgress Gimmick callback
1238 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1241 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1242 p.GetNumberScannedDirs(),
1243 p.GetNumberScannedFiles(),
1244 p.GetNumberHandledFiles(),
1245 p.GetNumberAddedFiles());
1246 // std::cout << "OnAddProgress "<<mess<<std::endl;
1247 wxString s(wxString::From8BitData(mess));
1248 // std::cout << "Pulse"<<std::endl;
1250 if(mProgressDialog != NULL)
1252 if (!mProgressDialog->Pulse(s))
1257 // std::cout << "OnAddProgress ok"<<std::endl;
1259 //=================================================
1261 //=================================================
1262 void WxGimmickView::DisplayAddSummary()
1264 std::stringstream mess(mGimmick->getSummary());
1267 mess << "time to scan :" << difftime(end,mstart) << "sec";
1268 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1271 ////////////////////////////////////////////////
1272 // Add a DB to application //
1273 // @param event : WxEvent //
1275 ////////////////////////////////////////////////
1276 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1279 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1280 std::string wc("*.sqlite3*");
1281 wxFileDialog* FD = new wxFileDialog( 0,
1289 if (FD->ShowModal()==wxID_OK)
1292 wxArrayString files;
1293 FD->GetPaths(files);
1294 std::stringstream st;
1295 for(int i = 0; i< files.size(); i++)
1297 //get name of DB (file name)
1298 size_t pos = files[i].find_last_of(_T("\\"));
1299 std::string name = crea::wx2std(files[i].substr(pos+1));
1300 pos = name.find_last_of(".");
1301 name = name.substr(0,pos);
1302 //create TreeHandler
1303 mGimmick->addDB(name, crea::wx2std(files[i]));
1305 CreateSingleTreeView(name);
1309 ////////////////////////////////////////////////////
1310 // Create a DB from an Attributes Descriptor files //
1311 // @param event : WxEvent //
1313 //////////////////////////////////////////////////
1314 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1316 // PACSConnection("");
1317 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1318 DescriptorPan->Layout();
1319 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1322 std::string file(DescriptorPan->GetDescriptor());
1325 size_t pos = file.find_last_of("\\");
1326 std::string name = file.substr(pos+1);
1327 std::string directory = file.substr(0,pos);
1328 pos = name.find_last_of(".");
1329 name = name.substr(0,pos);
1330 //get directory to store DB
1331 directory += "\\" + name + ".sqlite3";
1333 mGimmick->createDB(name, file,directory);
1334 //create TreeHandler
1335 mGimmick->addDB(name, directory);
1337 CreateSingleTreeView(name);
1342 void WxGimmickView::killProgress()
1344 mProgressDialog->Resume();
1345 mProgressDialog->Destroy();
1346 mProgressDialog = NULL;
1349 //=================================================
1351 //=================================================
1352 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1353 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1354 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1355 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1356 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1357 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1358 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1359 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1360 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1362 //=================================================
1364 } // EO namespace creaImageIO