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