render_area.hpp 11.4 KB
Newer Older
1 2 3 4 5 6 7
/*!
 *\file render_area.hpp
 */

#ifndef RENDER_AREA_HPP
#define RENDER_AREA_HPP

8

9 10
class Render_area;

11 12 13
typedef double Level;


14 15
#include <QtGui>
#include <QGLWidget>/* for the OpenGL Widget */
16
//#include "interface_graphic.hpp"
17

18
#include "render.hpp"
19
#include "resource.hpp"
20

21

22 23 24


/*!
25
 * \brief This class redefined the OpenGL widget - QGLWidget - to display the trace.
26
 */
27
class Render_area : public QGLWidget, public Render
28 29
 {
     Q_OBJECT
30 31


32

33
 protected:
34 35 36



37 38 39 40
     std::list<Element_pos> _text_pos;
     std::list<std::string> _text_value;


41 42 43 44 45 46 47 48 49
     /***********************************
      *
      * Environment attributes.
      *
      **********************************/
     
     /*!
      * \brief Refers to the parent widget of the render area.
      */
50
     // Interface_graphic* _parent;
51
     
52

53

54 55 56 57 58 59
     /***********************************
      *
      * Data structure attributes.
      *
      **********************************/
     
60
   
61 62


63 64 65 66 67 68

     /***********************************
      *
      * Render area state attributes.
      *
      **********************************/
69

70
     /*!
71 72 73 74 75 76 77 78
      * \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;
79

80
     /*!
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
      * \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.
107 108
      */
     void paintGL();
109 110 111 112 113 114 115 116 117 118 119 120

     /***********************************
      *
      * The wait screen drawing.
      *
      **********************************/

     
     /***********************************
      * The wait list Attributes.
      **********************************/
     
121
     /*!
122
     * \brief The wait GLu list.
123
     */
124
     GLuint _wait_list;
125 126
     GLuint _list_containers;
     GLuint _list_states;
127

128 129 130 131 132 133
     /*!
     * \brief Rotation angle for the wait.
     */
     float _wait_angle;

     /*!
134 135 136 137
      * \brief Time in ms between two frames for the waiting screen.
      */
     static const int DRAWING_TIMER_DEFAULT = 10;
     
138
     /*!
139 140
      * \brief Wait animation seconds per frame.
      */
141
     int _wait_spf;
142 143 144 145 146
     
     /*!
      * \brief Timer to animate the wait. 
      */
     QTimer* _wait_timer;
147

148

149 150 151 152
     /***********************************
      * Drawing function for the wait screen.
      **********************************/
     
153
     /*!
154 155
     * \brief Display a wait on the screen if there is no file opened.
     * \return Asset value of the wait.
156
     */
157 158 159 160
     GLuint draw_wait();



161

162 163 164 165 166 167 168 169 170 171 172
     /***********************************
      *
      * The trace drawing.
      *
      **********************************/


     /***********************************
      * The drawing list Attributes.
      **********************************/
     
173
     /*!
174
      * \brief The trace Glu list.
175
     */
176
     GLuint _drawing_list;
177

Olivier Lagrasse's avatar
Olivier Lagrasse committed
178
 
179 180
     Element_pos _container_x_max;
     Element_pos _container_y_max;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
181

182

183
     Element_pos _z_arrow;/* z position for arrows */
184 185 186 187

     /***********************************
      * Trace Drawing functions and attributes.
      **********************************/
188 189 190 191
 
     /*!
     * \brief Return the pos container of the list
     */
192
     // Container* get_container(const std::list <Container*> *list_container, const int pos) const;
193 194


Olivier Lagrasse's avatar
Olivier Lagrasse committed
195 196
     int _state_scale;/* temporary */
     int _state_translate;/* temporary */
197
     int _container_view_size;/* temporary */
198

199
 public:
200

201 202 203 204 205 206 207 208


     /***********************************
      *
      * Constructor and destructor.
      *
      **********************************/

209 210 211
     /*!
     * \brief The default constructor
     */
212
     Render_area(QWidget *parent);
213 214 215 216 217

     /*!
     * \brief The destructor
     */
     virtual ~Render_area();
218

219 220 221 222 223 224 225 226


     /***********************************
      *
      * Building functions.
      *
      **********************************/

227
     /*!
228
      * \brief This function draws the trace.
229
      * \arg trace the trace which be displayed. 
230
      */
231
     bool build();
232 233

     /*!
234 235
      * \brief This function releases the trace.
      */
236 237
     bool unbuild();

Olivier Lagrasse's avatar
Olivier Lagrasse committed
238 239
     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 */
240 241 242
     void change_container_view(int view_size);/* temporary -> to change the size of container view */
     

243
     void start_draw();
244

245
     void start_draw_containers();
246 247 248 249 250 251 252 253

     /*!
     * \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
     */
254
     void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h);
255 256 257 258 259 260 261

     /*!
      * \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.
      */
262
     void draw_container_text(const Element_pos x, const Element_pos y, const std::string value);
263

264
     void end_draw_containers();
Olivier Lagrasse's avatar
Olivier Lagrasse committed
265
     
266
     void start_draw_states();
267 268 269 270 271 272 273 274 275 276 277

     /*!
      * \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.
      */
278 279 280
     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();
281

282
     void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height);
283

284 285
     void draw_event(const Element_pos time, const Element_pos height,  const Element_pos container_height);

286
     void end_draw();
287
    
288 289
  };

290

291 292


293 294 295
/* inline function area */


296 297 298 299 300 301 302 303 304 305
/***********************************
 *
 *
 *
 * Drawing function for the trace.
 *
 *
 *
 **********************************/

306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339

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();

340 341
    if ((x+w)>_container_x_max)
        _container_x_max = x+w;
342
    
343 344
    if ((y+h)>_container_y_max)
        _container_y_max = y+h;
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382

}

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
    
383 384
    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;  
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410

#endif

  
    glBegin(GL_QUADS);/* create a quads */
    {
        glColor3d(r, g, b);glVertex2d(start, base);
        glColor3d(r, g, b);glVertex2d(start, base + height);
        glColor3d(r*2, g*2, b*2);glVertex2d(end, base + height);
        glColor3d(r*2, g*2, b*2);glVertex2d(end, base);
    }
    glEnd();
}


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;


    glPushMatrix();
411 412 413 414
    
    glTranslated(end_time, end_height, _z_arrow);
    glScalef(2, 2, 0);/* should be set */
    
415 416 417 418 419 420 421 422

    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) */
423 424 425
    else
        glRotatef(90,0, 0, 1);/* vertical alignment */
   
426
    
427

428 429
    glBegin(GL_TRIANGLES);/* create an arrow */
    {
430 431 432
        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);
433 434 435 436 437
    }
    glEnd();
    
    glPopMatrix();

438
    glPushMatrix();
439

440 441 442
    glTranslated(0, 0, _z_arrow);
    glLineWidth(2.5f);
    glBegin(GL_LINES);
443
    {
444 445
        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);
446 447
    }
    glEnd();
448 449 450
    glLineWidth(1.0f);/* 1 is the default value */

    glPopMatrix();
451 452 453 454

}


455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498

inline void Render_area::draw_event(const Element_pos time, const Element_pos height,  const Element_pos container_height){

    Element_pos radius;/* the circle radius */
    Element_pos angle;
    Element_pos delta_angle;
    int step;


 
    /* IMPROVEMENT: put the circle into a display list */

    /* draw a circle */
    radius = (container_height - height)/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 ; i<step ; i++){
            glVertex3d(time + cos(angle+delta_angle*i)*radius , height + sin(angle+delta_angle*i)*radius , _z_arrow);
        }
    }
    glEnd();

   /* draw line */
    glLineWidth(2.5f);
    glBegin(GL_LINES);
    {
        glColor3d(0.5, 0.8, 0.5);glVertex3d(time, height, _z_arrow);
        glColor3d(0.4, 0.7, 0.4);glVertex3d(time, height+container_height, _z_arrow);
    }
    glEnd();
    glLineWidth(1.0f);

}



499 500 501 502 503
inline void Render_area::end_draw(){

}


504
 #endif