Fawkes API  Fawkes Development Version
VisualDisplay2DInterface.cpp
1 
2 /***************************************************************************
3  * VisualDisplay2DInterface.cpp - Fawkes BlackBoard Interface - VisualDisplay2DInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2009 Tim Niemueller
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <interfaces/VisualDisplay2DInterface.h>
25 
26 #include <core/exceptions/software.h>
27 
28 #include <cstring>
29 #include <cstdlib>
30 
31 namespace fawkes {
32 
33 /** @class VisualDisplay2DInterface <interfaces/VisualDisplay2DInterface.h>
34  * VisualDisplay2DInterface Fawkes BlackBoard Interface.
35  *
36  This interface provides can be used by graphing applications to
37  provide a graphing service to other components. This is intended
38  to be used for debugging purposes. Usage of the interface should
39  be optional to turn it off during a competition.
40 
41  Add* messages will add the given object permanently, so the
42  graphical display can be considered as a scenegraph. The message
43  ID is becomes the ID and can be used to delete the object using
44  the DeleteObjectMessage. With the DeleteAll message all objects
45  can be removed (shall only remove objects added by the same
46  sender, thus data drawn by other senders is not touched).
47 
48  The units shall be in meters and radians. Color is given as four
49  byte RGBA value, one byte for each R, G, B and Alpha.
50 
51  * @ingroup FawkesInterfaces
52  */
53 
54 
55 
56 /** Constructor */
57 VisualDisplay2DInterface::VisualDisplay2DInterface() : Interface()
58 {
59  data_size = sizeof(VisualDisplay2DInterface_data_t);
60  data_ptr = malloc(data_size);
61  data = (VisualDisplay2DInterface_data_t *)data_ptr;
62  data_ts = (interface_data_ts_t *)data_ptr;
63  memset(data_ptr, 0, data_size);
64  add_fieldinfo(IFT_UINT32, "counter", 1, &data->counter, "");
65  add_messageinfo("AddCartLineMessage");
66  add_messageinfo("AddCartCircleMessage");
67  add_messageinfo("AddCartRectMessage");
68  add_messageinfo("AddCartTextMessage");
69  add_messageinfo("DeleteObjectMessage");
70  add_messageinfo("DeleteAllMessage");
71  unsigned char tmp_hash[] = {0xd9, 0x2, 0xad, 0xbb, 0x7a, 0x47, 0x40, 0x6a, 0x4f, 0x6d, 0xfa, 0xa, 0x20, 0x35, 0xe6, 0x1};
72  set_hash(tmp_hash);
73 }
74 
75 /** Destructor */
76 VisualDisplay2DInterface::~VisualDisplay2DInterface()
77 {
78  free(data_ptr);
79 }
80 /** Convert LineStyle constant to string.
81  * @param value value to convert to string
82  * @return constant value as string.
83  */
84 const char *
86 {
87  switch (value) {
88  case LS_SOLID: return "LS_SOLID";
89  case LS_DASHED: return "LS_DASHED";
90  case LS_DOTTED: return "LS_DOTTED";
91  case LS_DASH_DOTTED: return "LS_DASH_DOTTED";
92  default: return "UNKNOWN";
93  }
94 }
95 /** Convert Anchor constant to string.
96  * @param value value to convert to string
97  * @return constant value as string.
98  */
99 const char *
101 {
102  switch (value) {
103  case CENTERED: return "CENTERED";
104  case NORTH: return "NORTH";
105  case EAST: return "EAST";
106  case SOUTH: return "SOUTH";
107  case WEST: return "WEST";
108  case NORTH_EAST: return "NORTH_EAST";
109  case SOUTH_EAST: return "SOUTH_EAST";
110  case SOUTH_WEST: return "SOUTH_WEST";
111  case NORTH_WEST: return "NORTH_WEST";
112  default: return "UNKNOWN";
113  }
114 }
115 /* Methods */
116 /** Get counter value.
117  * Field
118  * @return counter value
119  */
120 uint32_t
122 {
123  return data->counter;
124 }
125 
126 /** Get maximum length of counter value.
127  * @return length of counter value, can be length of the array or number of
128  * maximum number of characters for a string
129  */
130 size_t
132 {
133  return 1;
134 }
135 
136 /** Set counter value.
137  * Field
138  * @param new_counter new counter value
139  */
140 void
141 VisualDisplay2DInterface::set_counter(const uint32_t new_counter)
142 {
143  data->counter = new_counter;
144  data_changed = true;
145 }
146 
147 /* =========== message create =========== */
148 Message *
150 {
151  if ( strncmp("AddCartLineMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
152  return new AddCartLineMessage();
153  } else if ( strncmp("AddCartCircleMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
154  return new AddCartCircleMessage();
155  } else if ( strncmp("AddCartRectMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
156  return new AddCartRectMessage();
157  } else if ( strncmp("AddCartTextMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
158  return new AddCartTextMessage();
159  } else if ( strncmp("DeleteObjectMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
160  return new DeleteObjectMessage();
161  } else if ( strncmp("DeleteAllMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
162  return new DeleteAllMessage();
163  } else {
164  throw UnknownTypeException("The given type '%s' does not match any known "
165  "message type for this interface type.", type);
166  }
167 }
168 
169 
170 /** Copy values from other interface.
171  * @param other other interface to copy values from
172  */
173 void
175 {
176  const VisualDisplay2DInterface *oi = dynamic_cast<const VisualDisplay2DInterface *>(other);
177  if (oi == NULL) {
178  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
179  type(), other->type());
180  }
181  memcpy(data, oi->data, sizeof(VisualDisplay2DInterface_data_t));
182 }
183 
184 const char *
185 VisualDisplay2DInterface::enum_tostring(const char *enumtype, int val) const
186 {
187  if (strcmp(enumtype, "LineStyle") == 0) {
188  return tostring_LineStyle((LineStyle)val);
189  }
190  if (strcmp(enumtype, "Anchor") == 0) {
191  return tostring_Anchor((Anchor)val);
192  }
193  throw UnknownTypeException("Unknown enum type %s", enumtype);
194 }
195 
196 /* =========== messages =========== */
197 /** @class VisualDisplay2DInterface::AddCartLineMessage <interfaces/VisualDisplay2DInterface.h>
198  * AddCartLineMessage Fawkes BlackBoard Interface Message.
199  *
200 
201  */
202 
203 
204 /** Constructor with initial values.
205  * @param ini_x initial value for x
206  * @param ini_y initial value for y
207  * @param ini_style initial value for style
208  * @param ini_color initial value for color
209  */
210 VisualDisplay2DInterface::AddCartLineMessage::AddCartLineMessage(const float * ini_x, const float * ini_y, const LineStyle ini_style, const uint8_t * ini_color) : Message("AddCartLineMessage")
211 {
212  data_size = sizeof(AddCartLineMessage_data_t);
213  data_ptr = malloc(data_size);
214  memset(data_ptr, 0, data_size);
215  data = (AddCartLineMessage_data_t *)data_ptr;
217  memcpy(data->x, ini_x, sizeof(float) * 2);
218  memcpy(data->y, ini_y, sizeof(float) * 2);
219  data->style = ini_style;
220  memcpy(data->color, ini_color, sizeof(uint8_t) * 4);
221  add_fieldinfo(IFT_FLOAT, "x", 2, &data->x, "");
222  add_fieldinfo(IFT_FLOAT, "y", 2, &data->y, "");
223  add_fieldinfo(IFT_ENUM, "style", 1, &data->style);
224  add_fieldinfo(IFT_BYTE, "color", 4, &data->color, "");
225 }
226 /** Constructor */
228 {
229  data_size = sizeof(AddCartLineMessage_data_t);
230  data_ptr = malloc(data_size);
231  memset(data_ptr, 0, data_size);
232  data = (AddCartLineMessage_data_t *)data_ptr;
234  add_fieldinfo(IFT_FLOAT, "x", 2, &data->x, "");
235  add_fieldinfo(IFT_FLOAT, "y", 2, &data->y, "");
236  add_fieldinfo(IFT_ENUM, "style", 1, &data->style);
237  add_fieldinfo(IFT_BYTE, "color", 4, &data->color, "");
238 }
239 
240 /** Destructor */
242 {
243  free(data_ptr);
244 }
245 
246 /** Copy constructor.
247  * @param m message to copy from
248  */
250 {
251  data_size = m->data_size;
252  data_ptr = malloc(data_size);
253  memcpy(data_ptr, m->data_ptr, data_size);
254  data = (AddCartLineMessage_data_t *)data_ptr;
256 }
257 
258 /* Methods */
259 /** Get x value.
260  * X coordinates of two points
261  * @return x value
262  */
263 float *
265 {
266  return data->x;
267 }
268 
269 /** Get x value at given index.
270  * X coordinates of two points
271  * @param index index of value
272  * @return x value
273  * @exception Exception thrown if index is out of bounds
274  */
275 float
277 {
278  if (index > 2) {
279  throw Exception("Index value %u out of bounds (0..2)", index);
280  }
281  return data->x[index];
282 }
283 
284 /** Get maximum length of x value.
285  * @return length of x value, can be length of the array or number of
286  * maximum number of characters for a string
287  */
288 size_t
290 {
291  return 2;
292 }
293 
294 /** Set x value.
295  * X coordinates of two points
296  * @param new_x new x value
297  */
298 void
300 {
301  memcpy(data->x, new_x, sizeof(float) * 2);
302 }
303 
304 /** Set x value at given index.
305  * X coordinates of two points
306  * @param new_x new x value
307  * @param index index for of the value
308  */
309 void
310 VisualDisplay2DInterface::AddCartLineMessage::set_x(unsigned int index, const float new_x)
311 {
312  if (index > 2) {
313  throw Exception("Index value %u out of bounds (0..2)", index);
314  }
315  data->x[index] = new_x;
316 }
317 /** Get y value.
318  * Y coordinates of two
319  points
320  * @return y value
321  */
322 float *
324 {
325  return data->y;
326 }
327 
328 /** Get y value at given index.
329  * Y coordinates of two
330  points
331  * @param index index of value
332  * @return y value
333  * @exception Exception thrown if index is out of bounds
334  */
335 float
337 {
338  if (index > 2) {
339  throw Exception("Index value %u out of bounds (0..2)", index);
340  }
341  return data->y[index];
342 }
343 
344 /** Get maximum length of y value.
345  * @return length of y value, can be length of the array or number of
346  * maximum number of characters for a string
347  */
348 size_t
350 {
351  return 2;
352 }
353 
354 /** Set y value.
355  * Y coordinates of two
356  points
357  * @param new_y new y value
358  */
359 void
361 {
362  memcpy(data->y, new_y, sizeof(float) * 2);
363 }
364 
365 /** Set y value at given index.
366  * Y coordinates of two
367  points
368  * @param new_y new y value
369  * @param index index for of the value
370  */
371 void
372 VisualDisplay2DInterface::AddCartLineMessage::set_y(unsigned int index, const float new_y)
373 {
374  if (index > 2) {
375  throw Exception("Index value %u out of bounds (0..2)", index);
376  }
377  data->y[index] = new_y;
378 }
379 /** Get style value.
380  * Style of this object.
381  * @return style value
382  */
385 {
386  return (VisualDisplay2DInterface::LineStyle)data->style;
387 }
388 
389 /** Get maximum length of style value.
390  * @return length of style value, can be length of the array or number of
391  * maximum number of characters for a string
392  */
393 size_t
395 {
396  return 1;
397 }
398 
399 /** Set style value.
400  * Style of this object.
401  * @param new_style new style value
402  */
403 void
405 {
406  data->style = new_style;
407 }
408 
409 /** Get color value.
410  * Color in RGBA
411  * @return color value
412  */
413 uint8_t *
415 {
416  return data->color;
417 }
418 
419 /** Get color value at given index.
420  * Color in RGBA
421  * @param index index of value
422  * @return color value
423  * @exception Exception thrown if index is out of bounds
424  */
425 uint8_t
427 {
428  if (index > 4) {
429  throw Exception("Index value %u out of bounds (0..4)", index);
430  }
431  return data->color[index];
432 }
433 
434 /** Get maximum length of color value.
435  * @return length of color value, can be length of the array or number of
436  * maximum number of characters for a string
437  */
438 size_t
440 {
441  return 4;
442 }
443 
444 /** Set color value.
445  * Color in RGBA
446  * @param new_color new color value
447  */
448 void
450 {
451  memcpy(data->color, new_color, sizeof(uint8_t) * 4);
452 }
453 
454 /** Set color value at given index.
455  * Color in RGBA
456  * @param new_color new color value
457  * @param index index for of the value
458  */
459 void
460 VisualDisplay2DInterface::AddCartLineMessage::set_color(unsigned int index, const uint8_t new_color)
461 {
462  if (index > 4) {
463  throw Exception("Index value %u out of bounds (0..4)", index);
464  }
465  data->color[index] = new_color;
466 }
467 /** Clone this message.
468  * Produces a message of the same type as this message and copies the
469  * data to the new message.
470  * @return clone of this message
471  */
472 Message *
474 {
476 }
477 /** @class VisualDisplay2DInterface::AddCartCircleMessage <interfaces/VisualDisplay2DInterface.h>
478  * AddCartCircleMessage Fawkes BlackBoard Interface Message.
479  *
480 
481  */
482 
483 
484 /** Constructor with initial values.
485  * @param ini_x initial value for x
486  * @param ini_y initial value for y
487  * @param ini_radius initial value for radius
488  * @param ini_style initial value for style
489  * @param ini_color initial value for color
490  */
491 VisualDisplay2DInterface::AddCartCircleMessage::AddCartCircleMessage(const float ini_x, const float ini_y, const float ini_radius, const LineStyle ini_style, const uint8_t * ini_color) : Message("AddCartCircleMessage")
492 {
493  data_size = sizeof(AddCartCircleMessage_data_t);
494  data_ptr = malloc(data_size);
495  memset(data_ptr, 0, data_size);
496  data = (AddCartCircleMessage_data_t *)data_ptr;
498  data->x = ini_x;
499  data->y = ini_y;
500  data->radius = ini_radius;
501  data->style = ini_style;
502  memcpy(data->color, ini_color, sizeof(uint8_t) * 4);
503  add_fieldinfo(IFT_FLOAT, "x", 1, &data->x, "");
504  add_fieldinfo(IFT_FLOAT, "y", 1, &data->y, "");
505  add_fieldinfo(IFT_FLOAT, "radius", 1, &data->radius, "");
506  add_fieldinfo(IFT_ENUM, "style", 1, &data->style);
507  add_fieldinfo(IFT_BYTE, "color", 4, &data->color, "");
508 }
509 /** Constructor */
511 {
512  data_size = sizeof(AddCartCircleMessage_data_t);
513  data_ptr = malloc(data_size);
514  memset(data_ptr, 0, data_size);
515  data = (AddCartCircleMessage_data_t *)data_ptr;
517  add_fieldinfo(IFT_FLOAT, "x", 1, &data->x, "");
518  add_fieldinfo(IFT_FLOAT, "y", 1, &data->y, "");
519  add_fieldinfo(IFT_FLOAT, "radius", 1, &data->radius, "");
520  add_fieldinfo(IFT_ENUM, "style", 1, &data->style);
521  add_fieldinfo(IFT_BYTE, "color", 4, &data->color, "");
522 }
523 
524 /** Destructor */
526 {
527  free(data_ptr);
528 }
529 
530 /** Copy constructor.
531  * @param m message to copy from
532  */
534 {
535  data_size = m->data_size;
536  data_ptr = malloc(data_size);
537  memcpy(data_ptr, m->data_ptr, data_size);
538  data = (AddCartCircleMessage_data_t *)data_ptr;
540 }
541 
542 /* Methods */
543 /** Get x value.
544  * X coordinate of center point
545  * @return x value
546  */
547 float
549 {
550  return data->x;
551 }
552 
553 /** Get maximum length of x value.
554  * @return length of x value, can be length of the array or number of
555  * maximum number of characters for a string
556  */
557 size_t
559 {
560  return 1;
561 }
562 
563 /** Set x value.
564  * X coordinate of center point
565  * @param new_x new x value
566  */
567 void
569 {
570  data->x = new_x;
571 }
572 
573 /** Get y value.
574  * Y coordinate of center point
575  * @return y value
576  */
577 float
579 {
580  return data->y;
581 }
582 
583 /** Get maximum length of y value.
584  * @return length of y value, can be length of the array or number of
585  * maximum number of characters for a string
586  */
587 size_t
589 {
590  return 1;
591 }
592 
593 /** Set y value.
594  * Y coordinate of center point
595  * @param new_y new y value
596  */
597 void
599 {
600  data->y = new_y;
601 }
602 
603 /** Get radius value.
604  * Radius of the circle.
605  * @return radius value
606  */
607 float
609 {
610  return data->radius;
611 }
612 
613 /** Get maximum length of radius value.
614  * @return length of radius value, can be length of the array or number of
615  * maximum number of characters for a string
616  */
617 size_t
619 {
620  return 1;
621 }
622 
623 /** Set radius value.
624  * Radius of the circle.
625  * @param new_radius new radius value
626  */
627 void
629 {
630  data->radius = new_radius;
631 }
632 
633 /** Get style value.
634  * Style of this object.
635  * @return style value
636  */
639 {
640  return (VisualDisplay2DInterface::LineStyle)data->style;
641 }
642 
643 /** Get maximum length of style value.
644  * @return length of style value, can be length of the array or number of
645  * maximum number of characters for a string
646  */
647 size_t
649 {
650  return 1;
651 }
652 
653 /** Set style value.
654  * Style of this object.
655  * @param new_style new style value
656  */
657 void
659 {
660  data->style = new_style;
661 }
662 
663 /** Get color value.
664  * Color in RGBA
665  * @return color value
666  */
667 uint8_t *
669 {
670  return data->color;
671 }
672 
673 /** Get color value at given index.
674  * Color in RGBA
675  * @param index index of value
676  * @return color value
677  * @exception Exception thrown if index is out of bounds
678  */
679 uint8_t
681 {
682  if (index > 4) {
683  throw Exception("Index value %u out of bounds (0..4)", index);
684  }
685  return data->color[index];
686 }
687 
688 /** Get maximum length of color value.
689  * @return length of color value, can be length of the array or number of
690  * maximum number of characters for a string
691  */
692 size_t
694 {
695  return 4;
696 }
697 
698 /** Set color value.
699  * Color in RGBA
700  * @param new_color new color value
701  */
702 void
704 {
705  memcpy(data->color, new_color, sizeof(uint8_t) * 4);
706 }
707 
708 /** Set color value at given index.
709  * Color in RGBA
710  * @param new_color new color value
711  * @param index index for of the value
712  */
713 void
714 VisualDisplay2DInterface::AddCartCircleMessage::set_color(unsigned int index, const uint8_t new_color)
715 {
716  if (index > 4) {
717  throw Exception("Index value %u out of bounds (0..4)", index);
718  }
719  data->color[index] = new_color;
720 }
721 /** Clone this message.
722  * Produces a message of the same type as this message and copies the
723  * data to the new message.
724  * @return clone of this message
725  */
726 Message *
728 {
730 }
731 /** @class VisualDisplay2DInterface::AddCartRectMessage <interfaces/VisualDisplay2DInterface.h>
732  * AddCartRectMessage Fawkes BlackBoard Interface Message.
733  *
734 
735  */
736 
737 
738 /** Constructor with initial values.
739  * @param ini_x initial value for x
740  * @param ini_y initial value for y
741  * @param ini_width initial value for width
742  * @param ini_height initial value for height
743  * @param ini_style initial value for style
744  * @param ini_color initial value for color
745  */
746 VisualDisplay2DInterface::AddCartRectMessage::AddCartRectMessage(const float ini_x, const float ini_y, const float ini_width, const float ini_height, const LineStyle ini_style, const uint8_t * ini_color) : Message("AddCartRectMessage")
747 {
748  data_size = sizeof(AddCartRectMessage_data_t);
749  data_ptr = malloc(data_size);
750  memset(data_ptr, 0, data_size);
751  data = (AddCartRectMessage_data_t *)data_ptr;
753  data->x = ini_x;
754  data->y = ini_y;
755  data->width = ini_width;
756  data->height = ini_height;
757  data->style = ini_style;
758  memcpy(data->color, ini_color, sizeof(uint8_t) * 4);
759  add_fieldinfo(IFT_FLOAT, "x", 1, &data->x, "");
760  add_fieldinfo(IFT_FLOAT, "y", 1, &data->y, "");
761  add_fieldinfo(IFT_FLOAT, "width", 1, &data->width, "");
762  add_fieldinfo(IFT_FLOAT, "height", 1, &data->height, "");
763  add_fieldinfo(IFT_ENUM, "style", 1, &data->style);
764  add_fieldinfo(IFT_BYTE, "color", 4, &data->color, "");
765 }
766 /** Constructor */
768 {
769  data_size = sizeof(AddCartRectMessage_data_t);
770  data_ptr = malloc(data_size);
771  memset(data_ptr, 0, data_size);
772  data = (AddCartRectMessage_data_t *)data_ptr;
774  add_fieldinfo(IFT_FLOAT, "x", 1, &data->x, "");
775  add_fieldinfo(IFT_FLOAT, "y", 1, &data->y, "");
776  add_fieldinfo(IFT_FLOAT, "width", 1, &data->width, "");
777  add_fieldinfo(IFT_FLOAT, "height", 1, &data->height, "");
778  add_fieldinfo(IFT_ENUM, "style", 1, &data->style);
779  add_fieldinfo(IFT_BYTE, "color", 4, &data->color, "");
780 }
781 
782 /** Destructor */
784 {
785  free(data_ptr);
786 }
787 
788 /** Copy constructor.
789  * @param m message to copy from
790  */
792 {
793  data_size = m->data_size;
794  data_ptr = malloc(data_size);
795  memcpy(data_ptr, m->data_ptr, data_size);
796  data = (AddCartRectMessage_data_t *)data_ptr;
798 }
799 
800 /* Methods */
801 /** Get x value.
802  * X coordinate of lower right corner
803  * @return x value
804  */
805 float
807 {
808  return data->x;
809 }
810 
811 /** Get maximum length of x value.
812  * @return length of x value, can be length of the array or number of
813  * maximum number of characters for a string
814  */
815 size_t
817 {
818  return 1;
819 }
820 
821 /** Set x value.
822  * X coordinate of lower right corner
823  * @param new_x new x value
824  */
825 void
827 {
828  data->x = new_x;
829 }
830 
831 /** Get y value.
832  * Y coordinate of lower right corner
833  * @return y value
834  */
835 float
837 {
838  return data->y;
839 }
840 
841 /** Get maximum length of y value.
842  * @return length of y value, can be length of the array or number of
843  * maximum number of characters for a string
844  */
845 size_t
847 {
848  return 1;
849 }
850 
851 /** Set y value.
852  * Y coordinate of lower right corner
853  * @param new_y new y value
854  */
855 void
857 {
858  data->y = new_y;
859 }
860 
861 /** Get width value.
862  * Width of rectangle
863  * @return width value
864  */
865 float
867 {
868  return data->width;
869 }
870 
871 /** Get maximum length of width value.
872  * @return length of width value, can be length of the array or number of
873  * maximum number of characters for a string
874  */
875 size_t
877 {
878  return 1;
879 }
880 
881 /** Set width value.
882  * Width of rectangle
883  * @param new_width new width value
884  */
885 void
887 {
888  data->width = new_width;
889 }
890 
891 /** Get height value.
892  * Height of rectangle
893  * @return height value
894  */
895 float
897 {
898  return data->height;
899 }
900 
901 /** Get maximum length of height value.
902  * @return length of height value, can be length of the array or number of
903  * maximum number of characters for a string
904  */
905 size_t
907 {
908  return 1;
909 }
910 
911 /** Set height value.
912  * Height of rectangle
913  * @param new_height new height value
914  */
915 void
917 {
918  data->height = new_height;
919 }
920 
921 /** Get style value.
922  * Style of this object.
923  * @return style value
924  */
927 {
928  return (VisualDisplay2DInterface::LineStyle)data->style;
929 }
930 
931 /** Get maximum length of style value.
932  * @return length of style value, can be length of the array or number of
933  * maximum number of characters for a string
934  */
935 size_t
937 {
938  return 1;
939 }
940 
941 /** Set style value.
942  * Style of this object.
943  * @param new_style new style value
944  */
945 void
947 {
948  data->style = new_style;
949 }
950 
951 /** Get color value.
952  * Color in RGBA
953  * @return color value
954  */
955 uint8_t *
957 {
958  return data->color;
959 }
960 
961 /** Get color value at given index.
962  * Color in RGBA
963  * @param index index of value
964  * @return color value
965  * @exception Exception thrown if index is out of bounds
966  */
967 uint8_t
969 {
970  if (index > 4) {
971  throw Exception("Index value %u out of bounds (0..4)", index);
972  }
973  return data->color[index];
974 }
975 
976 /** Get maximum length of color value.
977  * @return length of color value, can be length of the array or number of
978  * maximum number of characters for a string
979  */
980 size_t
982 {
983  return 4;
984 }
985 
986 /** Set color value.
987  * Color in RGBA
988  * @param new_color new color value
989  */
990 void
992 {
993  memcpy(data->color, new_color, sizeof(uint8_t) * 4);
994 }
995 
996 /** Set color value at given index.
997  * Color in RGBA
998  * @param new_color new color value
999  * @param index index for of the value
1000  */
1001 void
1002 VisualDisplay2DInterface::AddCartRectMessage::set_color(unsigned int index, const uint8_t new_color)
1003 {
1004  if (index > 4) {
1005  throw Exception("Index value %u out of bounds (0..4)", index);
1006  }
1007  data->color[index] = new_color;
1008 }
1009 /** Clone this message.
1010  * Produces a message of the same type as this message and copies the
1011  * data to the new message.
1012  * @return clone of this message
1013  */
1014 Message *
1016 {
1018 }
1019 /** @class VisualDisplay2DInterface::AddCartTextMessage <interfaces/VisualDisplay2DInterface.h>
1020  * AddCartTextMessage Fawkes BlackBoard Interface Message.
1021  *
1022 
1023  */
1024 
1025 
1026 /** Constructor with initial values.
1027  * @param ini_x initial value for x
1028  * @param ini_y initial value for y
1029  * @param ini_text initial value for text
1030  * @param ini_anchor initial value for anchor
1031  * @param ini_size initial value for size
1032  * @param ini_color initial value for color
1033  */
1034 VisualDisplay2DInterface::AddCartTextMessage::AddCartTextMessage(const float ini_x, const float ini_y, const char * ini_text, const Anchor ini_anchor, const float ini_size, const uint8_t * ini_color) : Message("AddCartTextMessage")
1035 {
1036  data_size = sizeof(AddCartTextMessage_data_t);
1037  data_ptr = malloc(data_size);
1038  memset(data_ptr, 0, data_size);
1039  data = (AddCartTextMessage_data_t *)data_ptr;
1041  data->x = ini_x;
1042  data->y = ini_y;
1043  strncpy(data->text, ini_text, 128);
1044  data->anchor = ini_anchor;
1045  data->size = ini_size;
1046  memcpy(data->color, ini_color, sizeof(uint8_t) * 4);
1047  add_fieldinfo(IFT_FLOAT, "x", 1, &data->x, "");
1048  add_fieldinfo(IFT_FLOAT, "y", 1, &data->y, "");
1049  add_fieldinfo(IFT_STRING, "text", 128, data->text, "");
1050  add_fieldinfo(IFT_ENUM, "anchor", 1, &data->anchor);
1051  add_fieldinfo(IFT_FLOAT, "size", 1, &data->size, "");
1052  add_fieldinfo(IFT_BYTE, "color", 4, &data->color, "");
1053 }
1054 /** Constructor */
1056 {
1057  data_size = sizeof(AddCartTextMessage_data_t);
1058  data_ptr = malloc(data_size);
1059  memset(data_ptr, 0, data_size);
1060  data = (AddCartTextMessage_data_t *)data_ptr;
1062  add_fieldinfo(IFT_FLOAT, "x", 1, &data->x, "");
1063  add_fieldinfo(IFT_FLOAT, "y", 1, &data->y, "");
1064  add_fieldinfo(IFT_STRING, "text", 128, data->text, "");
1065  add_fieldinfo(IFT_ENUM, "anchor", 1, &data->anchor);
1066  add_fieldinfo(IFT_FLOAT, "size", 1, &data->size, "");
1067  add_fieldinfo(IFT_BYTE, "color", 4, &data->color, "");
1068 }
1069 
1070 /** Destructor */
1072 {
1073  free(data_ptr);
1074 }
1075 
1076 /** Copy constructor.
1077  * @param m message to copy from
1078  */
1080 {
1081  data_size = m->data_size;
1082  data_ptr = malloc(data_size);
1083  memcpy(data_ptr, m->data_ptr, data_size);
1084  data = (AddCartTextMessage_data_t *)data_ptr;
1086 }
1087 
1088 /* Methods */
1089 /** Get x value.
1090  * X coordinate of upper left corner
1091  * @return x value
1092  */
1093 float
1095 {
1096  return data->x;
1097 }
1098 
1099 /** Get maximum length of x value.
1100  * @return length of x value, can be length of the array or number of
1101  * maximum number of characters for a string
1102  */
1103 size_t
1105 {
1106  return 1;
1107 }
1108 
1109 /** Set x value.
1110  * X coordinate of upper left corner
1111  * @param new_x new x value
1112  */
1113 void
1115 {
1116  data->x = new_x;
1117 }
1118 
1119 /** Get y value.
1120  * Y coordinate of upper left corner
1121  * @return y value
1122  */
1123 float
1125 {
1126  return data->y;
1127 }
1128 
1129 /** Get maximum length of y value.
1130  * @return length of y value, can be length of the array or number of
1131  * maximum number of characters for a string
1132  */
1133 size_t
1135 {
1136  return 1;
1137 }
1138 
1139 /** Set y value.
1140  * Y coordinate of upper left corner
1141  * @param new_y new y value
1142  */
1143 void
1145 {
1146  data->y = new_y;
1147 }
1148 
1149 /** Get text value.
1150  * Width of rectangle
1151  * @return text value
1152  */
1153 char *
1155 {
1156  return data->text;
1157 }
1158 
1159 /** Get maximum length of text value.
1160  * @return length of text value, can be length of the array or number of
1161  * maximum number of characters for a string
1162  */
1163 size_t
1165 {
1166  return 128;
1167 }
1168 
1169 /** Set text value.
1170  * Width of rectangle
1171  * @param new_text new text value
1172  */
1173 void
1175 {
1176  strncpy(data->text, new_text, sizeof(data->text));
1177 }
1178 
1179 /** Get anchor value.
1180  * Anchor which marks the
1181  alignment to the given point.
1182  * @return anchor value
1183  */
1186 {
1187  return (VisualDisplay2DInterface::Anchor)data->anchor;
1188 }
1189 
1190 /** Get maximum length of anchor value.
1191  * @return length of anchor value, can be length of the array or number of
1192  * maximum number of characters for a string
1193  */
1194 size_t
1196 {
1197  return 1;
1198 }
1199 
1200 /** Set anchor value.
1201  * Anchor which marks the
1202  alignment to the given point.
1203  * @param new_anchor new anchor value
1204  */
1205 void
1207 {
1208  data->anchor = new_anchor;
1209 }
1210 
1211 /** Get size value.
1212  * Font size (max height in m).
1213  * @return size value
1214  */
1215 float
1217 {
1218  return data->size;
1219 }
1220 
1221 /** Get maximum length of size value.
1222  * @return length of size value, can be length of the array or number of
1223  * maximum number of characters for a string
1224  */
1225 size_t
1227 {
1228  return 1;
1229 }
1230 
1231 /** Set size value.
1232  * Font size (max height in m).
1233  * @param new_size new size value
1234  */
1235 void
1237 {
1238  data->size = new_size;
1239 }
1240 
1241 /** Get color value.
1242  * Color in RGBA
1243  * @return color value
1244  */
1245 uint8_t *
1247 {
1248  return data->color;
1249 }
1250 
1251 /** Get color value at given index.
1252  * Color in RGBA
1253  * @param index index of value
1254  * @return color value
1255  * @exception Exception thrown if index is out of bounds
1256  */
1257 uint8_t
1259 {
1260  if (index > 4) {
1261  throw Exception("Index value %u out of bounds (0..4)", index);
1262  }
1263  return data->color[index];
1264 }
1265 
1266 /** Get maximum length of color value.
1267  * @return length of color value, can be length of the array or number of
1268  * maximum number of characters for a string
1269  */
1270 size_t
1272 {
1273  return 4;
1274 }
1275 
1276 /** Set color value.
1277  * Color in RGBA
1278  * @param new_color new color value
1279  */
1280 void
1282 {
1283  memcpy(data->color, new_color, sizeof(uint8_t) * 4);
1284 }
1285 
1286 /** Set color value at given index.
1287  * Color in RGBA
1288  * @param new_color new color value
1289  * @param index index for of the value
1290  */
1291 void
1292 VisualDisplay2DInterface::AddCartTextMessage::set_color(unsigned int index, const uint8_t new_color)
1293 {
1294  if (index > 4) {
1295  throw Exception("Index value %u out of bounds (0..4)", index);
1296  }
1297  data->color[index] = new_color;
1298 }
1299 /** Clone this message.
1300  * Produces a message of the same type as this message and copies the
1301  * data to the new message.
1302  * @return clone of this message
1303  */
1304 Message *
1306 {
1308 }
1309 /** @class VisualDisplay2DInterface::DeleteObjectMessage <interfaces/VisualDisplay2DInterface.h>
1310  * DeleteObjectMessage Fawkes BlackBoard Interface Message.
1311  *
1312 
1313  */
1314 
1315 
1316 /** Constructor with initial values.
1317  * @param ini_object_id initial value for object_id
1318  */
1319 VisualDisplay2DInterface::DeleteObjectMessage::DeleteObjectMessage(const uint32_t ini_object_id) : Message("DeleteObjectMessage")
1320 {
1321  data_size = sizeof(DeleteObjectMessage_data_t);
1322  data_ptr = malloc(data_size);
1323  memset(data_ptr, 0, data_size);
1324  data = (DeleteObjectMessage_data_t *)data_ptr;
1326  data->object_id = ini_object_id;
1327  add_fieldinfo(IFT_UINT32, "object_id", 1, &data->object_id, "");
1328 }
1329 /** Constructor */
1331 {
1332  data_size = sizeof(DeleteObjectMessage_data_t);
1333  data_ptr = malloc(data_size);
1334  memset(data_ptr, 0, data_size);
1335  data = (DeleteObjectMessage_data_t *)data_ptr;
1337  add_fieldinfo(IFT_UINT32, "object_id", 1, &data->object_id, "");
1338 }
1339 
1340 /** Destructor */
1342 {
1343  free(data_ptr);
1344 }
1345 
1346 /** Copy constructor.
1347  * @param m message to copy from
1348  */
1350 {
1351  data_size = m->data_size;
1352  data_ptr = malloc(data_size);
1353  memcpy(data_ptr, m->data_ptr, data_size);
1354  data = (DeleteObjectMessage_data_t *)data_ptr;
1356 }
1357 
1358 /* Methods */
1359 /** Get object_id value.
1360  * Object ID, which is
1361  the message ID of the Add* message.
1362  * @return object_id value
1363  */
1364 uint32_t
1366 {
1367  return data->object_id;
1368 }
1369 
1370 /** Get maximum length of object_id value.
1371  * @return length of object_id value, can be length of the array or number of
1372  * maximum number of characters for a string
1373  */
1374 size_t
1376 {
1377  return 1;
1378 }
1379 
1380 /** Set object_id value.
1381  * Object ID, which is
1382  the message ID of the Add* message.
1383  * @param new_object_id new object_id value
1384  */
1385 void
1387 {
1388  data->object_id = new_object_id;
1389 }
1390 
1391 /** Clone this message.
1392  * Produces a message of the same type as this message and copies the
1393  * data to the new message.
1394  * @return clone of this message
1395  */
1396 Message *
1398 {
1400 }
1401 /** @class VisualDisplay2DInterface::DeleteAllMessage <interfaces/VisualDisplay2DInterface.h>
1402  * DeleteAllMessage Fawkes BlackBoard Interface Message.
1403  *
1404 
1405  */
1406 
1407 
1408 /** Constructor */
1410 {
1411  data_size = sizeof(DeleteAllMessage_data_t);
1412  data_ptr = malloc(data_size);
1413  memset(data_ptr, 0, data_size);
1414  data = (DeleteAllMessage_data_t *)data_ptr;
1416 }
1417 
1418 /** Destructor */
1420 {
1421  free(data_ptr);
1422 }
1423 
1424 /** Copy constructor.
1425  * @param m message to copy from
1426  */
1428 {
1429  data_size = m->data_size;
1430  data_ptr = malloc(data_size);
1431  memcpy(data_ptr, m->data_ptr, data_size);
1432  data = (DeleteAllMessage_data_t *)data_ptr;
1434 }
1435 
1436 /* Methods */
1437 /** Clone this message.
1438  * Produces a message of the same type as this message and copies the
1439  * data to the new message.
1440  * @return clone of this message
1441  */
1442 Message *
1444 {
1446 }
1447 /** Check if message is valid and can be enqueued.
1448  * @param message Message to check
1449  * @return true if the message is valid, false otherwise.
1450  */
1451 bool
1453 {
1454  const AddCartLineMessage *m0 = dynamic_cast<const AddCartLineMessage *>(message);
1455  if ( m0 != NULL ) {
1456  return true;
1457  }
1458  const AddCartCircleMessage *m1 = dynamic_cast<const AddCartCircleMessage *>(message);
1459  if ( m1 != NULL ) {
1460  return true;
1461  }
1462  const AddCartRectMessage *m2 = dynamic_cast<const AddCartRectMessage *>(message);
1463  if ( m2 != NULL ) {
1464  return true;
1465  }
1466  const AddCartTextMessage *m3 = dynamic_cast<const AddCartTextMessage *>(message);
1467  if ( m3 != NULL ) {
1468  return true;
1469  }
1470  const DeleteObjectMessage *m4 = dynamic_cast<const DeleteObjectMessage *>(message);
1471  if ( m4 != NULL ) {
1472  return true;
1473  }
1474  const DeleteAllMessage *m5 = dynamic_cast<const DeleteAllMessage *>(message);
1475  if ( m5 != NULL ) {
1476  return true;
1477  }
1478  return false;
1479 }
1480 
1481 /// @cond INTERNALS
1482 EXPORT_INTERFACE(VisualDisplay2DInterface)
1483 /// @endcond
1484 
1485 
1486 } // end namespace fawkes
AddCartRectMessage Fawkes BlackBoard Interface Message.
LineStyle
Enumeration defining the possible line styles.
void set_anchor(const Anchor new_anchor)
Set anchor value.
size_t maxlenof_style() const
Get maximum length of style value.
void * data_ptr
Pointer to memory that contains local data.
Definition: message.h:114
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
virtual Message * clone() const
Clone this message.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:43
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
size_t maxlenof_x() const
Get maximum length of x value.
size_t maxlenof_color() const
Get maximum length of color value.
void set_hash(unsigned char *ihash)
Set hash.
Definition: interface.cpp:312
size_t maxlenof_width() const
Get maximum length of width value.
Fawkes library namespace.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
Definition: message.h:119
AddCartCircleMessage Fawkes BlackBoard Interface Message.
void set_radius(const float new_radius)
Set radius value.
size_t maxlenof_y() const
Get maximum length of y value.
unsigned int data_size
Minimal data size to hold data storage.
Definition: interface.h:207
Anchor
Enumeration defining the possible anchor points.
size_t maxlenof_style() const
Get maximum length of style value.
string field
Definition: types.h:45
virtual Message * clone() const
Clone this message.
byte field, alias for uint8
Definition: types.h:46
virtual Message * clone() const
Clone this message.
size_t maxlenof_y() const
Get maximum length of y value.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
void set_style(const LineStyle new_style)
Set style value.
void set_color(unsigned int index, const uint8_t new_color)
Set color value at given index.
size_t maxlenof_counter() const
Get maximum length of counter value.
AddCartTextMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_height() const
Get maximum length of height value.
size_t maxlenof_x() const
Get maximum length of x value.
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition: message.h:123
unsigned int data_size
Size of memory needed to hold all data.
Definition: message.h:115
size_t maxlenof_color() const
Get maximum length of color value.
size_t maxlenof_style() const
Get maximum length of style value.
void add_messageinfo(const char *name)
Add an entry to the message info list.
Definition: interface.cpp:368
DeleteObjectMessage Fawkes BlackBoard Interface Message.
bool data_changed
Indicator if data has changed.
Definition: interface.h:208
void set_color(unsigned int index, const uint8_t new_color)
Set color value at given index.
size_t maxlenof_object_id() const
Get maximum length of object_id value.
size_t maxlenof_x() const
Get maximum length of x value.
void * data_ptr
Pointer to local memory storage.
Definition: interface.h:206
Base class for exceptions in Fawkes.
Definition: exception.h:36
AddCartLineMessage Fawkes BlackBoard Interface Message.
void set_height(const float new_height)
Set height value.
void set_x(unsigned int index, const float new_x)
Set x value at given index.
size_t maxlenof_anchor() const
Get maximum length of anchor value.
size_t maxlenof_x() const
Get maximum length of x value.
const char * tostring_LineStyle(LineStyle value) const
Convert LineStyle constant to string.
uint32_t counter() const
Get counter value.
virtual void copy_values(const Interface *other)
Copy values from other interface.
size_t maxlenof_text() const
Get maximum length of text value.
void set_style(const LineStyle new_style)
Set style value.
size_t maxlenof_y() const
Get maximum length of y value.
size_t maxlenof_color() const
Get maximum length of color value.
virtual Message * clone() const
Clone this message.
Vertically and horitontally centered.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0)
Add an entry to the field info list.
Definition: interface.cpp:332
const char * tostring_Anchor(Anchor value) const
Convert Anchor constant to string.
float field
Definition: types.h:43
virtual Message * clone() const
Clone this message.
void set_color(unsigned int index, const uint8_t new_color)
Set color value at given index.
void set_object_id(const uint32_t new_object_id)
Set object_id value.
virtual Message * clone() const
Clone this message.
void set_color(unsigned int index, const uint8_t new_color)
Set color value at given index.
size_t maxlenof_color() const
Get maximum length of color value.
void set_width(const float new_width)
Set width value.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0)
Add an entry to the info list.
Definition: message.cpp:435
virtual Message * create_message(const char *type) const
Create message based on type name.
DeleteAllMessage Fawkes BlackBoard Interface Message.
interface_data_ts_t * data_ts
Pointer to data casted to timestamp struct.
Definition: interface.h:216
size_t maxlenof_size() const
Get maximum length of size value.
size_t maxlenof_y() const
Get maximum length of y value.
size_t maxlenof_radius() const
Get maximum length of radius value.
VisualDisplay2DInterface Fawkes BlackBoard Interface.
const char * type() const
Get type of interface.
Definition: interface.cpp:635
32 bit unsigned integer field
Definition: types.h:40
field with interface specific enum type
Definition: types.h:47
void set_y(unsigned int index, const float new_y)
Set y value at given index.
void set_style(const LineStyle new_style)
Set style value.
void set_counter(const uint32_t new_counter)
Set counter value.