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