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