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