Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00880_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00880_source.php on line 2
The ARGoS Website

qtopengl_user_functions.h
Go to the documentation of this file.
1 
7 #ifndef QTOPENGL_USER_FUNCTIONS_H
8 #define QTOPENGL_USER_FUNCTIONS_H
9 
10 namespace argos {
11  class CQTOpenGLUserFunctions;
12  class CFloorEntity;
13 }
14 
15 class QPainter;
16 
17 #include <argos3/core/utility/configuration/base_configurable_resource.h>
18 #include <argos3/plugins/simulator/visualizations/qt-opengl/qtopengl_main_window.h>
19 #include <argos3/plugins/simulator/visualizations/qt-opengl/qtopengl_widget.h>
20 #include <argos3/core/utility/datatypes/color.h>
21 #include <argos3/core/utility/math/quaternion.h>
22 
23 namespace argos {
24 
75 
76  public:
77 
82 
86  virtual ~CQTOpenGLUserFunctions();
87 
88  virtual void Init(TConfigurationNode& t_tree) {}
89  virtual void Reset() {}
90  virtual void Destroy() {}
91 
104  virtual void KeyPressed(QKeyEvent* pc_event);
105 
118  virtual void KeyReleased(QKeyEvent* pc_event);
119 
133  virtual void MouseKeyPressed(QMouseEvent* pc_event) {}
134 
148  virtual void MouseKeyReleased(QMouseEvent* pc_event) {}
149 
158  virtual void MouseMoved(QMouseEvent* pc_event) {}
159 
164  virtual void EntitySelected(CEntity& c_entity) {}
165 
170  virtual void EntityDeselected(CEntity& c_entity) {}
171 
176 
185  virtual void SelectEntity(CEntity& c_entity);
186 
193  virtual void DeselectEntity();
194 
198  virtual void Draw(CFloorEntity& c_entity) {}
199 
205  virtual void DrawInWorld() {}
206 
214  virtual void DrawOverlay(QPainter& c_painter) {}
215 
221 
226  void SetMainWindow(CQTOpenGLMainWindow& c_main_win);
227 
233 
238  void SetColor(const CColor& c_color);
239 
247  void DrawPoint(const CVector3& c_position,
248  const CColor& c_color = CColor::RED,
249  Real f_diameter = 5.0);
250 
262  void DrawTriangle(const CVector3& c_position,
263  const CQuaternion& c_orientation,
264  Real f_base,
265  Real f_height,
266  const CColor& c_color = CColor::RED,
267  const bool b_fill = true);
268 
278  void DrawPolygon(const CVector3& c_position,
279  const CQuaternion& c_orientation,
280  const std::vector<CVector2>& vec_points,
281  const CColor& c_color = CColor::RED,
282  const bool b_fill = true);
283 
295  void DrawCircle(const CVector3& c_position,
296  const CQuaternion& c_orientation,
297  Real f_radius,
298  const CColor& c_color = CColor::RED,
299  const bool b_fill = true,
300  GLuint un_vertices = 20);
301 
313  void DrawCylinder(const CVector3& c_position,
314  const CQuaternion& c_orientation,
315  Real f_radius,
316  Real f_height,
317  const CColor& c_color = CColor::RED,
318  GLuint un_vertices = 20);
319 
329  void DrawBox(const CVector3& c_position,
330  const CQuaternion& c_orientation,
331  const CVector3& c_size,
332  const CColor& c_color = CColor::RED);
333 
341  void DrawRay(const CRay3& c_ray,
342  const CColor& c_color = CColor::RED,
343  Real f_width = 1.0f);
344 
353  void DrawText(const CVector3& c_position,
354  const std::string& str_text,
355  const CColor& c_color = CColor::BLACK,
356  const QFont& c_font = QFont());
357 
358  protected:
359 
365 
375  template <typename USER_IMPL, typename ENTITY>
376  void Thunk(CEntity& c_entity);
377 
382  class CFunctionHolder {};
383 
391  template <typename USER_IMPL, typename ENTITY> class CFunctionHolderImpl : public CFunctionHolder {
392  public:
393  typedef void (USER_IMPL::*TFunction)(ENTITY&);
395  CFunctionHolderImpl(TFunction t_function) : Function(t_function) {}
396  };
397 
404 
409  std::vector<CFunctionHolder*> m_vecFunctionHolders;
410 
411  public:
412 
419  template <typename USER_IMPL, typename ENTITY>
420  void RegisterUserFunction(void(USER_IMPL::*pt_function)(ENTITY&));
421 
426  virtual void Call(CEntity& c_entity);
427 
428  private:
429 
433  CQTOpenGLMainWindow* m_pcQTOpenGLMainWindow;
434 
435  };
436 
437  /****************************************/
438  /****************************************/
439 
440  template <typename USER_IMPL, typename ENTITY>
442  /*
443  * When this method is called, the static type of 'this'
444  * is CQTOpenGLUserFunctions. Since we want to call
445  * method in USER_IMPL (subclass of CQTOpenGLUserFunctions),
446  * we need a cast. The cast is static because we trust
447  * the user on not doing anything stupid.
448  * The variable cImpl can be static because the cast is necessary
449  * only the first time this function is called.
450  */
451  static USER_IMPL& cImpl = static_cast<USER_IMPL&>(*this);
452  /* Cast the argument to the right type */
453  ENTITY& cEntity = static_cast<ENTITY&>(c_entity);
454  /* Cast the function holder to its effective type */
455  CFunctionHolderImpl<USER_IMPL,ENTITY>& cFunctionHolder = static_cast<CFunctionHolderImpl<USER_IMPL,ENTITY>&>(*m_vecFunctionHolders[GetTag<ENTITY,CEntity>()]);
456  /* Call the user-defined method */
457  (cImpl.*(cFunctionHolder.Function))(cEntity);
458  }
459 
460  template <typename USER_IMPL, typename ENTITY>
461  void CQTOpenGLUserFunctions::RegisterUserFunction(void(USER_IMPL::*pt_function)(ENTITY&)) {
462  /* Add the thunk to the VTable */
463  m_cThunks.Add<ENTITY>(&CQTOpenGLUserFunctions::Thunk<USER_IMPL,ENTITY>);
464  /* Add the function holder to the vector, padding gaps with NULL pointers */
465  size_t unIdx = GetTag<ENTITY,CEntity>();
466  if(m_vecFunctionHolders.size() <= unIdx) {
467  m_vecFunctionHolders.resize(unIdx+1, NULL);
468  }
469  m_vecFunctionHolders[unIdx] = new CFunctionHolderImpl<USER_IMPL,ENTITY>(pt_function);
470  }
471 
472  /****************************************/
473  /****************************************/
474 
475 }
476 
477 /* Definitions useful for dynamic linking of user functions */
478 #define REGISTER_QTOPENGL_USER_FUNCTIONS(CLASSNAME, LABEL) \
479  REGISTER_SYMBOL(CQTOpenGLUserFunctions, \
480  CLASSNAME, \
481  LABEL, \
482  "undefined", \
483  "undefined", \
484  "undefined", \
485  "undefined", \
486  "undefined")
487 
488 #endif
void DrawBox(const CVector3 &c_position, const CQuaternion &c_orientation, const CVector3 &c_size, const CColor &c_color=CColor::RED)
Draws a box.
void DrawPoint(const CVector3 &c_position, const CColor &c_color=CColor::RED, Real f_diameter=5.0)
Draws a point.
The QTOpenGL user functions.
virtual void EntitySelected(CEntity &c_entity)
Called every time an entity is selected.
virtual void Reset()
Resets the resource.
A 3D vector class.
Definition: vector3.h:29
CQTOpenGLWidget & GetQTOpenGLWidget()
Returns the QTOpenGLWidget.
static CColor BLACK
Definition: color.h:29
void(CQTOpenGLUserFunctions::* TThunk)(CEntity &)
Pointer-to-thunk type definition.
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The basic entity type.
Definition: entity.h:89
std::vector< CFunctionHolder * > m_vecFunctionHolders
A vector of function holders.
virtual void Destroy()
Undoes whatever was done by Init().
void SetMainWindow(CQTOpenGLMainWindow &c_main_win)
Sets the QTOpenGL main window for these user functions.
void RegisterUserFunction(void(USER_IMPL::*pt_function)(ENTITY &))
Registers a user method.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
virtual void DrawInWorld()
Drawing hook executed after all objects have been drawn.
virtual void SelectEntity(CEntity &c_entity)
Selects the specified entity.
void DrawRay(const CRay3 &c_ray, const CColor &c_color=CColor::RED, Real f_width=1.0f)
Draws a ray, with optional endpoint markers.
void SetColor(const CColor &c_color)
Sets the current drawing color.
void DrawCircle(const CVector3 &c_position, const CQuaternion &c_orientation, Real f_radius, const CColor &c_color=CColor::RED, const bool b_fill=true, GLuint un_vertices=20)
Draws a circle.
virtual void Call(CEntity &c_entity)
Calls a user method for the given entity.
void DrawText(const CVector3 &c_position, const std::string &str_text, const CColor &c_color=CColor::BLACK, const QFont &c_font=QFont())
Draws a string of text.
virtual ~CQTOpenGLUserFunctions()
Class destructor.
void DrawTriangle(const CVector3 &c_position, const CQuaternion &c_orientation, Real f_base, Real f_height, const CColor &c_color=CColor::RED, const bool b_fill=true)
Draws an isosceles triangle.
virtual void DeselectEntity()
Deselects the currently selected entity.
void DrawPolygon(const CVector3 &c_position, const CQuaternion &c_orientation, const std::vector< CVector2 > &vec_points, const CColor &c_color=CColor::RED, const bool b_fill=true)
Draws a 2D polygon.
virtual void KeyPressed(QKeyEvent *pc_event)
Called when a key press event occurs.
The basic color type.
Definition: color.h:25
CQTOpenGLMainWindow & GetMainWindow()
Returns the QTOpenGL main window.
CEntity * GetSelectedEntity()
Returns the currently selected entity, or NULL.
void Add(FUNCTION t_function)
Definition: vtable.h:158
static CColor RED
Definition: color.h:31
The actual vtable.
Definition: vtable.h:155
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
virtual void KeyReleased(QKeyEvent *pc_event)
Called when a key release event occurs.
virtual void Draw(CFloorEntity &c_entity)
Drawing hook executed after the floor is drawn.
virtual void MouseKeyPressed(QMouseEvent *pc_event)
Called when a mouse key is pressed.
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
virtual void EntityDeselected(CEntity &c_entity)
Called every time an entity is deselected.
This class is the base of all XML-configurable ARGoS interface.
void Thunk(CEntity &c_entity)
A templetized thunk.
virtual void MouseMoved(QMouseEvent *pc_event)
Called when the mouse is moved.
void DrawCylinder(const CVector3 &c_position, const CQuaternion &c_orientation, Real f_radius, Real f_height, const CColor &c_color=CColor::RED, GLuint un_vertices=20)
Draws a cylinder, with the height perpendicular to the XY plane.
virtual void MouseKeyReleased(QMouseEvent *pc_event)
Called when a mouse key is released.
CVTable< CQTOpenGLUserFunctions, CEntity, TThunk > m_cThunks
The vtable storing the thunks.
virtual void DrawOverlay(QPainter &c_painter)
Drawing hook to put graphics on top of the OpenGL window.