8 #include <Utils/ParamTypes.hh>
9 #include <Base/Debug/DebugSimple.hh>
10 #include <Gui/StringConv.hh>
16 typedef map<const std::string,BIAS::ParamTypeBase*>::const_iterator CI;
44 if (it->second->Group_ == GroupID)
48 if (
ParamTypeInt *item = dynamic_cast<ParamTypeInt*>(it->second) )
50 else if (
ParamTypeBool *item = dynamic_cast<ParamTypeBool*>(it->second) )
52 else if (
ParamTypeDouble *item = dynamic_cast<ParamTypeDouble*>(it->second) )
54 else if (
ParamTypeString *item = dynamic_cast<ParamTypeString*>(it->second) )
56 else if (
ParamTypeVecDbl *item = dynamic_cast<ParamTypeVecDbl*>(it->second) )
58 else if (
ParamTypeVecInt *item = dynamic_cast<ParamTypeVecInt*>(it->second) )
60 else if (
ParamTypeEnum *item = dynamic_cast<ParamTypeEnum*>(it->second) )
64 BIASERR(
"Invalid parameter type!");
70 wxSize size = panel->GetSize();
71 scrolled->SetScrollbars(1, 1, size.GetWidth(), size.GetHeight());
76 BIASERR(
"The requested group has no members!");
86 wxNotebook *notebook =
new wxNotebook( parent, -1,wxDefaultPosition,
87 wxDefaultSize, wxNB_TOP );
93 for(
unsigned int i=0; i<groups.size(); i++)
94 if (groups[i] != GRP_NOSHOW) {
96 panel =
GetPanel(notebook, groups[i]);
100 str.Printf(wxT(
"Group %d"),groups[i]);
106 if (!notebook->AddPage(panel, str))
108 BIASERR(
"Error adding notebook page!");
121 wxFrame *newframe =
new wxFrame(parent, -1, _T(
"ParamGUI Frame"),
122 wxDefaultPosition, wxDefaultSize);
124 #if wxCHECK_VERSION(2,5,2)
126 nbsizer =
new wxBoxSizer(wxHORIZONTAL);
127 nbsizer->Add(MyNotebook);
129 wxNotebookSizer *nbsizer;
130 nbsizer =
new wxNotebookSizer(MyNotebook);
132 newframe->SetSizer(nbsizer);
138 const wxString &title,
143 wxDefaultPosition, wxDefaultSize,
this, bChancelButton);
158 Grid_ =
new wxFlexGridSizer(1,3,2,5);
160 wxStaticText *Header1 =
new wxStaticText(
this, -1, _T(
"Parameter") );
161 wxStaticText *Header2 =
new wxStaticText(
this, -1, _T(
"Type") );
162 wxStaticText *Header3 =
new wxStaticText(
this, -1, _T(
"Value") );
164 Grid_->Add(Header1, 0, wxALIGN_CENTER);
165 Grid_->Add(Header2, 0, wxALIGN_CENTER);
166 Grid_->Add(Header3, 0, wxALIGN_CENTER);
187 wxString tooltip(
AsciiToWx(item->Help_));
188 unsigned int ID = wxNewId();
189 wxStaticText *LabelText =
new wxStaticText(
this, -1,
AsciiToWx(item->Name_) );
190 wxStaticText *TypeText =
new wxStaticText(
this, -1, _T(
"Integer") );
192 str.Printf(wxT(
"%d"),item->value_);
193 wxSpinCtrl *Spin =
new wxSpinCtrl(
this, ID, str, wxDefaultPosition,
194 wxDefaultSize, wxSP_ARROW_KEYS,
195 item->min_, item->max_ );
196 Spin->SetToolTip(tooltip);
197 Grid_->SetRows(Grid_->GetRows()+1);
198 Grid_->Add(LabelText, 0, wxALIGN_CENTER);
199 Grid_->Add(TypeText, 0, wxALIGN_CENTER);
200 Grid_->Add(Spin, 0, wxALIGN_CENTER);
204 NewStruct.
item = item;
205 pair<unsigned int, struct ItemAndWidget> NewPair( ID, NewStruct );
206 WidgetIDs_.insert(WidgetIDs_.end(), NewPair );
213 unsigned int ID = wxNewId();
214 wxStaticText *LabelText =
new wxStaticText(
this, -1,
AsciiToWx(item->
Name_) );
215 wxStaticText *TypeText =
new wxStaticText(
this, -1, _T(
"Boolean") );
216 wxCheckBox *CheckBox =
new wxCheckBox(
this, ID, wxEmptyString );
217 CheckBox->SetValue(item->
value_);
219 CheckBox->SetToolTip(tooltip);
222 Grid_->Add(LabelText, 0, wxALIGN_CENTER);
223 Grid_->Add(TypeText, 0, wxALIGN_CENTER);
224 Grid_->Add(CheckBox, 0, wxALIGN_CENTER);
227 NewStruct.
widget = CheckBox;
228 NewStruct.
item = item;
229 pair<unsigned int, struct ItemAndWidget> NewPair( ID, NewStruct );
230 WidgetIDs_.insert(WidgetIDs_.end(), NewPair );
237 unsigned int ID = wxNewId();
238 wxStaticText *LabelText =
new wxStaticText(
this, -1,
AsciiToWx(item->
Name_) );
239 wxStaticText *TypeText =
new wxStaticText(
this, -1, _T(
"Double") );
241 str.Printf(wxT(
"%f"),item->
value_);
242 wxTextCtrl *TextCtrl =
new wxTextCtrl(
this, ID, str, wxDefaultPosition,
243 wxDefaultSize, wxTE_PROCESS_ENTER );
244 TextCtrl->SetToolTip(tooltip);
247 Grid_->Add(LabelText, 0, wxALIGN_CENTER);
248 Grid_->Add(TypeText, 0, wxALIGN_CENTER);
249 Grid_->Add(TextCtrl, 0, wxALIGN_CENTER);
252 NewStruct.
widget = TextCtrl;
253 NewStruct.
item = item;
254 pair<unsigned int, struct ItemAndWidget> NewPair( ID, NewStruct );
255 WidgetIDs_.insert(WidgetIDs_.end(), NewPair );
262 unsigned int ID = wxNewId();
263 wxStaticText *LabelText =
new wxStaticText(
this, -1,
AsciiToWx(item->
Name_) );
264 wxStaticText *TypeText =
new wxStaticText(
this, -1, _T(
"String") );
266 wxTextCtrl *TextCtrl =
new wxTextCtrl(
this, ID, str, wxDefaultPosition,
267 wxSize(200,-1), wxTE_PROCESS_ENTER );
268 TextCtrl->SetToolTip(tooltip);
270 Grid_->Add(LabelText, 0, wxALIGN_CENTER);
271 Grid_->Add(TypeText, 0, wxALIGN_CENTER);
272 Grid_->Add(TextCtrl, 0, wxALIGN_CENTER);
275 NewStruct.
widget = TextCtrl;
276 NewStruct.
item = item;
277 pair<unsigned int, struct ItemAndWidget> NewPair( ID, NewStruct );
278 WidgetIDs_.insert(WidgetIDs_.end(), NewPair );
285 unsigned int ID = wxNewId();
286 wxStaticText *LabelText =
new wxStaticText(
this, -1,
AsciiToWx(item->
Name_) );
287 wxStaticText *TypeText =
new wxStaticText(
this, -1, _T(
"VecDbl") );
289 wxTextCtrl *TextCtrl =
new wxTextCtrl(
this, ID, str, wxDefaultPosition,
290 wxSize(200,-1), wxTE_PROCESS_ENTER );
291 TextCtrl->SetToolTip(tooltip);
293 Grid_->Add(LabelText, 0, wxALIGN_CENTER);
294 Grid_->Add(TypeText, 0, wxALIGN_CENTER);
295 Grid_->Add(TextCtrl, 0, wxALIGN_CENTER);
298 NewStruct.
widget = TextCtrl;
299 NewStruct.
item = item;
300 pair<unsigned int, struct ItemAndWidget> NewPair( ID, NewStruct );
301 WidgetIDs_.insert(WidgetIDs_.end(), NewPair );
308 unsigned int ID = wxNewId();
309 wxStaticText *LabelText =
new wxStaticText(
this, -1,
AsciiToWx(item->
Name_) );
310 wxStaticText *TypeText =
new wxStaticText(
this, -1, _T(
"VecInt") );
312 wxTextCtrl *TextCtrl =
new wxTextCtrl(
this, ID, str, wxDefaultPosition,
313 wxSize(200,-1), wxTE_PROCESS_ENTER );
314 TextCtrl->SetToolTip(tooltip);
316 Grid_->Add(LabelText, 0, wxALIGN_CENTER);
317 Grid_->Add(TypeText, 0, wxALIGN_CENTER);
318 Grid_->Add(TextCtrl, 0, wxALIGN_CENTER);
321 NewStruct.
widget = TextCtrl;
322 NewStruct.
item = item;
323 pair<unsigned int, struct ItemAndWidget> NewPair( ID, NewStruct );
324 WidgetIDs_.insert(WidgetIDs_.end(), NewPair );
331 unsigned int ID = wxNewId();
332 wxStaticText *LabelText =
new wxStaticText(
this, -1,
AsciiToWx(item->
Name_) );
333 wxStaticText *TypeText =
new wxStaticText(
this, -1, _T(
"Enum") );
334 int n = item->
Map_.size();
336 wxString *choices=
new wxString[n];
337 for(map<string,int>::iterator it=item->
Map_.begin(); it!=item->
Map_.end(); it++){
344 Choice->SetToolTip(tooltip);
347 for(map<string,int>::iterator it=item->
Map_.begin(); it!=item->
Map_.end(); it++){
352 Grid_->Add(LabelText, 0, wxALIGN_CENTER);
353 Grid_->Add(TypeText, 0, wxALIGN_CENTER);
354 Grid_->Add(Choice, 0, wxALIGN_CENTER);
357 NewStruct.
widget = Choice;
358 NewStruct.
item = item;
359 pair<unsigned int, struct ItemAndWidget> NewPair( ID, NewStruct );
360 WidgetIDs_.insert(WidgetIDs_.end(), NewPair );
365 Choice->SetSelection(v);
372 int ID =
event.GetId();
374 map<unsigned int,struct ItemAndWidget>::const_iterator it;
375 it = WidgetIDs_.find(ID);
376 if ( it == WidgetIDs_.end() ){
377 BIASERR(
"This error should never occur or otherwise\n "<<
378 "something with the event IDs went wrong");
382 dynamic_cast<ParamTypeInt*>(it->second.item) ) {
383 item->value_ = ((wxSpinCtrl*)(it->second.widget))->GetValue();
384 if (item->CallbackObject_ != NULL)
385 item->CallbackObject_->ParameterChanged(item->Name_, &item->value_);
389 BIASERR(
"Error during dynamic cast!");
397 int ID =
event.GetId();
399 map<unsigned int,struct ItemAndWidget>::const_iterator it;
400 it = WidgetIDs_.find(ID);
401 if ( it == WidgetIDs_.end() ){
402 BIASERR(
"This error should never occur or otherwise\n "<<
403 "something with the event IDs went wrong");
407 dynamic_cast<ParamTypeBool*>(it->second.item) ){
408 item->value_ = ((wxCheckBox*)(it->second.widget))->GetValue();
409 if (item->CallbackObject_ != NULL)
410 item->CallbackObject_->ParameterChanged(item->Name_, &item->value_);
413 BIASERR(
"Error during dynamic cast!");
420 COUT(
"Fetched TextEnter event!" << endl);
421 int ID =
event.GetId();
423 map<unsigned int,struct ItemAndWidget>::const_iterator it;
424 it = WidgetIDs_.find(ID);
425 if ( it == WidgetIDs_.end() ){
426 BIASERR(
"This error should never occur or otherwise\n "<<
427 "something with the event IDs went wrong");
431 dynamic_cast<ParamTypeDouble*>(it->second.item) ){
433 if ( !((wxTextCtrl*)it->second.widget)->GetValue().ToDouble(&newval) ){
434 wxMessageBox( wxT(
"Please check your input!"),
435 wxT(
"Not a double!"),
436 wxOK | wxICON_ERROR );
442 if ( newval > item->max_ ){
444 error.Printf(wxT(
"Your value outruns the upper border!\nValue clipped to %f!"),
446 wxMessageBox( error,wxT(
"Limits!"),wxOK | wxICON_ERROR );
447 item->value_ = item->max_;
449 else if ( newval < item->min_ )
452 error.Printf(wxT(
"Your value underruns the lower border!\nValue ")
453 wxT(
"clipped to %f!"),item->min_);
454 wxMessageBox( error,wxT(
"Limits!"),wxOK | wxICON_ERROR );
455 item->value_ = item->min_;
458 item->value_ = newval;
459 if (item->CallbackObject_ != NULL)
460 item->CallbackObject_->ParameterChanged(item->Name_, &item->value_);
464 dynamic_cast<ParamTypeString*>(it->second.item) ) {
465 item->value_ = WxToAscii(((wxTextCtrl*)(it->second.widget))->GetValue());
466 if (item->CallbackObject_ != NULL)
467 item->CallbackObject_->ParameterChanged(item->Name_, &item->value_);
470 dynamic_cast<ParamTypeVecDbl*>(it->second.item) ){
471 vector<double> entries;
472 string number = WxToAscii(((wxTextCtrl*)(it->second.widget))->GetValue());
473 string::iterator its = number.begin();
474 while((*its) ==
'\"'){
476 its = number.begin();
482 stringstream s(number);
487 entries.push_back(temp);
492 item->value_.newsize(entries.size());
493 for(
unsigned i=0;i<entries.size();i++){
494 item->value_[i] = entries[i];
499 if (item->CallbackObject_ != NULL)
500 item->CallbackObject_->ParameterChanged(item->Name_, &item->value_);
503 dynamic_cast<ParamTypeVecInt*>(it->second.item) ){
505 string number = WxToAscii(((wxTextCtrl*)(it->second.widget))->GetValue());
506 string::iterator its = number.begin();
507 while((*its) ==
'\"'){
509 its = number.begin();
515 stringstream s(number);
520 entries.push_back(temp);
525 item->value_.newsize(entries.size());
526 for(
unsigned i=0;i<entries.size();i++){
527 item->value_[i] = entries[i];
530 if (item->CallbackObject_ != NULL)
531 item->CallbackObject_->ParameterChanged(item->Name_, &item->value_);
534 BIASERR(
"Error during dynamic cast!");
542 COUT(
"Fetched Choice event!" << endl);
543 int ID =
event.GetId();
545 map<unsigned int,struct ItemAndWidget>::const_iterator it;
546 it = WidgetIDs_.find(ID);
547 if ( it == WidgetIDs_.end() )
549 BIASERR(
"This error should never occur or otherwise\n "<<
550 "something with the event IDs went wrong");
566 BIASERR(
"Error during dynamic cast, item is not of type ParamTypeEnum!");
582 std::map<int,int>::iterator it;
589 std::map<int,int>::iterator it;
596 const wxSize &s,
ParamGUI *pg,
bool bChancelButton )
597 :wxDialog(parent,-1,title, p,s, wxRESIZE_BORDER |wxCAPTION | wxSYSTEM_MENU)
601 wxBoxSizer *mainsizer =
new wxBoxSizer(wxVERTICAL);
602 wxBoxSizer *buttonsizer =
new wxBoxSizer(wxHORIZONTAL);
604 wxButton *ok =
new wxButton(
this,wxID_OK,wxT(
"OK"));
605 buttonsizer->Add(ok);
608 wxButton *cancel =
new wxButton(
this,wxID_CANCEL,wxT(
"Cancel"));
609 buttonsizer->Add(cancel);
611 #if wxCHECK_VERSION(2,5,2)
612 mainsizer->Add(MyNotebook, 1, wxEXPAND);
614 wxNotebookSizer *nbsizer;
615 nbsizer =
new wxNotebookSizer(MyNotebook);
616 mainsizer->Add(nbsizer);
618 mainsizer->Add(buttonsizer);
The main Parameter Gui interface, derived from BIAS::Param and extends this class.
void AddIntWidgets(BIAS::ParamTypeInt *item)
void OnChoice(wxCommandEvent &event)
virtual std::string GetValueString()
int GetSelectionForIndex(int index)
void AddStringWidgets(BIAS::ParamTypeString *item)
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
void OnCheckBox(wxCommandEvent &event)
ParamCallbackInterface * CallbackObject_
if some one changed a parameter, we should call CallbackObject_->ParameterChanged(Name_); ...
std::vector< int > UniqueSortedGroups()
Returns a vector of all group IDs (unique) in ascending order.
void AddDoubleWidgets(BIAS::ParamTypeDouble *item)
std::vector< std::string > GroupNames_
virtual void ParameterChanged(const std::string ¶mname, const void *data)
void AddVecIntWidgets(BIAS::ParamTypeVecInt *item)
std::map< std::string, int > Map_
ParamGUIDialog(wxWindow *parent, const wxString &title, const wxPoint &p, const wxSize &s, ParamGUI *pg, bool bChancelButton=true)
std::map< int, int > memoryIndexToSelection_
ParamGUIPanel(wxWindow *parent)
std::map< int, int > memorySelectionToIndex_
void AddBoolWidgets(BIAS::ParamTypeBool *item)
wxFrame * GetFrame(wxWindow *parent)
Builds up a standalone wxFrame with a notebook embedded in it.
this provides a gui interface for the BIAS::Param class.
void OnTextEnter(wxCommandEvent &event)
ParamGUIDialog * GetDialog(wxWindow *parent, const wxString &title, bool bChancelButton=true)
Builds up a wxDialog with a notebook embedded in it.
wxNotebook * GetNotebook(wxWindow *parent)
Builds up a wxNotebook with each parameter group on one page.
virtual std::string GetValueString()
void AddVecDblWidgets(BIAS::ParamTypeVecDbl *item)
This class Param provides generic support for parameters.
std::map< const std::string, BIAS::ParamTypeBase * > & GetParamMap()
this provides a gui interface for the BIAS::Param class.
int GetIndexForSelection(int selection)
void OnSpinCtrl(wxSpinEvent &event)
std::string GetGroupName(const int group_id)
gets the name of a group
void AddEnumWidgets(BIAS::ParamTypeEnum *item)
void AddDataToMemory(int index)
wxPanel * GetPanel(wxWindow *parent, int GroupID=GRP_ALL)
Builds up a wxPanel with the parameters specified by GroupID.