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