]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/HistogramDialogComboBox.cxx
#2844 creaMaracasVisu Feature New Normal - ManualPaint_model box, Refresh TransferF...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / HistogramDialogComboBox.cxx
index 649ade65563bd4614e045f91e24a171ba7b17983..e987f8c1b495c424e8993225607d4f0ea6508527 100644 (file)
@@ -1,3 +1,28 @@
+/*# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+#                        pour la Sant�)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+#  This software is governed by the CeCILL-B license under French law and
+#  abiding by the rules of distribution of free software. You can  use,
+#  modify and/ or redistribute the software under the terms of the CeCILL-B
+#  license as circulated by CEA, CNRS and INRIA at the following URL
+#  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+#  or in the file LICENSE.txt.
+#
+#  As a counterpart to the access to the source code and  rights to copy,
+#  modify and redistribute granted by the license, users are provided only
+#  with a limited warranty  and the software's author,  the holder of the
+#  economic rights,  and the successive licensors  have only  limited
+#  liability.
+#
+#  The fact that you are presently reading this means that you have had
+#  knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------ */
+
 #include "HistogramDialogComboBox.h"
 #include <vector>
 
 HistogramDialogComboBox::HistogramDialogComboBox(wxWindow* parent)
 : wxPanel(parent)
 {
-       _img                    = NULL;
+       _img                            = NULL;
        _bitmapcombo            = NULL;
        _slidercolor            = NULL;
        _sliderwindowlevel      = NULL;
+       _ckboxActive            = NULL;
        colorBar_Bitmap         = NULL;
        _bitmapsizer            = NULL;
-
+       InitCurrentPathColorsFuntion();
        this->SetSizer(getBitmapCombo());
-       _img                    = NULL;
-       _currentitem            = -1;
+       _img                            = NULL;
+       _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()
 {
 }
@@ -55,34 +70,39 @@ 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));
        Connect(edit->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&HistogramDialogComboBox::OnEditBitmapCombo);
-
+       _ckboxActive= new wxCheckBox( this, 
+                             -1, 
+                             _T(" "),
+                             wxDefaultPosition, 
+                             //wxSize(sizeX,sizeY),
+                             wxDefaultSize, 
+                             wxCHK_2STATE | wxALIGN_RIGHT);      
+       _ckboxActive->SetValue(false);
+
+    Connect( _ckboxActive->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) (void (wxPanel::*)(wxScrollEvent&))  &HistogramDialogComboBox::OnChkBoxActive);
+
+       comboeditsizer->Add(_ckboxActive,wxSizerFlags().Center().FixedMinSize());
        comboeditsizer->Add(_bitmapcombo,wxSizerFlags().Center().FixedMinSize());
        comboeditsizer->Add(edit,wxSizerFlags().Center());
-
        _bitmapsizer->Add(comboeditsizer,wxSizerFlags().FixedMinSize().Center());
        _bitmapsizer->AddSpacer(5);
        _bitmapsizer->Add(getSlidersWlCo(),wxSizerFlags().Expand().Center());
-
        return _bitmapsizer;
 }
 
 wxSizer* HistogramDialogComboBox::getSlidersWlCo()
 {
-       wxBoxSizer* sizersliders = new wxBoxSizer(wxVERTICAL);
-
-       _slidercolor = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
-       _sliderwindowlevel = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
-
+       wxBoxSizer* sizersliders        = new wxBoxSizer(wxVERTICAL);
+       _slidercolor                            = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
+       _sliderwindowlevel                      = new wxSlider(this, -1,1,0,1,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
        sizersliders->Add(_slidercolor,wxSizerFlags().Expand().Center());
        sizersliders->Add(_sliderwindowlevel,wxSizerFlags().Expand().Center());
-
-       Connect(_slidercolor->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction)&HistogramDialogComboBox::OnColorLevelChanged);
+    Connect(_slidercolor->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction)&HistogramDialogComboBox::OnColorLevelChanged);
        Connect(_sliderwindowlevel->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction)&HistogramDialogComboBox::OnWindowLevelChanged);
-
        return sizersliders;
 }
 
@@ -90,7 +110,9 @@ double HistogramDialogComboBox::GetWindowLevel()
 {
    double val(0.0);
    if(_sliderwindowlevel != NULL)
+       {
       val= _sliderwindowlevel->GetValue();
+       }
    return val; // JPR
 }
 
@@ -98,10 +120,31 @@ double HistogramDialogComboBox::GetColorLevel()
 {
    double val(0.0);
    if(_slidercolor != NULL)
+       {
       val = _slidercolor->GetValue();
+       }
    return val; // JPR
 }
 
+
+bool HistogramDialogComboBox::GetActive()
+{
+       bool result = false;
+       if (_ckboxActive!=NULL) 
+       {
+               result = _ckboxActive->GetValue();
+       }
+       return result;
+}
+
+
+void HistogramDialogComboBox::OnChkBoxActive(wxCommandEvent& event)
+{
+   wxCommandEvent newevent(wxEVT_COMMAND_COMBOBOX_SELECTED,this->GetId());
+   ProcessEvent(newevent);
+}
+
+
 void HistogramDialogComboBox::OnColorLevelChanged(wxCommandEvent& event)
 {
    _slidercolor->GetValue();
@@ -151,39 +194,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;
@@ -240,63 +277,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)
@@ -318,6 +384,7 @@ void HistogramDialogComboBox::OnLoadComboBoxData(std::vector<HistogramDialogComb
 
        //std::cout<<filename<<std::endl;
        itembitmaps.clear();
+
        if(file.is_open())
        {
                bool add = false;