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 printf("EED WxGimmickView::getSelectedFiles Start\n");
356 // First we select the files
357 std::vector<std::string> files;
358 printf("EED WxGimmickView::getSelectedFiles 1.1\n");
359 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
360 printf("EED WxGimmickView::getSelectedFiles 1.2\n");
361 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
362 printf("EED WxGimmickView::getSelectedFiles 1.3\n");
366 printf("EED WxGimmickView::getSelectedFiles 1.3.1\n");
367 bool bsingle = isSingle( files.front() );
368 printf("EED WxGimmickView::getSelectedFiles 1.3.2\n");
370 printf("EED WxGimmickView::getSelectedFiles 1.4\n");
371 mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking);
372 printf("EED WxGimmickView::getSelectedFiles 1.5\n");
373 mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim);
375 printf("EED WxGimmickView::getSelectedFiles 1.6\n");
377 if (asking == "true")
379 // display the output dialog box
382 sscanf(dim.c_str(),"%d",&idim);
383 printf("EED WxGimmickView::getSelectedFiles 1.7\n");
384 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
385 printf("EED WxGimmickView::getSelectedFiles 1.8\n");
386 if (dlg->ShowModal() == wxID_OK)
389 mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
390 mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
396 sscanf(dim.c_str(),"%d",&i_dim_out);
398 printf("EED WxGimmickView::getSelectedFiles 2\n");
401 // Next we create the structure for dicom output infos
410 Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
413 // We don't send informations!
414 } else if( i_attr.size() == 1 && i_attr.front() == "ALL")
416 // we send all database
417 Oattr.inside.push_back("ALL");
418 } else if( (i_attr.size() == 1 && i_attr.front() != "ALL")
419 || (i_attr.size() >1) )
421 mGimmick->fillVectInfos(i_attr, Oattr);
426 // Next we create model and sort files
427 std::vector<std::string> sort_files(files);
429 if( !out_model.empty() )
431 /* OutputModel mod(out_model);
432 mGimmick->isAttributeExist(db_name, mod);
433 mod.sort(files, sort_files);
436 if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
438 OutputModel *mod = new OutputModel();
439 zspacing = mod->orderFilesWithZspacing(sort_files);
442 // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
443 readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
445 printf("EED WxGimmickView::getSelectedFiles End\n");
452 //======================================================================
454 //======================================================================
457 //======================================================================
458 void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
460 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
462 //======================================================================
464 //======================================================================
465 void WxGimmickView::GetImages(int dim,
466 const std::vector<std::string>& files,
467 std::vector<vtkImageData*>& s)
469 ReadImagesNotThreaded(s,files,dim);
471 //======================================================================
474 //=================================================
475 void WxGimmickView::CreateIconList()
477 // Size of the icons;
481 // should correspond to Icon_xxx enum
482 icons[Icon_accept] = wxIcon(accept_xpm);
483 icons[Icon_add] = wxIcon(add_xpm);
484 icons[Icon_folder_down] = wxIcon(folder_down_xpm);
485 icons[Icon_page_down] = wxIcon(page_down_xpm);
486 icons[Icon_remove] = wxIcon(remove_xpm);
487 icons[Icon_database_add] = wxIcon(database_add_xpm);
488 icons[Icon_help] = wxIcon(help_xpm);
489 icons[Icon_synchronize] = wxIcon(synchronize_xpm);
490 icons[Icon_create_database] = wxIcon(create_database_xpm);
491 icons[Icon_settings] = wxIcon(settings_xpm);
492 icons[Icon_tools] = wxIcon(tools_xpm);
494 // unsigned int NbIcons = 8;
495 // Make an image list containing small icons
496 mIcon = new wxImageList(size,size,true);
498 // Make all icons the same size = size of the first one
499 int sizeOrig = icons[0].GetWidth();
500 for ( size_t i = 0; i < icon_number; i++ )
502 if ( size == sizeOrig )
504 mIcon->Add(icons[i]);
508 mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
512 //=================================================
515 //=================================================
516 void WxGimmickView::OnAddFiles(wxCommandEvent& event)
518 mViewer->StopPlayer();
520 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
521 #if wxMAJOR_VERSION <= 2
522 long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
524 long style = wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE;
529 wxFileDialog* FD = new wxFileDialog( 0,
537 if (FD->ShowModal()==wxID_OK)
544 std::vector<std::string> filenames;
545 for (i=0;i<files.GetCount();++i)
547 filenames.push_back(wx2std(files[i]));
548 GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
552 new wxProgressDialog(_T("Adding file(s)"),
558 // wxPD_ESTIMATED_TIME |
559 // wxPD_REMAINING_TIME |
562 // TO DO : select the current tree handler
563 mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
565 mProgressDialog->Pulse(_T("Updating view..."));
567 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
572 mViewer->StartPlayer();
574 //=================================================
576 //=================================================
577 void WxGimmickView::OnAddDir(wxCommandEvent& event)
579 mViewer->StopPlayer();
580 std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
581 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
584 _T("Select directory"),
588 if (FD->ShowModal()==wxID_OK)
591 std::string dirname = wx2std (FD->GetPath());
592 bool recurse = isNeedRecursive(dirname);
595 recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
599 wxString title(_T("Adding directory"));
601 title = _T("Adding directory (recursive)");
603 new wxProgressDialog(_T("Adding directory"),
605 NumberFilesToAdd(dirname,recurse),
612 // wxPD_ESTIMATED_TIME |
613 // wxPD_REMAINING_TIME |
616 mCurrentDirectory = FD->GetPath();
617 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
618 mProgressDialog->Pulse(_T("Updating view..."));
620 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
624 mViewer->StartPlayer();
629 //=================================================
630 // Determines number of files potentially to add to database
631 int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
634 if ( !boost::filesystem::exists( dirpath ) ) return nb;
635 boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
636 for ( boost::filesystem::directory_iterator itr( dirpath ); itr != end_itr; ++itr )
638 // If is directory & recurse : do recurse
639 if ( boost::filesystem::is_directory(itr->status()) )
643 nb += NumberFilesToAdd(itr->path().string(), recursive);
654 //=================================================
655 // Test a directory to know if contains sub-directory to analyze
656 bool WxGimmickView::isNeedRecursive(std::string i_name)
658 boost::filesystem::directory_iterator iter(i_name), end_iter;
659 //bool bfindir = false;
660 for(; iter != end_iter; ++iter)
662 if(boost::filesystem::is_directory(*iter))
669 //=================================================
671 //=================================================
672 void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
674 GimmickDebugMessage(5,"WxGimmickView::OnSelectionChange"<<std::endl);
680 valid= ValidateSelected(NULL,
681 mSelectionMinDimension,
682 mSelectionMaxDimension );
683 } else if(needProcess) {
685 std::vector<tree::Node*>::const_iterator i;
686 for(i=sel.begin();i!=sel.end()&&valid;++i)
688 valid= ValidateSelected((*i),
689 mSelectionMinDimension,
690 mSelectionMaxDimension );
692 } else if(isSelection) {
693 valid= ValidateSelected(sel.front(),
694 mSelectionMinDimension,
695 mSelectionMaxDimension );
698 std::vector<tree::Node*>::const_iterator i;
699 for(i=sel.begin();i!=sel.end()&&valid;++i)
701 valid= ValidateSelected((*i),
702 mSelectionMinDimension,
703 mSelectionMaxDimension );
706 mText->SetLabel(crea::std2wx(GetMessage()));
710 ReadImageThreaded(sel);
718 // ReadImageThreaded(sel);
722 //==================================================
724 //==================================================
725 ///Reads Images (Threaded)
726 void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
728 GimmickDebugMessage(5, "ReadImageThreaded" <<std::endl);
729 int maxprio = GetMaximalPriority();
730 int prio = maxprio + 2000;
734 //First load the selected images
735 mCurImageItemToShow = sel.front();
738 std::vector<tree::Node*>::const_iterator selected;
739 for(selected=sel.begin();selected!=sel.end();++selected)
741 GimmickDebugMessage(5,
742 "Requesting image from selected "
743 <<(*selected)->GetAttribute("FullFileName")
745 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
746 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
747 pointers.push_back(ph);
748 RequestReading(*selected,prio,index,ph);
749 // AddEntryToMap(*selected);
753 mViewer->SetImageVector(pointers);
756 std::vector<tree::Node*> up;
757 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
758 std::vector<tree::Node*>::iterator iterUp;
759 for(iterUp=up.begin();iterUp!=up.end();++iterUp)
761 GimmickDebugMessage(5,
762 "Requesting image from neighbors up "
763 <<(*iterUp)->GetAttribute("FullFileName")
765 // ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
766 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
767 RequestReading(*iterUp,prio,-1,ph);
768 // AddEntryToMap(*iterUp);
770 if (prio == maxprio) break;
775 std::vector<tree::Node*> down;
776 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
777 std::vector<tree::Node*>::iterator iterDown;
778 for(iterDown=down.begin();iterDown!=down.end();++iterDown)
780 GimmickDebugMessage(5,
781 "Requesting image from neighbors down "
782 <<(*iterDown)->GetAttribute("FullFileName")
784 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
785 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
786 RequestReading(*iterDown,prio,-1,ph);
787 // AddEntryToMap(*iterDown);
789 if (prio == maxprio) { break; }
793 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
794 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
795 pointers.push_back(ph);
796 mViewer->SetImageVector(pointers);
800 //==================================================
802 //==================================================
805 //==================================================
806 void WxGimmickView::OnInternalIdle()
808 if (!mConstructed) return;
809 static bool first_time = true;
815 // GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
816 // mViewer->StartPlayer();
819 mViewer->RefreshIfNecessary();
823 void WxGimmickView::UpdateWindowUI(long flags)
828 // GL Conflict because window is not showing the fist time
829 //EED mViewer->RefreshIfNecessary();
833 //==================================================
835 //==================================================
836 void WxGimmickView::ClearSelection()
839 pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
840 //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
841 mViewer->SetImageVector(pointers);
842 mViewer->RefreshIfNecessary();
846 //=================================================
848 //=================================================
849 void WxGimmickView::OnRemove(wxCommandEvent& event)
851 //TODO Select current tree handler
854 mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
855 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
856 mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
859 //=================================================
862 //=================================================
863 void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
865 mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
866 // GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
869 //=================================================
870 void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
872 mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
873 wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
876 //=================================================
877 void WxGimmickView::AddDir(std::string dirName)
879 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
884 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
885 mCurrentDirectory = crea::std2wx(dirName);
886 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
887 mProgressDialog->Pulse(_T("Updating view..."));
889 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
894 //=================================================
895 void WxGimmickView::OnSynchronize(wxCommandEvent& event)
898 const wxString choices[] = { _T("Check database for files deletion and addition and give a report."),
899 _T("Check database for files deletion, addition and attributes change. Then give a report."),
900 _T("Repair database (remove deleted files and add new files)."),
901 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
903 wxSingleChoiceDialog dialog(this,
904 _T("Select one of the following synchronization actions:\n")
905 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
906 _T("Synchronization Settings"),
907 WXSIZEOF(choices), choices);
909 //dialog.SetSelection(0);
911 if (dialog.ShowModal() == wxID_OK)
914 int sel=dialog.GetSelection();
916 bool checkAttributes=false;
917 if(sel==2 || sel==3){repair=true;}
918 if(sel==1 || sel==3){checkAttributes=true;}
919 std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
920 wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
921 if(sel==2 || sel==3){
922 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
927 //=================================================
929 //=================================================
930 void WxGimmickView::OnSettings(wxCommandEvent& event)
932 wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
933 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
935 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
937 siz->Add( nb,1,wxGROW ,0);
938 CreateSettingsDialog(nb,dial);
943 //=================================================
944 void WxGimmickView::OnImportExport(wxCommandEvent &Event)
947 // Test if one image is selected => export
949 if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
959 void WxGimmickView::ExportImages()
961 //Archive selection: name, emplacement
962 //same process than copy local but to a zip
963 // if settings are yes "always ask for descriptor addition", ask
964 // if settings are yes, adding descriptor
967 void WxGimmickView::ImportImages()
971 // Contain a descriptor.text
972 // create a new database, and add to database
973 // if not, add to current database
977 //=================================================
979 void WxGimmickView::OnTools(wxCommandEvent& event)
981 mViewer->StopPlayer();
983 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
985 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
986 wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
987 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
988 dialSizer->Add(nb,1,wxGROW,0);
989 dialSizer->Add(buttonsSizer,0,wxGROW);
991 #if defined(BUILD_BRUKER)
992 //First page: Bruker Image Reader
993 WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
994 nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
997 dial->SetSizer(dialSizer, true);
1001 if (dial->GetReturnCode() == wxID_OK)
1003 #if defined(BUILD_BRUKER)
1004 if (nb->GetSelection()==0)//Selection: Bruker Image Reader
1006 std::string inputDir = crea::wx2std(gimmickTools->getInputDir());
1007 std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
1009 bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
1011 if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
1013 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
1014 _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
1017 b2d.SetInputDirectory(inputDir);
1018 b2d.SetOutputDirectory(outputDir);
1019 b2d.SetConvertModeToDicom();
1024 std::cout <<"after addToDB" << std::endl;
1025 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
1030 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
1031 std::cout <<"after new wxProgressDialog" << std::endl;
1032 mCurrentDirectory = gimmickTools->getOutputDir();
1033 std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;
1034 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
1035 std::cout <<"after mGimmick->AddDir" << std::endl;
1036 mProgressDialog->Pulse(_T("Updating view..."));
1037 std::cout <<"after mProgressDialog->Pulse" << std::endl;
1038 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1039 std::cout <<"after UpdateTreeViewLevel" << std::endl;
1041 std::cout <<"after delete mProgressDialog" << std::endl;
1042 DisplayAddSummary();
1043 std::cout <<"after dDisplayAddSummary" << std::endl;
1049 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
1052 delete gimmickTools;
1055 mViewer->StartPlayer();
1058 //=================================================
1060 void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1062 //First page: Customization of configurations
1065 mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1066 //Database Path String
1068 mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1069 //Syncronization Event String
1071 mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1072 //Syncronization Frequency String
1074 mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1076 WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1078 nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1080 //Second page: Creation of Databases
1081 /*wxPanel* databaseCreation=new wxPanel(nb);
1082 nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1084 //Second page (temporary): Connection to PACS
1085 WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1086 nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1088 //Third page: CD/DVD Watch
1089 WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1090 nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1092 //Fourth page: Selection of attributes to show
1093 std::vector<std::string> shown;
1094 std::vector<std::string> nShown;
1095 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1096 int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1097 WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1098 nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1101 //===================================================================
1102 void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown,
1103 std::vector<std::string>& nShown, int level)
1105 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1108 //===================================================================
1109 void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1111 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1112 std::vector<std::string> n=nShown;
1113 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1115 //===================================================================
1116 void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1117 const std::string& dbPath,
1118 const std::string& syncEvent,
1119 const std::string& syncFreq)
1121 mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1122 mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1123 mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1124 mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1127 //===================================================================
1128 void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1130 mListener->SetMonitoredDrive(drive);
1131 mListener->SetAddFilesState(addFiles);
1132 mListener->SetRemoveFilesState(removeFiles);
1135 //========================================================================
1137 void WxGimmickView::OnDriveMount(bool mount)
1139 GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1141 mListener->GetMonitoredDrive(drive);
1145 mViewer->StopPlayer();
1147 wxString title(_T("Adding drive"));
1149 new wxProgressDialog(_T("Adding drive"),
1157 // wxPD_ESTIMATED_TIME |
1158 // wxPD_REMAINING_TIME |
1160 mCurrentDirectory = crea::std2wx(drive);
1161 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1162 mProgressDialog->Pulse(_T("Updating view..."));
1164 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1166 DisplayAddSummary();
1167 mViewer->StartPlayer();
1171 mGimmick->DeleteDrive(drive);
1172 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1176 //========================================================================
1178 void WxGimmickView::StartListeningThread()
1180 mListener->Resume();
1183 //========================================================================
1185 void WxGimmickView::StopListeningThread()
1190 //========================================================================
1191 void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1193 wxDialog *dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1194 wxBoxSizer *siz = new wxBoxSizer(wxVERTICAL);
1195 WxEditFieldsPanel *ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1197 siz->Add( ef,1,wxGROW ,0);
1198 dial->SetSizer(siz);
1204 //========================================================================
1205 void WxGimmickView::DumpTags(std::string i_filename)
1207 WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1211 //========================================================================
1212 void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1214 std::vector<std::string> storages;
1215 Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1216 for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1218 storages.push_back(it->first);
1221 WxExportDlg* exp= new WxExportDlg(this,storages);
1222 if ( exp->ShowModal() ==ID_EXPORT_OK)
1224 std::string storage = exp->GetStorage();
1226 new wxProgressDialog(_T("Adding file(s)"),
1234 // wxPD_ESTIMATED_TIME |
1235 // wxPD_REMAINING_TIME |
1237 mGimmick->AddFiles(storage,i_filenames);
1238 mProgressDialog->Pulse(_T("Updating view..."));
1239 UpdateTreeViewLevel(storage,1);
1241 DisplayAddSummary();
1247 //========================================================================
1248 void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1250 mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1251 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1254 //=================================================
1255 /// AddProgress Gimmick callback
1256 void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1259 sprintf(mess,"%i dirs : %i files :\n %i handled - %i added",
1260 p.GetNumberScannedDirs(),
1261 p.GetNumberScannedFiles(),
1262 p.GetNumberHandledFiles(),
1263 p.GetNumberAddedFiles());
1264 // std::cout << "OnAddProgress "<<mess<<std::endl;
1265 wxString s(wxString::From8BitData(mess));
1266 // std::cout << "Pulse"<<std::endl;
1268 if(mProgressDialog != NULL)
1270 if (!mProgressDialog->Pulse(s))
1275 // std::cout << "OnAddProgress ok"<<std::endl;
1277 //=================================================
1279 //=================================================
1280 void WxGimmickView::DisplayAddSummary()
1282 std::stringstream mess(mGimmick->getSummary());
1285 mess << "time to scan :" << difftime(end,mstart) << "sec";
1286 wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1289 ////////////////////////////////////////////////
1290 // Add a DB to application //
1291 // @param event : WxEvent //
1293 ////////////////////////////////////////////////
1294 void WxGimmickView::OnAddDB(wxCommandEvent& event)
1297 long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1298 std::string wc("*.sqlite3*");
1299 wxFileDialog* FD = new wxFileDialog( 0,
1307 if (FD->ShowModal()==wxID_OK)
1310 wxArrayString files;
1311 FD->GetPaths(files);
1312 std::stringstream st;
1313 for(int i = 0; i< files.size(); i++)
1315 //get name of DB (file name)
1316 size_t pos = files[i].find_last_of(_T("\\"));
1317 std::string name = crea::wx2std(files[i].substr(pos+1));
1318 pos = name.find_last_of(".");
1319 name = name.substr(0,pos);
1320 //create TreeHandler
1321 mGimmick->addDB(name, crea::wx2std(files[i]));
1323 CreateSingleTreeView(name);
1327 ////////////////////////////////////////////////////
1328 // Create a DB from an Attributes Descriptor files //
1329 // @param event : WxEvent //
1331 //////////////////////////////////////////////////
1332 void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1334 // PACSConnection("");
1335 WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1336 DescriptorPan->Layout();
1337 if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1340 std::string file(DescriptorPan->GetDescriptor());
1343 size_t pos = file.find_last_of("\\");
1344 std::string name = file.substr(pos+1);
1345 std::string directory = file.substr(0,pos);
1346 pos = name.find_last_of(".");
1347 name = name.substr(0,pos);
1348 //get directory to store DB
1349 directory += "\\" + name + ".sqlite3";
1351 mGimmick->createDB(name, file,directory);
1352 //create TreeHandler
1353 mGimmick->addDB(name, directory);
1355 CreateSingleTreeView(name);
1360 void WxGimmickView::killProgress()
1362 mProgressDialog->Resume();
1363 mProgressDialog->Destroy();
1364 mProgressDialog = NULL;
1367 //=================================================
1369 //=================================================
1370 BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1371 EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1372 EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1373 EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1374 EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1375 EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1376 EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1377 EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1378 EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1380 //=================================================
1382 } // EO namespace creaImageIO