Render_opengl_dl.hpp 27.2 KB
Newer Older
Mathieu Faverge's avatar
Mathieu Faverge committed
1 2 3 4 5 6 7 8
/*
** This file is part of the ViTE project.
**
** This software is governed by the CeCILL-A license under French law
** and abiding by the rules of distribution of free software. You can
** use, modify and/or redistribute the software under the terms of the
** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info".
Mathieu Faverge's avatar
Mathieu Faverge committed
9
**
Mathieu Faverge's avatar
Mathieu Faverge committed
10 11 12 13 14
** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited
** liability.
Mathieu Faverge's avatar
Mathieu Faverge committed
15
**
Mathieu Faverge's avatar
Mathieu Faverge committed
16 17 18 19 20 21 22 23 24 25
** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software,
** that may mean that it is complicated to manipulate, and that also
** therefore means that it is reserved for developers and experienced
** professionals having in-depth computer knowledge. Users are therefore
** encouraged to load and test the software's suitability as regards
** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security.
Mathieu Faverge's avatar
Mathieu Faverge committed
26
**
Mathieu Faverge's avatar
Mathieu Faverge committed
27 28 29 30
** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
31
** ViTE developers are (for version 0.* to 1.0):
Mathieu Faverge's avatar
Mathieu Faverge committed
32 33 34 35 36 37 38 39
**
**        - COULOMB Kevin
**        - FAVERGE Mathieu
**        - JAZEIX Johnny
**        - LAGRASSE Olivier
**        - MARCOUEILLE Jule
**        - NOISETTE Pascal
**        - REDONDY Arthur
Mathieu Faverge's avatar
Mathieu Faverge committed
40
**        - VUCHENER Clément
Mathieu Faverge's avatar
Mathieu Faverge committed
41 42
**
*/
43 44 45 46 47 48 49
/*!
 *\file Render_opengl_dl.hpp
 */

#ifndef RENDER_OPENGL_DL_HPP
#define RENDER_OPENGL_DL_HPP

50 51
class Render_opengl_dl;

52 53 54 55 56 57
/*!
 * \brief This class defined functions using the OpenGL display list rendering method.
 */
class Render_opengl_dl : public Render_opengl
{
    Q_OBJECT
58

59
protected:
60

61 62 63 64 65 66

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

68 69 70
    /***********************************
     * The wait list Attributes.
     **********************************/
71

72 73 74 75 76
    /*!
     * \brief The wait GLu list.
     */
    GLuint _wait_list;

77 78 79 80 81 82

    /*!
     * \brief Used to draw counter.
     */
    bool _start_new_line;

83 84 85 86 87 88 89 90 91 92 93
public:

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

    /*!
     * \brief The default constructor
     */
94
    Render_opengl_dl(Core* core, QWidget *parent)
95
        : Render_opengl(this, core, parent){
96
        _wait_list = 0;
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    }

    /*!
     * \brief The destructor
     */
    virtual ~Render_opengl_dl(){
    }


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

    /*!
     * \brief This function constructs the trace.
     */
    bool display_build();

    /*!
     * \brief This function releases the trace.
     */
    bool display_unbuild();

    /*!
     * \brief Proceeds with the initialization of the OpenGL draw functions.
     */
    void start_draw();

    /*!
     * \brief Creates and opens the display list for container draws.
     */
    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.
     *
     * This function stores text in a list. This list will be display each time the render area need to be updated.
     */
    void draw_container_text(const Element_pos x, const Element_pos y, const std::string value);

    /*!
     * \brief Closes the container display list.
     */
    void end_draw_containers();
155

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
    /*!
     * \brief Creates and opens the display list for stater draws.
     */
    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);

    /*!
     * \brief Closes the state display list.
     */
    void end_draw_states();

    /*!
     * \brief Open the arrow display list.
     */
    void start_draw_arrows();

    /*!
     * \brief Draw an arrow.
     * \param start_time the beginning time of the arrow.
     * \param end_time the ending time of the arrow.
     * \param start_height vertical position of the begining time of the arrow.
     * \param end_height vertical position of the ending time of the arrow.
     *
     * This function stores all the information of the arrow to display it each time the render area need to be updated.
     */
    void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height);

    /*!
     * \brief Closes the arrow display list.
     */
    void end_draw_arrows();

    /*!
     * \brief Draw arrows contained in the Arrow_ vector
     * \param arrows An arrow vector.
     */
    void draw_stored_arrows(std::vector<Arrow_> &arrows);

    /*!
     * \brief Draw an event.
     * \param time time when the event occurs.
     * \param height vertical position of the event.
     * \param container_height information to draw event. It corresponds to the container height when they are drawn horizontally.
     *
     * This function stores all the information of the event to display it each time the render area need to be updated.
     */
    void draw_event(const Element_pos time, const Element_pos height,  const Element_pos container_height);
Mathieu Faverge's avatar
Mathieu Faverge committed
214

215 216 217 218 219 220 221 222 223 224
    /*!
     * \brief Draw events contained in the Event_ vector
     * \param events An event vector.
     */
    void draw_stored_events(std::vector<Event_> &events);

    /*!
     * \brief Creates and opens the display list for counter draws.
     */
    void start_draw_counter();
225

226 227 228 229 230 231 232 233
    /*!
     * \brief Draw a point of the counter.
     * \param x x position of the point.
     * \param y y position of the point.
     *
     * Each time counter is increased, this function is called with the coordinates of the new point.
     */
    void draw_counter(const Element_pos x, const Element_pos y);
234

235 236 237 238 239 240 241 242 243 244
    /*!
     * \brief Closes the counter display list.
     */
    void end_draw_counter();

    /*!
     * \brief Do nothing (it is present for compatibility of the Render class).
     */
    void end_draw();

245

246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

    /***********************************
     *
     * Displaying functions.
     *
     **********************************/

    /*!
     * \brief Display on screen containers between container_begin and container_end.
     * \param container_begin integer value : id of the first container.
     * \param container_end integer value : id of the last container.
     */
    void display_container(Element_count container_begin, Element_count container_end);

    /*!
261
     * \brief Display on screen states between timer_begin and time_end,
262 263 264 265 266 267 268 269
     * container_begin and container_end and with timer width between depth_begin and depth_end.
     * \param time_begin floating point value : time of the first state.
     * \param time_end floating point value : time of the last state.
     * \param container_begin integer value : id of the first container.
     * \param container_end integer value : id of the last container.
     * \param depth_begin floating point value : width of the narrowest state.
     * \param depth_end floating point value : width of the widest state.
     */
270 271
    void display_state(Element_pos time_begin, Element_pos time_end,
                       Element_count container_begin, Element_count container_end,
272 273 274
                       Element_pos depth_begin, Element_pos depth_end);

    /*!
275
     * \brief Display on screen arrows between timer_begin and time_end,
276 277 278 279 280
     * container_begin and container_end and with timer width between depth_begin and depth_end.
     * \param time_begin floating point value : time of the smallest arrow time value.
     * \param time_end floating point value : time of the higher arrow time value.
     * \param container_begin integer value : id of the first container.
     * \param container_end integer value : id of the last container.
281
     * \param depth_begin floating point value : the narrowest difference between
282 283 284 285
     * the beginning time and the ending time of the arrow.
     * \param depth_end floating point value : width of the widest difference between
     * the beginning time and the ending time of the arrow.
     */
286 287
    void display_arrow(Element_pos time_begin, Element_pos time_end,
                       Element_count container_begin, Element_count container_end,
288 289 290
                       Element_pos depth_begin, Element_pos depth_end);

    /*!
291
     * \brief Display on screen events between timer_begin and time_end,
292 293 294 295 296 297
     * container_begin and container_end.
     * \param time_begin floating point value : time of the first event.
     * \param time_end floating point value : time of the last event.
     * \param container_begin integer value : id of the first container.
     * \param container_end integer value : id of the last container.
     */
298 299
    void display_event(Element_pos time_begin, Element_pos time_end,
                       Element_count container_begin, Element_count container_end);
300 301

    /*!
302
     * \brief Display on screen counters between timer_begin and time_end,
303 304 305 306 307 308
     * container_begin and container_end.
     * \param time_begin floating point value : time of the smallest counter time value.
     * \param time_end floating point value : time of the higher counter time value.
     * \param container_begin integer value : id of the first container.
     * \param container_end integer value : id of the last container.
     */
309 310 311
    void display_counter(Element_pos time_begin, Element_pos time_end,
                         Element_count container_begin, Element_count container_end);

312 313 314 315 316 317 318 319 320 321

    void set_color(float, float, float){}
    void draw_quads(Element_pos, Element_pos, Element_pos, Element_pos, Element_pos){}
    void draw_text(Element_pos, Element_pos, Element_pos, std::string){}
    void draw_triangle(Element_pos, Element_pos, Element_pos,
                       Element_pos, Element_pos, Element_pos,
                       Element_pos, Element_pos, Element_pos){}
    void draw_line(Element_pos, Element_pos, Element_pos,
                   Element_pos, Element_pos, Element_pos){}
    void draw_circle(Element_pos, Element_pos, Element_pos, Element_pos){}
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
};




/* inline function area */





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


inline bool Render_opengl_dl::display_build(){
345

346 347 348 349 350 351
    if (glIsList(_wait_list) == GL_TRUE){/* if the list exists */
        glDeleteLists(_wait_list, 1);
        _wait_list = 0;
    }

    if (glIsList(_wait_list) == GL_TRUE){
352
        *Message::get_instance() << tr("Cannot unbuild the waiting animation").toStdString() << Message::endw;
353
    }
354

355 356
    if ((_wait_timer != NULL) && _wait_timer->isActive())/* if timer for the wait animation is running */
        _wait_timer->stop();
357

358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
    return true;
}



inline bool Render_opengl_dl::display_unbuild(){

    /********************
     *
     * Launch timer again
     *
     ********************/

    if (!_wait_timer->isActive())/* if timer for the wait animation is not running */
        _wait_timer->start(_wait_spf);
373

374 375 376 377 378 379 380 381 382 383

    /*****************
     *
     * Draw the rabbit
     *
     *****************/

    if (glIsList(_wait_list) == GL_FALSE)
        _wait_list = draw_wait();/* create the wait draw */
    else {
384
        *Message::get_instance() << tr("The wait draw was not released.").toStdString() << Message::endw;
385 386
        return false;
    }
387

388 389
    /* if there is an error, do not display the wait an return immediatly */
    if (glIsList(_wait_list) == GL_FALSE) {
390
        *Message::get_instance() << tr("Cannot create the wait draw.").toStdString() << Message::endw;
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
        return false;
    }


    return true;
}




/***********************************
 *
 *
 *
 * Drawing functions for the trace.
 *
 *
 *
 **********************************/


inline void Render_opengl_dl::start_draw(){
    /* clear lists to store container texts */
    _text_pos.clear();
    _text_value.clear();

    /* clear the event vector */
    _events.clear();

    /* clear the arrow vector */
    _arrows.clear();
}


inline void Render_opengl_dl::start_draw_containers(){

    _list_containers = glGenLists(1);/* create the list */
    if (_list_containers == 0) {
429

430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
        //        _parent->warning("Error when creating list");
    }

    glNewList(_list_containers, GL_COMPILE);/* open the list */

}


inline void Render_opengl_dl::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;
454

455 456 457 458 459
    if ((y+h)>_container_y_max)
        _container_y_max = y+h;

    if (_container_x_min > x)
        _container_x_min = x;
460

461 462 463 464 465 466 467
    if (_container_y_min > y)
        _container_y_min = y;



#ifdef DEBUG_MODE_RENDER_AREA

468
    std::cerr << __FILE__ << " l." << __LINE__ << ":" << std::endl;
469
    std::cerr < "Container drawing:" << std::endl;
470
    std::cerr << "x: " << x << " y: " << y << " w: " << w << " h: " << h << " xmax-xmin: " << _container_x_max << " - " << _container_x_min << " ymax-ymin: " << _container_y_max << " - " << _container_y_min << std::endl;
471 472 473 474 475 476 477

#endif

}

inline void Render_opengl_dl::draw_container_text(const Element_pos x, const Element_pos y, const std::string value){

478
    _text_pos.push_back(x);
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
    _text_pos.push_back(y);
    _text_value.push_back(value);

}



inline void Render_opengl_dl::end_draw_containers(){
    glEndList();/* close the list */
}




inline void Render_opengl_dl::start_draw_states(){

    _list_states = glGenLists(1);/* create the list */
    if (_list_states == 0) {
497

498 499
        //      _parent->warning("Error when creating list");
    }
500

501 502 503 504 505 506
    glNewList(_list_states, GL_COMPILE);/* open the list */
}


inline void Render_opengl_dl::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) {

507

508 509

#ifdef DEBUG_MODE_RENDER_AREA
510 511 512

    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;
513 514 515 516 517 518 519

#endif

    /** DEBUG **/
    //  if (start==end)
    /* std::cout << std::setprecision(15) << std::endl;
       std::cerr << "Start "<< start << " end " << end << std::endl;*/
520

521 522 523 524 525 526 527 528 529 530 531
    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;
532

533 534 535 536 537
    if ((base+height) > _state_y_max)
        _state_y_max = base+height;

    if (_state_x_min > start)
        _state_x_min = start;
538

539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
    if (_state_y_min > base)
        _state_y_min = base;
}


inline void Render_opengl_dl::end_draw_states(){
    glEndList();/* close the list */
}


inline void Render_opengl_dl::start_draw_arrows(){
}

inline void Render_opengl_dl::draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height){

    Arrow_ buf;

    buf.start_time = start_time;
    buf.end_time = end_time;
    buf.start_height = start_height;
    buf.end_height = end_height;

    _arrows.push_back(buf);
}


inline void Render_opengl_dl::end_draw_arrows(){
}



inline void Render_opengl_dl::draw_stored_arrows(std::vector<Arrow_> &arrows){

    Element_pos start_time, end_time, start_height, end_height;

    /* Manage the event drawing size from state size and render area dimensions */
    Element_pos arrow_scale_x = _x_state_scale*((_render_width-_default_entity_x_translate)/(_state_x_max-_state_x_min));
    Element_pos arrow_scale_y = _y_state_scale*(_render_height-_ruler_height)/_container_y_max;

    Element_pos angle;

580 581
    const int arrows_size = arrows.size();
    for (int i = 0 ; i < arrows_size ; i ++){
582 583 584 585


        start_time = arrows[i].start_time*arrow_scale_x + _default_entity_x_translate -_x_state_translate;
        end_time = arrows[i].end_time*arrow_scale_x + _default_entity_x_translate - _x_state_translate;
586 587 588 589 590 591 592 593 594
        start_height = arrows[i].start_height*arrow_scale_y;// - _y_state_translate;
        end_height = arrows[i].end_height*arrow_scale_y;// - _y_state_translate;

        /* DEBUG */
        // std::cerr << "Arrow draw: (" << start_time << ", " << start_height << ") to (" << end_time << ", " << end_height << ")" << std::endl;


        glPushMatrix();
        {
595

596 597
            glTranslated(end_time, end_height-_y_state_translate, _z_arrow);
            glScalef(2, 2, 0);/* should be set */
598 599


600
            if (start_time != end_time){
601

602
                angle = atan2((end_height - start_height), (end_time - start_time))*180.0f/M_PI;/* arc tangent */
603

604
                glRotatef(angle, 0, 0, 1);
605

606 607 608
            }/* end if (start_time != end_time) */
            else
                glRotatef(90, 0, 0, 1);/* vertical alignment */
609 610 611



612 613 614 615 616 617 618
            glBegin(GL_TRIANGLES);/* create an arrow */
            {
                glColor3d(1.0, 1.0, 1.0);glVertex2d(0.0, 0.0);
                glColor3d(0.9, 0.9, 0.9);glVertex2d(-0.6, -0.2);
                glColor3d(0.9, 0.9, 0.9);glVertex2d(-0.6, 0.2);
            }
            glEnd();
619

620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
        }
        glPopMatrix();

        glPushMatrix();
        {
            glTranslated(0, 0, _z_arrow);
            // glLineWidth(1.5f);
            glBegin(GL_LINES);
            {
                glColor3d(0.8, 0.8, 0.8);glVertex2d(start_time, start_height-_y_state_translate);
                glColor3d(1.0, 1.0, 1.0);glVertex2d(end_time, end_height-_y_state_translate);
            }
            glEnd();
            // glLineWidth(1.0f);/* 1 is the default value */
        }
        glPopMatrix();
    }
}


inline void Render_opengl_dl::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);
}


inline void Render_opengl_dl::draw_stored_events(std::vector<Event_> &events){

    Element_pos time, height, container_height;

    /* Manage the event drawing size from state size and render area dimensions */
    Element_pos event_scale_x = _x_state_scale*((_render_width-_default_entity_x_translate)/(_state_x_max-_state_x_min));
    Element_pos event_scale_y = _y_state_scale*(_render_height-_ruler_height)/_container_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 ++){

668
        time = events[i].time*event_scale_x + _default_entity_x_translate -_x_state_translate;
669 670 671 672 673 674
        height = events[i].height*event_scale_y -_y_state_translate;
        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;
675

676 677

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

679 680 681 682 683 684


        /* draw a circle */
        radius = 0.3f;
        angle = M_PI/2.0f;
        step = 20;/* 20 polygons for the circle */
685

686 687
        if (step!=0)
            delta_angle = 2*M_PI/step;
688 689


690 691 692 693 694 695 696 697
        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_event);
            }
        }
        glEnd();
698

699 700 701 702 703 704 705
        /* draw line */
        glBegin(GL_LINES);
        {
            glColor3d(0.5, 0.8, 0.5);glVertex3d(time, height, _z_event);
            glColor3d(0.4, 0.7, 0.4);glVertex3d(time, height+container_height, _z_event);
        }
        glEnd();
706

707 708 709 710 711 712 713 714 715 716 717 718
    }/* and loop */
}


/********************
 * Counter
 *******************/

inline void Render_opengl_dl::start_draw_counter(){

    _list_counters = glGenLists(1);/* create the list */
    if (_list_counters == 0) {
719
        *Message::get_instance() << tr("Error when creating list").toStdString() << Message::ende;
720
    }
721

722
    glNewList(_list_counters, GL_COMPILE);/* open the list */
723
    _start_new_line = true;
724 725 726 727
}


inline void Render_opengl_dl::draw_counter(const Element_pos x, const Element_pos y){
728

729
    if (_start_new_line){/* Start a new line */
730

731 732
        glBegin(GL_LINE_STRIP);/* set of connected verteces */
        glColor3d(1.0, 1.0, 1.0);glVertex2d(0.0, y);/* draw the init point */
Mathieu Faverge's avatar
Mathieu Faverge committed
733

734 735 736
        _counter_last_x = x;
        _counter_last_y = y;
        _start_new_line = false;
737

738
    }else{/* line is already started */
739

740
        if (x <= 0.0){/* convention: the line is over */
741

742 743 744 745
            glColor3d(1.0, 1.0, 1.0);glVertex2d(_state_x_max, _counter_last_y);
            glEnd();
            _start_new_line = true;
        }else{/* add new points to the line */
746

747 748
            glColor3d(1.0, 1.0, 1.0);glVertex2d(x, _counter_last_y);
            glColor3d(1.0, 1.0, 1.0);glVertex2d(x, y);
749

750 751 752 753
            _counter_last_x = x;
            _counter_last_y = y;
        }
    }
754 755 756 757
}


inline void Render_opengl_dl::end_draw_counter(){
758

759
    if (!_start_new_line) {/* if a line was previously opened */
760
      glEnd();/* suppose that line is not ended */
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
    }
    glEndList();/* close the list */

    /* Find the most suitable scale depending of the state x min and x max */
    _x_state_scale = 1;//(_render_width - _default_entity_x_translate)/(_state_x_max - _state_x_min);
}



inline void Render_opengl_dl::end_draw(){

}




 /***********************************
  *
  *
  *
  * Displaying functions.
  *
  *
  *
  **********************************/

inline void Render_opengl_dl::display_container(Element_count , Element_count ){

    std::list<Element_pos>::iterator it_pos;
    std::list<std::string>::iterator it_txt;
    Element_pos buf_x;
    Element_pos buf_y;
793
    std::string buf_txt;
794 795 796 797 798 799 800


    /* Draw container */
    glPushMatrix();
    {
        glTranslatef(0.0f, -_y_state_translate, _z_container);
        glScalef( (_render_width/_container_x_max)*_x_scale_container_state, _y_state_scale*(_render_height-_ruler_height)/_container_y_max, 0.0f);
801

802
#ifdef DEBUG_MODE_RENDER_OPENGL
803 804
        cerr << __FILE__ << " l." << __LINE__ << ":" << endl;
        cerr << "Default container position (before translation and scaling) : (x_max = " << _container_x_max << ", y_max = " << _container_y_max << ")" << endl << endl;
805
#endif
806

807
        if (glIsList(_list_containers)==GL_FALSE)
808
            *Message::get_instance() << tr("ERROR LIST not exist for containers.").toStdString() << Message::ende;
809 810 811 812
        else
            glCallList(_list_containers);
    }
    glPopMatrix();
813 814


815
    /* Draw container texts */
816 817
    for (it_txt=_text_value.begin(), it_pos=_text_pos.begin() ; it_txt!=_text_value.end(); it_txt ++, it_pos ++){

818 819
        buf_x = *it_pos;
        it_pos ++;
820

821 822
        buf_y =  *it_pos;
        buf_txt = *it_txt;
823

824
        glPushMatrix();
Mathieu Faverge's avatar
Mathieu Faverge committed
825
        {
826 827
            glTranslatef(0.0f, -_y_state_translate, 0.0f);
            glScalef((_render_width/_container_x_max)*_x_scale_container_state, _y_state_scale*(_render_height-_ruler_height)/_container_y_max, 0.0f);
828

829 830
            glColor3d(1, 1, 1);
            glRasterPos2f(buf_x, buf_y);
831

832
#ifdef DEBUG_MODE_RENDER_OPENGL
833 834
            cerr << __FILE__ << " l." << __LINE__ << ":" << endl;
            cerr << "Container texts position: (x = " << buf_x << ", y = " << buf_y << ") -> '" << buf_txt << "'" << endl << endl;
835
#endif
836

837 838
            float length = 0;
            const unsigned int buf_text_size = buf_txt.length();
839
            const int size_of_container = (const int)(20*_x_scale_container_state*_render_width/_container_x_max);
840 841 842 843 844 845 846 847 848
            for(unsigned int i = 0 ; i < buf_text_size ; i ++){
                const char letter = buf_txt.c_str()[i];
                length += glutBitmapWidth(GLUT_BITMAP_HELVETICA_10, letter);
                if(length > size_of_container){
                    break;
                }
                glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, letter);
            }
        }
849
        glPopMatrix();
850 851 852 853 854
    }/* end for (it_txt=...) */

}


855 856
inline void Render_opengl_dl::display_state(Element_pos , Element_pos ,
                          Element_count , Element_count ,
857 858 859 860 861 862
                          Element_pos , Element_pos ){

    glPushMatrix();
    {
        glTranslated( _default_entity_x_translate - _x_state_translate , -_y_state_translate, _z_state);
        glScalef(_x_state_scale*((_render_width-_default_entity_x_translate)/(_state_x_max-_state_x_min)), _y_state_scale*(_render_height-_ruler_height)/_container_y_max, 0.0f);
863

864
        if (glIsList(_list_states) == GL_FALSE)
865
            *Message::get_instance() << tr("ERROR LIST not exist for states.").toStdString() << Message::ende;
866 867 868 869 870 871 872
        else
            glCallList(_list_states);
    }
    glPopMatrix();
}


873 874
inline void Render_opengl_dl::display_arrow(Element_pos , Element_pos ,
                          Element_count , Element_count ,
875 876 877 878 879 880
                          Element_pos , Element_pos ){

    draw_stored_arrows(_arrows);/*draw arrows without display lists */
}


881
inline void Render_opengl_dl::display_event(Element_pos , Element_pos ,
882 883 884 885 886 887 888 889 890 891 892 893 894
                          Element_count , Element_count ){

    draw_stored_events(_events);/* draw events without display lists */
}


inline void Render_opengl_dl::display_counter(Element_pos , Element_pos ,
                            Element_count , Element_count ){

    glPushMatrix();
    {
        glTranslated(_default_entity_x_translate - _x_state_translate , -_y_state_translate, _z_counter);
        glScalef(_x_state_scale*((_render_width-_default_entity_x_translate)/(_state_x_max-_state_x_min)), _y_state_scale*(_render_height-_ruler_height)/_container_y_max, 0.0f);
895

896
        if (glIsList(_list_counters) == GL_FALSE) {
897
            *Message::get_instance() << tr("ERROR LIST not exist for counters.").toStdString() << Message::ende;
898 899 900 901 902 903 904 905
        }
        else
            glCallList(_list_counters);
    }
    glPopMatrix();
}

#endif