$search
00001 /* 00002 * Copyright (c) 2009, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 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(*wxBLACK); 00057 if (plugin->isLoaded()) 00058 { 00059 p->SetBackgroundColour(wxColour( 200, 255, 200 )); 00060 } 00061 else 00062 { 00063 p->SetBackgroundColour(*wxWHITE); 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|wxALL, 3); 00077 s->Add(autoload_cb, 0, wxALIGN_CENTER|wxALL, 3); 00078 s->Add(new wxStaticText(p, wxID_ANY, wxString::FromAscii(plugin->getName().c_str()), wxDefaultPosition, wxDefaultSize, 0), 1, wxALIGN_CENTER|wxALL, 3); 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( 200, 255, 200 )); 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(*wxWHITE); 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 } // namespace rviz