creaImageIOWxDescriptorPanel.cpp

Go to the documentation of this file.
00001 #include "creaImageIOWxDescriptorPanel.h"
00002 #include <creaImageIOSystem.h>
00003 #if defined(USE_GDCM)
00004 #include <gdcmGlobal.h>
00005 #include <gdcmDictSet.h>
00006 #endif
00007 
00008 #if defined(USE_GDCM2)
00009 #include <gdcmGlobal.h>
00010 #include <gdcmDicts.h>
00011 #include <gdcmDict.h>
00012 #endif
00013 #include <boost/algorithm/string.hpp>
00014 
00015 namespace creaImageIO
00016 {
00017   // CTor
00018                    
00019         WxDescriptorPanel::WxDescriptorPanel(wxWindow *parent, const std::string path)
00020                 : wxDialog(parent, -1,_T("Descriptor Creation"), wxDefaultPosition, wxSize(550,550)) , m_path(path)
00021 {
00022 
00023   
00024     GimmickDebugMessage(1,"WxDescriptorPanel::WxDescriptorPanel"
00025                         <<std::endl);
00026 
00027         lv = 0;
00028         ownatt["FullFileName"]      = "Full_File_Name";
00029         ownatt["FullFileDirectory"] = "Full_File_Directory";
00030         
00031 
00032         // START BUTTONS
00033         wxButton *NewDescriptor = new wxButton(this, -1,_T("Create a new descriptor"), wxPoint(10,7) );
00034         Connect( NewDescriptor->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxDescriptorPanel::OnNew ); 
00035 
00036         wxButton *LoadDescriptor = new wxButton(this, -1,_T("Load a descriptor"), wxPoint(150,7) );
00037         Connect( LoadDescriptor->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxDescriptorPanel::OnLoad ); 
00038         
00039         wxStaticLine *line1 = new wxStaticLine(this, -1, wxPoint(5,40), wxSize(540,2));
00040 
00041         // LEVEL
00042         wxStaticText * LevelText=new wxStaticText(this,-1,_T(" Level: "), wxPoint(5,50));
00043         LevelCtrl=new wxTextCtrl(this, ID_GR_CTRL,_T("patient"), wxPoint(50,50), wxSize(50,25));
00044         wxButton *addLevel = new wxButton(this, ID_LEVEL_ADD,_T("add a level"), wxPoint(150,50) );
00045         Connect( addLevel->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxDescriptorPanel::OnAddLevel ); 
00046 
00047         wxStaticLine *line2 = new wxStaticLine(this, -1, wxPoint(5,75), wxSize(540,2));
00048 
00049         // ATTRIBUTES
00050 
00051         wxStaticText * GR=new wxStaticText(this,-1,_T(" DICOM Group: "), wxPoint(5,110));
00052         GRCtrl=new wxTextCtrl(this, ID_GR_CTRL,_T("0x0010"), wxPoint(82,110), wxSize(50,25));
00053         Connect( GRCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED , (wxObjectEventFunction) &WxDescriptorPanel::OnDicomAttribute ); 
00054         
00055         wxStaticText * EL=new wxStaticText(this,-1,_T(" DICOM Element: "), wxPoint(140,110));
00056         ELCtrl=new wxTextCtrl(this, ID_EL_CTRL,_T("0x0010"), wxPoint(230,110), wxSize(50,25));
00057         Connect( ELCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED , (wxObjectEventFunction) &WxDescriptorPanel::OnDicomAttribute ); 
00058 
00059         
00060         wxString choices[3];
00061         choices[0] = _T("Unknow Attribute");
00062         std::map<std::string, std::string>::iterator it_att =ownatt.begin();
00063         for(int i = 1; it_att != ownatt.end(); it_att++, i++)
00064         {
00065                 choices[i] = crea::std2wx(it_att->second);
00066         }
00067         
00068 
00069         AttributeCombo  = new wxComboBox(this, ID_ATTRIBUTE_CTRL,_T(""),wxPoint(300,110), wxSize(120,25),3,choices, wxCB_READONLY);
00070         AttributeCombo->SetSelection(0);
00071         
00072 
00073         wxButton *addAttribute = new wxButton(this, ID_ATTRIBUTE_ADD,_T("add an attribute"), wxPoint(440,110) );
00074         Connect( addAttribute->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxDescriptorPanel::OnAddAttribute ); 
00075 
00076         wxStaticLine *line3 = new wxStaticLine(this, -1, wxPoint(5,140), wxSize(540,2));
00077 
00078         // RESULT
00079 
00080         ResultCtrl=new wxTextCtrl(this, ID_EL_CTRL,_T(""), wxPoint(5,150), wxSize(250,310), wxTE_READONLY| wxMac | wxTE_MULTILINE | wxTE_RICH );
00081         wxButton *RemoveCtrl = new wxButton(this, ID_REMOVE_ADD,_T("Remove an entry"), wxPoint(280,200) );
00082         Connect( RemoveCtrl->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxDescriptorPanel::OnRemove ); 
00083 
00084         wxStaticLine *line4 = new wxStaticLine(this, -1, wxPoint(5,470), wxSize(540,2));
00085         // VALIDATION BUTTON
00086         wxButton *Ok = new wxButton(this, -1,_T("OK"), wxPoint(10,480) );
00087         Connect( Ok->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxDescriptorPanel::OnOK ); 
00088 
00089         wxButton *Apply = new wxButton(this, -1,_T("APPLY"), wxPoint(150,480) );
00090         Connect( Apply->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxDescriptorPanel::OnApply ); 
00091         
00092         wxButton *Cancel = new wxButton(this, wxID_CANCEL,_T("CANCEL"), wxPoint(250,480) );
00093 //      Connect( Cancel->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxCloseEvent) &wxWindow::Close ); 
00094 
00095         Layout(); 
00096         CreateDescriptor(0);
00097   }
00098 
00100   WxDescriptorPanel::~WxDescriptorPanel()
00101   {
00102     GimmickDebugMessage(1,"WxCustomizeConfigPanel::~WxCustomizeConfigPanel"
00103                         <<std::endl);
00104   }
00105 
00107   // Add an attribute  //
00108   // @param event : Wxevent  //
00109   // @return : -                                                  //
00111   void WxDescriptorPanel::OnAddAttribute(wxCommandEvent& event)
00112   {
00113           std::string name_lv;
00114           std::string name_att;
00115           if (AttributeCombo->GetSelection() == 0)
00116           {
00117              name_att = "D" + crea::wx2std(GRCtrl->GetValue()) + "_" + crea::wx2std(ELCtrl->GetValue());
00118           }
00119           else
00120           {     
00121              wxString wd = AttributeCombo->GetValue();
00122              std::string st = crea::wx2std(wd);
00123              name_att = OwnAttribute(st);
00124           }
00125           onAddAttribute(crea::wx2std(AttributeCombo->GetValue()), name_att);
00126   }
00128   // add an attribute  //
00129   // @param att :  attribute //
00130   // @param name_att :  's name //
00131   // @param level : level to add the attribute  //
00132   // @return : -                                                  //
00134   void WxDescriptorPanel::onAddAttribute( const std::string &att, const std::string &name_att,std::string level )
00135   {
00136           if(lv == 0)
00137           {
00138                   wxMessageBox(_T("Need a level first!"),crea::std2wx("WARNING"),wxOK,this);
00139           }
00140           else
00141           {
00142                 if( !att.empty() )
00143                 {
00144                 // Find Name of level
00145                         if(level.empty())
00146                         {
00147                                 level = findLevel();
00148                         }
00149 
00150                         if (!addAtribute(level, name_att))
00151                         {
00152                                 wxMessageBox(_T("Attribute already used in this level"),crea::std2wx("WARNING"),wxOK,this);
00153                         }
00154                         else
00155                         {
00156                                 ResultCtrl->SetInsertionPoint(InsertPt);
00157                 for (int i = 1; i<=lv;i++)
00158                                 { 
00159                                    ResultCtrl->WriteText(_T("   "));
00160                                 }
00161                                 ResultCtrl->WriteText(_T("| - "));
00162                                 ResultCtrl->WriteText(crea::std2wx(att));
00163                                 wxTextAttr ResultAttr(ResultCtrl->GetDefaultStyle());
00164                                 ResultAttr.SetTextColour(*wxWHITE);
00165                                 ResultCtrl->SetDefaultStyle(ResultAttr);
00166                                 std::string text = " ";
00167                                 ResultCtrl->WriteText(crea::std2wx(" " + name_att));
00168                                 ResultAttr.SetTextColour(*wxBLACK);
00169                                 ResultCtrl->SetDefaultStyle(ResultAttr);
00170                                 ResultCtrl->WriteText(_T("\n"));
00171                         }
00172                         InsertPt = ResultCtrl->GetInsertionPoint();
00173                 }
00174           }
00175   }
00176   
00178   // add a level //
00179   // @param event : Wxevent  //
00180   // @return : -                                                  //
00182   void WxDescriptorPanel::OnAddLevel(wxCommandEvent& event)
00183   {
00184           if( !LevelCtrl->GetValue().IsEmpty() )
00185           {
00186                   onAddLevel(crea::wx2std(LevelCtrl->GetValue()));
00187           }
00188   }
00189 
00191   // add a level  //
00192   // @param level : level's name   //
00193   // @return : -                                                  //
00195   void WxDescriptorPanel::onAddLevel(const std::string &level)
00196   {
00197                   if(addLevel(level))
00198                   {
00199                           wxMessageBox(_T("Level already used"),crea::std2wx(("WARNING")),wxOK,this);
00200                           return;
00201                   }
00202                   
00203                    lv++;
00204                    ResultCtrl->SetInsertionPoint(InsertPt);
00205                    for (int i = 1; i<lv;i++)
00206                    { 
00207                            ResultCtrl->WriteText(_T("   "));
00208                    }
00209                    if(lv>1)
00210                    {    ResultCtrl->WriteText(_T("| \n"));
00211                                 for (int i = 1; i<lv;i++)
00212                                 { 
00213                                         ResultCtrl->WriteText(_T("   "));
00214                                 }
00215                                 ResultCtrl->WriteText(_T("|_"));
00216                    }
00217                    
00218                         wxTextAttr ResultAttr(ResultCtrl->GetDefaultStyle());
00219                         ResultAttr.SetTextColour(*wxRED);
00220                         ResultCtrl->SetDefaultStyle(ResultAttr);
00221                         ResultCtrl->WriteText(crea::std2wx(level));
00222                         ResultAttr.SetTextColour(*wxBLACK);
00223                         ResultCtrl->SetDefaultStyle(ResultAttr);
00224                         ResultCtrl->WriteText(_T("\n"));
00225                         InsertPt = ResultCtrl->GetInsertionPoint();
00226           
00227   }
00228 
00230   // Find a DICOM attribute from group and element values //
00231   // @param event : Wxevent  //
00232   // @return : -                                                  //
00234   void WxDescriptorPanel::OnDicomAttribute(wxCommandEvent& event)
00235   {
00236           int i = 0;
00237           if(!GRCtrl->GetValue().IsEmpty() && !ELCtrl->GetValue().IsEmpty() 
00238                   && GRCtrl->GetValue().Len() == 6 && ELCtrl->GetValue().Len() == 6 && AttributeCombo->GetSelection() == 0)
00239           {
00240 
00241                   std::string gr = crea::wx2std(GRCtrl->GetValue());
00242                   std::string el = crea::wx2std(ELCtrl->GetValue());
00243                   std::stringstream val;
00244         
00245                   unsigned short group;
00246                   unsigned short element;
00247                   val <<   std::dec << gr ;
00248                   val >> std::hex >> group;
00249                   val.clear();
00250                   val <<   std::dec << el ;
00251                   val >> std::hex >> element;
00252 #if defined(USE_GDCM)   
00253                  // Retrieve the name from gdcm dict
00254                   GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(group, element);
00255                  // AttributeCombo->Clear();
00256                   if(entry)
00257                   {
00258                           AttributeCombo->Delete(0);
00259                           AttributeCombo->Insert(crea::std2wx(entry->GetName()), 0);
00260                   }
00261                   else
00262                   {
00263                           AttributeCombo->Delete(0);
00264                           AttributeCombo->Insert(_T("Unknown Attribute"),0);
00265                   }
00266 #endif
00267                           AttributeCombo->SetSelection(0);
00268                 
00269           }
00270     
00271   }
00272 
00273 
00275   // determine values for own attributes //
00276   // @param name : attribute's name  //
00277   // @param key : indicates key map or not  //
00278   // @return : -                                                  //
00280   std::string WxDescriptorPanel::OwnAttribute(const std::string name)
00281   {
00282           std::string result;
00283 
00284           std::map<std::string, std::string>::iterator it_att = ownatt.begin();
00285           for(; it_att != ownatt.end(); it_att++)
00286           {
00287                   if(it_att->second == name)
00288                   {
00289                           result = it_att->first.c_str();
00290                           break;
00291                   }
00292           }
00293           return result;
00294   }
00295         
00297   // Find a level in function of position in Return Ctrl  //
00298   // @param - :   //
00299   // @return : -                                                  //
00301   std::string WxDescriptorPanel::findLevel()
00302   {
00303           long column;
00304           long line;
00305           
00306           ResultCtrl->PositionToXY( ResultCtrl->GetInsertionPoint(),&column, &line);
00307           std::string tx(crea::wx2std(ResultCtrl->GetRange(0, ResultCtrl->XYToPosition(0,line+1))).c_str());
00308           std::string::size_type level_pos_start = tx.rfind("|_");
00309           if(level_pos_start == -1)
00310           {
00311                   level_pos_start = 0;
00312           }
00313           else
00314           {
00315                   level_pos_start += 2;
00316           }
00317 
00318           std::string::size_type level_pos_end = tx.find_first_of("\n",level_pos_start);
00319           return  tx.substr(level_pos_start,level_pos_end - level_pos_start);
00320   }
00321 
00323   // Remove an item                               //
00324   // @param event : Wxevent  //
00325   // @return : -                                                  //
00327   void WxDescriptorPanel::OnRemove(wxCommandEvent& event)
00328   {
00329           long line;
00330           long column;
00331           long pos_start;
00332           long pos_end;
00333 
00334           pos_start = ResultCtrl->GetInsertionPoint();
00335           ResultCtrl->PositionToXY( pos_start,&column, &line);
00336           if (line == 0) 
00337           {
00338                   std::string name("root");
00339                   RemoveLevel(name);
00340                   ResultCtrl->Clear();
00341                   lv = 0;
00342           }
00343           else
00344           {
00345                 wxString text = ResultCtrl->GetLineText(line);
00346                 if ( text.Find(_T("|_")) == -1)
00347                 {
00348                   std::string level = findLevel();
00349                   // find GR and EL values to remove
00350                   std::string tx = crea::wx2std(text);
00351                   std::string::size_type  EL_start_pos = tx.find_last_of(" ");
00352                   RemoveAttribute(level, tx.substr(EL_start_pos+1,tx.size() - EL_start_pos));
00353                   ResultCtrl->Remove( ResultCtrl->XYToPosition(0,line), ResultCtrl->XYToPosition(0,line+1));
00354                 }
00355                 else
00356                 {       
00357                          RemoveLevel(crea::wx2std(text.AfterFirst('_')));
00358                          lv = text.Find(_T("|"))/3;
00359                          pos_start= ResultCtrl->XYToPosition(0,line-1);
00360                          ResultCtrl->SetInsertionPointEnd();
00361                          pos_end = ResultCtrl->GetInsertionPoint();
00362                          ResultCtrl->Remove(pos_start, pos_end);
00363                 }
00364           }
00365 
00366   }
00368   // create a descriptor structure               //
00369   // @param name : level's name to add           //
00370   // @return : boolean result                    //
00372    void WxDescriptorPanel::CreateDescriptor(int type)
00373    {
00374            if(type == 0) // First initialization
00375            {
00376                    outDscp.clear();
00377                    outDscp += "<level>";
00378                    outDscp += "\n";
00379                    outDscp += "root";
00380                    outDscp += "\n";
00381                    outDscp += "O Name Name 4";
00382                    outDscp += "\n";
00383            }
00384            if(type == 1)
00385            {
00386                    if(lv > 1)
00387                    {
00388                         outDscp += "O NumberOfChildren ";
00389                         outDscp += crea::wx2std(LevelCtrl->GetValue());
00390                         outDscp += "s";
00391                         outDscp += "\n";
00392                    }
00393                    outDscp += "<level>";
00394                    outDscp += "\n";
00395                    outDscp += crea::wx2std(LevelCtrl->GetValue());
00396                    outDscp += "\n";
00397                    
00398            }
00399            if(type == 2)
00400            {
00401                    outDscp += "D";
00402                    outDscp += " ";
00403                    outDscp += crea::wx2std(GRCtrl->GetValue());
00404                    outDscp += " ";
00405                    outDscp += crea::wx2std(ELCtrl->GetValue());
00406                    outDscp += " ";
00407                    outDscp += "3";
00408                    outDscp += "\n";
00409            }
00410            
00411 
00412    }
00413 
00414 
00416   // add a level                                  //
00417   // @param name : level's name to add  //
00418   // @return : boolean result                                             //
00420    bool WxDescriptorPanel::addLevel(const std::string &name)
00421    {
00422            bool bfound = false;
00423            std::map<std::string, std::vector <std::string> >::iterator it_tree = DscpTree.begin();
00424            for (;it_tree != DscpTree.end(); it_tree++)
00425            {
00426                    if(it_tree->first == name)
00427                    {
00428                            bfound = true;
00429                            break;
00430                    }
00431            }
00432            if(!bfound)
00433            {
00434                     lvlist[lv] = name;
00435                         std::vector <std::string> branch;
00436                         DscpTree[name] = branch;
00437            }
00438                 return bfound;
00439    }
00440 
00442   // remove a level                               //
00443   // @param name : level's name to remove  //
00444   // @return : boolean result                                             //
00446    bool WxDescriptorPanel::RemoveLevel(const std::string &name)
00447    {
00448            bool bresult = false;
00449            std::map<int, std::string>::iterator it_list= lvlist.begin();
00450            for(; it_list != lvlist.end(); it_list++)
00451            {
00452                    if(it_list->second == name)
00453                    {
00454                            break;
00455                    }
00456            }
00457            std::map<int, std::string>::iterator it_list2 = it_list;
00458            for(;it_list != lvlist.end(); it_list++)
00459            {
00460                         std::map<std::string, std::vector <std::string> >::iterator it_tree = DscpTree.begin();
00461                         for (;it_tree != DscpTree.end(); it_tree++)
00462                         {       
00463                                 if(it_tree->first == name)
00464                                 {
00465                                         DscpTree.erase(it_tree);
00466                                         break;
00467                                 }
00468                         }
00469            }
00470            lvlist.erase(it_list2, lvlist.end());
00471            return bresult;
00472    }
00473 
00474 
00476   // add an attribute in a level                                  //
00477   // @param level : level's name to add attribute  //
00478   // @param name : attribute's name                                       //
00479   // @return : boolean result                                             //
00481    bool WxDescriptorPanel::addAtribute(const std::string &level, const std::string &name)
00482    {
00483            bool bresult = true;
00484            std::map<std::string, std::vector <std::string> >::iterator it_tree = DscpTree.begin();
00485            for (;it_tree != DscpTree.end(); it_tree++)
00486            {
00487                    if (it_tree->first.c_str() == level)
00488                    {
00489                            std::vector<std::string>::iterator it_branch = it_tree->second.begin();
00490                            for(;it_branch != it_tree->second.end(); it_branch++)
00491                            { 
00492                                    if(it_branch->c_str() == name)
00493                                    {
00494                                            bresult = false;
00495                                    }
00496                            }
00497                            if(bresult)
00498                            {
00499                                         it_tree->second.push_back(name);
00500                                         break;
00501                            }
00502                    }
00503            }
00504            return bresult;
00505    }
00506 
00508   // remove an attribute from a level                             //
00509   // @param level : level's name to remove attribute  //
00510   // @param name : attribute's name                                       //
00511   // @return : boolean result                                             //
00513    bool WxDescriptorPanel::RemoveAttribute(const std::string &level, const std::string &name)
00514    {
00515               bool bresult = false;
00516            std::map<std::string, std::vector <std::string> >::iterator it_tree = DscpTree.begin();
00517            for (;it_tree != DscpTree.end(); it_tree++)
00518            {
00519                    if(it_tree->first == level)
00520                    {
00521                            std::vector<std::string>::iterator it_branch = it_tree->second.begin();
00522                            cout << it_tree->second.size();
00523                            for(;it_branch != it_tree->second.end(); it_branch++)
00524                            {
00525                                    if(it_branch->c_str() == name)
00526                                    {
00527                                            bresult = true;
00528                                            it_tree->second.erase(it_branch);
00529                                            break;
00530                                    }
00531                            }
00532                    }
00533            }
00534            return bresult;
00535    }
00536 
00538   // create a new descriptor                                    //
00539   // @param event : WxEvent                                     //
00540   // @return : -                                                //
00542    void WxDescriptorPanel::OnNew(wxCommandEvent &Event)
00543    {
00544            LevelCtrl->SetValue(_T("patient"));
00545            ResultCtrl->Clear();
00546            DscpTree.clear();
00547            lv = 0;
00548    }
00549 
00551   // Load a descriptor file                                             //
00552   // @param event : WxEvent                                             //
00553   // @return : -                                                        //
00555    void WxDescriptorPanel::OnLoad(wxCommandEvent &Event)
00556    {
00557             long style = wxOPEN | wxFILE_MUST_EXIST;
00558            LevelCtrl->SetValue(_T("patient"));
00559            ResultCtrl->Clear();
00560            DscpTree.clear();
00561            lv = 0;
00562                 
00563            std::string wc("*.dscp");
00564            wxFileDialog* FD = new wxFileDialog( 0, 
00565                                          _T("Select file"),
00566                                          crea::std2wx(m_path),
00567                                          _T(""),
00568                                          crea::std2wx(wc),
00569                                          style,
00570                                          wxDefaultPosition);
00571         if (FD->ShowModal()==wxID_OK)
00572         {
00573                 loadDescriptor(crea::wx2std(FD->GetPath()).c_str());
00574         }
00575         
00576    }
00577 
00579   // Save a descriptor                                                    //
00580   // @param event : WxEvent                                               //
00581   // @return : -                                                         //
00583    void WxDescriptorPanel::OnOK(wxCommandEvent &Event)
00584    {
00585           saveDescriptor();
00586           wxWindow::Close();
00587    }
00588    
00590   // Save a descriptor  and apply it (create a new DB//
00591   // @param event : WxEvent                                             //
00592   // @return : -                                                        //
00594    void WxDescriptorPanel::OnApply(wxCommandEvent &Event)
00595    {
00596                 m_DscpFile = saveDescriptor();
00597                 wxWindow::Close();
00598                 SetReturnCode(ID_DSCP_APPLY);
00599    }
00600 
00601    const std::string WxDescriptorPanel::saveDescriptor()
00602    {
00603            std::string file = "";
00604                 long style = wxSAVE;
00605                 std::string wc("*.dscp");
00606                 wxFileDialog* FD = new wxFileDialog( 0, 
00607                                                 _T("Select file"),
00608                                                 _T(""),
00609                                                 _T(""),
00610                                                 crea::std2wx(wc),
00611                                                 style,
00612                                                 wxDefaultPosition);
00613 
00614 
00615                 if (FD->ShowModal()==wxID_OK)
00616                 {
00617                         createDescriptorFile();
00618                         file = crea::wx2std(FD->GetPath()).c_str();
00619                         std::ofstream ofs(file.c_str());
00620                         ofs.clear();
00621                         ofs << outDscp;
00622                         ofs.close();
00623                 }
00624                 return file.c_str();
00625    }
00626  
00628    // Cancel action                                                             //
00629    // @param event :    WxEvent                                                 //
00630    // @return : -                                                               //
00632 
00633    void WxDescriptorPanel::OnCancel(wxCommandEvent& event)
00634    {
00635    }
00636    
00638    // create  a descriptor      file                                            //
00639    // @param - :                                                                //
00640    // @return : -                                                               //
00642    void WxDescriptorPanel::createDescriptorFile()
00643    {
00644                 
00645                    outDscp.clear();
00646                    outDscp += "<level>";
00647                    outDscp += "\n";
00648                    outDscp += "Root";
00649                    outDscp += "\n";
00650                    outDscp += "O Name Name 4";
00651                    outDscp += "\n";
00652                    std::map<std::string, std::vector <std::string> >::iterator it_tree = DscpTree.begin();
00653                    std::map<int, std::string >::iterator it_lv_nb = lvlist.begin();
00654                    std::map<int, std::string >::iterator it_lv = lvlist.begin();
00655                    it_lv_nb++;
00656                    for (;it_lv != lvlist.end(); it_lv++)
00657                {
00658                            outDscp +="<level>";
00659                        outDscp += "\n";
00660                            outDscp += it_lv->second.c_str();
00661                              outDscp += "\n";
00662                             if(it_lv_nb != lvlist.end())
00663                            {
00664                                    outDscp += "O NumberOfChildren ";
00665                                    outDscp += it_lv_nb->second.c_str();
00666                                    outDscp += "s";
00667                                    outDscp += "\n";
00668                                    it_lv_nb++;
00669                            }
00670                            std::vector<std::string>::iterator it_branch = DscpTree[it_lv->second.c_str()].begin();      
00671                       for(;it_branch != DscpTree[it_lv->second.c_str()].end(); it_branch++)
00672                           {      
00673                                   std::string att = it_branch->c_str();
00674                                   if(att[0] == 'D' && att[7] == '_' && att.size() == 14) 
00675                                   {
00676                                       outDscp += "D ";
00677                                           outDscp += att.substr(1,6) + " "; // GR
00678                                           outDscp += att.substr(8,6) + " ";// EL
00679                                           outDscp += "3";
00680                                           outDscp += "\n";
00681                                   }
00682                                   else
00683                                   {
00684                                           outDscp += "O ";
00685                                           outDscp += it_branch->c_str();
00686                                           outDscp += " ";
00687                                           outDscp += ownatt[att];
00688                                           outDscp += " ";
00689                                           outDscp += "2";
00690                                           outDscp += "\n";
00691                                   }
00692                           }
00693 
00694                    }
00695    }
00696 
00697    
00699    // load a descriptor                                                                 //
00700    // @param i_name : file name to load                             //
00701    // @return : -                                                                               //
00703    void WxDescriptorPanel::loadDescriptor(const std::string i_name)
00704    {
00705            std::ifstream i_file(i_name.c_str());
00706            std::stringstream buffer;
00707            buffer << i_file.rdbuf();
00708            std::string line;
00709            std::string level;
00710 
00711 #if defined(USE_GDCM2)
00712            const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
00713            const gdcm::Dicts &dicts = g.GetDicts();
00714            const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
00715 #endif
00716           
00717 
00718                 bool bname;
00719                 int ilevel = -1;
00720 
00721                 
00722                 while(std::getline(buffer, line))
00723                 {
00724                         if(line =="<level>")
00725                         {       //increment levels.
00726                                 ilevel++;
00727                                 bname = true;
00728                         }
00729                         else if(bname)
00730                         {
00731                                 // For each level, a name to describe it
00732                                 level = line;
00733                                 if(ilevel>0)
00734                                 {
00735                                         onAddLevel(level);
00736                                 }
00737                                 bname = false;
00738                         }
00739                         else
00740                         { 
00741                                 // split line to find all tags
00742                                 std::vector<std::string> descriptors;
00743                                 std::string separator = " ";
00744                                 std::string::size_type last_pos = line.find_first_not_of(separator);
00745                                 //find first separator
00746                                 std::string::size_type pos = line.find_first_of(separator, last_pos);
00747                                 while(std::string::npos != pos || std::string::npos != last_pos)
00748                                 {
00749                                         descriptors.push_back(line.substr(last_pos, pos - last_pos));
00750                                         last_pos = line.find_first_not_of(separator, pos);
00751                                         pos = line.find_first_of(separator, last_pos);
00752                                 }
00753                                 
00754                                 // By default, the last tag is at zero and not recorded but if take in count
00755                                 unsigned int flag = 0;
00756                                 if(descriptors.size() == 4)
00757                                 {
00758                                         std::stringstream val;
00759                                         val << std::dec << descriptors[3];
00760                                         val>> flag;
00761                                 }
00762 
00763                                 // if Dicom tag, use "group" and "element" descriptor
00764                                 if(descriptors[0] == "D")
00765                                 {       std::stringstream val, val2;
00766                                         unsigned short group;
00767                                         unsigned short element;
00768                                         val <<   std::dec << descriptors[1] ;
00769                                         val >> std::hex >> group;
00770                                         val2 << std::dec <<  descriptors[2];
00771                                         val2 >> std::hex >> element;
00772                                         std::string compose =  "D";
00773                                         compose +=  descriptors[1];
00774                                         compose += "_";
00775                                         compose +=  descriptors[2];
00776 #if defined(USE_GDCM)
00777                                         GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(group, element);
00778                                         if(ilevel>0)
00779                                         {
00780                                                 onAddAttribute( entry->GetName(),compose, level);
00781                                         }
00782 #endif
00783 
00784 #if defined(USE_GDCM2)
00785                                         gdcm::DictEntry dictentry =  dict.GetDictEntry(gdcm::Tag(group, element));
00786                                         if(ilevel>0)
00787                                         {
00788                                                 onAddAttribute( dictentry.GetName(),compose, level);
00789                                         }
00790         
00791 
00792 #endif
00793                                 }
00794                                 else if(descriptors[0].find("#") != -1)
00795                                 {
00796                                         // commented line continue to next line
00797                                 }
00798                                 else // "O" means if user's own tag.
00799                                 {       
00800                                         boost::algorithm::replace_all(descriptors[2],"_"," ");
00801                                         if(ilevel>0 && descriptors[1] != "NumberOfChildren" )
00802                                         {       
00803                                                 onAddAttribute( descriptors[2].c_str(),descriptors[1].c_str(), level);
00804                                         }
00805                                 }
00806                         }
00807                 }
00808    }
00809    
00810 //======================================================================
00811   
00812 //====================================================================== 
00813 
00814 } // EO namespace creaImageIO
00815 
00816