creaImageIOWxGimmickView.cpp

Go to the documentation of this file.
00001 #include <creaImageIOPACSConnection.h>
00002 #include <creaImageIOWxPACSConnectionPanel.h>
00003 #include <creaImageIOWxGimmickView.h>
00004 #include <creaImageIOWxTreeView.h>
00005 #include <creaImageIOSystem.h>
00006 #include <creaImageIOWxCustomizeConfigPanel.h>
00007 #include <creaImageIOWxListenerPanel.h>
00008 #include <creaImageIOWxEditFieldsPanel.h>
00009 #include <creaImageIOWxAttributeSelectionPanel.h>
00010 #include <creaImageIOWxDescriptorPanel.h>
00011 #include <creaImageIOWxDumpPanel.h>
00012 #include <creaImageIOWxExportDlg.h>
00013 #include <creaImageIOWxOutputDlg.h>
00014 #include <creaImageIOOutputModel.h>
00015 
00016 using namespace crea;
00017 // Icons
00018 #include "icons/accept.xpm"
00019 #include "icons/add.xpm"
00020 #include "icons/folder-down.xpm"
00021 #include "icons/page-down.xpm"
00022 #include "icons/remove.xpm"
00023 #include "icons/database-add.xpm"
00024 #include "icons/create-database.xpm"
00025 #include "icons/help.xpm"
00026 #include "icons/synchronize.xpm"
00027 #include "icons/settings.xpm"
00028 #include "icons/tools.xpm"
00029 //#include "icons/import.xpm"
00030 
00031 #include <wx/imaglist.h>
00032 #include <wx/popupwin.h>
00033 #include<boost/filesystem/operations.hpp>
00034 #if defined(BUILD_BRUKER)
00035         #include "bruker2dicom.h"
00036 #endif
00037 
00038 
00039 #include <creaImageIOGimmick.h>
00040 #ifdef _DEBUG
00041 #define new DEBUG_NEW
00042 #endif
00043 
00044 namespace creaImageIO
00045 {
00046    
00047   //======================================================================
00048   // The ids of the different tools
00049   enum
00050     {
00051         TOOL_ADDFILES_ID    = 1,
00052         TOOL_ADDDIR_ID      = 2,
00053         TOOL_ADDDATABASE_ID = 3,
00054         TOOL_REMOVE_ID      = 4,
00055         TOOL_SYNCHRONIZE_ID = 5,
00056         TOOL_HELP_ID        = 6,
00057         TOOL_SETTINGS_ID    = 7,
00058         TOOL_TOOLS_ID       = 8,
00059         TOOL_CREATEDB_ID    = 9,
00060         TOOL_PACS_ID        = 10
00061     };
00062   //======================================================================
00063 
00064   //================================================================
00065   // 
00066   const int icon_number = 11;
00067   // Icon ids
00068   typedef enum
00069     {
00070       Icon_create_database,
00071       Icon_accept,
00072       Icon_add,
00073       Icon_folder_down,
00074       Icon_page_down,
00075       Icon_database_add,
00076       Icon_remove,
00077       Icon_synchronize,
00078       Icon_help,
00079       Icon_settings,
00080       Icon_tools
00081     }
00082     icon_id;
00083   //================================================================
00084 
00085   //================================================================
00086   /*
00087   const icon_id Icon[5] = { Icon_Database,  
00088                             Icon_Patient,
00089                             Icon_Study,
00090                             Icon_Series,
00091                             Icon_Image };
00092   */
00093   //================================================================
00094 
00095 
00096   //======================================================================
00097   // CTor
00098         WxGimmickView::WxGimmickView(boost::shared_ptr<Gimmick> gimmick,
00099                                wxWindow *parent, 
00100                                const wxWindowID id,
00101                                const wxPoint& pos, 
00102                                const wxSize& size,
00103                                int min_dim,
00104                                int max_dim,
00105                                int number_of_threads)
00106     : wxPanel(parent,id,pos,size),
00107       GimmickView(gimmick, number_of_threads),
00108       mProgressDialog(0),
00109       mConstructed(false)
00110   {
00111     GimmickDebugMessage(1,"WxGimmickView::WxGimmickView"
00112                         <<std::endl);
00113     // Sets the current directory to the home dir
00114     mCurrentDirectory =  std2wx(gimmick->GetHomeDirectory());
00115 
00116 
00117      // Connect the AddProgress callback
00118     gimmick->ConnectAddProgressObserver 
00119      ( boost::bind( &WxGimmickView::OnAddProgress , this, _1 ) );
00120 
00121     // Create the list of icons (mIcon)
00122     CreateIconList();
00123 
00124     // Global sizer
00125     msizer = new wxBoxSizer(wxVERTICAL);
00126 
00127     // Create the tool bar
00128     CreateToolBar(); 
00129     msizer->Add( mToolBar, 0, wxGROW, 0);
00130 
00131     // Split part below toolbar into notebook for views and panel
00132     // for preview, messages...
00133     mSplitter = new wxSplitterWindow( this , -1);
00134 
00135     // Notebook
00136     mNotebook = new wxNotebook(mSplitter,
00137                                -1, wxDefaultPosition, wxDefaultSize, 0);
00138 
00139     //Gimmick
00140     mGimmick=gimmick;
00141 
00142     mSelectionMaxDimension = max_dim;
00143     mSelectionMinDimension = min_dim;
00144     
00145     // Create the views
00146     CreateTreeViews();
00147 
00148     // Bottom panel 
00149     mBottomPanel = new wxPanel(mSplitter,-1);
00150     
00151     mbottom_sizer = new wxBoxSizer(wxVERTICAL); //HORIZONTAL);
00152     
00153     
00154     // Previewer
00155     mViewer = new WxViewer(mBottomPanel, wxID_ANY, wxT("Gimmick! Viewer"),wxDefaultPosition, wxDefaultSize );
00156         //pointers.push_back(new ImagePointerHolder(GetDefaultImage())
00157         pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
00158 
00159         mViewer->SetImageVector(pointers);
00160         mViewer->StartPlayer();
00161 
00162 
00163     mbottom_sizer->Add(mViewer,1,wxGROW,1);
00164     //    mViewer->Show();
00165 
00166     mText = new wxStaticText(mBottomPanel, wxID_ANY, wxT("Welcome to Gimmick!"));
00167     mbottom_sizer->Add(mText,0,wxGROW,0);
00168 
00169           
00170           
00171     mBottomPanel->SetSizer(mbottom_sizer);
00172 
00173     // Splitting
00174     int hsize = size.GetHeight();
00175 
00176     int top_minsize = 450;
00177     int bottom_minsize = 50;
00178 
00179     mSplitter->SetMinimumPaneSize( bottom_minsize );
00180     mSplitter->SplitHorizontally( mNotebook, mBottomPanel, 
00181                                   top_minsize);
00182 
00183     msizer->Add( mSplitter, 1, wxGROW, 0);
00184 
00185     mProgressDialog=0;
00186     SetSizer( msizer );     
00187     SetAutoLayout(true);
00188     Layout();
00189     //mListener=new Listener();
00190     //mListener->ConnectObserver(boost::bind( &WxGimmickView::OnDriveMount, this, _1 ) );
00191     //mListener->Create();
00192    // mListener->Run();
00193    // mListener->Pause();
00194 
00195     mConstructed = true;
00196   }
00197   //======================================================================
00198 
00199   //======================================================================
00201   WxGimmickView::~WxGimmickView()
00202   {
00203         // stop the viewer before application exit.
00204     mViewer->StopPlayer();
00205     GimmickDebugMessage(1,"WxGimmickView::~WxGimmickView"
00206                         <<std::endl);
00207         delete mIcon;
00208         delete mViewer;
00209     //if(mListener->IsAlive())   {        mListener->Delete();    }
00210   }
00211   //======================================================================
00212   
00213   //======================================================================
00215   void WxGimmickView::CreateToolBar()
00216   {
00217     long style = wxTB_HORIZONTAL | wxNO_BORDER | wxTB_TEXT;
00218     mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize,
00219                              style);
00220 
00221     mToolAddFile = mToolBar->AddTool( TOOL_ADDFILES_ID, 
00222                                       _T("Add file(s)"),
00223                                       mIcon->GetBitmap(Icon_page_down),
00224                                       _T("Add one or more file to database")
00225                                       );
00226     mToolAddDir = mToolBar->AddTool( TOOL_ADDDIR_ID, 
00227                                       _T("Add folder"),
00228                                       mIcon->GetBitmap(Icon_folder_down),
00229                                       _T("Add the content of a folder to database")
00230                                       );
00231     mToolAddDatabase = mToolBar->AddTool( TOOL_ADDDATABASE_ID, 
00232                                       _T("Open database"),
00233                                       mIcon->GetBitmap(Icon_database_add),
00234                                       _T("Open a local or distant database")
00235                                       );
00236     mToolRemove = mToolBar->AddTool( TOOL_REMOVE_ID, 
00237                                       _T("Remove"),
00238                                       mIcon->GetBitmap(Icon_remove),
00239                                       _T("Remove selected items")
00240                                       );
00241     mToolSynchronize = mToolBar->AddTool( TOOL_SYNCHRONIZE_ID, 
00242                                       _T("Synchronize"),
00243                                       mIcon->GetBitmap(Icon_synchronize),
00244                                       _T("Synchronizes the database with disk")
00245                                       );
00246     mToolHelp = mToolBar->AddTool( TOOL_HELP_ID, 
00247                                       _T("Help"),
00248                                       mIcon->GetBitmap(Icon_help),
00249                                       _T("Open help window")
00250                                       );
00251     mToolSettings = mToolBar->AddTool( TOOL_SETTINGS_ID, 
00252                                       _T("System settings"),
00253                                       mIcon->GetBitmap(Icon_settings),
00254                                       _T("Allows the modification of various system settings")
00255                                       );
00256     mToolTools = mToolBar->AddTool( TOOL_TOOLS_ID, 
00257                                       _T("Tools"),
00258                                       mIcon->GetBitmap(Icon_tools),
00259                                       _T("Applies tools to images")
00260                                       );
00261     mToolAddFile = mToolBar->AddTool( TOOL_CREATEDB_ID, 
00262                                       _T("Create database"),
00263                                       mIcon->GetBitmap(Icon_create_database),
00264                                       _T("Create DB from an Attributes Descriptor file")
00265                                       );
00266 #if defined(BUILD_PACS)
00267         mToolAddFile = mToolBar->AddTool( TOOL_PACS_ID, 
00268                                       _T("PACS Connection,"),
00269                                       mIcon->GetBitmap(Icon_create_database),
00270                                       _T("Echo, Find and Get to a PACS")
00271                                       );
00272 #endif
00273     //const wxBitmap& bitmap1, const wxString& shortHelpString = "", wxItemKind kind = wxITEM_NORMAL)
00274 
00275     mToolBar->Realize();
00276   }
00277   //======================================================================
00278 
00279  
00280   //======================================================================
00282   void WxGimmickView::CreateTreeView( TreeHandler* h)
00283   {
00284     std::string name(h->GetTree().GetAttribute("Name"));
00285     GimmickMessage(2,"Creating the tree view for '"<<
00286                    name<<"'"<<std::endl);
00287     // Create the WxTreeView
00288     WxTreeView* view = new WxTreeView(h, this, mNotebook, -1);
00289 
00290     // TO DO : TEST THAT A VIEW WITH SAME NAME IS NOT
00291     // ALREADY IN THE MAP
00292     GetTreeViewMap()[name] = view;
00293 
00294     // Add Notebook page
00295     mNotebook->AddPage( view, crea::std2wx(name) );
00296         
00297   }
00298 
00299   //======================================================================
00300   void WxGimmickView::GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
00301   {
00302         std::vector<std::string> files;
00303         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
00304         //ReadImagesNotThreaded(s, files, dim);
00305 
00306 
00307                 std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
00308         //              ReadImagesNotThreadedInfosInVector(db_name,output, files,dim,1);
00309   }
00310 
00311 
00312 
00313   //======================================================================
00314   void WxGimmickView::GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
00315   {
00316         std::vector<std::string> files;
00317         std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
00318         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
00319 
00320         ReadImagesNotThreadedInVector(s, files, dim);
00321   }
00322 
00323 
00326   void WxGimmickView::getSelectedFiles(std::vector<OutStrGimmick> &outG, std::vector< std::string> i_attr, 
00327                                        bool mult, const std::string out_model)
00328   {
00329         // First we select the files
00330         std::vector<std::string> files;
00331         std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
00332         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files);
00333 
00334         std::string asking;
00335         std::string dim;
00336         bool bsingle = isSingle(files.front());
00337         int i_dim_out;
00338         mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking);
00339         mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim);
00340 
00341         if (asking == "true")
00342         {
00343                 // display the output dialog box
00344                 // get dim
00345                 int idim;
00346                 sscanf(dim.c_str(),"%d",&idim);
00347                 WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle);
00348                 if (dlg->ShowModal() == wxID_OK)
00349                 {
00350                         dim = dlg->getDim();
00351                         mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking());
00352                         mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim);
00353                 }
00354                 else
00355                 {
00356                         return;
00357                 } 
00358         }
00359         else
00360         {
00361         }
00362         sscanf(dim.c_str(),"%d",&i_dim_out);
00363 
00364 
00365         // Next we create the structure for dicom output infos
00366         OutputAttr Oattr;
00367         Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()));
00368         if(i_attr.empty())
00369         {
00370                 // We don't send informations!
00371         }
00372         else if( i_attr.size() == 1 && i_attr.front() == "ALL")
00373         {
00374                 // we send all database
00375                 Oattr.inside.push_back("ALL");
00376         }
00377         else if( (i_attr.size() == 1 && i_attr.front() != "ALL") 
00378                 || (i_attr.size() >1) )
00379         {
00380                 mGimmick->fillVectInfos(i_attr, Oattr);
00381         }
00382         else
00383         {
00384                 // nothing
00385         }
00386 
00387         // Next we create model and sort files
00388         std::vector<std::string> sort_files(files);
00389         double zspacing = 1;
00390         if( !out_model.empty() )
00391         {
00392         /*      OutputModel mod(out_model);
00393                 mGimmick->isAttributeExist(db_name, mod);
00394                 mod.sort(files, sort_files);
00395         */}
00396 
00397         if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) )
00398         {
00399                 OutputModel *mod = new OutputModel();
00400                 zspacing = mod->orderFilesWithZspacing(sort_files);
00401                 delete mod;
00402         }
00403         // Now we read and create the waiting output (vtkImageData * or OutGimmickData *)
00404         readImages(outG, sort_files, Oattr, i_dim_out, zspacing);
00405   }
00406 
00407 
00408 
00409 
00410   //======================================================================
00411 
00412   //======================================================================
00413 
00414 
00415   //======================================================================
00416   void WxGimmickView::GetSelectedFiles(std::vector<std::string>& s)
00417   {
00418         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(s);
00419   }
00420   //======================================================================
00421 
00422   //======================================================================
00423   void WxGimmickView::GetImages(int dim, 
00424                                 const std::vector<std::string>& files, 
00425                                 std::vector<vtkImageData*>& s)
00426   {
00427         ReadImagesNotThreaded(s,files,dim);
00428   }
00429   //======================================================================
00430 
00431 
00432   //=================================================
00433   void WxGimmickView::CreateIconList()
00434   {
00435     // Size of the icons;
00436     int size = 16;
00437 
00438     wxIcon icons[20];
00439     // should correspond to Icon_xxx enum
00440     icons[Icon_accept]          = wxIcon(accept_xpm);
00441     icons[Icon_add]             = wxIcon(add_xpm);
00442     icons[Icon_folder_down]     = wxIcon(folder_down_xpm);
00443     icons[Icon_page_down]       = wxIcon(page_down_xpm);
00444     icons[Icon_remove]          = wxIcon(remove_xpm);
00445     icons[Icon_database_add]    = wxIcon(database_add_xpm);
00446     icons[Icon_help]            = wxIcon(help_xpm);
00447     icons[Icon_synchronize]     = wxIcon(synchronize_xpm);
00448     icons[Icon_create_database] = wxIcon(create_database_xpm);
00449     icons[Icon_settings]        = wxIcon(settings_xpm);
00450     icons[Icon_tools]           = wxIcon(tools_xpm);
00451 
00452     //   unsigned int NbIcons = 8;
00453     // Make an image list containing small icons
00454     mIcon = new wxImageList(size,size,true);
00455     
00456     // Make all icons the same size = size of the first one
00457     int sizeOrig = icons[0].GetWidth();
00458     for ( size_t i = 0; i < icon_number; i++ )
00459       {
00460         if ( size == sizeOrig )
00461           {
00462             mIcon->Add(icons[i]);
00463           }
00464         else
00465           {
00466             mIcon->Add(wxBitmap(wxBitmap(icons[i]).ConvertToImage().Rescale(size, size)));
00467           }
00468       }
00469   }
00470   //=================================================
00471 
00472 
00473   //=================================================
00474   void WxGimmickView::OnAddFiles(wxCommandEvent& event)
00475   {
00476     mViewer->StopPlayer();
00477     long style = wxOPEN | wxFILE_MUST_EXIST | wxFD_MULTIPLE;
00478     std::string wc("*");
00479     wxFileDialog* FD = new wxFileDialog( 0, 
00480                                          _T("Select file"),
00481                                          _T(""),
00482                                          _T(""),
00483                                          crea::std2wx(wc),
00484                                          style,
00485                                          wxDefaultPosition);
00486     
00487     if (FD->ShowModal()==wxID_OK)
00488       {
00489         wxBusyCursor busy;
00490 
00491         wxArrayString files;
00492         FD->GetPaths(files);
00493         unsigned int i;
00494         std::vector<std::string> filenames;
00495         for (i=0;i<files.GetCount();++i)
00496         {
00497           filenames.push_back(wx2std(files[i]));
00498           GimmickMessage(2,"Adding File "<<files[i]<<"."<<std::endl);
00499         }
00500 
00501         mProgressDialog = 
00502           new wxProgressDialog(_T("Adding file(s)"),
00503                                _T(""),
00504                                1000,
00505 //                             this,
00506                                NULL,
00507                                wxPD_ELAPSED_TIME |
00508                                // wxPD_ESTIMATED_TIME |
00509                                // wxPD_REMAINING_TIME |
00510                                wxPD_CAN_ABORT );
00511 
00512         // TO DO : select the current tree handler
00513         mGimmick->AddFiles(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),filenames);
00514 
00515         mProgressDialog->Pulse(_T("Updating view..."));
00516 
00517         UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
00518         killProgress();
00519         DisplayAddSummary();    
00520 
00521       }
00522         mViewer->StartPlayer(); 
00523   }
00524   //=================================================
00525 
00526   //=================================================
00527   void WxGimmickView::OnAddDir(wxCommandEvent& event)
00528   {
00529     mViewer->StopPlayer();
00530         std::string name = crea::wx2std(mNotebook->GetCurrentPage()->GetName());
00531     long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
00532     wxDirDialog* FD = 
00533          new wxDirDialog( 0, 
00534                        _T("Select directory"),
00535                        mCurrentDirectory,
00536                        style);
00537     
00538     if (FD->ShowModal()==wxID_OK)
00539     {
00540                         time(&mstart);
00541         std::string dirname = wx2std (FD->GetPath());
00542         bool recurse =  isNeedRecursive(dirname);
00543         if (recurse)
00544         {
00545              recurse = wxMessageBox(_T("Recurse into sub-directories ?"), _T("Scan directory"), wxYES_NO,this ) == wxYES ? true : false;
00546         }
00547 
00548                 wxBusyCursor busy;
00549                 wxString title(_T("Adding directory"));
00550                 if (recurse) 
00551                 title = _T("Adding directory (recursive)");
00552                 mProgressDialog = 
00553                 new wxProgressDialog(_T("Adding directory"),
00554                                         _T(""),
00555                                         NumberFilesToAdd(dirname,recurse),
00556 
00557 //EED                                   this,
00558                                         NULL,
00559 
00560                                         wxPD_ELAPSED_TIME | 
00561                                         wxPD_SMOOTH |
00562                                         // wxPD_ESTIMATED_TIME |
00563                                         // wxPD_REMAINING_TIME |
00564                                         wxPD_CAN_ABORT );
00565 
00566                 mCurrentDirectory = FD->GetPath();  
00567                 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirname,recurse);
00568                 mProgressDialog->Pulse(_T("Updating view..."));
00569 
00570                 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
00571                 killProgress();
00572                 DisplayAddSummary();
00573           }
00574     mViewer->StartPlayer();
00575         delete FD;
00576   }
00577 
00578 
00579   //=================================================
00580   // Determines number of files potentially to add to database
00581    int WxGimmickView::NumberFilesToAdd(const std::string &dirpath, bool recursive)
00582   {
00583            int nb = 0;
00584            if ( !boost::filesystem::exists( dirpath ) ) return nb;
00585            boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
00586            for ( boost::filesystem::directory_iterator itr( dirpath );  itr != end_itr;  ++itr )
00587           {
00588                 // If is directory & recurse : do recurse
00589                 if ( boost::filesystem::is_directory(itr->status()) )
00590                 {
00591                         if (recursive) 
00592                         {
00593                                 nb += NumberFilesToAdd(itr->string(), recursive);
00594                         }
00595                 }
00596                 else
00597                 {
00598                         nb++;
00599                 }
00600           }
00601         return nb;
00602   }
00603 
00604    //=================================================
00605    // Test a directory to know if contains sub-directory to analyze
00606   bool WxGimmickView::isNeedRecursive(std::string i_name)
00607   {
00608       boost::filesystem::directory_iterator iter(i_name), end_iter;
00609           bool bfindir = false;
00610                   for(; iter != end_iter; ++iter)
00611                   {
00612                           if(boost::filesystem::is_directory(*iter))
00613                           {
00614                                   return true;
00615                           }
00616                   }
00617                   return false;
00618   }
00619   //=================================================
00620 
00621   //=================================================
00622   void WxGimmickView::OnSelectionChange(const std::vector<tree::Node*>& sel, bool isSelection, int selection, bool needProcess)
00623   {      
00624     GimmickDebugMessage(5,
00625                         "WxGimmickView::OnSelectionChange"
00626                         <<std::endl);
00627     wxBusyCursor busy;
00628         bool valid=true;
00629         
00630         if(sel.size()==0)
00631         {
00632                 valid= ValidateSelected(NULL,
00633                                 mSelectionMinDimension,
00634                                 mSelectionMaxDimension );
00635         }
00636         else if(needProcess)
00637         {
00638                 ResetExtent();
00639                 std::vector<tree::Node*>::const_iterator i;
00640                 for(i=sel.begin();i!=sel.end()&&valid;++i)
00641                 {
00642                         valid= ValidateSelected((*i),
00643                                 mSelectionMinDimension,
00644                                 mSelectionMaxDimension );
00645                 }
00646         }
00647         else if(isSelection)
00648         {
00649                 valid= ValidateSelected(sel.front(),
00650                                 mSelectionMinDimension,
00651                                 mSelectionMaxDimension );
00652         }
00653         else
00654         {
00655                 ResetExtent();
00656                 std::vector<tree::Node*>::const_iterator i;
00657                 for(i=sel.begin();i!=sel.end()&&valid;++i)
00658                 {
00659                         valid= ValidateSelected((*i),
00660                                 mSelectionMinDimension,
00661                                 mSelectionMaxDimension );
00662                 }
00663         }
00664         mText->SetLabel(crea::std2wx(GetMessage()));
00665     /*if(valid)
00666       {
00667         ReadImageThreaded(sel);
00668       }
00669     else
00670       {
00671                   ClearSelection();
00672       }*/
00673         ReadImageThreaded(sel);
00674    }
00675 
00676   //==================================================
00677 
00678   //==================================================
00680   void WxGimmickView::ReadImageThreaded(const std::vector<tree::Node*>& sel)
00681   {     
00682    GimmickDebugMessage(5,
00683                        "ReadImageThreaded"
00684                        <<std::endl);
00685    int maxprio = GetMaximalPriority();
00686    int prio = maxprio + 2000;
00687 
00688    if(sel.size()>0)
00689    {
00690    //First load the selected images
00691    mCurImageItemToShow = sel.front();
00692    pointers.clear();
00693    int index = 0;
00694    std::vector<tree::Node*>::const_iterator selected;
00695    for(selected=sel.begin();selected!=sel.end();++selected)
00696      {
00697        GimmickDebugMessage(5,
00698                            "Requesting image from selected "
00699                            <<(*selected)->GetAttribute("FullFileName")
00700                            <<std::endl);
00701            //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
00702            boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
00703            pointers.push_back(ph);
00704        RequestReading(*selected,prio,index,ph);
00705        //       AddEntryToMap(*selected);
00706        prio--;
00707        index++;
00708      }
00709         mViewer->SetImageVector(pointers);
00710         //Going up
00711         prio = maxprio + 20;
00712         std::vector<tree::Node*> up;
00713         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(up,true);
00714         std::vector<tree::Node*>::iterator iterUp;
00715         for(iterUp=up.begin();iterUp!=up.end();++iterUp)
00716         {
00717                 GimmickDebugMessage(5,
00718                                 "Requesting image from neighbors up "
00719                                 <<(*iterUp)->GetAttribute("FullFileName")
00720                                 <<std::endl);
00721 //              ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
00722                 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
00723                 RequestReading(*iterUp,prio,-1,ph);
00724                 //              AddEntryToMap(*iterUp);
00725                 prio--;
00726                 if (prio == maxprio) break;
00727         }
00728 
00729         //Going down
00730         prio = maxprio + 19;
00731         std::vector<tree::Node*> down;
00732         GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNodes(down,false);
00733         std::vector<tree::Node*>::iterator iterDown;
00734         for(iterDown=down.begin();iterDown!=down.end();++iterDown)
00735         {
00736                 GimmickDebugMessage(5,
00737                                 "Requesting image from neighbors down "
00738                                 <<(*iterDown)->GetAttribute("FullFileName")
00739                                 <<std::endl);
00740                 //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
00741                 boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
00742                 RequestReading(*iterDown,prio,-1,ph);
00743                 //              AddEntryToMap(*iterDown);
00744                 prio--;
00745                 if (prio == maxprio) break;
00746         }
00747    }
00748    else
00749    {
00750            pointers.clear();
00751            //ImagePointerHolder* ph=new ImagePointerHolder(GetDefaultImage());
00752            boost::shared_ptr<ImagePointerHolder> ph(new ImagePointerHolder(GetDefaultImage()));
00753            pointers.push_back(ph);
00754            mViewer->SetImageVector(pointers);
00755    }
00756   }
00757 
00758   //==================================================
00759 
00760   //==================================================
00761 
00762 #if defined(WIN32)
00763   //==================================================
00764    void  WxGimmickView::OnInternalIdle()
00765    {
00766      if (!mConstructed) return;
00767      static bool first_time = true;
00768      if (false)
00769      {
00770        first_time = false;
00771      }
00772    //   GimmickMessage(1,"WxGimmickView : Refresh viewer"<<std::endl);
00773         //  mViewer->StartPlayer();
00774      if(mViewer)
00775      {
00776         mViewer->RefreshIfNecessary();
00777      }
00778   }
00779 #else
00780   void WxGimmickView::UpdateWindowUI(long flags)
00781   {
00782           if(mViewer)
00783      {
00784         mViewer->RefreshIfNecessary();
00785      }
00786   }
00787 #endif
00788    //==================================================
00789 
00790   //==================================================
00791    void  WxGimmickView::ClearSelection()
00792    {
00793         pointers.clear();
00794         pointers.push_back(boost::shared_ptr<creaImageIO::ImagePointerHolder>(new ImagePointerHolder(GetDefaultImage())));
00795         //pointers.push_back(new ImagePointerHolder(GetDefaultImage()));
00796         mViewer->SetImageVector(pointers);
00797         mViewer->RefreshIfNecessary();
00798         ResetExtent();
00799   }
00800 
00801   //=================================================
00802  
00803   //=================================================
00804   void WxGimmickView::OnRemove(wxCommandEvent& event)
00805   {
00806         //TODO Select current tree handler       
00807      wxBusyCursor busy;
00808          std::string remove;
00809          mGimmick->GetSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
00810          GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->RemoveSelected(remove);
00811          mGimmick->UpdateSetting(SETTINGS_REMOVE_PATIENT_DISPLAY,remove);
00812      ClearSelection();
00813   }
00814   //=================================================
00815 
00816 
00817   //=================================================
00818   void WxGimmickView::AddIgnoreFile(tree::Node* toRemove)
00819   {
00820      mGimmick->RemoveFile(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),toRemove);
00821    //  GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
00822   }
00823 
00824   //=================================================
00825   void WxGimmickView::CopyFiles(const std::vector<std::string>& filenames)
00826   {
00827      mGimmick->CopyFiles(filenames, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())));
00828      wxMessageBox(std2wx("The selected files have been copied"),_T("Copy files"),wxOK,this);
00829   }
00830 
00831    //=================================================
00832   void WxGimmickView::AddDir(std::string dirName)
00833   {
00834      mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
00835 
00836 //EED                                           this,
00837                                                 NULL,
00838         
00839                                                 wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
00840      mCurrentDirectory = crea::std2wx(dirName);
00841      mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),dirName,true);
00842      mProgressDialog->Pulse(_T("Updating view..."));
00843 
00844      UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
00845      killProgress();
00846      DisplayAddSummary();
00847   }
00848 
00849    //=================================================
00850   void WxGimmickView::OnSynchronize(wxCommandEvent& event)
00851   {       
00852     wxBusyCursor busy;
00853     const wxString choices[] = { _T("Check database for files deletion and addition and give a report."), 
00854                                 _T("Check database for files deletion, addition and attributes change. Then give a report."), 
00855                                 _T("Repair database (remove deleted files and add new files)."), 
00856                                 _T("Repair database (remove deleted files, add new files and reset changed attributes).") } ;
00857 
00858     wxSingleChoiceDialog dialog(this,
00859                                 _T("Select one of the following synchronization actions:\n")
00860                                 _T("Please note that, due to the heavy amount of operations required, this action might take a while."),
00861                                 _T("Synchronization Settings"),
00862                                 WXSIZEOF(choices), choices);
00863 
00864     //dialog.SetSelection(0);
00865 
00866     if (dialog.ShowModal() == wxID_OK)
00867     {
00868                         wxBusyCursor busy;
00869         int sel=dialog.GetSelection();
00870         bool repair=false;
00871         bool checkAttributes=false;
00872         if(sel==2 || sel==3){repair=true;}
00873         if(sel==1 || sel==3){checkAttributes=true;}
00874         std::string mess=mGimmick->Synchronize(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),repair, checkAttributes);
00875         wxMessageBox(std2wx(mess),_T("Synchronization result"),wxOK,this);
00876         if(sel==2 || sel==3){
00877                 GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->UpdateLevel(1);
00878         }
00879                 
00880     }
00881   }
00882   //=================================================
00883 
00884   //=================================================
00885   void WxGimmickView::OnSettings(wxCommandEvent& event)
00886   {
00887     wxDialog* dial= new wxDialog (this,-1,_T("System Settings"),wxDefaultPosition, wxSize(450,220));
00888     wxBoxSizer  *siz = new wxBoxSizer(wxVERTICAL);
00889     // Notebook
00890     wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
00891     
00892     siz->Add( nb,1,wxGROW  ,0);  
00893     CreateSettingsDialog(nb,dial);
00894     dial->SetSizer(siz);
00895     dial->ShowModal();
00896   }
00897 
00898   //=================================================
00899   void WxGimmickView::OnImportExport(wxCommandEvent &Event)
00900   {
00901         wxBusyCursor busy;
00902         // Test if one image is selected => export
00903         // if not =>import
00904     if (GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))])
00905         {
00906                 ExportImages();
00907         }
00908         else
00909         {
00910                 ImportImages();
00911         }
00912   }
00913 
00914   void WxGimmickView::ExportImages()
00915   {
00916                 //Archive selection: name, emplacement
00917                 //same process than copy local but to a zip
00918                 // if settings are yes "always ask for descriptor addition", ask
00919                 // if settings are yes, adding descriptor
00920   }
00921 
00922   void WxGimmickView::ImportImages()
00923   {
00924                 //Find the *.zip
00925                 //dezip
00926                 // Contain a descriptor.text
00927                 // create a new database, and add to database
00928                 // if not, add to current database
00929                 // 
00930   }
00931 
00932   //=================================================
00933   //AndresDonadio
00934   void WxGimmickView::OnTools(wxCommandEvent& event)
00935   {
00936         mViewer->StopPlayer();
00937         
00938         wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(550,350));
00939 
00940         wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
00941         wxNotebook* nb= new wxNotebook(dial, -1, wxDefaultPosition, wxDefaultSize, 0);
00942         wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);     
00943         dialSizer->Add(nb,1,wxGROW,0);
00944         dialSizer->Add(buttonsSizer,0,wxGROW);
00945 
00946 #if defined(BUILD_BRUKER)
00947         //First page: Bruker Image Reader
00948         WxGimmickTools * gimmickTools = new WxGimmickTools(nb, mCurrentDirectory);
00949         nb->AddPage( gimmickTools, _T("Bruker Image Reader") );
00950 #endif
00951 
00952         dial->SetSizer(dialSizer, true);
00953         dial->Layout();
00954         dial->ShowModal();
00955 
00956         if (dial->GetReturnCode() == wxID_OK)
00957         {
00958 #if defined(BUILD_BRUKER)
00959                 if (nb->GetSelection()==0)//Selection: Bruker Image Reader  
00960                 {
00961                         std::string inputDir  = crea::wx2std(gimmickTools->getInputDir());
00962                         std::string outputDir = crea::wx2std(gimmickTools->getOutputDir());
00963 
00964                         bool addToDB = gimmickTools->getAddToDBCheckBoxValue();
00965 
00966                         if (inputDir.compare("")!=0 && outputDir.compare("")!=0)
00967                         {
00968                                 if ( wxMessageBox(_T("Depending on the amount of Data the process can take several minutes. Do you want to continue?"),
00969                                                   _T("Please confirm"), wxICON_QUESTION | wxYES_NO) == wxYES )
00970                                 {
00971                                         Bruker2Dicom b2d;    
00972                                         b2d.SetInputDirectory(inputDir);
00973                                         b2d.SetOutputDirectory(outputDir);
00974                                         b2d.SetConvertModeToDicom();
00975                                         b2d.verbose=false;
00976                                         b2d.Execute();
00977                                         if (addToDB)
00978                                         {
00979         std::cout <<"after addToDB" << std::endl;
00980                                                 mProgressDialog = new wxProgressDialog(_T("Adding directory"),_T(""),1000,
00981 
00982 //EED                                                                                   this,
00983                                                                                         NULL,
00984 
00985                                                                                         wxPD_ELAPSED_TIME |wxPD_CAN_ABORT );
00986         std::cout <<"after new wxProgressDialog" << std::endl;                                          
00987                                                 mCurrentDirectory = gimmickTools->getOutputDir();
00988         std::cout <<"after gimmickTools->getOutputDir[" <<mCurrentDirectory << std::endl;                                               
00989                                                 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),outputDir,true);
00990         std::cout <<"after mGimmick->AddDir" << std::endl;                                      
00991                                                 mProgressDialog->Pulse(_T("Updating view..."));
00992         std::cout <<"after mProgressDialog->Pulse" << std::endl;
00993                                                 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
00994         std::cout <<"after UpdateTreeViewLevel" << std::endl;                                           
00995                                                 killProgress();
00996         std::cout <<"after delete mProgressDialog" << std::endl;                                                        
00997                                                 DisplayAddSummary();
00998         std::cout <<"after dDisplayAddSummary" << std::endl;                                            
00999                                         }       
01000                                 }
01001                         }
01002                         else
01003                         {
01004                                 wxMessageBox(_T("One or both of the directory fields are empty"),_T("Empty Fields"),wxOK,this);
01005                         }
01006         }
01007         delete gimmickTools;
01008 #endif
01009         }
01010         mViewer->StartPlayer();
01011   }
01012 
01013   //=================================================
01014 
01015   void WxGimmickView::CreateSettingsDialog(wxNotebook* nb, wxDialog* dial)
01016   {
01017           //First page: Customization of configurations
01018           //Copy Path string
01019           std::string cp;
01020           mGimmick->GetSetting(SETTINGS_COPY_PATH,cp);
01021           //Database Path String
01022           std::string dp;
01023           mGimmick->GetSetting(SETTINGS_DBPATH,dp);
01024           //Syncronization Event String
01025           std::string se;
01026           mGimmick->GetSetting(SETTINGS_SYNC_EVENT,se);
01027           //Syncronization Frequency String
01028           std::string sf;
01029           mGimmick->GetSetting(SETTINGS_SYNC_FREQ,sf);
01030 
01031           WxCustomizeConfigPanel * customConfig=new WxCustomizeConfigPanel(nb,dial,this,cp,dp,se,sf);
01032 
01033           nb->AddPage( customConfig, crea::std2wx("Customize Configuration") );
01034 
01035           //Second page: Creation of Databases
01036           /*wxPanel* databaseCreation=new wxPanel(nb);
01037           nb->AddPage( databaseCreation, crea::std2wx("Create Database") );*/
01038 
01039           //Second page (temporary): Connection to PACS
01040           WxPACSConnectionPanel* pacs=new WxPACSConnectionPanel(nb,dial, this);
01041           nb->AddPage( pacs, crea::std2wx("Connect to PACS") );
01042 
01043           //Third page: CD/DVD Watch
01044           WxListenerPanel* cdWatch=new WxListenerPanel(nb,dial, this,true);//, mListener->IsPaused());
01045           nb->AddPage( cdWatch, crea::std2wx("CD/DVD") );
01046 
01047           //Fourth page: Selection of attributes to show
01048           std::vector<std::string> shown;
01049           std::vector<std::string> nShown;
01050           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,1);
01051           int nLev=GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetNumberOfLevels();
01052           WxAttributeSelectionPanel* attSelection=new WxAttributeSelectionPanel(nb,dial,this,shown,nShown,nLev);
01053           nb->AddPage( attSelection, crea::std2wx("Selection of Attributes") );
01054   }
01055 
01056   //===================================================================
01057   void WxGimmickView::GetVisibleAttributes(std::vector<std::string>& shown, 
01058           std::vector<std::string>& nShown, int level)
01059   {
01060           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetAttributes(shown,nShown,level);
01061   }
01062 
01063   //===================================================================
01064   void WxGimmickView::OnAttributesChanged(const std::vector<std::string>& nShown, int level)
01065   {
01066           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->SetNonVisibleAttributes(nShown,level);
01067           std::vector<std::string> n=nShown;
01068           GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->CreateCtrl(n,level);
01069   }
01070   //===================================================================
01071   void WxGimmickView::OnSaveSettingsCallback(const std::string& copyPath,
01072           const std::string& dbPath,
01073           const std::string& syncEvent,
01074           const std::string& syncFreq)
01075   {
01076           mGimmick->UpdateSetting(SETTINGS_COPY_PATH,copyPath);
01077           mGimmick->UpdateSetting(SETTINGS_DBPATH,dbPath);
01078           mGimmick->UpdateSetting(SETTINGS_SYNC_EVENT,syncEvent);
01079           mGimmick->UpdateSetting(SETTINGS_SYNC_FREQ,syncFreq);
01080   }
01081 
01082   //===================================================================
01083   void WxGimmickView::OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles)
01084   {
01085          mListener->SetMonitoredDrive(drive);
01086          mListener->SetAddFilesState(addFiles);
01087          mListener->SetRemoveFilesState(removeFiles);
01088   }
01089 
01090   //========================================================================
01091 
01092   void WxGimmickView::OnDriveMount(bool mount)
01093   {
01094           GimmickMessage(1, "Gimmick::OnDriveMount"<<std::endl);
01095           std::string drive;
01096           mListener->GetMonitoredDrive(drive);
01097           
01098           if(mount)
01099           {
01100                 mViewer->StopPlayer();
01101                 wxBusyCursor busy;
01102                 wxString title(_T("Adding drive"));
01103                 mProgressDialog = 
01104                 new wxProgressDialog(_T("Adding drive"),
01105                                         _T(""),
01106                                         1000,
01107 
01108 //EED                                   this,
01109                                         NULL,
01110 
01111                                         wxPD_ELAPSED_TIME |
01112                                         //                             wxPD_ESTIMATED_TIME | 
01113                                         //                             wxPD_REMAINING_TIME |
01114                                         wxPD_CAN_ABORT );
01115                 mCurrentDirectory = crea::std2wx(drive);
01116                 mGimmick->AddDir(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),drive,true);
01117                 mProgressDialog->Pulse(_T("Updating view..."));
01118                 
01119                 UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
01120                 killProgress();
01121                 DisplayAddSummary();
01122                 mViewer->StartPlayer();  
01123           }
01124           else
01125           {  
01126                   mGimmick->DeleteDrive(drive);
01127                   UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
01128           } 
01129   }
01130 
01131    //========================================================================
01132 
01133   void WxGimmickView::StartListeningThread()
01134   {
01135           mListener->Resume();
01136   }
01137 
01138    //========================================================================
01139 
01140   void WxGimmickView::StopListeningThread()
01141   {
01142           mListener->Pause();
01143   }
01144 
01145   //========================================================================
01146   void WxGimmickView::CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
01147   {
01148     wxDialog* dial= new wxDialog (this,-1,crea::std2wx("Edit Fields for node "+node->GetLabel()),wxDefaultPosition, wxSize(350,155));
01149     wxBoxSizer  *siz = new wxBoxSizer(wxVERTICAL);
01150     WxEditFieldsPanel* ef = new WxEditFieldsPanel(dial, dial, this, node, names, keys);
01151 
01152     siz->Add( ef,1,wxGROW  ,0); 
01153     dial->SetSizer(siz);
01154     dial->ShowModal();  
01155   }
01156 
01157         
01158 
01159  //========================================================================
01160   void WxGimmickView::DumpTags(std::string i_filename)
01161   {
01162     WxDumpPanel* pan= new WxDumpPanel (this,i_filename);
01163     pan->ShowModal();  
01164   }
01165 
01166   //========================================================================
01167   void WxGimmickView::ExportToStorage(const std::vector<std::string> i_filenames)
01168   {
01169         std::vector<std::string> storages;
01170         Gimmick::TreeHandlerMapType::iterator it = mGimmick->GetTreeHandlerMap().begin();
01171         for(;it != mGimmick->GetTreeHandlerMap().end(); it++)
01172         {
01173                 storages.push_back(it->first);
01174         }
01175 
01176     WxExportDlg* exp= new WxExportDlg(this,storages);
01177         if ( exp->ShowModal() ==ID_EXPORT_OK)
01178         {
01179                 std::string storage = exp->GetStorage();
01180                 mProgressDialog = 
01181             new wxProgressDialog(_T("Adding file(s)"),
01182                                _T(""),
01183                                1000,
01184 
01185 //EED                           this,
01186                                 NULL,
01187 
01188                                wxPD_ELAPSED_TIME |
01189                                // wxPD_ESTIMATED_TIME |
01190                                // wxPD_REMAINING_TIME |
01191                                wxPD_CAN_ABORT );
01192                 mGimmick->AddFiles(storage,i_filenames);
01193                 mProgressDialog->Pulse(_T("Updating view..."));
01194                 UpdateTreeViewLevel(storage,1);
01195                 killProgress();
01196                 DisplayAddSummary();    
01197         }
01198   }
01199 
01200 
01201 
01202   //========================================================================
01203   void WxGimmickView::OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val)
01204   {
01205      mGimmick->EditField(node, crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())), name, key, val);
01206      UpdateTreeViewLevel(crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())),1);
01207   }
01208 
01209   //=================================================
01211   void WxGimmickView::OnAddProgress( Gimmick::AddProgress& p)
01212   {
01213     char mess[200];
01214     sprintf(mess,"%i dirs : %i files :\n            %i handled - %i added",
01215            p.GetNumberScannedDirs(),
01216            p.GetNumberScannedFiles(),
01217            p.GetNumberHandledFiles(),
01218            p.GetNumberAddedFiles());
01219     //    std::cout << "OnAddProgress "<<mess<<std::endl;
01220     wxString s(wxString::From8BitData(mess));
01221     //  std::cout << "Pulse"<<std::endl;
01222 
01223         if(mProgressDialog != 0)
01224         {
01225                 if (!mProgressDialog->Pulse(s)) 
01226                   {
01227                 p.SetStop();
01228                   }
01229         }
01230     //  std::cout << "OnAddProgress ok"<<std::endl;
01231   }
01232   //=================================================
01233 
01234   //=================================================
01235   void WxGimmickView::DisplayAddSummary()
01236   {
01237       std::stringstream mess(mGimmick->getSummary());
01238     time_t end;
01239         time(&end);
01240         mess << "time to scan :" << difftime(end,mstart) << "sec";
01241     wxMessageBox(std2wx(mess.str()),_T("Addition result"),wxOK,this);
01242   }
01243 
01245   // Add a DB to application                    //
01246   // @param event : WxEvent                     //
01247   // @return : -                                //
01249   void WxGimmickView::OnAddDB(wxCommandEvent& event)
01250   {
01251           //Select DB
01252           long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
01253           std::string wc("*.sqlite3*");
01254           wxFileDialog* FD = new wxFileDialog( 0, 
01255                                          _T("Select file"),
01256                                          _T(""),
01257                                          _T(""),
01258                                          crea::std2wx(wc),
01259                                          style,
01260                                          wxDefaultPosition);
01261     
01262     if (FD->ShowModal()==wxID_OK)
01263         {
01264                 wxBusyCursor busy;
01265                 wxArrayString files;
01266                 FD->GetPaths(files);
01267                 std::stringstream st;
01268                 for(int i = 0; i< files.size(); i++)
01269                 {
01270                         //get name of DB (file name)
01271                   size_t pos = files[i].find_last_of(_T("\\"));
01272                   std::string name = crea::wx2std(files[i].substr(pos+1));
01273                   pos = name.find_last_of(".");
01274                   name = name.substr(0,pos);
01275                   //create TreeHandler
01276                   mGimmick->addDB(name, crea::wx2std(files[i]));
01277                   //create TreeView
01278                   CreateSingleTreeView(name);
01279                 }
01280         }
01281   }
01283   // Create a DB from an Attributes Descriptor files  //
01284   // @param event : WxEvent                                     //
01285   // @return : -                                                //
01287   void WxGimmickView::OnCreateDB(wxCommandEvent& event)
01288   {
01289         //  PACSConnection("");
01290         WxDescriptorPanel * DescriptorPan = new WxDescriptorPanel(this, mGimmick->GetHomeDirectory());
01291         DescriptorPan->Layout();
01292         if ( DescriptorPan->ShowModal() == ID_DSCP_APPLY)
01293         {
01294                 wxBusyCursor busy;
01295                 std::string file(DescriptorPan->GetDescriptor());
01296                 if (!file.empty())
01297                 {
01298                         size_t pos = file.find_last_of("\\");
01299                         std::string name = file.substr(pos+1);
01300                         std::string directory = file.substr(0,pos);
01301                         pos = name.find_last_of(".");
01302                         name = name.substr(0,pos);
01303                         //get directory to store DB
01304                         directory +=  "\\" + name + ".sqlite3";
01305                         //create createDB
01306                         mGimmick->createDB(name, file,directory);
01307                         //create TreeHandler
01308                         mGimmick->addDB(name, directory);
01309                         //create TreeView
01310                         CreateSingleTreeView(name);
01311                 }
01312         }
01313   }
01314 
01315   void WxGimmickView::killProgress()
01316   {
01317                 mProgressDialog->Resume();
01318                 mProgressDialog->Destroy();
01319                 mProgressDialog = 0;
01320   }
01321 
01322    //=================================================
01323 
01324    //=================================================
01325   BEGIN_EVENT_TABLE(WxGimmickView, wxPanel)
01326     EVT_TOOL(TOOL_CREATEDB_ID, WxGimmickView::OnCreateDB)
01327     EVT_TOOL(TOOL_ADDFILES_ID, WxGimmickView::OnAddFiles)
01328     EVT_TOOL(TOOL_ADDDIR_ID, WxGimmickView::OnAddDir)
01329     EVT_TOOL(TOOL_ADDDATABASE_ID, WxGimmickView::OnAddDB)
01330     EVT_TOOL(TOOL_REMOVE_ID, WxGimmickView::OnRemove)
01331     EVT_TOOL(TOOL_SYNCHRONIZE_ID, WxGimmickView::OnSynchronize)
01332     EVT_TOOL(TOOL_SETTINGS_ID, WxGimmickView::OnSettings)
01333     EVT_TOOL(TOOL_TOOLS_ID, WxGimmickView::OnTools)
01334   END_EVENT_TABLE()
01335   //=================================================
01336 
01337 } // EO namespace creaImageIO
01338