23 #include "field_view.h"
25 #include <worldinfo_utils/data_container.h>
26 #include <cairomm/context.h>
32 using namespace fawkes;
52 m_show_pose_default = show_pose;
53 m_show_ball_default = show_ball;
54 m_show_opponents_default = show_opponents;
56 m_data_container = data;
71 std::map< Glib::ustring, bool >::iterator iter = m_show_pose.find( name );
72 if ( iter != m_show_pose.end() )
74 iter->second = iter->second ?
false :
true;
79 m_show_pose[ name ] = m_show_pose_default;
80 return m_show_pose_default;
91 std::map< Glib::ustring, bool >::iterator iter = m_show_ball.find( name );
92 if ( iter != m_show_ball.end() )
94 iter->second = iter->second ?
false :
true;
99 m_show_ball[ name ] = m_show_ball_default;
100 return m_show_ball_default;
111 std::map< Glib::ustring, bool >::iterator iter = m_show_opponents.find( name );
112 if ( iter != m_show_opponents.end() )
114 iter->second = iter->second ?
false :
true;
119 m_show_opponents[ name ] = m_show_opponents_default;
120 return m_show_opponents_default;
130 m_show_pose.erase( name );
131 m_show_ball.erase( name );
132 m_show_opponents.erase( name );
143 Glib::RefPtr<Gdk::Window> window = get_window();
147 Gtk::Allocation allocation = get_allocation();
148 const int width = allocation.get_width();
149 const int height = allocation.get_height();
153 if ( (width / 22.0) <= (height / 16.0) )
154 { unit = width / 22.0; }
156 { unit = height / 16.0; }
158 context->translate( width / 2.0, height / 2.0 );
159 context->scale(unit, -unit);
161 draw_field_msl(context);
163 list<string> hosts = m_data_container->get_hosts();
165 for ( list<string>::iterator i = hosts.begin();
169 const char* host = i->c_str();
173 std::map<unsigned int, HomPoint> opp_positions;
178 std::map< Glib::ustring, bool >::iterator iter;
180 iter = m_show_pose.find( *i );
181 if ( iter == m_show_pose.end() )
182 { show_pose = m_show_pose_default; }
184 { show_pose = iter->second; }
186 iter = m_show_ball.find( *i );
187 if ( iter == m_show_ball.end() )
188 { show_ball = m_show_ball_default; }
190 { show_ball = iter->second; }
192 iter = m_show_opponents.find( *i );
193 if ( iter == m_show_opponents.end() )
194 { show_opponents = m_show_opponents_default; }
196 { show_opponents = iter->second; }
199 if ( m_data_container->get_robot_pose( host, pose ) )
202 { draw_robot( context, pose.
x(), pose.
y(), pose.
yaw(), host ); }
204 if ( m_data_container->get_ball_pos_global( host, ball_pos ) &&
207 draw_ball( context, ball_pos.
x(), ball_pos.
y(),
208 pose.
x(), pose.
y() );
220 if ( m_data_container->get_ball_pos_relative( host, ball_pos ) &&
223 draw_ball( context, ball_pos.
x(), ball_pos.
y(), 0.0, 0.0 );
228 std::map<unsigned int, HomPoint> opponents;
229 if ( m_data_container->get_opponent_pos( host, opponents ) &&
232 for ( std::map<unsigned int, HomPoint>::iterator i = opponents.begin();
233 i != opponents.end();
237 draw_obstacle( context, p.
x(), p.
y(), 0.2 );
247 FieldView::draw_field_msl(Cairo::RefPtr<Cairo::Context> context)
253 context->set_source_rgb(48.0 / 255.0, 215.0 / 255.0, 31.0 / 255.0);
258 context->set_line_width(0.125);
259 context->set_source_rgb(1.0, 1.0, 1.0);
263 context->set_source_rgb(237.0 / 255.0, 240.0 / 255.0, 12.0 / 255.0);
264 context->move_to(9.0, 1.0625);
265 context->line_to(9.5, 1.0625);
266 context->line_to(9.5,-1.0625);
267 context->line_to(9.0,-1.0625);
272 context->set_source_rgb(12.0 / 255.0, 14.0 / 255.0, 240.0 / 255.0);
273 context->move_to(-9.0, 1.0625);
274 context->line_to(-9.5, 1.0625);
275 context->line_to(-9.5,-1.0625);
276 context->line_to(-9.0,-1.0625);
281 context->arc(0.0, 0.0, 2.0, 0.0, 2 * M_PI);
284 context->move_to(9.0, 6.0);
285 context->arc(9.0, 6.0, 0.75, M_PI, -M_PI/2.0);
286 context->move_to(9.0,-6.0);
287 context->arc(9.0, -6.0, 0.75, M_PI/2.0, M_PI);
288 context->move_to(-9.0, -6.0);
289 context->arc(-9.0, -6.0, 0.75, 0.0, M_PI/2.0);
290 context->move_to(-9.0, 6.0);
291 context->arc(-9.0, 6.0, 0.75, -M_PI/2.0, 0.0);
295 context->set_line_cap(Cairo::LINE_CAP_SQUARE);
296 context->move_to( 0.0, 6.0);
297 context->line_to( 0.0,-6.0);
298 context->move_to( 9.0, 6.0);
299 context->line_to( 9.0,-6.0);
300 context->line_to(-9.0,-6.0);
301 context->line_to(-9.0, 6.0);
302 context->close_path();
306 context->move_to(9.0, 1.75);
307 context->line_to(8.25, 1.75);
308 context->line_to(8.25,-1.75);
309 context->line_to(9.0,-1.75);
310 context->move_to(-9.0, 1.75);
311 context->line_to(-8.25, 1.75);
312 context->line_to(-8.25,-1.75);
313 context->line_to(-9.0,-1.75);
316 context->move_to(9.0, 3.25);
317 context->line_to(6.75, 3.25);
318 context->line_to(6.75,-3.25);
319 context->line_to(9.0,-3.25);
320 context->move_to(-9.0, 3.25);
321 context->line_to(-6.75, 3.25);
322 context->line_to(-6.75,-3.25);
323 context->line_to(-9.0,-3.25);
326 context->move_to(0.0, 0.0);
327 context->arc(0.0, 0.0, 0.05, 0.0, 2.0 * M_PI);
328 context->move_to(6.0, 0.0);
329 context->arc(6.0, 0.0, 0.05, 0.0, 2.0 * M_PI);
330 context->move_to(-6.0, 0.0);
331 context->arc(-6.0, 0.0, 0.05, 0.0, 2.0 * M_PI);
338 FieldView::draw_robot( Cairo::RefPtr<Cairo::Context> context,
345 context->set_source_rgb(0.2, 0.2, 0.2);
346 context->set_line_width(0.05);
347 context->move_to(x, y);
348 context->arc(x, y, 0.3, ori, 2*M_PI + ori);
353 context->select_font_face(
"Sans",
354 Cairo::FONT_SLANT_NORMAL,
355 Cairo::FONT_WEIGHT_NORMAL );
356 context->set_font_size( 4 );
357 context->scale(0.1, -0.1);
359 Cairo::TextExtents extents;
360 context->get_text_extents( name.c_str(), extents );
362 context->move_to( 10 * x - extents.width/2.0 - extents.x_bearing,
363 -10 * y - extents.height/2.0 - extents.y_bearing + 8 );
364 context->show_text( name.c_str() );
367 if (asprintf( &pos,
"%.2f, %.2f [%.2f]", x, y, ori ) != -1) {
368 context->get_text_extents( pos, extents );
370 context->move_to( 10 * x - extents.width/2.0 - extents.x_bearing,
371 -10 * y - extents.height/2.0 - extents.y_bearing + 12 );
372 context->show_text( pos );
382 FieldView::draw_obstacle(Cairo::RefPtr<Cairo::Context> context,
float x,
float y,
float extend)
385 context->set_source_rgba(0.0, 0.0, 1.0, 0.6);
386 context->set_line_width(0.05);
387 context->arc(x, y, 0.25 , 0.0, 2.0 * M_PI);
393 FieldView::draw_ball( Cairo::RefPtr<Cairo::Context> context,
394 float ball_x,
float ball_y,
395 float bot_x,
float bot_y )
398 context->set_source_rgb(1.0, 0.3, 0.0);
399 context->set_line_width(0.05);
400 context->move_to(bot_x, bot_y);
401 context->line_to(ball_x, ball_y);
403 context->arc(ball_x, ball_y, 0.15, 0.0, 2.0 * M_PI);
Data container to store and exchange worldinfo data.
virtual ~FieldView()
Destructor.
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &context)
Overloaded signal handler.
virtual float y() const
RO-getter for y.
A homogeneous representation of a polar coordinate.
A 2-dimensional pose, i.e.
bool toggle_show_pose(Glib::ustring name)
Toggle whether to show the pose of the specified robot.
float yaw() const
Get the angle of the current orientation [0...2pi].
void remove_host(Glib::ustring name)
Remove a host.
float x() const
Get the x-coordinate of the position.
bool toggle_show_opponents(Glib::ustring name)
Toggle whether to show the opponents seen by the specified robot.
virtual float x() const
RO-getter for x.
bool toggle_show_ball(Glib::ustring name)
Toggle whether to show the ball detected by the specified robot.
float y() const
Get the y-coordinate of the position.
FieldView(fawkes::WorldInfoDataContainer *data, bool show_pose=true, bool show_ball=true, bool show_opponents=false)
Constructor.