#include <guienvironment.h>
Public Member Functions | |
GUIEnvironment (wxWindow *parent) | |
Class constructor. | |
~GUIEnvironment () | |
Class destructor. | |
wxControl * | GetControl (const Parameter::ParameterIdentificator ¶mID) |
Find GUI control for given parameter, NULL if not found. | |
void | ShowParams (const Parameter::ParameterIdentificator ¶mID) |
Show matching previously registered parameters in GUI if hidden ('?' and '*' allowed). | |
void | HideParams (const Parameter::ParameterIdentificator ¶mID, bool unregister=false) |
bool | RegisterGUIParam (const GUIParamInfo ¶mInfo, const wxString &value) |
void | SetParam (const Parameter::ParameterIdentificator ¶mID, const wxString &value) |
Set parameter's value in its GUI control. | |
Protected Member Functions | |
WX_DECLARE_STRING_HASH_MAP (GUIParamInfo, GUIInfoList) | |
Hash map type mapping parameter fullname to GUI parameter info. | |
void | onCommandEvent (wxCommandEvent &evt) |
On command event. | |
Protected Attributes | |
GUIInfoList | controlsInfo |
Hash map mapping parameter fullname to GUI parameter info. | |
Classes | |
struct | GUIParamInfo |
Identificator and GUI properties of a parameter. More... |
Definition at line 121 of file guienvironment.h.
GUIEnvironment::GUIEnvironment | ( | wxWindow * | parent | ) |
Class constructor.
Definition at line 26 of file guienvironment.cpp.
00026 : wxAuiNotebook(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_DEFAULT_STYLE | wxAUI_NB_WINDOWLIST_BUTTON) 00027 { 00028 KERNEL->GetMessageSink()->RegisterListener(this, Event::EVT_PARAM_GUIREGISTER); 00029 Connect(wxID_ANY, Event::EVT_PARAM_GUIREGISTER, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00030 KERNEL->GetMessageSink()->RegisterListener(this, Event::EVT_PARAM_GUIUNREGISTER); 00031 Connect(wxID_ANY, Event::EVT_PARAM_GUIUNREGISTER, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00032 KERNEL->GetMessageSink()->RegisterListener(this, Event::EVT_GUI_PARAM_SHOW); 00033 Connect(wxID_ANY, Event::EVT_GUI_PARAM_SHOW, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00034 KERNEL->GetMessageSink()->RegisterListener(this, Event::EVT_PARAM_SET); 00035 Connect(wxID_ANY, Event::EVT_PARAM_SET, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00036 }
GUIEnvironment::~GUIEnvironment | ( | ) |
VRUT::GUIEnvironment::WX_DECLARE_STRING_HASH_MAP | ( | GUIParamInfo | , | |
GUIInfoList | ||||
) | [protected] |
Hash map type mapping parameter fullname to GUI parameter info.
void GUIEnvironment::onCommandEvent | ( | wxCommandEvent & | evt | ) | [protected] |
On command event.
Definition at line 44 of file guienvironment.cpp.
00045 { 00046 switch (evt.GetEventType()) 00047 { 00048 case Event::EVT_PARAM_GUIREGISTER: 00049 { 00050 GUIParamInfo pi(*((GUIParamInfo *)evt.GetClientData())); 00051 RegisterGUIParam(pi, evt.GetString()); 00052 } 00053 break; 00054 case Event::EVT_PARAM_GUIUNREGISTER: 00055 { 00056 Parameter::ParameterIdentificator pi = Parameter::ParameterIdentificator::FromParamName(*((wxString *)evt.GetClientData())); 00057 if (!pi.paramName.IsSameAs(wxT("*"))) 00058 LOGWARNING(wxT("<GUIEnvironment>Only whole pool page with parameters can be hidden, use 'pool' or 'pool.*.inst' ('?' and '*' allowed)")); 00059 else 00060 HideParams(pi, true); 00061 } 00062 break; 00063 case Event::EVT_GUI_PARAM_SHOW: 00064 { 00065 Parameter::ParameterIdentificator pi = Parameter::ParameterIdentificator::FromParamName(evt.GetString()); 00066 if (evt.GetInt()) 00067 ShowParams(pi); 00068 else 00069 { 00070 if (!pi.paramName.IsSameAs(wxT("*"))) 00071 LOGWARNING(wxT("<GUIEnvironment>Only whole pool page with parameters can be hidden, use 'pool' or 'pool.*.inst' ('?' and '*' allowed)")); 00072 else 00073 HideParams(pi); 00074 } 00075 } 00076 break; 00077 case Event::EVT_PARAM_SET: 00078 { 00079 wxString value = ((wxString *)evt.GetClientData())->AfterFirst('='); 00080 SetParam(Parameter::ParameterIdentificator::FromEvent(evt), value); 00081 } 00082 break; 00083 default: 00084 { 00085 wxWindow * win = dynamic_cast<wxWindow *>(evt.GetEventObject()); 00086 if (win) 00087 { 00088 Parameter::ParameterIdentificator pi = Parameter::ParameterIdentificator::FromParamName(win->GetName()); 00089 if (pi.IsValid()) 00090 { 00091 wxString newValue; 00092 if (evt.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED) 00093 newValue = (evt.IsChecked() ? wxT("1") : wxT("0")); 00094 else if ( (evt.GetEventType() == wxEVT_SCROLL_THUMBTRACK) || 00095 (evt.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) || 00096 (evt.GetEventType() == wxEVT_SCROLL_PAGEDOWN) || 00097 (evt.GetEventType() == wxEVT_SCROLL_PAGEUP) || 00098 (evt.GetEventType() == wxEVT_SCROLL_TOP) || 00099 (evt.GetEventType() == wxEVT_SCROLL_BOTTOM) || 00100 (evt.GetEventType() == wxEVT_SCROLL_LINEUP) || 00101 (evt.GetEventType() == wxEVT_SCROLL_LINEDOWN) || 00102 (evt.GetEventType() == wxEVT_SCROLL_CHANGED) ) 00103 newValue = wxString::Format(wxT("%i"), evt.GetInt()); 00104 else if (evt.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED) 00105 { 00106 newValue = KERNEL->environment.GetParam(pi); 00107 long tmpVal = 0; 00108 newValue.ToLong(&tmpVal); 00109 newValue = wxString::Format(wxT("%i"), tmpVal + 1); 00110 } 00111 else if (evt.GetEventType() == wxEVT_COMMAND_TEXT_ENTER) 00112 newValue = evt.GetString(); 00113 else if (evt.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED) 00114 { 00115 if (evt.GetEventObject()->IsKindOf(wxClassInfo::FindClass(wxT("wxSpinCtrl")))) 00116 newValue = wxString::Format(wxT("%i"), ((wxSpinCtrl *)evt.GetEventObject())->GetValue()); 00117 //TODO: implemented in wxWidgets 2.9.0 00118 // else if (evt.GetEventObject()->IsKindOf(wxClassInfo::FindClass(wxT("wxSpinCtrlDouble")))) 00119 // newValue = wxString::Format(wxT("%i"), ((wxSpinCtrlDouble *)evt.GetEventObject())->GetValue()); 00120 else 00121 newValue = evt.GetString(); 00122 } 00123 else 00124 break; 00125 KERNEL->environment.SetParam(pi, newValue); 00126 } 00127 } 00128 } 00129 break; 00130 } 00131 }
wxControl * GUIEnvironment::GetControl | ( | const Parameter::ParameterIdentificator & | paramID | ) |
Find GUI control for given parameter, NULL
if not found.
Definition at line 134 of file guienvironment.cpp.
00135 { 00136 wxString poolInstName = wxString::Format(wxT("%s.%s"), paramID.poolName.c_str(), paramID.instName.c_str()); 00137 if (paramID.poolName.IsSameAs(wxT("kernel"))) 00138 poolInstName = paramID.poolName; 00139 wxWindow * paramPage = (wxWindow *)NULL; 00140 for (size_t pg = 0; pg < GetPageCount() && !paramPage; pg++) 00141 { 00142 if (GetPageText(pg).IsSameAs(poolInstName)) 00143 paramPage = GetPage(pg); 00144 } 00145 if (paramPage) 00146 { 00147 wxGridSizer * sizer = (wxGridSizer *)paramPage->GetSizer(); 00148 for (wxSizerItemList::const_iterator it = sizer->GetChildren().begin(); 00149 it != sizer->GetChildren().end(); it++) 00150 { 00151 wxWindow * win = (*it)->GetWindow(); 00152 if (win && win->GetName().IsSameAs(paramID.ToString())) 00153 return dynamic_cast<wxControl *>(win); 00154 } 00155 } 00156 00157 return (wxControl *)NULL; 00158 }
void GUIEnvironment::ShowParams | ( | const Parameter::ParameterIdentificator & | paramID | ) |
Show matching previously registered parameters in GUI if hidden ('?' and '*' allowed).
Definition at line 161 of file guienvironment.cpp.
00162 { 00163 for (GUIInfoList::iterator it = controlsInfo.begin(); it != controlsInfo.end(); it++) 00164 if (it->second.paramID.Matches(paramID)) 00165 { 00166 std::vector<Environment::NameValue> vals; 00167 KERNEL->environment.GetParams(it->second.paramID, &vals); 00168 if (!vals.empty()) 00169 RegisterGUIParam(it->second, vals.front().second); 00170 } 00171 }
void GUIEnvironment::HideParams | ( | const Parameter::ParameterIdentificator & | paramID, | |
bool | unregister = false | |||
) |
Hide matching pages with parameters if shown ('?' and '*' allowed, guiPI.paramName
must be '*')
[in] | paramID | Parameter identificator (paramID.paramName has to be '*' or nothing happens) |
[in] | unregister | If true parameter is unregistered and cannot be unhidden later |
Definition at line 174 of file guienvironment.cpp.
00175 { 00176 if (unregister) 00177 { 00178 std::vector<GUIInfoList::iterator> forDeletion; 00179 for (GUIInfoList::iterator it = controlsInfo.begin(); 00180 it != controlsInfo.end(); it++) 00181 if (it->second.paramID.Matches(paramID)) 00182 forDeletion.push_back(it); 00183 for (std::vector<GUIInfoList::iterator>::const_iterator delIt = forDeletion.begin(); 00184 delIt != forDeletion.end(); delIt++) 00185 controlsInfo.erase(*delIt); 00186 } 00187 for (size_t pg = 0; pg < GetPageCount(); ) 00188 { 00189 wxStringTokenizer tkz(GetPageText(pg), wxT(".")); 00190 Parameter::ParameterIdentificator pgi(tkz.GetNextToken()); 00191 if (tkz.HasMoreTokens()) 00192 pgi.instName = tkz.GetNextToken(); 00193 if (pgi.Matches(paramID)) 00194 DeletePage(pg); 00195 else 00196 pg++; 00197 } 00198 }
bool GUIEnvironment::RegisterGUIParam | ( | const GUIParamInfo & | paramInfo, | |
const wxString & | value | |||
) |
Register new parameter into GUI or show if already registered
[in] | paramInfo | Parameter full identificator and GUI properties |
[in] | value | Initial value |
true
if successful Get instance name - '0' by default
Check if already shown
Get pool notebook
Add new param control
Definition at line 201 of file guienvironment.cpp.
00202 { 00203 if (paramInfo.paramID.IsValid()) 00204 { 00206 wxString instNameExact = wxT("0"); 00207 if ((paramInfo.paramID.instName.Find('*') == wxNOT_FOUND) 00208 && (paramInfo.paramID.instName.Find('?') == wxNOT_FOUND) 00209 && !paramInfo.paramID.instName.IsEmpty()) 00210 instNameExact = CloneWxString(paramInfo.paramID.instName); 00211 00212 Parameter::ParameterIdentificator pi(paramInfo.paramID.poolName, paramInfo.paramID.paramName, instNameExact); 00214 if (GetControl(pi)) 00215 return false; 00216 wxString fullName = pi.ToString(); 00217 GUIInfoList::iterator cit = controlsInfo.find(fullName); 00218 if (cit == controlsInfo.end()) 00219 controlsInfo.insert(GUIInfoList::value_type(fullName, paramInfo)); 00220 00222 wxWindow * paramPage = (wxWindow *)NULL; 00223 wxString poolInstName = wxString::Format(wxT("%s.%s"), paramInfo.paramID.poolName.c_str(), paramInfo.paramID.instName.c_str()); 00224 if (paramInfo.paramID.poolName.IsSameAs(wxT("kernel"))) 00225 poolInstName = paramInfo.paramID.poolName; 00226 for (size_t pg = 0; pg < GetPageCount() && !paramPage; pg++) 00227 { 00228 if (GetPageText(pg).IsSameAs(poolInstName)) 00229 paramPage = GetPage(pg); 00230 } 00231 if (!paramPage) 00232 { 00233 paramPage = new wxPanel(this, wxID_ANY); 00234 paramPage->SetName(poolInstName); 00235 wxGridSizer * sizer = new wxGridSizer(2); 00236 paramPage->SetSizer(sizer); 00237 AddPage(paramPage, poolInstName, true); 00238 } 00240 wxWindow * control = (wxWindow *)NULL; 00241 switch (paramInfo.type) 00242 { 00243 case GUIParamInfo::GUI_TYPE_CHECKBOX: 00244 control = new wxCheckBox(paramPage, wxID_ANY, wxEmptyString); 00245 ((wxCheckBox *)control)->SetValue(isTrue(value)); 00246 control->Connect(wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00247 break; 00248 case GUIParamInfo::GUI_TYPE_SLIDER: 00249 { 00250 long val = roundVR(paramInfo.minval); 00251 value.ToLong(&val); 00252 control = new wxSlider(paramPage, 00253 wxID_ANY, 00254 int(val), 00255 roundVR(paramInfo.minval), 00256 roundVR(paramInfo.maxval), 00257 wxDefaultPosition, 00258 wxSize(170, wxDefaultCoord), 00259 wxHORIZONTAL | wxSL_LABELS); 00260 control->Connect(wxID_ANY, wxEVT_SCROLL_THUMBTRACK, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00261 control->Connect(wxID_ANY, wxEVT_SCROLL_THUMBRELEASE, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00262 control->Connect(wxID_ANY, wxEVT_SCROLL_PAGEDOWN, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00263 control->Connect(wxID_ANY, wxEVT_SCROLL_PAGEUP, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00264 control->Connect(wxID_ANY, wxEVT_SCROLL_TOP, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00265 control->Connect(wxID_ANY, wxEVT_SCROLL_BOTTOM, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00266 control->Connect(wxID_ANY, wxEVT_SCROLL_LINEUP, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00267 control->Connect(wxID_ANY, wxEVT_SCROLL_LINEDOWN, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00268 control->Connect(wxID_ANY, wxEVT_SCROLL_CHANGED, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00269 } 00270 break; 00271 case GUIParamInfo::GUI_TYPE_SPINCONTROL: 00272 control = new wxSpinCtrl(paramPage, wxID_ANY, value, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, roundVR(paramInfo.minval), roundVR(paramInfo.maxval)); 00273 control->Connect(wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00274 break; 00275 //TODO: implemented in wxWidgets 2.9.0 00276 // case GUIParamInfo::GUI_TYPE_SPINCONTROL_DOUBLE: 00277 // control = new wxSpinCtrlDouble(paramPage, wxID_ANY, value, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, paramInfo.minval, paramInfo.maxval, 0, paramInfo.step); 00278 // control->Connect(wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00279 // break; 00280 case GUIParamInfo::GUI_TYPE_COMBOBOX: 00281 control = new wxComboBox(paramPage, wxID_ANY, value, wxDefaultPosition, wxDefaultSize, paramInfo.values, wxCB_SORT | wxCB_READONLY); 00282 control->Connect(wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00283 break; 00284 case GUIParamInfo::GUI_TYPE_BUTTON: 00285 control = new wxButton(paramPage, wxID_ANY, paramInfo.paramID.paramName); 00286 control->Connect(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00287 break; 00288 case GUIParamInfo::GUI_TYPE_TEXTCONTROL: 00289 default: 00290 control = new wxTextCtrl(paramPage, wxID_ANY, value, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); 00291 control->Connect(wxID_ANY, wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(GUIEnvironment::onCommandEvent), (wxObject *)NULL, this); 00292 break; 00293 } 00294 control->SetName(paramInfo.paramID.ToString()); 00295 control->SetToolTip(paramInfo.paramID.description); 00296 wxGridSizer * sizer = (wxGridSizer *)paramPage->GetSizer(); 00297 if (paramInfo.type != GUIParamInfo::GUI_TYPE_BUTTON) 00298 sizer->Add( new wxStaticText( paramPage, wxID_ANY, paramInfo.paramID.paramName ), 0, wxALIGN_CENTRE ); 00299 sizer->Add( control, 1, wxALIGN_CENTRE ); 00300 paramPage->Layout(); 00301 KERNEL->GetMainWindow()->GetAUIManager()->Update(); 00302 00303 return true; 00304 } 00305 return false; 00306 }
void GUIEnvironment::SetParam | ( | const Parameter::ParameterIdentificator & | paramID, | |
const wxString & | value | |||
) |
Set parameter's value in its GUI control.
Definition at line 309 of file guienvironment.cpp.
00310 { 00311 wxControl * control = GetControl(paramID); 00312 GUIInfoList::iterator cit = controlsInfo.find(paramID.ToString()); 00313 if (control && (cit != controlsInfo.end())) 00314 { 00315 switch (cit->second.type) 00316 { 00317 case GUIParamInfo::GUI_TYPE_CHECKBOX: 00318 { 00319 bool newState = isTrue(value); 00320 if (((wxCheckBox *)control)->IsChecked() != newState) 00321 ((wxCheckBox *)control)->SetValue(newState); 00322 } 00323 break; 00324 case GUIParamInfo::GUI_TYPE_SLIDER: 00325 { 00326 long val = roundVR(cit->second.minval); 00327 if (value.ToLong(&val) && ((wxSlider *)control)->GetValue() != val) 00328 ((wxSlider *)control)->SetValue(val); 00329 } 00330 break; 00331 case GUIParamInfo::GUI_TYPE_SPINCONTROL: 00332 { 00333 long val = roundVR(cit->second.minval); 00334 if (value.ToLong(&val) && ((wxSpinCtrl *)control)->GetValue() != val) 00335 ((wxSpinCtrl *)control)->SetValue(val); 00336 } 00337 break; 00338 //TODO: implemented in wxWidgets 2.9.0 00339 // case GUIParamInfo::GUI_TYPE_SPINCONTROL_DOUBLE: 00340 // { 00341 // double val = cit->second.minval; 00342 // if (value.ToDouble(&val) && ((wxSpinCtrlDouble *)control)->GetValue() != val) 00343 // ((wxSpinCtrlDouble *)control)->SetValue(val); 00344 // } 00345 // break; 00346 case GUIParamInfo::GUI_TYPE_COMBOBOX: 00347 if (((wxComboBox *)control)->GetValue() != value) 00348 ((wxComboBox *)control)->SetValue(value); 00349 break; 00350 case GUIParamInfo::GUI_TYPE_TEXTCONTROL: 00351 if (((wxTextCtrl *)control)->GetValue() != value) 00352 ((wxTextCtrl *)control)->SetValue(value); 00353 break; 00354 case GUIParamInfo::GUI_TYPE_BUTTON: 00355 default: 00356 break; 00357 } 00358 } 00359 }
GUIInfoList VRUT::GUIEnvironment::controlsInfo [protected] |
Hash map mapping parameter fullname to GUI parameter info.
Definition at line 168 of file guienvironment.h.