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