$search
00001 00002 /*************************************************************************** 00003 * rosspawn_gui.cpp - Plugin Tool Gui 00004 * 00005 * Created: Thu Nov 09 20:16:23 2007 00006 * Copyright 2007 Daniel Beck 00007 * 2008-2009 Tim Niemueller [www.niemueller.de] 00008 * 00009 ****************************************************************************/ 00010 00011 /* This program is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2 of the License, or 00014 * (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL file in the doc directory. 00022 */ 00023 00024 #include "rosspawn_gui.h" 00025 00026 #include <rosspawn/NodeAction.h> 00027 #include <rosspawn/ListLoaded.h> 00028 #include <rosspawn/ListAvailable.h> 00029 00030 #include <string> 00031 00043 RosSpawnGuiWindow::RosSpawnGuiWindow(BaseObjectType* cobject, 00044 const Glib::RefPtr<Gtk::Builder> &builder) 00045 : Gtk::Window(cobject) 00046 { 00047 builder->get_widget("stb_status", m_stb_status); 00048 builder->get_widget("trv_plugins", m_trv_plugins); 00049 00050 m_plugin_list = Gtk::ListStore::create(m_plugin_record); 00051 m_trv_plugins->set_model(m_plugin_list); 00052 m_trv_plugins->append_column("#", m_plugin_record.index); 00053 m_trv_plugins->append_column_editable("Status", m_plugin_record.loaded); 00054 m_trv_plugins->append_column("Plugin", m_plugin_record.name); 00055 m_trv_plugins->append_column("Status", m_plugin_record.status); 00056 00057 __redraw_dispatcher.connect(sigc::mem_fun(*this, &Gtk::Window::queue_draw)); 00058 00059 Gtk::CellRendererToggle* renderer; 00060 renderer = dynamic_cast<Gtk::CellRendererToggle*>( m_trv_plugins->get_column_cell_renderer(1) ); 00061 renderer->signal_toggled().connect( sigc::mem_fun(*this, &RosSpawnGuiWindow::on_status_toggled)); 00062 00063 m_stb_status->push("Started"); 00064 } 00065 00067 RosSpawnGuiWindow::~RosSpawnGuiWindow() 00068 { 00069 m_stb_status->push("Exiting"); 00070 } 00071 00072 00073 void 00074 RosSpawnGuiWindow::cb_node_event(const rosspawn::NodeEvent::ConstPtr &msg) 00075 { 00076 // Find row 00077 00078 Gtk::TreeIter iter; 00079 for ( iter = m_plugin_list->children().begin(); 00080 iter != m_plugin_list->children().end(); 00081 ++iter ) 00082 { 00083 Glib::ustring n = (*iter)[m_plugin_record.name]; 00084 if ( n == msg->node_name ) { 00085 switch (msg->event_type) { 00086 case rosspawn::NodeEvent::NODE_STARTED: 00087 (*iter)[m_plugin_record.loaded] = true; 00088 (*iter)[m_plugin_record.status] = "running"; 00089 break; 00090 00091 case rosspawn::NodeEvent::NODE_DIED: 00092 (*iter)[m_plugin_record.loaded] = false; 00093 (*iter)[m_plugin_record.status] = "stopped"; 00094 break; 00095 00096 case rosspawn::NodeEvent::NODE_PAUSED: 00097 (*iter)[m_plugin_record.loaded] = true; 00098 (*iter)[m_plugin_record.status] = "paused"; 00099 break; 00100 00101 case rosspawn::NodeEvent::NODE_CONTINUED: 00102 (*iter)[m_plugin_record.loaded] = true; 00103 (*iter)[m_plugin_record.status] = "continued"; 00104 break; 00105 00106 case rosspawn::NodeEvent::NODE_SEGFAULT: 00107 (*iter)[m_plugin_record.loaded] = true; 00108 (*iter)[m_plugin_record.status] = "segfault"; 00109 break; 00110 default: 00111 break; 00112 } 00113 } 00114 00115 break; 00116 } 00117 00118 __redraw_dispatcher(); 00119 } 00120 00121 00126 void 00127 RosSpawnGuiWindow::on_status_toggled(const Glib::ustring& path) 00128 { 00129 Gtk::TreeModel::Row row = *m_plugin_list->get_iter(path); 00130 Glib::ustring node_file_name = row[m_plugin_record.name]; 00131 bool loaded = ! row[m_plugin_record.loaded]; 00132 00133 rosspawn::NodeAction na; 00134 na.request.node_file_name = node_file_name; 00135 00136 if (loaded) { 00137 __srv_stop.call(na); 00138 } else { 00139 __srv_start.call(na); 00140 } 00141 } 00142 00143 void 00144 RosSpawnGuiWindow::set_ros_node(ros::NodeHandle &n) 00145 { 00146 __n = n; 00147 __srv_start = __n.serviceClient<rosspawn::NodeAction>("/rosspawn/start"); 00148 __srv_stop = __n.serviceClient<rosspawn::NodeAction>("/rosspawn/stop"); 00149 __srv_pause = __n.serviceClient<rosspawn::NodeAction>("/rosspawn/pause"); 00150 __srv_cont = __n.serviceClient<rosspawn::NodeAction>("/rosspawn/continue"); 00151 __srv_lstld = __n.serviceClient<rosspawn::ListLoaded>("/rosspawn/list_loaded"); 00152 __srv_lstav = __n.serviceClient<rosspawn::ListAvailable>("/rosspawn/list_available"); 00153 00154 __sub_node_events = __n.subscribe("/rosspawn/node_events", 10, 00155 &RosSpawnGuiWindow::cb_node_event, this); 00156 00157 rosspawn::ListAvailable lstav; 00158 if (__srv_lstav.call(lstav)) { 00159 for (std::vector<std::string>::iterator i = lstav.response.bin_files.begin(); 00160 i != lstav.response.bin_files.end(); ++i) { 00161 00162 Gtk::TreeModel::Row row = *m_plugin_list->append(); 00163 unsigned int index = m_plugin_list->children().size(); 00164 row[m_plugin_record.index] = index; 00165 row[m_plugin_record.name] = *i; 00166 row[m_plugin_record.description] = ""; 00167 row[m_plugin_record.loaded] = false; 00168 row[m_plugin_record.status] = "unknown"; 00169 } 00170 } 00171 00172 rosspawn::ListLoaded lstld; 00173 if (__srv_lstld.call(lstld)) { 00174 for (std::vector<std::string>::iterator i = lstld.response.nodes.begin(); 00175 i != lstld.response.nodes.end(); ++i) { 00176 00177 Gtk::TreeIter iter; 00178 for ( iter = m_plugin_list->children().begin(); 00179 iter != m_plugin_list->children().end(); 00180 ++iter ) 00181 { 00182 Glib::ustring n = (*iter)[m_plugin_record.name]; 00183 if ( n == *i ) { 00184 (*iter)[m_plugin_record.loaded] = true; 00185 (*iter)[m_plugin_record.status] = "running"; 00186 break; 00187 } 00188 } 00189 } 00190 } 00191 }