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