1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 * \brief ClassThresholdImageViewPanel .
31 #include "mBarRange2.h"
34 DEFINE_EVENT_TYPE(wxEVT_BarRange2_Change)
40 mBarRange2::mBarRange2(wxWindow* parent,int width, int height)
41 : wxPanel(parent, -1, wxDefaultPosition, wxSize(width,height), wxBORDER_SUNKEN)
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 );
72 //----------------------------------------------------------------------------
73 mBarRange2::~mBarRange2()
77 //----------------------------------------------------------------------------
78 wxString mBarRange2::CleanNumberStr(wxString string)
80 wxString tmpStr=string;
81 while (tmpStr[tmpStr.Length()-1]=='0')
83 tmpStr=tmpStr.SubString (0, tmpStr.Length()-1-1 );
86 if (tmpStr[tmpStr.Length()-1]=='.')
88 tmpStr.Append(_T("0"));
94 //----------------------------------------------------------------------------
95 double mBarRange2::GetStartValue()
100 //----------------------------------------------------------------------------
101 double mBarRange2::GetEndValue()
106 //----------------------------------------------------------------------------
107 void mBarRange2::RefreshTextCntrl()
109 double startPorcentage = _mBarRange->GetStart();
110 double endPorcentage = _mBarRange->GetEnd();
111 _startValue = (_maxValue-_minValue)*(startPorcentage/100) + _minValue;
112 _endValue = (_maxValue-_minValue)*(endPorcentage/100) + _minValue;
114 wxString startValueStr;
115 wxString endValueStr;
117 if ( (_scalarType==10) || (_scalarType==11) ) // 10=VTK_FLOAT 11=VTK_DOUBLE
119 startValueStr.Printf(_T("%f"),_startValue);
120 startValueStr=CleanNumberStr( startValueStr );
121 endValueStr.Printf(_T("%f"),_endValue);
122 endValueStr=CleanNumberStr( endValueStr );
124 startValueStr.Printf(_T("%d"),(int)_startValue);
125 endValueStr.Printf(_T("%d"),(int)_endValue);
128 _textctrlStart->SetValue( startValueStr );
129 _textctrlEnd->SetValue( endValueStr );
133 //----------------------------------------------------------------------------
134 void mBarRange2::createAndSendEvent(WXTYPE theEventType)
136 wxCommandEvent cevent( theEventType, GetId() );
137 cevent.SetEventObject( this );
138 GetEventHandler()->ProcessEvent( cevent );
143 //----------------------------------------------------------------------------
144 void mBarRange2::onBarRangeChange(wxCommandEvent& event)
147 createAndSendEvent( wxEVT_BarRange2_Change );
150 //----------------------------------------------------------------------------
151 void mBarRange2::onTxtCtrl(wxCommandEvent& event)
154 double startPorcentage;
155 double endPorcentage;
156 if (_textctrlStart->GetValue().ToDouble(&value)==true)
158 startPorcentage = (value - _minValue)*100/(_maxValue-_minValue);
159 _mBarRange->SetStart( startPorcentage );
162 if (_textctrlEnd->GetValue().ToDouble(&value)==true)
164 endPorcentage = (value - _minValue)*100/(_maxValue-_minValue);
165 _mBarRange->SetEnd( endPorcentage );
171 //----------------------------------------------------------------------------
172 void mBarRange2::SetMinMaxValue(double min, double max)
180 //----------------------------------------------------------------------------
181 void mBarRange2::SetScalarType(int value)
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 )