]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxGimmickView.cpp
Feature #1764
[creaImageIO.git] / src / creaImageIOWxGimmickView.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
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
9 #
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.
16 #
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
21 #  liability. 
22 #
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 # ------------------------------------------------------------------------
26 */
27
28
29 #include <creaImageIOPACSConnection.h>
30 #include <creaImageIOWxPACSConnectionPanel.h>
31 #include <creaImageIOWxGimmickView.h>
32 #include <creaImageIOWxTreeView.h>
33 #include <creaImageIOSystem.h>
34 #include <creaImageIOWxCustomizeConfigPanel.h>
35 #include <creaImageIOWxListenerPanel.h>
36 #include <creaImageIOWxEditFieldsPanel.h>
37 #include <creaImageIOWxAttributeSelectionPanel.h>
38 #include <creaImageIOWxDescriptorPanel.h>
39 #include <creaImageIOWxDumpPanel.h>
40 #include <creaImageIOWxExportDlg.h>
41 #include <creaImageIOWxOutputDlg.h>
42 #include <creaImageIOOutputModel.h>
43
44 using namespace crea;
45 // Icons
46 #include "icons/accept.xpm"
47 #include "icons/add.xpm"
48 #include "icons/folder-down.xpm"
49 #include "icons/page-down.xpm"
50 #include "icons/remove.xpm"
51 #include "icons/database-add.xpm"
52 #include "icons/create-database.xpm"
53 #include "icons/help.xpm"
54 #include "icons/synchronize.xpm"
55 #include "icons/settings.xpm"
56 #include "icons/tools.xpm"
57 //#include "icons/import.xpm"
58
59 #include <wx/imaglist.h>
60 #include <wx/popupwin.h>
61 #include<boost/filesystem/operations.hpp>
62 #if defined(BUILD_BRUKER)
63         #include "bruker2dicom.h"
64 #endif
65
66
67 #include <creaImageIOGimmick.h>
68 #ifdef _DEBUG
69 #define new DEBUG_NEW
70 #endif
71
72 namespace creaImageIO
73 {
74    
75   //======================================================================
76   // The ids of the different tools
77   enum
78     {
79         TOOL_ADDFILES_ID    = 1,
80         TOOL_ADDDIR_ID      = 2,
81         TOOL_ADDDATABASE_ID = 3,
82         TOOL_REMOVE_ID      = 4,
83         TOOL_SYNCHRONIZE_ID = 5,
84         TOOL_HELP_ID        = 6,
85         TOOL_SETTINGS_ID    = 7,
86         TOOL_TOOLS_ID       = 8,
87         TOOL_CREATEDB_ID    = 9,
88         TOOL_PACS_ID        = 10
89     };
90   //======================================================================
91
92   //================================================================
93   // 
94   const int icon_number = 11;
95   // Icon ids
96   typedef enum
97     {
98       Icon_create_database,
99       Icon_accept,
100       Icon_add,
101       Icon_folder_down,
102       Icon_page_down,
103       Icon_database_add,
104       Icon_remove,
105       Icon_synchronize,
106       Icon_help,
107       Icon_settings,
108       Icon_tools
109     }
110     icon_id;
111   //================================================================
112
113   //================================================================
114   /*
115   const icon_id Icon[5] = { Icon_Database,  
116                             Icon_Patient,
117                             Icon_Study,
118                             Icon_Series,
119                             Icon_Image };
120   */
121   //================================================================
122
123
124   //======================================================================
125   // CTor
126         WxGimmickView::WxGimmickView(boost::shared_ptr<Gimmick> gimmick,
127                                wxWindow *parent, 
128                                const wxWindowID id,
129                                const wxPoint& pos, 
130                                const wxSize& size,
131                                int min_dim,
132                                int max_dim,
133                                int number_of_threads)
134     : wxPanel(parent,id,pos,size),
135       GimmickView(gimmick, number_of_threads),
136       mProgressDialog(0),
137       mConstructed(false)
138   {
139     GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
140                         <<std::endl);
141     // Sets the current directory to the home dir
142     mCurrentDirectory =  std2wx(gimmick->GetHomeDirectory());
143
144
145      // Connect the AddProgress callback
146     gimmick->ConnectAddProgressObserver 
147      ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
148
149     // Create the list of icons (mIcon)
150     CreateIconList();
151
152     // Global sizer
153     msizer = new wxBoxSizer(wxVERTICAL);
154
155     // Create the tool bar
156     CreateToolBar(); 
157     msizer->Add( mToolBar, 0, wxGROW, 0);
158
159     // Split part below toolbar into notebook for views and panel
160     // for preview, messages...
161     mSplitter = new wxSplitterWindow( this , -1);
162
163     // Notebook
164     mNotebook = new wxNotebook(mSplitter,
165                                -1, wxDefaultPosition, wxDefaultSize, 0);
166
167     //Gimmick
168     mGimmick=gimmick;
169
170     mSelectionMaxDimension = max_dim;
171     mSelectionMinDimension = min_dim;
172     
173     // Create the views
174     CreateTreeViews();
175
176     // Bottom panel 
177     mBottomPanel = new wxPanel(mSplitter,-1);
178     
179     mbottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
180     
181     
182     // Previewer
183     mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
184         //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
185         pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
186
187         mViewer->SetImageVector(pointers);
188         mViewer->StartPlayer();
189
190
191     mbottom_sizer->Add(mViewer,1,wxGROW,1);
192     //    mViewer->Show();
193
194     mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
195     mbottom_sizer->Add(mText,0,wxGROW,0);
196
197           
198           
199     mBottomPanel->SetSizer(mbottom_sizer);
200
201     // Splitting
202     /// \TODO fix warning: unused variable hsize
203     int hsize = size.GetHeight();
204
205     int top_minsize = 450;
206     int bottom_minsize = 50;
207
208     mSplitter->SetMinimumPaneSize( bottom_minsize );
209     mSplitter->SplitHorizontally( mNotebook, mBottomPanel, 
210                                   top_minsize);
211
212     msizer->Add( mSplitter, 1, wxGROW, 0);
213
214     mProgressDialog=0;
215     SetSizer( msizer );     
216     SetAutoLayout(true);
217     Layout();
218     //mListener=new Listener();
219     //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
220     //mListener->Create();
221    // mListener->Run();
222    // mListener->Pause();
223
224     mConstructed = true;
225   }
226   //======================================================================
227
228   //======================================================================
229   /// Destructor
230   WxGimmickView::~WxGimmickView()
231   {
232         // stop the viewer before application exit.
233     mViewer->StopPlayer();
234     GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
235                         <<std::endl);
236         delete mIcon;
237         delete mViewer;
238     //if(mListener->IsAlive())   {        mListener->Delete();    }
239   }
240   //======================================================================
241   
242   //======================================================================
243   /// Creates the tool bar
244   void WxGimmickView::CreateToolBar()
245   {
246     long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
247     mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
248                              style);
249
250     mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID, 
251                                       _T("Add file(s)"),
252                                       mIcon->GetBitmap(Icon_page_down),
253                                       _T("Add one or more file to database")
254                                       );
255     mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID, 
256                                       _T("Add folder"),
257                                       mIcon->GetBitmap(Icon_folder_down),
258                                       _T("Add the content of a folder to database")
259                                       );
260     mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID, 
261                                       _T("Open database"),
262                                       mIcon->GetBitmap(Icon_database_add),
263                                       _T("Open a local or distant database")
264                                       );
265     mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID, 
266                                       _T("Remove"),
267                                       mIcon->GetBitmap(Icon_remove),
268                                       _T("Remove selected items")
269                                       );
270     mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID, 
271                                       _T("Synchronize"),
272                                       mIcon->GetBitmap(Icon_synchronize),
273                                       _T("Synchronizes the database with disk")
274                                       );
275     mToolHelp = mToolBar->AddTool( TOOL_HELP_ID, 
276                                       _T("Help"),
277                                       mIcon->GetBitmap(Icon_help),
278                                       _T("Open help window")
279                                       );
280     mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID, 
281                                       _T("System settings"),
282                                       mIcon->GetBitmap(Icon_settings),
283                                       _T("Allows the modification of various system settings")
284                                       );
285     mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID, 
286                                       _T("Tools"),
287                                       mIcon->GetBitmap(Icon_tools),
288                                       _T("Applies tools to images")
289                                       );
290     mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID, 
291                                       _T("Create database"),
292                                       mIcon->GetBitmap(Icon_create_database),
293                                       _T("Create DB from an Attributes Descriptor file")
294                                       );
295 #if defined(BUILD_PACS)
296         mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID, 
297                                       _T("PACS Connection,"),
298                                       mIcon->GetBitmap(Icon_create_database),
299                                       _T("Echo, Find and Get to a PACS")
300                                       );
301 #endif
302     //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
303
304     mToolBar->Realize();
305   }
306   //======================================================================
307
308  
309   //======================================================================
310   /// Create the tree view for TreeHandler provided
311   void WxGimmickView::CreateTreeView( TreeHandler* h)
312   {
313     std::string name(h->GetTree().GetAttribute("Name"));
314     GimmickMessage(2,"Creating the tree view for '"<<
315                    name<<"'"<<std::endl);
316     // Create the WxTreeView
317     WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
318
319     // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
320     // ALREADY IN THE MAP
321     GetTreeViewMap()[name] = view;
322
323     // Add Notebook page
324     mNotebook->AddPage( view, crea::std2wx(name) );
325         
326   }
327
328   //======================================================================
329   void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
330   {
331         std::vector<std::string> files;
332         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
333         //ReadImagesNotThreaded(s, files, dim);
334
335
336                 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
337         //              ReadImagesNotThreadedInfosInVector(db_name,output, files,dim,1);
338   }
339
340
341
342   //======================================================================
343   void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
344   {
345         std::vector<std::string> files;
346         std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
347         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
348
349         ReadImagesNotThreadedInVector(s, files, dim);
350   }
351
352
353   /// By default if out_infos is empty, we dont' provide informations, we return only vtkImageData 
354   /// if out_infos has only one entry "all" we provide all database informations
355   void WxGimmickView::getSelectedFiles(std::vector<OutStrGimmick> &outG, std::vector< std::string> i_attr, 
356                                        bool mult, const std::string out_model)
357   {
358         // First we select the files
359         std::vector<std::string> files;
360         std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
361         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
362
363         std::string asking;
364         std::string dim;
365         bool bsingle = isSingle(files.front());
366         int i_dim_out;
367         mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking);
368         mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim);
369
370         if (asking == "true")
371         {
372                 // display the output dialog box
373                 // get dim
374                 int idim;
375                 sscanf(dim.c_str(),"%d",&idim);
376                 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
377                 if (dlg->ShowModal() == wxID_OK)
378                 {
379                         dim = dlg->getDim();
380                         mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
381                         mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
382                 }
383                 else
384                 {
385                         return;
386                 } 
387         }
388         else
389         {
390         }
391         sscanf(dim.c_str(),"%d",&i_dim_out);
392
393
394         // Next we create the structure for dicom output infos
395         OutputAttr Oattr;
396         Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
397         if(i_attr.empty())
398         {
399                 // We don't send informations!
400         }
401         else if( i_attr.size() == 1 && i_attr.front() == "ALL")
402         {
403                 // we send all database
404                 Oattr.inside.push_back("ALL");
405         }
406         else if( (i_attr.size() == 1 && i_attr.front() != "ALL") 
407                 || (i_attr.size() >1) )
408         {
409                 mGimmick->fillVectInfos(i_attr, Oattr);
410         }
411         else
412         {
413                 // nothing
414         }
415
416         // Next we create model and sort files
417         std::vector<std::string> sort_files(files);
418         double zspacing = 1;
419         if( !out_model.empty() )
420         {
421         /*      OutputModel mod(out_model);
422                 mGimmick->isAttributeExist(db_name, mod);
423                 mod.sort(files, sort_files);
424         */}
425
426         if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
427         {
428                 OutputModel *mod = new OutputModel();
429                 zspacing = mod->orderFilesWithZspacing(sort_files);
430                 delete mod;
431         }
432         // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
433         readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
434   }
435
436
437
438
439   //======================================================================
440
441   //======================================================================
442
443
444   //======================================================================
445   void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
446   {
447         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
448   }
449   //======================================================================
450
451   //======================================================================
452   void WxGimmickView::GetImages(int dim, 
453                                 const std::vector<std::string>& files, 
454                                 std::vector<vtkImageData*>& s)
455   {
456         ReadImagesNotThreaded(s,files,dim);
457   }
458   //======================================================================
459
460
461   //=================================================
462   void WxGimmickView::CreateIconList()
463   {
464     // Size of the icons;
465     int size = 16;
466
467     wxIcon icons[20];
468     // should correspond to Icon_xxx enum
469     icons[Icon_accept]          = wxIcon(accept_xpm);
470     icons[Icon_add]             = wxIcon(add_xpm);
471     icons[Icon_folder_down]     = wxIcon(folder_down_xpm);
472     icons[Icon_page_down]       = wxIcon(page_down_xpm);
473     icons[Icon_remove]          = wxIcon(remove_xpm);
474     icons[Icon_database_add]    = wxIcon(database_add_xpm);
475     icons[Icon_help]            = wxIcon(help_xpm);
476     icons[Icon_synchronize]     = wxIcon(synchronize_xpm);
477     icons[Icon_create_database] = wxIcon(create_database_xpm);
478     icons[Icon_settings]        = wxIcon(settings_xpm);
479     icons[Icon_tools]           = wxIcon(tools_xpm);
480
481     //   unsigned int NbIcons = 8;
482     // Make an image list containing small icons
483     mIcon = new wxImageList(size,size,true);
484     
485     // Make all icons the same size = size of the first one
486     int sizeOrig = icons[0].GetWidth();
487     for ( size_t i = 0; i < icon_number; i++ )
488       {
489         if ( size == sizeOrig )
490           {
491             mIcon->Add(icons[i]);
492           }
493         else
494           {
495             mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
496           }
497       }
498   }
499   //=================================================
500
501
502   //=================================================
503   void WxGimmickView::OnAddFiles(wxCommandEvent& event)
504   {
505     mViewer->StopPlayer();
506     long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
507     std::string wc("*");
508     wxFileDialog* FD = new wxFileDialog( 0, 
509                                          _T("Select file"),
510                                          _T(""),
511                                          _T(""),
512                                          crea::std2wx(wc),
513                                          style,
514                                          wxDefaultPosition);
515     
516     if (FD->ShowModal()==wxID_OK)
517       {
518         wxBusyCursor busy;
519
520         wxArrayString files;
521         FD->GetPaths(files);
522         unsigned int i;
523         std::vector<std::string> filenames;
524         for (i=0;i<files.GetCount();++i)
525         {
526           filenames.push_back(wx2std(files[i]));
527           GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
528         }
529
530         mProgressDialog = 
531           new wxProgressDialog(_T("Adding file(s)"),
532                                _T(""),
533                                1000,
534 //                             this,
535                                NULL,
536                                wxPD_ELAPSED_TIME |
537                                // wxPD_ESTIMATED_TIME |
538                                // wxPD_REMAINING_TIME |
539                                wxPD_CAN_ABORT );
540
541         // TO DO : select the current tree handler
542         mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
543
544         mProgressDialog->Pulse(_T("Updating view..."));
545
546         UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
547         killProgress();
548         DisplayAddSummary();    
549
550       }
551         mViewer->StartPlayer(); 
552   }
553   //=================================================
554
555   //=================================================
556   void WxGimmickView::OnAddDir(wxCommandEvent& event)
557   {
558     mViewer->StopPlayer();
559         std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
560     long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
561     wxDirDialog* FD = 
562          new wxDirDialog( 0, 
563                        _T("Select directory"),
564                        mCurrentDirectory,
565                        style);
566     
567     if (FD->ShowModal()==wxID_OK)
568     {
569                         time(&mstart);
570         std::string dirname = wx2std (FD->GetPath());
571         bool recurse =  isNeedRecursive(dirname);
572         if (recurse)
573         {
574              recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
575         }
576
577                 wxBusyCursor busy;
578                 wxString title(_T("Adding directory"));
579                 if (recurse) 
580                 title = _T("Adding directory (recursive)");
581                 mProgressDialog = 
582                 new wxProgressDialog(_T("Adding directory"),
583                                         _T(""),
584                                         NumberFilesToAdd(dirname,recurse),
585
586 //EED                                   this,
587                                         NULL,
588
589                                         wxPD_ELAPSED_TIME | 
590                                         wxPD_SMOOTH |
591                                         // wxPD_ESTIMATED_TIME |
592                                         // wxPD_REMAINING_TIME |
593                                         wxPD_CAN_ABORT );
594
595                 mCurrentDirectory = FD->GetPath();  
596                 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
597                 mProgressDialog->Pulse(_T("Updating view..."));
598
599                 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
600                 killProgress();
601                 DisplayAddSummary();
602           }
603     mViewer->StartPlayer();
604         delete FD;
605   }
606
607
608   //=================================================
609   // Determines number of files potentially to add to database
610    int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
611   {
612            int nb = 0;
613            if ( !boost::filesystem::exists( dirpath ) ) return nb;
614            boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
615            for ( boost::filesystem::directory_iterator itr( dirpath );  itr != end_itr;  ++itr )
616           {
617                 // If is directory & recurse : do recurse
618                 if ( boost::filesystem::is_directory(itr->status()) )
619                 {
620                         if (recursive) 
621                         {
622                                 nb += NumberFilesToAdd(itr->string(), recursive);
623                         }
624                 }
625                 else
626                 {
627                         nb++;
628                 }
629           }
630         return nb;
631   }
632
633    //=================================================
634    // Test a directory to know if contains sub-directory to analyze
635   bool WxGimmickView::isNeedRecursive(std::string i_name)
636   {
637       boost::filesystem::directory_iterator iter(i_name), end_iter;
638       //bool bfindir = false;
639                   for(; iter != end_iter; ++iter)
640                   {
641                           if(boost::filesystem::is_directory(*iter))
642                           {
643                                   return true;
644                           }
645                   }
646                   return false;
647   }
648   //=================================================
649
650   //=================================================
651   void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
652   {      
653     GimmickDebugMessage(5,
654                         "WxGimmickView::OnSelectionChange"
655                         <<std::endl);
656     wxBusyCursor busy;
657         bool valid=true;
658         
659         if(sel.size()==0)
660         {
661                 valid= ValidateSelected(NULL,
662                                 mSelectionMinDimension,
663                                 mSelectionMaxDimension );
664         }
665         else if(needProcess)
666         {
667                 ResetExtent();
668                 std::vector<tree::Node*>::const_iterator i;
669                 for(i=sel.begin();i!=sel.end()&&valid;++i)
670                 {
671                         valid= ValidateSelected((*i),
672                                 mSelectionMinDimension,
673                                 mSelectionMaxDimension );
674                 }
675         }
676         else if(isSelection)
677         {
678                 valid= ValidateSelected(sel.front(),
679                                 mSelectionMinDimension,
680                                 mSelectionMaxDimension );
681         }
682         else
683         {
684                 ResetExtent();
685                 std::vector<tree::Node*>::const_iterator i;
686                 for(i=sel.begin();i!=sel.end()&&valid;++i)
687                 {
688                         valid= ValidateSelected((*i),
689                                 mSelectionMinDimension,
690                                 mSelectionMaxDimension );
691                 }
692         }
693         mText->SetLabel(crea::std2wx(GetMessage()));
694     /*if(valid)
695       {
696         ReadImageThreaded(sel);
697       }
698     else
699       {
700                   ClearSelection();
701       }*/
702         ReadImageThreaded(sel);
703    }
704
705   //==================================================
706
707   //==================================================
708   ///Reads Images (Threaded)
709   void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
710   {     
711    GimmickDebugMessage(5,
712                        "ReadImageThreaded"
713                        <<std::endl);
714    int maxprio = GetMaximalPriority();
715    int prio = maxprio + 2000;
716
717    if(sel.size()>0)
718    {
719    //First load the selected images
720    mCurImageItemToShow = sel.front();
721    pointers.clear();
722    int index = 0;
723    std::vector<tree::Node*>::const_iterator selected;
724    for(selected=sel.begin();selected!=sel.end();++selected)
725      {
726        GimmickDebugMessage(5,
727                            "Requesting image from selected "
728                            <<(*selected)->GetAttribute("FullFileName")
729                            <<std::endl);
730            //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
731            boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
732            pointers.push_back(ph);
733        RequestReading(*selected,prio,index,ph);
734        //       AddEntryToMap(*selected);
735        prio--;
736        index++;
737      }
738         mViewer->SetImageVector(pointers);
739         //Going up
740         prio = maxprio + 20;
741         std::vector<tree::Node*> up;
742         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
743         std::vector<tree::Node*>::iterator iterUp;
744         for(iterUp=up.begin();iterUp!=up.end();++iterUp)
745         {
746                 GimmickDebugMessage(5,
747                                 "Requesting image from neighbors up "
748                                 <<(*iterUp)->GetAttribute("FullFileName")
749                                 <<std::endl);
750 //              ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
751                 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
752                 RequestReading(*iterUp,prio,-1,ph);
753                 //              AddEntryToMap(*iterUp);
754                 prio--;
755                 if (prio == maxprio) break;
756         }
757
758         //Going down
759         prio = maxprio + 19;
760         std::vector<tree::Node*> down;
761         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
762         std::vector<tree::Node*>::iterator iterDown;
763         for(iterDown=down.begin();iterDown!=down.end();++iterDown)
764         {
765                 GimmickDebugMessage(5,
766                                 "Requesting image from neighbors down "
767                                 <<(*iterDown)->GetAttribute("FullFileName")
768                                 <<std::endl);
769                 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
770                 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
771                 RequestReading(*iterDown,prio,-1,ph);
772                 //              AddEntryToMap(*iterDown);
773                 prio--;
774                 if (prio == maxprio) break;
775         }
776    }
777    else
778    {
779            pointers.clear();
780            //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
781            boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
782            pointers.push_back(ph);
783            mViewer->SetImageVector(pointers);
784    }
785   }
786
787   //==================================================
788
789   //==================================================
790
791 #if defined(WIN32)
792   //==================================================
793    void  WxGimmickView::OnInternalIdle()
794    {
795      if (!mConstructed) return;
796      static bool first_time = true;
797      if (false)
798      {
799        first_time = false;
800      }
801    //   GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
802         //  mViewer->StartPlayer();
803      if(mViewer)
804      {
805         mViewer->RefreshIfNecessary();
806      }
807   }
808 #else
809   void WxGimmickView::UpdateWindowUI(long flags)
810   {
811           if(mViewer)
812      {
813         mViewer->RefreshIfNecessary();
814      }
815   }
816 #endif
817    //==================================================
818
819   //==================================================
820    void  WxGimmickView::ClearSelection()
821    {
822         pointers.clear();
823         pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
824         //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
825         mViewer->SetImageVector(pointers);
826         mViewer->RefreshIfNecessary();
827         ResetExtent();
828   }
829
830   //=================================================
831  
832   //=================================================
833   void WxGimmickView::OnRemove(wxCommandEvent& event)
834   {
835         //TODO Select current tree handler       
836      wxBusyCursor busy;
837          std::string remove;
838          mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
839          GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
840          mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
841      ClearSelection();
842   }
843   //=================================================
844
845
846   //=================================================
847   void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
848   {
849      mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
850    //  GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
851   }
852
853   //=================================================
854   void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
855   {
856      mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
857      wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
858   }
859
860    //=================================================
861   void WxGimmickView::AddDir(std::string dirName)
862   {
863      mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
864
865 //EED                                           this,
866                                                 NULL,
867         
868                                                 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
869      mCurrentDirectory = crea::std2wx(dirName);
870      mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
871      mProgressDialog->Pulse(_T("Updating view..."));
872
873      UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
874      killProgress();
875      DisplayAddSummary();
876   }
877
878    //=================================================
879   void WxGimmickView::OnSynchronize(wxCommandEvent& event)
880   {       
881     wxBusyCursor busy;
882     const wxString choices[] = { _T("Check database for files deletion and addition and give a report."), 
883                                 _T("Check database for files deletion, addition and attributes change. Then give a report."), 
884                                 _T("Repair database (remove deleted files and add new files)."), 
885                                 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
886
887     wxSingleChoiceDialog dialog(this,
888                                 _T("Select one of the following synchronization actions:\n")
889                                 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
890                                 _T("Synchronization Settings"),
891                                 WXSIZEOF(choices), choices);
892
893     //dialog.SetSelection(0);
894
895     if (dialog.ShowModal() == wxID_OK)
896     {
897                         wxBusyCursor busy;
898         int sel=dialog.GetSelection();
899         bool repair=false;
900         bool checkAttributes=false;
901         if(sel==2 || sel==3){repair=true;}
902         if(sel==1 || sel==3){checkAttributes=true;}
903         std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
904         wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
905         if(sel==2 || sel==3){
906                 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
907         }
908                 
909     }
910   }
911   //=================================================
912
913   //=================================================
914   void WxGimmickView::OnSettings(wxCommandEvent& event)
915   {
916     wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
917     wxBoxSizer  *siz = new wxBoxSizer(wxVERTICAL);
918     // Notebook
919     wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
920     
921     siz->Add( nb,1,wxGROW  ,0);  
922     CreateSettingsDialog(nb,dial);
923     dial->SetSizer(siz);
924     dial->ShowModal();
925   }
926
927   //=================================================
928   void WxGimmickView::OnImportExport(wxCommandEvent &Event)
929   {
930         wxBusyCursor busy;
931         // Test if one image is selected => export
932         // if not =>import
933     if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
934         {
935                 ExportImages();
936         }
937         else
938         {
939                 ImportImages();
940         }
941   }
942
943   void WxGimmickView::ExportImages()
944   {
945                 //Archive selection: name, emplacement
946                 //same process than copy local but to a zip
947                 // if settings are yes "always ask for descriptor addition", ask
948                 // if settings are yes, adding descriptor
949   }
950
951   void WxGimmickView::ImportImages()
952   {
953                 //Find the *.zip
954                 //dezip
955                 // Contain a descriptor.text
956                 // create a new database, and add to database
957                 // if not, add to current database
958                 // 
959   }
960
961   //=================================================
962   //AndresDonadio
963   void WxGimmickView::OnTools(wxCommandEvent& event)
964   {
965         mViewer->StopPlayer();
966         
967         wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
968
969         wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
970         wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
971         wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);     
972         dialSizer->Add(nb,1,wxGROW,0);
973         dialSizer->Add(buttonsSizer,0,wxGROW);
974
975 #if defined(BUILD_BRUKER)
976         //First page: Bruker Image Reader
977         WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
978         nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
979 #endif
980
981         dial->SetSizer(dialSizer, true);
982         dial->Layout();
983         dial->ShowModal();
984
985         if (dial->GetReturnCode() == wxID_OK)
986         {
987 #if defined(BUILD_BRUKER)
988                 if (nb->GetSelection()==0)//Selection: Bruker Image Reader  
989                 {
990                         std::string inputDir  = crea::wx2std(gimmickTools->getInputDir());
991                         std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
992
993                         bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
994
995                         if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
996                         {
997                                 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
998                                                   _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
999                                 {
1000                                         Bruker2Dicom b2d;    
1001                                         b2d.SetInputDirectory(inputDir);
1002                                         b2d.SetOutputDirectory(outputDir);
1003                                         b2d.SetConvertModeToDicom();
1004                                         b2d.verbose=false;
1005                                         b2d.Execute();
1006                                         if (addToDB)
1007                                         {
1008         std::cout <<"after addToDB" << std::endl;
1009                                                 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
1010
1011 //EED                                                                                   this,
1012                                                                                         NULL,
1013
1014                                                                                         wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
1015         std::cout <<"after new wxProgressDialog" << std::endl;                                          
1016                                                 mCurrentDirectory = gimmickTools->getOutputDir();
1017         std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;                                               
1018                                                 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
1019         std::cout <<"after mGimmick->AddDir" << std::endl;                                      
1020                                                 mProgressDialog->Pulse(_T("Updating view..."));
1021         std::cout <<"after mProgressDialog->Pulse" << std::endl;
1022                                                 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1023         std::cout <<"after UpdateTreeViewLevel" << std::endl;                                           
1024                                                 killProgress();
1025         std::cout <<"after delete mProgressDialog" << std::endl;                                                        
1026                                                 DisplayAddSummary();
1027         std::cout <<"after dDisplayAddSummary" << std::endl;                                            
1028                                         }       
1029                                 }
1030                         }
1031                         else
1032                         {
1033                                 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
1034                         }
1035         }
1036         delete gimmickTools;
1037 #endif
1038         }
1039         mViewer->StartPlayer();
1040   }
1041
1042   //=================================================
1043
1044   void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1045   {
1046           //First page: Customization of configurations
1047           //Copy Path string
1048           std::string cp;
1049           mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1050           //Database Path String
1051           std::string dp;
1052           mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1053           //Syncronization Event String
1054           std::string se;
1055           mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1056           //Syncronization Frequency String
1057           std::string sf;
1058           mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1059
1060           WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1061
1062           nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1063
1064           //Second page: Creation of Databases
1065           /*wxPanel* databaseCreation=new wxPanel(nb);
1066           nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1067
1068           //Second page (temporary): Connection to PACS
1069           WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1070           nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1071
1072           //Third page: CD/DVD Watch
1073           WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1074           nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1075
1076           //Fourth page: Selection of attributes to show
1077           std::vector<std::string> shown;
1078           std::vector<std::string> nShown;
1079           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1080           int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1081           WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1082           nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1083   }
1084
1085   //===================================================================
1086   void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown, 
1087           std::vector<std::string>& nShown, int level)
1088   {
1089           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1090   }
1091
1092   //===================================================================
1093   void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1094   {
1095           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1096           std::vector<std::string> n=nShown;
1097           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1098   }
1099   //===================================================================
1100   void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1101           const std::string& dbPath,
1102           const std::string& syncEvent,
1103           const std::string& syncFreq)
1104   {
1105           mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1106           mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1107           mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1108           mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1109   }
1110
1111   //===================================================================
1112   void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1113   {
1114          mListener->SetMonitoredDrive(drive);
1115          mListener->SetAddFilesState(addFiles);
1116          mListener->SetRemoveFilesState(removeFiles);
1117   }
1118
1119   //========================================================================
1120
1121   void WxGimmickView::OnDriveMount(bool mount)
1122   {
1123           GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1124           std::string drive;
1125           mListener->GetMonitoredDrive(drive);
1126           
1127           if(mount)
1128           {
1129                 mViewer->StopPlayer();
1130                 wxBusyCursor busy;
1131                 wxString title(_T("Adding drive"));
1132                 mProgressDialog = 
1133                 new wxProgressDialog(_T("Adding drive"),
1134                                         _T(""),
1135                                         1000,
1136
1137 //EED                                   this,
1138                                         NULL,
1139
1140                                         wxPD_ELAPSED_TIME |
1141                                         //                             wxPD_ESTIMATED_TIME | 
1142                                         //                             wxPD_REMAINING_TIME |
1143                                         wxPD_CAN_ABORT );
1144                 mCurrentDirectory = crea::std2wx(drive);
1145                 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1146                 mProgressDialog->Pulse(_T("Updating view..."));
1147                 
1148                 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1149                 killProgress();
1150                 DisplayAddSummary();
1151                 mViewer->StartPlayer();  
1152           }
1153           else
1154           {  
1155                   mGimmick->DeleteDrive(drive);
1156                   UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1157           } 
1158   }
1159
1160    //========================================================================
1161
1162   void WxGimmickView::StartListeningThread()
1163   {
1164           mListener->Resume();
1165   }
1166
1167    //========================================================================
1168
1169   void WxGimmickView::StopListeningThread()
1170   {
1171           mListener->Pause();
1172   }
1173
1174   //========================================================================
1175   void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1176   {
1177     wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1178     wxBoxSizer  *siz = new wxBoxSizer(wxVERTICAL);
1179     WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1180
1181     siz->Add( ef,1,wxGROW  ,0); 
1182     dial->SetSizer(siz);
1183     dial->ShowModal();  
1184   }
1185
1186         
1187
1188  //========================================================================
1189   void WxGimmickView::DumpTags(std::string i_filename)
1190   {
1191     WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1192     pan->ShowModal();  
1193   }
1194
1195   //========================================================================
1196   void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1197   {
1198         std::vector<std::string> storages;
1199         Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1200         for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1201         {
1202                 storages.push_back(it->first);
1203         }
1204
1205     WxExportDlg* exp= new WxExportDlg(this,storages);
1206         if ( exp->ShowModal() ==ID_EXPORT_OK)
1207         {
1208                 std::string storage = exp->GetStorage();
1209                 mProgressDialog = 
1210             new wxProgressDialog(_T("Adding file(s)"),
1211                                _T(""),
1212                                1000,
1213
1214 //EED                           this,
1215                                 NULL,
1216
1217                                wxPD_ELAPSED_TIME |
1218                                // wxPD_ESTIMATED_TIME |
1219                                // wxPD_REMAINING_TIME |
1220                                wxPD_CAN_ABORT );
1221                 mGimmick->AddFiles(storage,i_filenames);
1222                 mProgressDialog->Pulse(_T("Updating view..."));
1223                 UpdateTreeViewLevel(storage,1);
1224                 killProgress();
1225                 DisplayAddSummary();    
1226         }
1227   }
1228
1229
1230
1231   //========================================================================
1232   void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1233   {
1234      mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1235      UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1236   }
1237
1238   //=================================================
1239   /// AddProgress Gimmick callback
1240   void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1241   {
1242     char mess[200];
1243     sprintf(mess,"%i dirs : %i files :\n            %i handled - %i added",
1244            p.GetNumberScannedDirs(),
1245            p.GetNumberScannedFiles(),
1246            p.GetNumberHandledFiles(),
1247            p.GetNumberAddedFiles());
1248     //    std::cout << "OnAddProgress "<<mess<<std::endl;
1249     wxString s(wxString::From8BitData(mess));
1250     //  std::cout << "Pulse"<<std::endl;
1251
1252         if(mProgressDialog != 0)
1253         {
1254                 if (!mProgressDialog->Pulse(s)) 
1255                   {
1256                 p.SetStop();
1257                   }
1258         }
1259     //  std::cout << "OnAddProgress ok"<<std::endl;
1260   }
1261   //=================================================
1262
1263   //=================================================
1264   void WxGimmickView::DisplayAddSummary()
1265   {
1266       std::stringstream mess(mGimmick->getSummary());
1267     time_t end;
1268         time(&end);
1269         mess << "time to scan :" << difftime(end,mstart) << "sec";
1270     wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1271   }
1272
1273   ////////////////////////////////////////////////
1274   // Add a DB to application                    //
1275   // @param event : WxEvent                     //
1276   // @return : -                                //
1277   ////////////////////////////////////////////////
1278   void WxGimmickView::OnAddDB(wxCommandEvent& event)
1279   {
1280           //Select DB
1281           long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1282           std::string wc("*.sqlite3*");
1283           wxFileDialog* FD = new wxFileDialog( 0, 
1284                                          _T("Select file"),
1285                                          _T(""),
1286                                          _T(""),
1287                                          crea::std2wx(wc),
1288                                          style,
1289                                          wxDefaultPosition);
1290     
1291     if (FD->ShowModal()==wxID_OK)
1292         {
1293                 wxBusyCursor busy;
1294                 wxArrayString files;
1295                 FD->GetPaths(files);
1296                 std::stringstream st;
1297                 for(int i = 0; i< files.size(); i++)
1298                 {
1299                         //get name of DB (file name)
1300                   size_t pos = files[i].find_last_of(_T("\\"));
1301                   std::string name = crea::wx2std(files[i].substr(pos+1));
1302                   pos = name.find_last_of(".");
1303                   name = name.substr(0,pos);
1304                   //create TreeHandler
1305                   mGimmick->addDB(name, crea::wx2std(files[i]));
1306                   //create TreeView
1307                   CreateSingleTreeView(name);
1308                 }
1309         }
1310   }
1311     ////////////////////////////////////////////////////
1312   // Create a DB from an Attributes Descriptor files  //
1313   // @param event : WxEvent                                     //
1314   // @return : -                                                //
1315   //////////////////////////////////////////////////
1316   void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1317   {
1318         //  PACSConnection("");
1319         WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1320         DescriptorPan->Layout();
1321         if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1322         {
1323                 wxBusyCursor busy;
1324                 std::string file(DescriptorPan->GetDescriptor());
1325                 if (!file.empty())
1326                 {
1327                         size_t pos = file.find_last_of("\\");
1328                         std::string name = file.substr(pos+1);
1329                         std::string directory = file.substr(0,pos);
1330                         pos = name.find_last_of(".");
1331                         name = name.substr(0,pos);
1332                         //get directory to store DB
1333                         directory +=  "\\" + name + ".sqlite3";
1334                         //create createDB
1335                         mGimmick->createDB(name, file,directory);
1336                         //create TreeHandler
1337                         mGimmick->addDB(name, directory);
1338                         //create TreeView
1339                         CreateSingleTreeView(name);
1340                 }
1341         }
1342   }
1343
1344   void WxGimmickView::killProgress()
1345   {
1346                 mProgressDialog->Resume();
1347                 mProgressDialog->Destroy();
1348                 mProgressDialog = 0;
1349   }
1350
1351    //=================================================
1352
1353    //=================================================
1354   BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1355     EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1356     EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1357     EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1358     EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1359     EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1360     EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1361     EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1362     EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1363   END_EVENT_TABLE()
1364   //=================================================
1365
1366 } // EO namespace creaImageIO
1367