]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBox.cxx
2108 Bug Volume Rendering widget options are not stable
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / HistogramDialogComboBox.cxx
index 88d8c52a9ea34b5ecebfa8f2bc639f436c60990f..e57059a3fed44f08493276d8d7f8684a49800434 100644 (file)
@@ -43,23 +43,17 @@ HistogramDialogComboBox::HistogramDialogComboBox(wxWindow* parent)
        colorBar_Bitmap         = NULL;
        _bitmapsizer            = NULL;
 
+       InitCurrentPathColorsFuntion();
        this->SetSizer(getBitmapCombo());
        _img                    = NULL;
-       _currentitem            = -1;
+       _currentitem            = -1;    
        _maxgreyvalue           = 0;
-printf("EED HistogramDialogComboBox\n");
-#ifdef LINUX
-       std::string currentpath = crea::System::GetExecutablePath();
 
 
-    currentpath.append("../share/creaMaracasVisu/data/");
-printf("EED JCP OOOOJJJOOO cambiar esto HistogramDialogComboBox::HistogramDialog writting in this directory\n");
-    currentpath = "/home/davila/dataHistogram";
+}
+
 
 
-       crea::System::createDirectory(currentpath.c_str());
-#endif
-}
 
 HistogramDialogComboBox::~HistogramDialogComboBox()
 {
@@ -80,6 +74,7 @@ wxSizer* HistogramDialogComboBox::getBitmapCombo()
 
        wxBoxSizer* comboeditsizer = new wxBoxSizer(wxHORIZONTAL);
        _bitmapcombo = getBitmapComboElements();
+        BitmapComboItemSelect(0);
 
        wxBitmap bitmap1(Edit_xpm);
        wxBitmapButton* edit = new wxBitmapButton(this, -1, bitmap1,wxDefaultPosition,wxSize(30,30));
@@ -176,39 +171,33 @@ void HistogramDialogComboBox::OnEditBitmapCombo(wxCommandEvent& event)
                        dialog->UpdateCurrentComboElement();
                        _bitmapsitems = dialog->getComboBoxItems();
 
-                       //std::string currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu"); // JPR
-                       std::string dllLastName;
-                       std::string currentpath;
-                       #ifdef WIN32
-                       dllLastName = "bbcreaMaracasVisu";
-                       currentpath = crea::System::GetDllAppPath(dllLastName);
-                       #endif
-                       #ifdef LINUX
-                       currentpath = crea::System::GetExecutablePath();
-                       currentpath.append("../share/creaMaracasVisu/data/");
-                       #endif
-                       currentpath.append(FILENAME);
-
                        std::vector<double> redvect,greenvect,bluevect;
                        std::vector<double> greyvect;
 
-                       saveCurrentConfiguration(_bitmapsitems, currentpath);
+                       saveCurrentConfiguration(_bitmapsitems, GetFileNameOfColorsFunction() );
                        wxBitmapComboBox* tempbitmapcombo = _bitmapcombo;
-                       for(int i = 0; i < _bitmapsitems.size();i++){
+                       for(int i = 0; i < _bitmapsitems.size();i++)
+                       {
                                delete _bitmapsitems[i];
                        }
                        _bitmapsitems.clear();
                        _bitmapcombo = getBitmapComboElements();
-                       if(_bitmapsizer->Replace(tempbitmapcombo,_bitmapcombo)){
-
-                               tempbitmapcombo->Destroy();
-                       }
+                       
+// EED Eraseme                 
+//                     if(_bitmapsizer->Replace(tempbitmapcombo,_bitmapcombo))
+//                     {
+//                             tempbitmapcombo->Destroy();
+//                     } else {
+//                             printf ("EED ERROR HistogramDialogComboBox::OnEditBitmapCombo. Can't replace bitmapcombo \n");
+//                     }
+                       
                        this->Layout();
                }
                dialog->Destroy();
        }
 }
 
+
 void HistogramDialogComboBox::saveCurrentConfiguration(std::vector<HistogramDialogComboBoxItem*>& itembitmaps,std::string filename)
 {
        std::ofstream file;
@@ -265,63 +254,92 @@ void HistogramDialogComboBox::saveCurrentConfiguration(std::vector<HistogramDial
        file.close();
 }
 
-wxBitmapComboBox* HistogramDialogComboBox::getBitmapComboElements()
+void HistogramDialogComboBox::InitCurrentPathColorsFuntion()
 {
-       std::string currentpath = "";
+      _currentpathColorsFuntion = "";
 #ifdef WIN32
-       currentpath = crea::System::GetDllAppPath("bbcreaMaracasVisu");
+       _currentpathColorsFuntion = crea::System::GetDllAppPath("bbcreaMaracasVisu");
 #endif
 #ifdef LINUX
-       currentpath = crea::System::GetExecutablePath();
-       currentpath.append("../share/CreaMaracasVisu/data/");
+       _currentpathColorsFuntion = crea::System::GetExecutablePath();
+       _currentpathColorsFuntion.append("/../share/creaMaracasVisu/data/");
+#endif
+       crea::System::createDirectory(_currentpathColorsFuntion.c_str());
+}
 
-printf("EED JCP OOOOJJJOOO cambiar esto HistogramDialogComboBox::HistogramDialog writting in this file ******************\n");
-    currentpath = "/home/davila/dataHistogram";
 
-#endif
-       currentpath.append(FILENAME);
 
-       std::cout<<"current file name " <<currentpath<<std::endl;
+std::string HistogramDialogComboBox::GetFileNameOfColorsFunction()
+{
+   std::string filename;
+   filename = _currentpathColorsFuntion;                                                       
+   filename.append(COLORSFUNCTIONFILENAME);                                                                                                                       
+   return filename;
+}
 
+
+wxBitmapComboBox* HistogramDialogComboBox::getBitmapComboElements()
+{
        std::vector<HistogramDialogComboBoxItem*> bitmapsitems;
-       OnLoadComboBoxData(bitmapsitems, currentpath);
+       OnLoadComboBoxData(bitmapsitems, GetFileNameOfColorsFunction() );
        _bitmapsitems = bitmapsitems;
        wxString* choices;
        choices = new wxString[bitmapsitems.size()];
        for(int i = 0; i < bitmapsitems.size();i++)
        {
-               choices[i] = _T("");
+               choices[i] = _T("Color Function");
+       }
+       
+       wxBitmapComboBox* bitmapcombo;
+//EED  wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, bitmapsitems.size(),choices);
+       if (_bitmapcombo!=NULL)
+       {
+               _bitmapcombo->Clear();
+               bitmapcombo=_bitmapcombo;
+       } else {
+               bitmapcombo = new wxBitmapComboBox(this, -1, _T(""));
        }
-       wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, bitmapsitems.size(),choices);
-       bitmapcombo->SetSize(65,30);
+//     wxBitmapComboBox* bitmapcombo = new wxBitmapComboBox(this, -1, _T(""));
+       bitmapcombo->SetSize(165,30);
 
        Connect(bitmapcombo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction)&HistogramDialogComboBox::OnBitmapComboItemSelected);
 
        for(int i = 0; i < bitmapsitems.size(); i++)
        {
-        bitmapcombo->SetItemBitmap(i, bitmapsitems[i]->GetBitmap());
+               bitmapcombo->Append(_T("ColorFunction"), bitmapsitems[i]->GetBitmap() );
+//        bitmapcombo->SetItemBitmap(i, bitmapsitems[i]->GetBitmap());
        }
+       BitmapComboItemSelect(0);
        return  bitmapcombo;
 }
 
-void HistogramDialogComboBox::OnBitmapComboItemSelected(wxCommandEvent& event)
+
+void HistogramDialogComboBox::BitmapComboItemSelect(int value)
 {
+       HistogramDialogComboBoxItem* currentconfig;
        if(_bitmapcombo!=NULL)
        {
-               _currentitem = event.GetInt();
+               _currentitem = value;
+               _bitmapcombo->Select(value);
                if(_bitmapsitems.size()>_currentitem)
                {
-                       HistogramDialogComboBoxItem* currentconfig = _bitmapsitems[_currentitem];
-                       _greyvect = currentconfig->getGreyVector();
-                       _redvect = currentconfig->getRedVector();
-                       _greenvect = currentconfig->getGreenVector();
-                       _bluevect= currentconfig->getBlueVector();
-                       _greyvecttransfer = currentconfig->getGreyVectorTransfer();
-                       _value  = currentconfig->getValueVector();
+                       currentconfig           = _bitmapsitems[_currentitem];
+                       _greyvect                       = currentconfig->getGreyVector();
+                       _redvect                        = currentconfig->getRedVector();
+                       _greenvect                      = currentconfig->getGreenVector();
+                       _bluevect                       = currentconfig->getBlueVector();
+                       _greyvecttransfer       = currentconfig->getGreyVectorTransfer();
+                       _value                          = currentconfig->getValueVector();
                        wxCommandEvent newevent(wxEVT_COMMAND_COMBOBOX_SELECTED,this->GetId());
             ProcessEvent(newevent);
-               }
-       }
+               } // if size
+       } // _bitmapcombo
+}
+
+
+void HistogramDialogComboBox::OnBitmapComboItemSelected(wxCommandEvent& event)
+{
+       BitmapComboItemSelect(  event.GetInt() );
 }
 
 void HistogramDialogComboBox::OnLoadComboBoxData(std::vector<HistogramDialogComboBoxItem*>& itembitmaps, std::string filename)
@@ -343,6 +361,7 @@ void HistogramDialogComboBox::OnLoadComboBoxData(std::vector<HistogramDialogComb
 
        //std::cout<<filename<<std::endl;
        itembitmaps.clear();
+
        if(file.is_open())
        {
                bool add = false;