00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __DebugDrawings2_h_
00009 #define __DebugDrawings2_h_
00010
00011 #include "Tools/Debugging/Debugging.h"
00012 #include "Tools/Debugging/DebugKeyTable.h"
00013
00014 #ifndef NEWDEBUGGING
00015
00016
00017 #define NDECLARE_DEBUGDRAWING( id, type, description)
00018 #define NCIRCLE(id, center_x, center_y, radius, penWidth, penStyle, penColor)
00019 #define NDOT(id, x, y, penColor, fillColor)
00020 #define NLARGE_DOT(id, x, y, penColor, fillColor)
00021 #define NARROW(id, x1, y1, x2, y2, penWidth, penStyle, penColor)
00022 #define NLINE(id, x1, y1, x2, y2, penWidth, penStyle, penColor)
00023 #define NCOLORED_LINE(id, x1, y1, x2, y2, penWidth, penStyle, penColorR, penColorG, penColorB)
00024 #define NPOSE_2D_SAMPLE(id, p, color)
00025 #define NOCTANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8, color, fill)
00026 #define NQUADRANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4, penWidth, penStyle, penColor)
00027 #define NRECTANGLE(id, x1,y1,x2,y2, penWidth, penStyle, penColor)
00028 #define NCROSS(id, x, y, size, penWidth, penStyle, penColor)
00029 #define NCOMPLEX_DRAWING(id,expression)
00030 #define NDEBUG_DRAWING_FINISHED(id)
00031
00032 #else
00033 #ifdef WIN32
00034 #pragma warning(disable:4786)
00035 #include <typeinfo.h>
00036 #if _MSC_VER > 1200
00037 #include <hash_map>
00038 using stdext::hash_map;
00039 #else
00040 #include <map>
00041 #define hash_map map
00042 using std::map;
00043 #endif
00044 #else
00045 #include <typeinfo>
00046 #include <ext/hash_map>
00047 using __gnu_cxx::hash_map;
00048 #endif
00049
00050 class DrawingManager;
00051
00052 In& operator>>(In& stream, DrawingManager&);
00053 Out& operator<<(Out& stream, const DrawingManager&);
00054
00055 class DrawingManager
00056 {
00057 typedef hash_map< const char*, char> DrawingNameTypeTable;
00058 DrawingNameTypeTable drawingNameTypeTable;
00059 int idCounter, typeCounter;
00060 bool freeStrings;
00061
00062 void reset();
00063
00064 public:
00065 class DrawingNameIdTableEntry
00066 {
00067 public:
00068 char id;
00069 char type;
00070 const char* description;
00071 };
00072
00073
00074 typedef hash_map< const char*, DrawingNameIdTableEntry> DrawingNameIdTable;
00075 DrawingNameIdTable drawingNameIdTable;
00076
00077 DrawingManager():idCounter(0), typeCounter(2), freeStrings(false)
00078 {
00079 drawingNameTypeTable["drawingOnField"] = 0;
00080 drawingNameTypeTable["drawingOnImage"] = 1;
00081 }
00082
00083 ~DrawingManager() {reset();}
00084
00085 void addDrawingId(const char* name, const char* typeName, const char* description);
00086
00087 char getDrawingId(const char* name) const
00088 {
00089 DrawingNameIdTable::const_iterator i = drawingNameIdTable.find(name);
00090 if(i != drawingNameIdTable.end())
00091 return i->second.id;
00092 OUTPUT(idText, text, "Warning! Debug drawing " << name << " not declared");
00093 return -1;
00094 }
00095
00096 const char* getDrawingType(const char* name) const
00097 {
00098 DrawingNameIdTable::const_iterator i = drawingNameIdTable.find(name);
00099 if(i != drawingNameIdTable.end())
00100 {
00101 for(DrawingNameTypeTable::const_iterator j = drawingNameTypeTable.begin();
00102 j != drawingNameTypeTable.end(); ++j)
00103 if(j->second == i->second.type)
00104 return j->first;
00105 OUTPUT(idText, text, "Warning! Debug drawing " << name << " has unknown type " << int(i->second.type));
00106 return "unknown";
00107 }
00108 OUTPUT(idText, text, "Warning! Debug drawing " << name << " not declared");
00109 return "unknown";
00110 }
00111
00112 const char* getDrawingName(char id) const
00113 {
00114 for(DrawingNameIdTable::const_iterator i = drawingNameIdTable.begin();
00115 i != drawingNameIdTable.end(); ++i)
00116 if(i->second.id == id)
00117 return i->first;
00118 OUTPUT(idText, text, "Warning! Unknown debug drawing id " << int(id));
00119 return "unknown";
00120 }
00121
00122 friend In& operator>>(In& stream, DrawingManager&);
00123 friend Out& operator<<(Out& stream, const DrawingManager&);
00124 };
00125
00126 #ifdef NDEBUG
00127 #define NODEBUGDRAWINGS
00128 #endif
00129 #ifdef NO_DEBUG_DRAWING
00130 #define NODEBUGDRAWINGS
00131 #endif
00132
00133 #ifdef NODEBUGDRAWINGS
00134
00135 #define NDECLARE_DEBUGDRAWING( id, type, description)
00136 #define NCIRCLE(id, center_x, center_y, radius, penWidth, penStyle, penColor)
00137 #define NDOT(id, x, y, penColor, fillColor)
00138 #define NLARGE_DOT(id, x, y, penColor, fillColor)
00139 #define NARROW(id, x1, y1, x2, y2, penWidth, penStyle, penColor)
00140 #define NLINE(id, x1, y1, x2, y2, penWidth, penStyle, penColor)
00141 #define NCOLORED_LINE(id, x1, y1, x2, y2, penWidth, penStyle, penColorR, penColorG, penColorB)
00142 #define NPOSE_2D_SAMPLE(id, p, color)
00143 #define NOCTANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8, color, fill)
00144 #define NQUADRANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4, penWidth, penStyle, penColor)
00145 #define NRECTANGLE(id, x1,y1,x2,y2, penWidth, penStyle, penColor)
00146 #define NCROSS(id, x, y, size, penWidth, penStyle, penColor)
00147 #define NCOMPLEX_DRAWING(id,expression)
00148 #define NDEBUG_DRAWING_FINISHED(id)
00149
00150 #else //NODEBUGDRAWINGS
00151
00152
00153 void initDrawingManager(DrawingManager* streamHandlerPtr);
00154 DrawingManager& getDrawingManager();
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 #define NDECLARE_DEBUGDRAWING( id, type, description) \
00166 getDrawingManager().addDrawingId( id, type, description);\
00167 DEBUG_RESPONSE("debug drawing:" id , );
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 #define NCIRCLE(id, center_x, center_y, radius, penWidth, penStyle, penColor) \
00181 NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00182 OUTPUT( idDebugDrawing2, bin, \
00183 (char)Drawings::circle << \
00184 (char)getDrawingManager().getDrawingId( id ) << \
00185 (int)(center_x) << (int)(center_y) << (int)(radius) << (char)(penWidth) << \
00186 (char)(penStyle) << (char)(penColor) \
00187 ); \
00188 );
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 #define NDOT(id, x, y, penColor, fillColor) \
00200 NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00201 OUTPUT( idDebugDrawing2, bin, \
00202 (char)Drawings::dot << \
00203 (char)getDrawingManager().getDrawingId( id ) << \
00204 (int)(x) << (int)(y) << (char)(penColor) << (char)(fillColor) \
00205 ); \
00206 );
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 #define NLARGE_DOT(id, x, y, penColor, fillColor) \
00218 NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00219 OUTPUT( idDebugDrawing2, bin, \
00220 (char)Drawings::largeDot << \
00221 (char)getDrawingManager().getDrawingId( id ) << \
00222 (int)(x) << (int)(y) << (char)(penColor) << (char)(fillColor) \
00223 ); \
00224 );
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 #define NLINE(id, x1, y1, x2, y2, penWidth, penStyle, penColor) \
00238 NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00239 OUTPUT( idDebugDrawing2, bin, \
00240 (char)Drawings::line << \
00241 (char)getDrawingManager().getDrawingId( id ) << \
00242 (int)(x1) << (int)(y1) << (int)(x2) << (int)(y2) << (char)(penWidth) << (char)(penStyle) << (char)(penColor) \
00243 ); \
00244 );
00245
00246 #define NCOLORED_LINE(id, x1, y1, x2, y2, penWidth, penStyle, penColorR, penColorG, penColorB) \
00247 NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00248 OUTPUT( idDebugDrawing2, bin, \
00249 (char)Drawings::coloredLine << \
00250 (char)getDrawingManager().getDrawingId( id ) << \
00251 (int)(x1) << (int)(y1) << (int)(x2) << (int)(y2) << (char)(penWidth) << (char)(penStyle) << (char)(penColorR) << (char)(penColorG) << (char)(penColorB)\
00252 ); \
00253 );
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 #define NARROW(id, x1, y1, x2, y2, penWidth, penStyle, penColor) \
00268 NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00269 OUTPUT( idDebugDrawing2, bin, \
00270 (char)Drawings::arrow << \
00271 (char)getDrawingManager().getDrawingId( id ) << \
00272 (int)(x1) << (int)(y1) << (int)(x2) << (int)(y2) << (char)(penWidth) << (char)(penStyle) << (char)(penColor) \
00273 ); \
00274 );
00275
00276
00277
00278
00279
00280
00281
00282
00283 #define NPOSE_2D_SAMPLE(id, p, color) \
00284 Pose2D current = p; current += Pose2D(-100,0); \
00285 NLINE(id, int(current.translation.x),int(current.translation.y), int(p.translation.x), int(p.translation.y), \
00286 1, Drawings::ps_solid, color); \
00287 current = p; current += Pose2D(-40,-40); \
00288 NLINE(id, int(current.translation.x), int(current.translation.y), int(p.translation.x), int(p.translation.y), \
00289 1, Drawings::ps_solid, color); \
00290 current = p; current += Pose2D(-40,40); \
00291 NLINE(id, int(current.translation.x),int(current.translation.y),int(p.translation.x), int(p.translation.y), \
00292 1, Drawings::ps_solid, color); \
00293
00294
00295
00296
00297
00298
00299
00300
00301 #define NOCTANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8, color, fill) \
00302 NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" #id , \
00303 OUTPUT( idDebugDrawing2, bin, \
00304 (char)Drawings::octangle << \
00305 (char)getDrawingManager().getDrawingId( #id ) << \
00306 (int)(x1) << (int)(y1) << (int)(x2) << (int)(y2) << (int)(x3) << (int)(y3) << (int)(x4) << (int)(y4) << \
00307 (int)(x5) << (int)(y5) << (int)(x6) << (int)(y6) << (int)(x7) << (int)(y7) << (int)(x8) << (int)(y8) << \
00308 (char)ColorClasses::colorClassToDrawingsColor(color) << (char)fill \
00309 );
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 #define NQUADRANGLE(id, x1,y1,x2,y2,x3,y3,x4,y4, penWidth, penStyle, penColor) \
00320 NLINE(id, x1, y1, x2, y2, penWidth, penStyle, penColor); \
00321 NLINE(id, x2, y2, x3, y3, penWidth, penStyle, penColor); \
00322 NLINE(id, x3, y3, x4, y4, penWidth, penStyle, penColor); \
00323 NLINE(id, x4, y4, x1, y1, penWidth, penStyle, penColor);
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 #define NRECTANGLE(id, x1,y1,x2,y2, penWidth, penStyle, penColor) \
00334 NLINE(id, x1, y1, x1, y2, penWidth, penStyle, penColor); \
00335 NLINE(id, x1, y2, x2, y2, penWidth, penStyle, penColor); \
00336 NLINE(id, x2, y2, x2, y1, penWidth, penStyle, penColor); \
00337 NLINE(id, x2, y1, x1, y1, penWidth, penStyle, penColor);
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348 #define NCROSS(id, x, y, size, penWidth, penStyle, penColor)\
00349 NLINE(id, x+size, y+size, x-size, y-size, penWidth, penStyle, penColor);\
00350 NLINE(id, x+size, y-size, x-size, y+size, penWidth, penStyle, penColor);
00351
00352
00353
00354
00355
00356 #define NCOMPLEX_DRAWING(id,expression) \
00357 NOT_POLLABLE_DEBUG_RESPONSE("debug drawing:" id , \
00358 expression;\
00359 );
00360
00361 #endif //NODEBUGDRAWINGS
00362
00363 #endif //__DebugDrawings_h_
00364
00365 #endif