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