00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdint.h>
00031
00032 #include "plugin_manager_dialog.h"
00033 #include "plugin/plugin_manager.h"
00034 #include "plugin/plugin.h"
00035
00036 #include <ros/console.h>
00037
00038 #include <wx/checkbox.h>
00039 #include <wx/msgdlg.h>
00040
00041 namespace rviz
00042 {
00043
00044 PluginManagerDialog::PluginManagerDialog(wxWindow* parent, PluginManager* manager)
00045 : PluginManagerDialogGenerated(parent)
00046 , manager_(manager)
00047 {
00048 const L_Plugin& plugins = manager->getPlugins();
00049 L_Plugin::const_iterator it = plugins.begin();
00050 L_Plugin::const_iterator end = plugins.end();
00051 for (; it != end; ++it)
00052 {
00053 const PluginPtr& plugin = *it;
00054
00055 wxPanel* p = new wxPanel(scrolled_window_);
00056 p->SetForegroundColour(*wxLIGHT_GREY);
00057 if (plugin->isLoaded())
00058 {
00059 p->SetBackgroundColour(wxColour( 32, 116, 38 ));
00060 }
00061 else
00062 {
00063 p->SetBackgroundColour(wxColour( 151, 24, 41 ));
00064 }
00065 plugins_sizer_->Add(p, 0, wxEXPAND);
00066
00067 uint32_t row_index = rows_.size();
00068
00069 wxBoxSizer* s = new wxBoxSizer(wxHORIZONTAL);
00070 wxCheckBox* loaded_cb = new wxCheckBox(p, wxID_ANY, wxT("Loaded"));
00071 loaded_cb->SetValue(plugin->isLoaded());
00072 loaded_cb->SetClientData((void*)row_index);
00073 wxCheckBox* autoload_cb = new wxCheckBox(p, wxID_ANY, wxT("Auto Load"));
00074 autoload_cb->SetValue(plugin->isAutoLoad());
00075 autoload_cb->SetClientData((void*)row_index);
00076 s->Add(loaded_cb, 0, wxALIGN_CENTER);
00077 s->Add(autoload_cb, 0, wxALIGN_CENTER);
00078 s->Add(new wxStaticText(p, wxID_ANY, wxString::FromAscii(plugin->getName().c_str()), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT), 1, wxALIGN_CENTER|wxEXPAND);
00079 p->SetSizer(s);
00080
00081 loaded_cb->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(PluginManagerDialog::onLoadedChecked), 0, this);
00082 autoload_cb->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler(PluginManagerDialog::onAutoLoadChecked), 0, this);
00083
00084 Row r;
00085 r.panel = p;
00086 r.loaded = loaded_cb;
00087 r.autoload = autoload_cb;
00088 r.plugin = plugin.get();
00089 rows_.push_back(r);
00090 }
00091 }
00092
00093 void PluginManagerDialog::onLoadedChecked(wxCommandEvent& evt)
00094 {
00095 wxCheckBox* box = (wxCheckBox*)evt.GetEventObject();
00096 uintptr_t row_index = (uintptr_t)box->GetClientData();
00097 Plugin* plugin = rows_[row_index].plugin;
00098 if (evt.IsChecked())
00099 {
00100 try
00101 {
00102 plugin->load();
00103 rows_[row_index].panel->SetBackgroundColour(wxColour( 32, 116, 38 ));
00104 }
00105 catch (std::runtime_error& e)
00106 {
00107 box->SetValue(false);
00108 wxMessageBox(wxString::FromAscii(e.what()), wxT("Error Loading Plugin"), wxOK|wxICON_ERROR, this);
00109 }
00110 }
00111 else
00112 {
00113 plugin->unload();
00114 rows_[row_index].panel->SetBackgroundColour(wxColour( 151, 24, 41 ));
00115 }
00116 }
00117
00118 void PluginManagerDialog::onAutoLoadChecked(wxCommandEvent& evt)
00119 {
00120 wxCheckBox* box = (wxCheckBox*)evt.GetEventObject();
00121 uintptr_t row_index = (uintptr_t)box->GetClientData();
00122 Plugin* plugin = rows_[row_index].plugin;
00123
00124 plugin->setAutoLoad(evt.IsChecked());
00125 }
00126
00127 }