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