25 #include <Gui/PanelForDoubleValueWx.hh>
27 #include <wx/valtext.h>
33 const wxString& label,
34 const double minlimit,
35 const double maxlimit,
36 const double initialval,
41 : wxPanel(parent, id, pos, size, style),
42 MainSizer(new wxBoxSizer(wxHORIZONTAL)),
43 Label(new wxStaticText(this,
48 StepSizeLabel(new wxStaticText(this,
53 TextCtrl(new wxTextCtrl(this,
56 Slider(new wxSlider(this,
63 wxSL_HORIZONTAL | wxSL_AUTOTICKS)),
64 SpinCtrl(new wxSpinCtrl(this,
75 ParamMaxLimit(maxlimit),
76 ParamMinLimit(minlimit)
78 if (this->ParamMaxLimit <= this->ParamMinLimit) {
82 this->SetSizer(MainSizer);
84 this->MainSizer->Add(this->
Label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
85 this->MainSizer->Add(this->TextCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
86 this->MainSizer->Add(this->Slider, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
87 this->MainSizer->Add(this->StepSizeLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
88 this->MainSizer->Add(this->SpinCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
90 Connect(PanelForDoubleValueWx::ID_TEXT_CTRL,
91 wxEVT_COMMAND_TEXT_UPDATED,
92 wxCommandEventHandler(PanelForDoubleValueWx::OnTextCtrl));
93 Connect(PanelForDoubleValueWx::ID_SLIDER,
94 wxEVT_COMMAND_SLIDER_UPDATED,
95 wxCommandEventHandler(PanelForDoubleValueWx::OnSlider));
96 Connect(PanelForDoubleValueWx::ID_SPIN_CTRL,
97 wxEVT_COMMAND_SPINCTRL_UPDATED,
98 wxSpinEventHandler(PanelForDoubleValueWx::OnSpinCtrl));
102 wxString strVal(wxT(
""));
103 strVal = wxString::Format(wxT(
"%f"), initialval);
104 this->TextCtrl->SetValue(strVal);
105 this->TextCtrl->SetValue(strVal);
108 this->Slider->SetRange(0, stepsize);
110 this->MainSizer->Fit(
this);
119 wxString strVal = this->TextCtrl->GetValue();
121 strVal.ToDouble(&val);
128 return this->ParamMaxLimit;
134 return this->ParamMinLimit;
140 return this->StepSize;
146 if (maxlimit >= this->ParamMinLimit) {
148 if (maxlimit < this->TextCtrlValue) {
149 this->TextCtrlValue = maxlimit;
150 this->TextCtrl->SetValue(wxString::Format(wxT(
"%f"), this->TextCtrlValue));
153 this->ParamMaxLimit = maxlimit;
154 this->UpdateSlider();
167 if (minlimit <= this->ParamMaxLimit) {
169 if (minlimit > this->TextCtrlValue) {
170 this->TextCtrlValue = minlimit;
171 this->TextCtrl->SetValue(wxString::Format(wxT(
"%f"), this->TextCtrlValue));
174 this->ParamMinLimit = minlimit;
175 this->UpdateSlider();
188 this->
Label->SetLabel(label);
194 this->StepSize = stepsize;
195 this->Slider->SetRange(0, this->StepSize);
196 this->UpdateSlider();
202 void PanelForDoubleValueWx::OnTextCtrl(wxCommandEvent& WXUNUSED(event))
204 wxString strVal = this->TextCtrl->GetValue();
207 if (strVal.ToDouble(&val)) {
210 if (strVal.Contains(wxT(
"e")) || strVal.Contains(wxT(
"E"))) {
212 strVal = wxString::Format(wxT(
"%f"), this->TextCtrlValue);
213 this->TextCtrl->SetValue(strVal);
219 if (val > this->ParamMaxLimit) {
220 this->TextCtrlValue = this->ParamMaxLimit;
221 strVal = wxString::Format(wxT(
"%f"), this->TextCtrlValue);
222 this->TextCtrl->SetValue(strVal);
223 }
else if (val < this->ParamMinLimit) {
224 this->TextCtrlValue = this->ParamMinLimit;
225 strVal = wxString::Format(wxT(
"%f"), this->TextCtrlValue);
226 this->TextCtrl->SetValue(strVal);
228 this->TextCtrlValue = val;
233 strVal = wxString::Format(wxT(
"%f"), this->TextCtrlValue);
234 this->TextCtrl->SetValue(strVal);
237 this->UpdateSlider();
241 void PanelForDoubleValueWx::OnSlider(wxCommandEvent& WXUNUSED(event))
245 Disconnect(PanelForDoubleValueWx::ID_TEXT_CTRL,
246 wxEVT_COMMAND_TEXT_UPDATED,
247 wxCommandEventHandler(PanelForDoubleValueWx::OnTextCtrl));
248 int sliderValue = this->Slider->GetValue();
249 double ratio =
static_cast<double>(sliderValue) / this->StepSize;
250 double diffMinMax = this->ParamMaxLimit - this->ParamMinLimit;
251 double distance = this->ParamMinLimit + (diffMinMax * ratio);
252 wxString strVal = wxString::Format(wxT(
"%f"), distance);
253 this->TextCtrlValue = distance;
254 this->TextCtrl->SetValue(strVal);
255 Connect(PanelForDoubleValueWx::ID_TEXT_CTRL,
256 wxEVT_COMMAND_TEXT_UPDATED,
257 wxCommandEventHandler(PanelForDoubleValueWx::OnTextCtrl));
261 void PanelForDoubleValueWx::OnSpinCtrl(wxSpinEvent& WXUNUSED(event))
267 void PanelForDoubleValueWx::UpdateSlider()
269 double diffMinMax = this->ParamMaxLimit - this->ParamMinLimit;
270 double distance = this->TextCtrlValue - this->ParamMinLimit;
271 double ratio = distance / diffMinMax;
272 int newSliderVal = ratio * this->StepSize;
273 this->Slider->SetValue(newSliderVal);
PanelForDoubleValueWx(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &label=wxT("LABEL:"), const double minlimit=0.0, const double maxlimit=1.0, const double initialval=0.5, const int stepsize=10000, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
double GetParamValue() const
void SetParamLabel(const wxString &label)
Gives the parameter a name.
Helper Class For Parameter Input To Take Floating Point Numbers.
void SetStepSize(const int stepsize)
Sets the RANGE for the slider for precision (and also here: name is misleading)
double GetParamMaxLimit() const
double GetParamMinLimit() const
bool SetParamMaxLimit(const double maxlimit)
Sets the maximum limit for a parameter.
bool SetParamMinLimit(const double minlimit)
Sets the minimum limit for a parameter.
does a connected component analysis and labels all connected regions