]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxGimmickView.cpp
#3208 creaImageIO Feature New Normal - branch mingw64
[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
508 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
509 #if wxMAJOR_VERSION <= 2
510     long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
511 #else
512     long style = wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE;
513 #endif
514
515
516     std::string wc("*");
517     wxFileDialog* FD = new wxFileDialog( 0, 
518                                          _T("Select file"),
519                                          _T(""),
520                                          _T(""),
521                                          crea::std2wx(wc),
522                                          style,
523                                          wxDefaultPosition);
524     
525     if (FD->ShowModal()==wxID_OK)
526       {
527         wxBusyCursor busy;
528
529         wxArrayString files;
530         FD->GetPaths(files);
531         unsigned int i;
532         std::vector<std::string> filenames;
533         for (i=0;i<files.GetCount();++i)
534         {
535           filenames.push_back(wx2std(files[i]));
536           GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
537         }
538
539         mProgressDialog = 
540           new wxProgressDialog(_T("Adding file(s)"),
541                                _T(""),
542                                1000,
543 //                             this,
544                                NULL,
545                                wxPD_ELAPSED_TIME |
546                                // wxPD_ESTIMATED_TIME |
547                                // wxPD_REMAINING_TIME |
548                                wxPD_CAN_ABORT );
549
550         // TO DO : select the current tree handler
551         mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
552
553         mProgressDialog->Pulse(_T("Updating view..."));
554
555         UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
556         killProgress();
557         DisplayAddSummary();    
558
559       }
560         mViewer->StartPlayer(); 
561   }
562   //=================================================
563
564   //=================================================
565   void WxGimmickView::OnAddDir(wxCommandEvent& event)
566   {
567     mViewer->StopPlayer();
568         std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
569     long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
570     wxDirDialog* FD = 
571          new wxDirDialog( 0, 
572                        _T("Select directory"),
573                        mCurrentDirectory,
574                        style);
575     
576     if (FD->ShowModal()==wxID_OK)
577     {
578                         time(&mstart);
579         std::string dirname = wx2std (FD->GetPath());
580         bool recurse =  isNeedRecursive(dirname);
581         if (recurse)
582         {
583              recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
584         }
585
586                 wxBusyCursor busy;
587                 wxString title(_T("Adding directory"));
588                 if (recurse) 
589                 title = _T("Adding directory (recursive)");
590                 mProgressDialog = 
591                 new wxProgressDialog(_T("Adding directory"),
592                                         _T(""),
593                                         NumberFilesToAdd(dirname,recurse),
594
595 //EED                                   this,
596                                         NULL,
597
598                                         wxPD_ELAPSED_TIME | 
599                                         wxPD_SMOOTH |
600                                         // wxPD_ESTIMATED_TIME |
601                                         // wxPD_REMAINING_TIME |
602                                         wxPD_CAN_ABORT );
603
604                 mCurrentDirectory = FD->GetPath();  
605                 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
606                 mProgressDialog->Pulse(_T("Updating view..."));
607
608                 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
609                 killProgress();
610                 DisplayAddSummary();
611           }
612     mViewer->StartPlayer();
613         delete FD;
614   }
615
616
617   //=================================================
618   // Determines number of files potentially to add to database
619    int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
620   {
621            int nb = 0;
622            if ( !boost::filesystem::exists( dirpath ) ) return nb;
623            boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
624            for ( boost::filesystem::directory_iterator itr( dirpath );  itr != end_itr;  ++itr )
625           {
626                 // If is directory & recurse : do recurse
627                 if ( boost::filesystem::is_directory(itr->status()) )
628                 {
629                         if (recursive) 
630                         {
631                                 nb += NumberFilesToAdd(itr->path().string(), recursive);
632                         }
633                 }
634                 else
635                 {
636                         nb++;
637                 }
638           }
639         return nb;
640   }
641
642    //=================================================
643    // Test a directory to know if contains sub-directory to analyze
644   bool WxGimmickView::isNeedRecursive(std::string i_name)
645   {
646       boost::filesystem::directory_iterator iter(i_name), end_iter;
647       //bool bfindir = false;
648                   for(; iter != end_iter; ++iter)
649                   {
650                           if(boost::filesystem::is_directory(*iter))
651                           {
652                                   return true;
653                           }
654                   }
655                   return false;
656   }
657   //=================================================
658
659   //=================================================
660   void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
661   {      
662     GimmickDebugMessage(5,
663                         "WxGimmickView::OnSelectionChange"
664                         <<std::endl);
665     wxBusyCursor busy;
666         bool valid=true;
667         
668         if(sel.size()==0)
669         {
670                 valid= ValidateSelected(NULL,
671                                 mSelectionMinDimension,
672                                 mSelectionMaxDimension );
673         }
674         else if(needProcess)
675         {
676                 ResetExtent();
677                 std::vector<tree::Node*>::const_iterator i;
678                 for(i=sel.begin();i!=sel.end()&&valid;++i)
679                 {
680                         valid= ValidateSelected((*i),
681                                 mSelectionMinDimension,
682                                 mSelectionMaxDimension );
683                 }
684         }
685         else if(isSelection)
686         {
687                 valid= ValidateSelected(sel.front(),
688                                 mSelectionMinDimension,
689                                 mSelectionMaxDimension );
690         }
691         else
692         {
693                 ResetExtent();
694                 std::vector<tree::Node*>::const_iterator i;
695                 for(i=sel.begin();i!=sel.end()&&valid;++i)
696                 {
697                         valid= ValidateSelected((*i),
698                                 mSelectionMinDimension,
699                                 mSelectionMaxDimension );
700                 }
701         }
702         mText->SetLabel(crea::std2wx(GetMessage()));
703     /*if(valid)
704       {
705         ReadImageThreaded(sel);
706       }
707     else
708       {
709                   ClearSelection();
710       }*/
711           
712   printf("EED Warnning WxGimmickView::OnSelectionChange ....... To avoid threads conflicts//ReadImageThreaded(sel)\n ");
713 //EED1  ReadImageThreaded(sel);
714
715
716    }
717
718   //==================================================
719
720   //==================================================
721   ///Reads Images (Threaded)
722   void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
723   {     
724    GimmickDebugMessage(5,
725                        "ReadImageThreaded"
726                        <<std::endl);
727    int maxprio = GetMaximalPriority();
728    int prio = maxprio + 2000;
729
730    if(sel.size()>0)
731    {
732    //First load the selected images
733    mCurImageItemToShow = sel.front();
734    pointers.clear();
735    int index = 0;
736    std::vector<tree::Node*>::const_iterator selected;
737    for(selected=sel.begin();selected!=sel.end();++selected)
738      {
739        GimmickDebugMessage(5,
740                            "Requesting image from selected "
741                            <<(*selected)->GetAttribute("FullFileName")
742                            <<std::endl);
743            //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
744            boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
745            pointers.push_back(ph);
746        RequestReading(*selected,prio,index,ph);
747        //       AddEntryToMap(*selected);
748        prio--;
749        index++;
750      }
751         mViewer->SetImageVector(pointers);
752         //Going up
753         prio = maxprio + 20;
754         std::vector<tree::Node*> up;
755         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
756         std::vector<tree::Node*>::iterator iterUp;
757         for(iterUp=up.begin();iterUp!=up.end();++iterUp)
758         {
759                 GimmickDebugMessage(5,
760                                 "Requesting image from neighbors up "
761                                 <<(*iterUp)->GetAttribute("FullFileName")
762                                 <<std::endl);
763 //              ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
764                 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
765                 RequestReading(*iterUp,prio,-1,ph);
766                 //              AddEntryToMap(*iterUp);
767                 prio--;
768                 if (prio == maxprio) break;
769         }
770
771         //Going down
772         prio = maxprio + 19;
773         std::vector<tree::Node*> down;
774         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
775         std::vector<tree::Node*>::iterator iterDown;
776         for(iterDown=down.begin();iterDown!=down.end();++iterDown)
777         {
778                 GimmickDebugMessage(5,
779                                 "Requesting image from neighbors down "
780                                 <<(*iterDown)->GetAttribute("FullFileName")
781                                 <<std::endl);
782                 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
783                 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
784                 RequestReading(*iterDown,prio,-1,ph);
785                 //              AddEntryToMap(*iterDown);
786                 prio--;
787                 if (prio == maxprio) break;
788         }
789    }
790    else
791    {
792            pointers.clear();
793            //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
794            boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
795            pointers.push_back(ph);
796            mViewer->SetImageVector(pointers);
797    }
798   }
799
800   //==================================================
801
802   //==================================================
803
804 #if defined(WIN32)
805   //==================================================
806    void  WxGimmickView::OnInternalIdle()
807    {
808      if (!mConstructed) return;
809      static bool first_time = true;
810      if (false)
811      {
812        first_time = false;
813      }
814    //   GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
815         //  mViewer->StartPlayer();
816      if(mViewer)
817      {
818         mViewer->RefreshIfNecessary();
819      }
820   }
821 #else
822   void WxGimmickView::UpdateWindowUI(long flags)
823   {
824           if(mViewer)
825      {
826         mViewer->RefreshIfNecessary();
827      }
828   }
829 #endif
830    //==================================================
831
832   //==================================================
833    void  WxGimmickView::ClearSelection()
834    {
835         pointers.clear();
836         pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
837         //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
838         mViewer->SetImageVector(pointers);
839         mViewer->RefreshIfNecessary();
840         ResetExtent();
841   }
842
843   //=================================================
844  
845   //=================================================
846   void WxGimmickView::OnRemove(wxCommandEvent& event)
847   {
848         //TODO Select current tree handler       
849      wxBusyCursor busy;
850          std::string remove;
851          mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
852          GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
853          mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
854      ClearSelection();
855   }
856   //=================================================
857
858
859   //=================================================
860   void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
861   {
862      mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
863    //  GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
864   }
865
866   //=================================================
867   void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
868   {
869      mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
870      wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
871   }
872
873    //=================================================
874   void WxGimmickView::AddDir(std::string dirName)
875   {
876      mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
877
878 //EED                                           this,
879                                                 NULL,
880         
881                                                 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
882      mCurrentDirectory = crea::std2wx(dirName);
883      mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
884      mProgressDialog->Pulse(_T("Updating view..."));
885
886      UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
887      killProgress();
888      DisplayAddSummary();
889   }
890
891    //=================================================
892   void WxGimmickView::OnSynchronize(wxCommandEvent& event)
893   {       
894     wxBusyCursor busy;
895     const wxString choices[] = { _T("Check database for files deletion and addition and give a report."), 
896                                 _T("Check database for files deletion, addition and attributes change. Then give a report."), 
897                                 _T("Repair database (remove deleted files and add new files)."), 
898                                 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
899
900     wxSingleChoiceDialog dialog(this,
901                                 _T("Select one of the following synchronization actions:\n")
902                                 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
903                                 _T("Synchronization Settings"),
904                                 WXSIZEOF(choices), choices);
905
906     //dialog.SetSelection(0);
907
908     if (dialog.ShowModal() == wxID_OK)
909     {
910                         wxBusyCursor busy;
911         int sel=dialog.GetSelection();
912         bool repair=false;
913         bool checkAttributes=false;
914         if(sel==2 || sel==3){repair=true;}
915         if(sel==1 || sel==3){checkAttributes=true;}
916         std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
917         wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
918         if(sel==2 || sel==3){
919                 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
920         }
921                 
922     }
923   }
924   //=================================================
925
926   //=================================================
927   void WxGimmickView::OnSettings(wxCommandEvent& event)
928   {
929     wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
930     wxBoxSizer  *siz = new wxBoxSizer(wxVERTICAL);
931     // Notebook
932     wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
933     
934     siz->Add( nb,1,wxGROW  ,0);  
935     CreateSettingsDialog(nb,dial);
936     dial->SetSizer(siz);
937     dial->ShowModal();
938   }
939
940   //=================================================
941   void WxGimmickView::OnImportExport(wxCommandEvent &Event)
942   {
943         wxBusyCursor busy;
944         // Test if one image is selected => export
945         // if not =>import
946     if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
947         {
948                 ExportImages();
949         }
950         else
951         {
952                 ImportImages();
953         }
954   }
955
956   void WxGimmickView::ExportImages()
957   {
958                 //Archive selection: name, emplacement
959                 //same process than copy local but to a zip
960                 // if settings are yes "always ask for descriptor addition", ask
961                 // if settings are yes, adding descriptor
962   }
963
964   void WxGimmickView::ImportImages()
965   {
966                 //Find the *.zip
967                 //dezip
968                 // Contain a descriptor.text
969                 // create a new database, and add to database
970                 // if not, add to current database
971                 // 
972   }
973
974   //=================================================
975   //AndresDonadio
976   void WxGimmickView::OnTools(wxCommandEvent& event)
977   {
978         mViewer->StopPlayer();
979         
980         wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
981
982         wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
983         wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
984         wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);     
985         dialSizer->Add(nb,1,wxGROW,0);
986         dialSizer->Add(buttonsSizer,0,wxGROW);
987
988 #if defined(BUILD_BRUKER)
989         //First page: Bruker Image Reader
990         WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
991         nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
992 #endif
993
994         dial->SetSizer(dialSizer, true);
995         dial->Layout();
996         dial->ShowModal();
997
998         if (dial->GetReturnCode() == wxID_OK)
999         {
1000 #if defined(BUILD_BRUKER)
1001                 if (nb->GetSelection()==0)//Selection: Bruker Image Reader  
1002                 {
1003                         std::string inputDir  = crea::wx2std(gimmickTools->getInputDir());
1004                         std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
1005
1006                         bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
1007
1008                         if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
1009                         {
1010                                 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
1011                                                   _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
1012                                 {
1013                                         Bruker2Dicom b2d;    
1014                                         b2d.SetInputDirectory(inputDir);
1015                                         b2d.SetOutputDirectory(outputDir);
1016                                         b2d.SetConvertModeToDicom();
1017                                         b2d.verbose=false;
1018                                         b2d.Execute();
1019                                         if (addToDB)
1020                                         {
1021         std::cout <<"after addToDB" << std::endl;
1022                                                 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
1023
1024 //EED                                                                                   this,
1025                                                                                         NULL,
1026
1027                                                                                         wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
1028         std::cout <<"after new wxProgressDialog" << std::endl;                                          
1029                                                 mCurrentDirectory = gimmickTools->getOutputDir();
1030         std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;                                               
1031                                                 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
1032         std::cout <<"after mGimmick->AddDir" << std::endl;                                      
1033                                                 mProgressDialog->Pulse(_T("Updating view..."));
1034         std::cout <<"after mProgressDialog->Pulse" << std::endl;
1035                                                 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1036         std::cout <<"after UpdateTreeViewLevel" << std::endl;                                           
1037                                                 killProgress();
1038         std::cout <<"after delete mProgressDialog" << std::endl;                                                        
1039                                                 DisplayAddSummary();
1040         std::cout <<"after dDisplayAddSummary" << std::endl;                                            
1041                                         }       
1042                                 }
1043                         }
1044                         else
1045                         {
1046                                 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
1047                         }
1048         }
1049         delete gimmickTools;
1050 #endif
1051         }
1052         mViewer->StartPlayer();
1053   }
1054
1055   //=================================================
1056
1057   void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
1058   {
1059           //First page: Customization of configurations
1060           //Copy Path string
1061           std::string cp;
1062           mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
1063           //Database Path String
1064           std::string dp;
1065           mGimmick->GetSetting(SETTINGS_DBPATH,dp);
1066           //Syncronization Event String
1067           std::string se;
1068           mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
1069           //Syncronization Frequency String
1070           std::string sf;
1071           mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
1072
1073           WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
1074
1075           nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
1076
1077           //Second page: Creation of Databases
1078           /*wxPanel* databaseCreation=new wxPanel(nb);
1079           nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
1080
1081           //Second page (temporary): Connection to PACS
1082           WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
1083           nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
1084
1085           //Third page: CD/DVD Watch
1086           WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
1087           nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
1088
1089           //Fourth page: Selection of attributes to show
1090           std::vector<std::string> shown;
1091           std::vector<std::string> nShown;
1092           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
1093           int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
1094           WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
1095           nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
1096   }
1097
1098   //===================================================================
1099   void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown, 
1100           std::vector<std::string>& nShown, int level)
1101   {
1102           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
1103   }
1104
1105   //===================================================================
1106   void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
1107   {
1108           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
1109           std::vector<std::string> n=nShown;
1110           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
1111   }
1112   //===================================================================
1113   void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
1114           const std::string& dbPath,
1115           const std::string& syncEvent,
1116           const std::string& syncFreq)
1117   {
1118           mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
1119           mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
1120           mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
1121           mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
1122   }
1123
1124   //===================================================================
1125   void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
1126   {
1127          mListener->SetMonitoredDrive(drive);
1128          mListener->SetAddFilesState(addFiles);
1129          mListener->SetRemoveFilesState(removeFiles);
1130   }
1131
1132   //========================================================================
1133
1134   void WxGimmickView::OnDriveMount(bool mount)
1135   {
1136           GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
1137           std::string drive;
1138           mListener->GetMonitoredDrive(drive);
1139           
1140           if(mount)
1141           {
1142                 mViewer->StopPlayer();
1143                 wxBusyCursor busy;
1144                 wxString title(_T("Adding drive"));
1145                 mProgressDialog = 
1146                 new wxProgressDialog(_T("Adding drive"),
1147                                         _T(""),
1148                                         1000,
1149
1150 //EED                                   this,
1151                                         NULL,
1152
1153                                         wxPD_ELAPSED_TIME |
1154                                         //                             wxPD_ESTIMATED_TIME | 
1155                                         //                             wxPD_REMAINING_TIME |
1156                                         wxPD_CAN_ABORT );
1157                 mCurrentDirectory = crea::std2wx(drive);
1158                 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
1159                 mProgressDialog->Pulse(_T("Updating view..."));
1160                 
1161                 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1162                 killProgress();
1163                 DisplayAddSummary();
1164                 mViewer->StartPlayer();  
1165           }
1166           else
1167           {  
1168                   mGimmick->DeleteDrive(drive);
1169                   UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1170           } 
1171   }
1172
1173    //========================================================================
1174
1175   void WxGimmickView::StartListeningThread()
1176   {
1177           mListener->Resume();
1178   }
1179
1180    //========================================================================
1181
1182   void WxGimmickView::StopListeningThread()
1183   {
1184           mListener->Pause();
1185   }
1186
1187   //========================================================================
1188   void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
1189   {
1190     wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
1191     wxBoxSizer  *siz = new wxBoxSizer(wxVERTICAL);
1192     WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
1193
1194     siz->Add( ef,1,wxGROW  ,0); 
1195     dial->SetSizer(siz);
1196     dial->ShowModal();  
1197   }
1198
1199         
1200
1201  //========================================================================
1202   void WxGimmickView::DumpTags(std::string i_filename)
1203   {
1204     WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
1205     pan->ShowModal();  
1206   }
1207
1208   //========================================================================
1209   void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
1210   {
1211         std::vector<std::string> storages;
1212         Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
1213         for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
1214         {
1215                 storages.push_back(it->first);
1216         }
1217
1218     WxExportDlg* exp= new WxExportDlg(this,storages);
1219         if ( exp->ShowModal() ==ID_EXPORT_OK)
1220         {
1221                 std::string storage = exp->GetStorage();
1222                 mProgressDialog = 
1223             new wxProgressDialog(_T("Adding file(s)"),
1224                                _T(""),
1225                                1000,
1226
1227 //EED                           this,
1228                                 NULL,
1229
1230                                wxPD_ELAPSED_TIME |
1231                                // wxPD_ESTIMATED_TIME |
1232                                // wxPD_REMAINING_TIME |
1233                                wxPD_CAN_ABORT );
1234                 mGimmick->AddFiles(storage,i_filenames);
1235                 mProgressDialog->Pulse(_T("Updating view..."));
1236                 UpdateTreeViewLevel(storage,1);
1237                 killProgress();
1238                 DisplayAddSummary();    
1239         }
1240   }
1241
1242
1243
1244   //========================================================================
1245   void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
1246   {
1247      mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
1248      UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
1249   }
1250
1251   //=================================================
1252   /// AddProgress Gimmick callback
1253   void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
1254   {
1255     char mess[200];
1256     sprintf(mess,"%i dirs : %i files :\n            %i handled - %i added",
1257            p.GetNumberScannedDirs(),
1258            p.GetNumberScannedFiles(),
1259            p.GetNumberHandledFiles(),
1260            p.GetNumberAddedFiles());
1261     //    std::cout << "OnAddProgress "<<mess<<std::endl;
1262     wxString s(wxString::From8BitData(mess));
1263     //  std::cout << "Pulse"<<std::endl;
1264
1265         if(mProgressDialog != 0)
1266         {
1267                 if (!mProgressDialog->Pulse(s)) 
1268                   {
1269                 p.SetStop();
1270                   }
1271         }
1272     //  std::cout << "OnAddProgress ok"<<std::endl;
1273   }
1274   //=================================================
1275
1276   //=================================================
1277   void WxGimmickView::DisplayAddSummary()
1278   {
1279       std::stringstream mess(mGimmick->getSummary());
1280     time_t end;
1281         time(&end);
1282         mess << "time to scan :" << difftime(end,mstart) << "sec";
1283     wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
1284   }
1285
1286   ////////////////////////////////////////////////
1287   // Add a DB to application                    //
1288   // @param event : WxEvent                     //
1289   // @return : -                                //
1290   ////////////////////////////////////////////////
1291   void WxGimmickView::OnAddDB(wxCommandEvent& event)
1292   {
1293           //Select DB
1294           long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
1295           std::string wc("*.sqlite3*");
1296           wxFileDialog* FD = new wxFileDialog( 0, 
1297                                          _T("Select file"),
1298                                          _T(""),
1299                                          _T(""),
1300                                          crea::std2wx(wc),
1301                                          style,
1302                                          wxDefaultPosition);
1303     
1304     if (FD->ShowModal()==wxID_OK)
1305         {
1306                 wxBusyCursor busy;
1307                 wxArrayString files;
1308                 FD->GetPaths(files);
1309                 std::stringstream st;
1310                 for(int i = 0; i< files.size(); i++)
1311                 {
1312                         //get name of DB (file name)
1313                   size_t pos = files[i].find_last_of(_T("\\"));
1314                   std::string name = crea::wx2std(files[i].substr(pos+1));
1315                   pos = name.find_last_of(".");
1316                   name = name.substr(0,pos);
1317                   //create TreeHandler
1318                   mGimmick->addDB(name, crea::wx2std(files[i]));
1319                   //create TreeView
1320                   CreateSingleTreeView(name);
1321                 }
1322         }
1323   }
1324     ////////////////////////////////////////////////////
1325   // Create a DB from an Attributes Descriptor files  //
1326   // @param event : WxEvent                                     //
1327   // @return : -                                                //
1328   //////////////////////////////////////////////////
1329   void WxGimmickView::OnCreateDB(wxCommandEvent& event)
1330   {
1331         //  PACSConnection("");
1332         WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
1333         DescriptorPan->Layout();
1334         if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
1335         {
1336                 wxBusyCursor busy;
1337                 std::string file(DescriptorPan->GetDescriptor());
1338                 if (!file.empty())
1339                 {
1340                         size_t pos = file.find_last_of("\\");
1341                         std::string name = file.substr(pos+1);
1342                         std::string directory = file.substr(0,pos);
1343                         pos = name.find_last_of(".");
1344                         name = name.substr(0,pos);
1345                         //get directory to store DB
1346                         directory +=  "\\" + name + ".sqlite3";
1347                         //create createDB
1348                         mGimmick->createDB(name, file,directory);
1349                         //create TreeHandler
1350                         mGimmick->addDB(name, directory);
1351                         //create TreeView
1352                         CreateSingleTreeView(name);
1353                 }
1354         }
1355   }
1356
1357   void WxGimmickView::killProgress()
1358   {
1359                 mProgressDialog->Resume();
1360                 mProgressDialog->Destroy();
1361                 mProgressDialog = 0;
1362   }
1363
1364    //=================================================
1365
1366    //=================================================
1367   BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
1368     EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
1369     EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
1370     EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
1371     EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
1372     EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
1373     EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
1374     EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
1375     EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
1376   END_EVENT_TABLE()
1377   //=================================================
1378
1379 } // EO namespace creaImageIO
1380