/*! *\file render_area.hpp */ #ifndef RENDER_AREA_HPP #define RENDER_AREA_HPP class Render_area; typedef double Level; #include #include /* for the OpenGL Widget */ //#include "interface_graphic.hpp" #include "render.hpp" //#include "render_svg.hpp" #include "resource.hpp" struct Event_{ Element_pos time; Element_pos height; Element_pos container_height; }; /*! * \brief This class redefined the OpenGL widget - QGLWidget - to display the trace. */ class Render_area : public QGLWidget, public Render { Q_OBJECT protected: std::list _text_pos; std::list _text_value; std::vector _events; /*********************************** * * Environment attributes. * **********************************/ /*! * \brief Refers to the parent widget of the render area. */ // Interface_graphic* _parent; /*********************************** * * Data structure attributes. * **********************************/ /*********************************** * * Render area state attributes. * **********************************/ /*! * \brief State when there is no file opened. */ static const int DRAWING_STATE_WAINTING = 1; /*! * \brief State when the application is drawing traces. */ static const int DRAWING_STATE_DRAWING = 2; /*! * \brief Contains the kind of state for the render area (drawing, waiting, etc.). */ int _state; /*********************************** * * Default QGLWidget functions. * **********************************/ /*! * \brief Call by the system to initialize the OpenGL render area. */ void initializeGL(); /*! * \brief Call by the system when the render area was resized (occurs during a window resizement). * \arg width : the new width of the render area. * height : the new height of the render area. */ void resizeGL(int width, int height); /*! * \brief Call by the system each time the render area need to be updated. */ void paintGL(); /*********************************** * * The wait screen drawing. * **********************************/ /*********************************** * The wait list Attributes. **********************************/ /*! * \brief The wait GLu list. */ GLuint _wait_list; GLuint _list_containers; GLuint _list_states; GLuint _list_counters; /*! * \brief Rotation angle for the wait. */ float _wait_angle; /*! * \brief Time in ms between two frames for the waiting screen. */ static const int DRAWING_TIMER_DEFAULT = 10; /*! * \brief Wait animation seconds per frame. */ int _wait_spf; /*! * \brief Timer to animate the wait. */ QTimer* _wait_timer; /*********************************** * Drawing function for the wait screen. **********************************/ /*! * \brief Display a wait on the screen if there is no file opened. * \return Asset value of the wait. */ GLuint draw_wait(); /*********************************** * * The trace drawing. * **********************************/ /*********************************** * The drawing list Attributes. **********************************/ /*! * \brief The trace Glu list. */ GLuint _drawing_list; Element_pos _counter_last_x; Element_pos _counter_last_y; /*! * \brief The opengl render area width in pixels. */ Element_pos _screen_width; /*! * \brief The opengl render area height in pixels. */ Element_pos _screen_height; /*! * \brief The opengl visibled scene width in the OpenGL units. */ Element_pos _render_width; /*! * \brief The opengl visibled scene height in the OpenGL units. */ Element_pos _render_height; Element_pos _container_x_max; Element_pos _container_y_max; Element_pos _event_x_max; Element_pos _event_y_max; Element_pos _state_x_max; Element_pos _state_y_max; Element_pos _x_scale_container_state; Element_pos _z_container;/* z position for containers */ Element_pos _z_state;/* z position for states */ Element_pos _z_arrow;/* z position for arrows */ /*********************************** * Trace Drawing functions and attributes. **********************************/ /*! * \brief Return the pos container of the list */ // Container* get_container(const std::list *list_container, const int pos) const; int _state_scale;/* temporary */ int _state_translate;/* temporary */ // int _container_view_size;/* temporary */ public: /*********************************** * * Constructor and destructor. * **********************************/ /*! * \brief The default constructor */ Render_area(QWidget *parent); /*! * \brief The destructor */ virtual ~Render_area(); /*********************************** * * Building functions. * **********************************/ /*! * \brief This function draws the trace. * \arg trace the trace which be displayed. */ bool build(); /*! * \brief This function releases the trace. */ bool unbuild(); void change_scale(int scale);/* temporary -> to change the scale to view states */ void change_translate(int translate);/* temporary -> to change the translate to view states */ void change_scale_container_state(int view_size);/* temporary -> to change the size of container view */ void start_draw(); void start_draw_containers(); /*! * \brief Draw a container according to the parameters * \param x the x position of the container * \param y the y position of the container * \param w the width of the container * \param h the height of the container */ void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h); /*! * \brief Draw the text of a container. * \param x the x position of the text. * \param y the y position of the text. * \param value the string value of the text. */ void draw_container_text(const Element_pos x, const Element_pos y, const std::string value); void end_draw_containers(); void start_draw_states(); /*! * \brief Draw a state of the trace. * \param start the beginning time of the state. * \param end the ending time of the state. * \param base vertical position of the state. * \param height the state height. * \param r the red color rate of the state. * \param g the green color rate of the state. * \param b the blue color rate of the state. */ void draw_state(const Element_pos start , const Element_pos end, const Element_pos base, const Element_pos height, const Element_col r, const Element_col g, const Element_col b); void end_draw_states(); void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height); void draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height); void draw_stored_events(std::vector &events); void start_draw_counter(); void draw_counter(const Element_pos x, const Element_pos y); void end_draw_counter(); void end_draw(); }; /* inline function area */ /*********************************** * * * * Drawing function for the trace. * * * **********************************/ inline void Render_area::start_draw(){ /* clear lists to store container texts */ _text_pos.clear(); _text_value.clear(); } inline void Render_area::start_draw_containers(){ _list_containers = glGenLists(1);/* create the list */ if (_list_containers==0){ // _parent->warning("Error when creating list"); } glNewList(_list_containers, GL_COMPILE);/* open the list */ } inline void Render_area::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h) { float j=0.6; glBegin(GL_QUADS);/* create a quads */ { glColor3d(0, 0, j);glVertex2d(x, y); glColor3d(0, 0, j-0.1);glVertex2d(x, y+h); glColor3d(0, 0, j-0.1);glVertex2d(x+w, y+h); glColor3d(0, 0, j);glVertex2d(x+w, y); } glEnd(); if ((x+w)>_container_x_max) _container_x_max = x+w; if ((y+h)>_container_y_max) _container_y_max = y+h; } inline void Render_area::draw_container_text(const Element_pos x, const Element_pos y, const std::string value){ _text_pos.push_back(x); _text_pos.push_back(y); _text_value.push_back(value); } inline void Render_area::end_draw_containers(){ glEndList();/* close the list */ } inline void Render_area::start_draw_states(){ _list_states = glGenLists(1);/* create the list */ if (_list_states==0){ // _parent->warning("Error when creating list"); } glNewList(_list_states, GL_COMPILE);/* open the list */ } inline void Render_area::draw_state(const Element_pos start, const Element_pos end, const Element_pos base, const Element_pos height, const Element_col r, const Element_col g, const Element_col b){ #ifdef DEBUG_MODE_RENDER_AREA std::cerr << __FILE__ << " l." << __LINE__ << ":" << std::endl; std::cerr << "States position (for drawing): (x = " << start << ", y = " << base << ", w = " << end-start << ", h = " << height << ")" << std::endl << std::endl; #endif glBegin(GL_QUADS);/* create a quads */ { glColor3d(r, g, b);glVertex2d(start, base); glColor3d(r, g, b);glVertex2d(start, base + height); glColor3d(r/1.5, g/1.5, b/1.5);glVertex2d(end, base + height); glColor3d(r/1.5, g/1.5, b/1.5);glVertex2d(end, base); } glEnd(); if (end>_state_x_max) _state_x_max = end; if ((base+height)>_state_y_max) _state_y_max = base+height; } inline void Render_area::end_draw_states(){ glEndList();/* close the list */ } inline void Render_area::draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height){ Element_pos angle; /* DEBUG */ // std::cerr << "Arrow draw: (" << start_time << ", " << start_height << ") to (" << end_time << ", " << end_height << ")" << std::endl; glPushMatrix(); glTranslated(end_time, end_height, _z_arrow); glScalef(2, 2, 0);/* should be set */ if (start_time != end_time){ angle = atan2((end_height - start_height), (end_time - start_time))*180.0f/PI;/* arc tangent */ glRotatef(angle,0, 0, 1); }/* end if (start_time != end_time) */ else glRotatef(90,0, 0, 1);/* vertical alignment */ // glBegin(GL_TRIANGLES);/* create an arrow */ /* { glColor3d(1.0, 0.7, 0.7);glVertex2d(0.5, 0.0); glColor3d(0.9, 0.6, 0.6);glVertex2d(-0.5, -0.5); glColor3d(0.9, 0.6, 0.6);glVertex2d(-0.5, 0.5); } glEnd();*/ glPopMatrix(); glPushMatrix(); glTranslated(0, 0, _z_arrow); glLineWidth(2.5f); glBegin(GL_LINES); { glColor3d(1.0, 0.7, 0.7);glVertex3d(start_time, start_height, _z_arrow); glColor3d(0.9, 0.6, 0.6);glVertex3d(end_time, end_height, _z_arrow); } glEnd(); glLineWidth(1.0f);/* 1 is the default value */ glPopMatrix(); } inline void Render_area::draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height){ Event_ buf; buf.time = time; buf.height = height; buf.container_height = container_height; _events.push_back(buf); if (time>_event_x_max) _event_x_max = time; if ((height+container_height)>_event_y_max) _event_y_max = (height+container_height); } inline void Render_area::draw_stored_events(std::vector &events){ Element_pos time, height, container_height; /* Manage the event drawing size from state size and render area dimensions */ Element_pos event_scale_x = _state_scale*(_render_width/_state_x_max); Element_pos event_scale_y = _render_height/_state_y_max; Element_pos radius;/* the circle radius */ Element_pos angle; Element_pos delta_angle; int step; for (long i=0 ; i<(long)events.size() ; i++){ time = events[i].time*event_scale_x + _render_width*_x_scale_container_state-_state_translate; height = events[i].height*event_scale_y; container_height = events[i].container_height*event_scale_y; /* DEBUG */ // std::cerr << "Event draw: (" << time << ", " << height << ") with height of:" << container_height << " - " << _render_width << " : " << _render_height << std::endl; /* IMPROVEMENT: put the circle into a display list */ /* draw a circle */ radius = 2.0f; angle = PI/2.0f; step = 20;/* 20 polygons for the circle */ if (step!=0) delta_angle = 2*PI/step; glColor3d(0.5, 0.8, 0.5); glBegin(GL_POLYGON); { for(int i =0 ; iwarning("Error when creating list"); } glNewList(_list_counters, GL_COMPILE);/* open the list */ } inline void Render_area::draw_counter(const Element_pos x, const Element_pos y){ static bool which_color = true; float a; if (which_color==true){/* yellow color */ a = 0.0f; which_color = false; }else{/* white color */ a = 1.0f; which_color = true; } glLineWidth(2.5f); glBegin(GL_QUADS); { glColor3d(1.0, 1.0, a);glVertex2d(_counter_last_x, 0); glColor3d(1.0, 1.0, a);glVertex2d(_counter_last_x, _counter_last_y); glColor3d(1.0, 1.0, a);glVertex2d(x, y); glColor3d(1.0, 1.0, a);glVertex2d(x, 0); } glEnd(); glLineWidth(1.0f); _counter_last_x = x; _counter_last_y = y; } inline void Render_area::end_draw_counter(){ glEndList();/* close the list */ } inline void Render_area::end_draw(){ } #endif