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