]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/mBarRange2.cxx
#2490 creaMaracasVisu Feature New High - Histogram Interaction
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / mBarRange2.cxx
1  /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /**
27  *  \file 
28  *  \brief ClassThresholdImageViewPanel . 
29  */
30
31 #include "mBarRange2.h"
32
33
34 DEFINE_EVENT_TYPE(wxEVT_BarRange2_Change)
35
36
37 /**
38  ** Begin of the  panel
39  **/
40 mBarRange2::mBarRange2(wxWindow* parent,int width, int height)
41 : wxPanel(parent, -1, wxDefaultPosition, wxSize(width,height), wxBORDER_SUNKEN)
42 {
43         _minValue                       = 0;
44         _maxValue                       = 100;
45         _scalarType                     = 0;
46         _mBarRange                      = new mBarRange(this,width,height);
47         _mBarRange->SetOrientation( true );
48         _mBarRange->setActiveStateTo(true);
49         _mBarRange->setVisibleLabels( false );
50         _mBarRange->setDeviceEndMargin(10);
51         _mBarRange->setDeviceBlitStart(10,10); 
52         _mBarRange->setIfWithActualDrawed( false );
53         _mBarRange->setRepresentedValues( 0, 100 );
54         _mBarRange->SetStart(0);
55         _mBarRange->SetEnd(100);  
56         _textctrlStart  = new wxTextCtrl( this, -1, _T(""),wxDefaultPosition, wxSize(60,20),wxTE_PROCESS_ENTER );
57         _textctrlEnd            = new wxTextCtrl( this, -1, _T(""),wxDefaultPosition, wxSize(60,20),wxTE_PROCESS_ENTER );
58         Connect( _textctrlStart->GetId(), wxEVT_COMMAND_TEXT_ENTER      , (wxObjectEventFunction) &mBarRange2::onTxtCtrl );
59         Connect( _textctrlEnd->GetId(), wxEVT_COMMAND_TEXT_ENTER        , (wxObjectEventFunction) &mBarRange2::onTxtCtrl );
60         wxFlexGridSizer * sizer                                 = new wxFlexGridSizer(1);
61         wxFlexGridSizer * sizerTextCtrl         = new wxFlexGridSizer(2);
62         sizerTextCtrl -> Add( _textctrlStart    , 1, wxGROW );  
63         sizerTextCtrl -> Add( _textctrlEnd              , 1, wxGROW );  
64         sizer -> Add( _mBarRange                                        , 1, wxGROW );  
65         sizer -> Add( sizerTextCtrl                             , 1, wxGROW );  
66         this->SetSizer( sizer );
67         this->SetAutoLayout( true );
68         this->Layout();
69         RefreshTextCntrl();
70 }
71
72 //----------------------------------------------------------------------------
73 mBarRange2::~mBarRange2()
74 {
75 }
76
77 //----------------------------------------------------------------------------
78 wxString mBarRange2::CleanNumberStr(wxString string)
79 {
80         wxString tmpStr=string;
81         while (tmpStr[tmpStr.Length()-1]=='0') 
82         {
83                 tmpStr=tmpStr.SubString (0, tmpStr.Length()-1-1 );
84         } //
85
86         if (tmpStr[tmpStr.Length()-1]=='.')
87         {
88                 tmpStr.Append(_T("0"));
89         }
90         return tmpStr;
91 }
92
93
94 //----------------------------------------------------------------------------
95 double mBarRange2::GetStartValue()
96 {
97         return _startValue;
98 }
99
100 //----------------------------------------------------------------------------
101 double mBarRange2::GetEndValue()
102 {
103         return _endValue;
104 }
105
106 //----------------------------------------------------------------------------
107 void mBarRange2::RefreshTextCntrl()
108 {
109    double startPorcentage       = _mBarRange->GetStart();
110         double endPorcentage    = _mBarRange->GetEnd();  
111         _startValue                             = (_maxValue-_minValue)*(startPorcentage/100) + _minValue;
112         _endValue                                       = (_maxValue-_minValue)*(endPorcentage/100) + _minValue;
113
114         wxString startValueStr;
115         wxString endValueStr;
116
117         if ( (_scalarType==10) || (_scalarType==11) )  // 10=VTK_FLOAT   11=VTK_DOUBLE  
118         {
119                 startValueStr.Printf(_T("%f"),_startValue);
120                 startValueStr=CleanNumberStr( startValueStr );
121                 endValueStr.Printf(_T("%f"),_endValue);
122                 endValueStr=CleanNumberStr( endValueStr );
123         } else {
124                 startValueStr.Printf(_T("%d"),(int)_startValue);        
125                 endValueStr.Printf(_T("%d"),(int)_endValue);
126         }
127
128         _textctrlStart->SetValue( startValueStr );
129         _textctrlEnd->SetValue( endValueStr );  
130 }
131
132
133 //----------------------------------------------------------------------------
134 void mBarRange2::createAndSendEvent(WXTYPE theEventType)
135 {
136         wxCommandEvent cevent( theEventType, GetId() );
137         cevent.SetEventObject( this );
138         GetEventHandler()->ProcessEvent( cevent );
139 }
140
141
142
143 //----------------------------------------------------------------------------
144 void mBarRange2::onBarRangeChange(wxCommandEvent& event)
145 {
146         RefreshTextCntrl();
147         createAndSendEvent( wxEVT_BarRange2_Change );
148 }
149
150 //----------------------------------------------------------------------------
151 void mBarRange2::onTxtCtrl(wxCommandEvent& event)
152 {
153         double value;
154         double startPorcentage;
155         double endPorcentage;
156         if (_textctrlStart->GetValue().ToDouble(&value)==true)
157         { 
158                 startPorcentage = (value - _minValue)*100/(_maxValue-_minValue);
159                 _mBarRange->SetStart( startPorcentage );
160         } 
161
162         if (_textctrlEnd->GetValue().ToDouble(&value)==true)
163         { 
164                 endPorcentage = (value - _minValue)*100/(_maxValue-_minValue);
165                 _mBarRange->SetEnd( endPorcentage );
166         } 
167
168         RefreshTextCntrl();             
169 }
170
171 //----------------------------------------------------------------------------
172 void mBarRange2::SetMinMaxValue(double min, double max)
173 {
174         _minValue = min;
175         _maxValue = max;
176         RefreshTextCntrl();             
177 }
178
179
180 //----------------------------------------------------------------------------
181 void mBarRange2::SetScalarType(int value)
182 {
183         _scalarType = value;
184 }
185
186
187
188 //----------------------------------------------------------------------------
189 BEGIN_EVENT_TABLE(mBarRange2, wxPanel)
190   EVT_COMMAND( wxID_ANY, wxEVT_TSBAR_START      , mBarRange2::onBarRangeChange  )
191   EVT_COMMAND( wxID_ANY, wxEVT_TSBAR_END                , mBarRange2::onBarRangeChange  )
192   EVT_COMMAND( wxID_ANY, wxEVT_TSBAR_MOVED      , mBarRange2::onBarRangeChange  )       
193 END_EVENT_TABLE()
194
195
196 // EOF
197