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