23 #include "worldinfo_viewer.h"
24 #include "field_view.h"
26 #include <worldinfo_utils/data_container.h>
27 #include <blackboard/remote.h>
36 using namespace fawkes;
53 builder->get_widget(
"wndMain", m_wnd_main);
54 builder->get_widget(
"vbxField", m_vbx_field);
55 builder->get_widget(
"trvRobots", m_trv_robots);
56 builder->get_widget(
"stbStatus", m_stb_status);
58 m_field_view =
new FieldView( data_container,
true,
true,
false );
59 m_vbx_field->pack_start( *m_field_view );
62 m_robots_list = Gtk::ListStore::create( m_robot_record );
63 m_trv_robots->set_model( m_robots_list );
64 m_trv_robots->append_column(
"Name", m_robot_record.hostname );
65 m_trv_robots->append_column_editable(
"Pose", m_robot_record.show_pose );
66 m_trv_robots->append_column_editable(
"Ball", m_robot_record.show_ball );
67 m_trv_robots->append_column_editable(
"Opponents", m_robot_record.show_opponents );
69 Gtk::CellRendererToggle* renderer;
70 renderer =
dynamic_cast< Gtk::CellRendererToggle*
>( m_trv_robots->get_column_cell_renderer(1) );
71 renderer->signal_toggled().connect( sigc::mem_fun( *
this,
72 &WorldInfoViewer::on_show_pose_toggled ) );
73 renderer =
dynamic_cast< Gtk::CellRendererToggle*
>( m_trv_robots->get_column_cell_renderer(2) );
74 renderer->signal_toggled().connect( sigc::mem_fun( *
this,
75 &WorldInfoViewer::on_show_ball_toggled ) );
76 renderer =
dynamic_cast< Gtk::CellRendererToggle*
>( m_trv_robots->get_column_cell_renderer(3) );
77 renderer->signal_toggled().connect( sigc::mem_fun( *
this,
78 &WorldInfoViewer::on_show_opponents_toggled ) );
80 m_data_container = data_container;
82 m_stb_message_id = m_stb_status->push(
"No game state information available." );
85 sigc::connection conn =
114 bool robot_removed =
false;
116 if ( m_data_container->check_timeout() )
118 robot_removed =
true;
119 list<string> timedout_hosts = m_data_container->get_timedout_hosts();
122 printf(
"Removing %zu timed out host.\n", timedout_hosts.size() );
126 for ( list<string>::iterator hit = timedout_hosts.begin();
127 hit != timedout_hosts.end();
130 m_field_view->remove_host( Glib::ustring( *hit ) );
132 Gtk::TreeModel::Children children = m_robots_list->children();
133 Gtk::TreeModel::iterator cit = children.begin();
134 while ( cit != children.end() )
136 Gtk::TreeModel::Row row = *cit;
137 if ( Glib::ustring( *hit ) == row[ m_robot_record.fqdn ] )
138 { cit = m_robots_list->erase( cit ); }
146 if ( !m_data_container->new_data_available() )
149 { m_field_view->queue_draw(); }
153 list<string> hosts = m_data_container->get_hosts();
156 for ( list<string>::iterator hit = hosts.begin();
162 Gtk::TreeModel::Children children = m_robots_list->children();
163 for ( Gtk::TreeModel::iterator i = children.begin();
167 Gtk::TreeModel::Row row = *i;
168 if ( Glib::ustring( *hit ) == row[ m_robot_record.fqdn ] )
180 Glib::ustring fqdn_str = Glib::ustring( *hit );
182 fqdn = strdup( hit->c_str() );
183 hostname = strtok( fqdn, &delim );
184 int i = atoi( hostname );
186 Gtk::TreeModel::Row row = *m_robots_list->append();
189 { row[ m_robot_record.hostname ] = Glib::ustring( hostname ); }
191 { row[ m_robot_record.hostname ] = fqdn_str; }
192 row[ m_robot_record.fqdn ] = fqdn_str;
193 row[ m_robot_record.show_pose ] = m_field_view->toggle_show_pose( fqdn_str );
194 row[ m_robot_record.show_ball ] = m_field_view->toggle_show_ball( fqdn_str );
195 row[ m_robot_record.show_opponents ] = m_field_view->toggle_show_opponents( fqdn_str );
201 m_field_view->queue_draw();
211 if ( asprintf( &status_string,
212 "Team color: %s Goal color: %s Mode: %s Score: %d:%d Half: %s",
213 m_data_container->get_own_team_color_string().c_str(),
214 m_data_container->get_own_goal_color_string().c_str(),
215 m_data_container->get_game_state_string().c_str(),
216 m_data_container->get_own_score(),
217 m_data_container->get_other_score(),
218 m_data_container->get_half_string().c_str() ) != -1 )
220 m_stb_status->remove_message(m_stb_message_id);
221 m_stb_message_id = m_stb_status->push( Glib::ustring(status_string) );
228 WorldInfoViewer::on_show_pose_toggled(
const Glib::ustring& path )
230 Gtk::TreeModel::Row row = *m_robots_list->get_iter( path );
231 Glib::ustring fqdn = row[ m_robot_record.fqdn ];
233 row[ m_robot_record.show_pose ] = m_field_view->toggle_show_pose( fqdn );
235 m_field_view->queue_draw();
239 WorldInfoViewer::on_show_ball_toggled(
const Glib::ustring& path )
241 Gtk::TreeModel::Row row = *m_robots_list->get_iter( path );
242 Glib::ustring fqdn = row[ m_robot_record.fqdn ];
244 row[ m_robot_record.show_ball ] = m_field_view->toggle_show_ball( fqdn );
246 m_field_view->queue_draw();
250 WorldInfoViewer::on_show_opponents_toggled(
const Glib::ustring& path )
252 Gtk::TreeModel::Row row = *m_robots_list->get_iter( path );
253 Glib::ustring fqdn = row[ m_robot_record.fqdn ];
255 row[ m_robot_record.show_opponents ] = m_field_view->toggle_show_opponents( fqdn );
257 m_field_view->queue_draw();