Render_opengl.hpp 19.7 KB
Newer Older
Mathieu Faverge's avatar
Mathieu Faverge committed
1
/*
Mathieu Faverge's avatar
Mathieu Faverge committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
 ** 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".
 **
 ** 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.
 **
 ** 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.
 **
 ** 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.
 **
 **
 ** ViTE developers are (for version 0.* to 1.0):
 **
 **        - COULOMB Kevin
 **        - FAVERGE Mathieu
 **        - JAZEIX Johnny
 **        - LAGRASSE Olivier
 **        - MARCOUEILLE Jule
 **        - NOISETTE Pascal
 **        - REDONDY Arthur
 **        - VUCHENER Clément
 **
 */
43 44 45 46 47 48 49
/*!
 *\file Render_opengl.hpp
 */

#ifndef RENDER_OPENGL_HPP
#define RENDER_OPENGL_HPP

50 51
/* For moc compilation */
#include <stack>
52
#include <cmath>
Mathieu Faverge's avatar
Mathieu Faverge committed
53
#include <sstream>
54 55
/* -- */
#include <QObject>
56
#include <QGLWidget>
57 58
#include <QLabel>
#include <QPainter>
59 60
/* -- */
#include "common/common.hpp"
61
#include "common/Info.hpp"
62 63
/* -- */
#include "render/Geometry.hpp"
64
#include "render/Hook_event.hpp"
65
#include "render/Render_template.hpp"
66 67
#include "render/Minimap.hpp"
#include "render/Ruler.hpp"
68
#include "render/GanttDiagram.hpp"
69

70
struct Container_text_;
71 72
/*template<typename T>

Mathieu Faverge's avatar
Mathieu Faverge committed
73 74 75 76 77 78 79 80 81
 class CSingleton
 {
 public:
 static T& Instance()
 {
 static T me;
 return me;
 }
 };
82 83


Mathieu Faverge's avatar
Mathieu Faverge committed
84
 */
85 86 87 88 89 90 91 92 93

/*!
 * \brief Structure used to store arrow information.
 */
struct Arrow_{
    /*!
     * \brief Coordinates.
     */
    Element_pos start_time, end_time, start_height, end_height;
94 95 96
    /*!
     * \brief Colors.
     */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
97
    Element_col red, green, blue;
98 99 100
};

/*!
101
 * \brief Structure used to store event information.
102
 */
103
struct Event_{
104 105 106
    /*!
     * \brief Coordinates and radius.
     */
107
    Element_pos time, height, container_height;
108 109 110 111
    /*!
     * \brief Colors.
     */
    Element_col red, green, blue;
112 113
};

114 115 116 117 118 119 120 121 122 123 124
/*!
 * \brief Structure used to store event information.
 */
struct Variable_text_{
    /*!
     * \brief Coordinates and radius.
     */
    Element_pos y;
    Element_pos value;
};

125 126 127 128

/*!
 * \brief This class redefined the OpenGL widget - QGLWidget - to display the trace.
 */
129
class Render_opengl :  /*public QGLWidget,*/ public Hook_event, public Render_template
130 131
{
    Q_OBJECT
Mathieu Faverge's avatar
Mathieu Faverge committed
132 133


Mathieu Faverge's avatar
Mathieu Faverge committed
134
private:
Mathieu Faverge's avatar
Mathieu Faverge committed
135

136 137 138 139 140
    bool _draw_container;
    bool _draw_state;
    bool _draw_ruler;
    bool _draw_arrow;
    bool _draw_event;
Mathieu Faverge's avatar
Mathieu Faverge committed
141

142
protected:
Mathieu Faverge's avatar
Mathieu Faverge committed
143

Olivier Lagrasse's avatar
Olivier Lagrasse committed
144 145 146
    /*!
     * \brief The waiting screen display list.
     */
Mathieu Faverge's avatar
Mathieu Faverge committed
147
    GLuint _wait_list;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
148

149 150 151 152
    /*!
     * \brief The minimap.
     */
    Minimap _minimap;
153 154 155 156 157

    /*!
     * \brief The container GLu list.
     */
    GLuint _list_containers;
Mathieu Faverge's avatar
Mathieu Faverge committed
158

159 160 161 162
    /*!
     * \brief The state GLu list.
     */
    GLuint _list_states;
Mathieu Faverge's avatar
Mathieu Faverge committed
163

Mathieu Faverge's avatar
Mathieu Faverge committed
164 165 166
    /*!
     * \brief The counter GLu list.
     */
167
    GLuint _list_counters;
Mathieu Faverge's avatar
Mathieu Faverge committed
168 169


Mathieu Faverge's avatar
Mathieu Faverge committed
170 171 172
    /*!
     * \brief The arrows GLu list.
     */
173
    GLuint _list_arrows;
174

Mathieu Faverge's avatar
Mathieu Faverge committed
175

176 177 178 179
    /*!
     * \brief The wait GLu list.
     */
    //  GLuint _wait_list;
180 181

    float _red, _green, _blue;
Mathieu Faverge's avatar
Mathieu Faverge committed
182

183
    std::vector<Container_text_> _texts;
184
    std::map<long int, Variable_text_> _variable_texts;
185
    std::vector<Arrow_> _arrows;
186
    std::vector<Event_> _circles;
187 188


Olivier Lagrasse's avatar
Olivier Lagrasse committed
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 214
    /***********************************
     *
     * The wait screen drawing.
     *
     **********************************/

    /***********************************
     * The wait list Attributes.
     **********************************/


    /*!
     * \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;

    /*!
     * \brief Wait animation seconds per frame.
     */
    int _wait_spf;

Mathieu Faverge's avatar
Mathieu Faverge committed
215 216 217 218
    /*!
     * \brief Offset of the vertical helper line
     */
    Element_pos vertical_line;
219 220


Olivier Lagrasse's avatar
Olivier Lagrasse committed
221 222 223 224
    /*!
     * \brief Timer to animate the wait.
     */
    QTimer* _wait_timer;
Mathieu Faverge's avatar
Mathieu Faverge committed
225

226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
    /*!
     * \brief QLabel to display minimap.
     */
    //  QLabel* _minimap_widget;

    /*!
     * \brief QImage to store the trace thumbnail.
     */
    // QImage* _minimap_image;

    /*!
     * \brief Create a minimap from the current render.
     * \param width The desired width for the image.
     * \param height The desired height for the image.
     */
    // void create_minimap(const int width, const int height);

    /*!
     * \brief Update the minimap according to the current viewport.
     */
    //   void update_minimap();

    /*!
     * \brief Release data for minimap.
     */
    //  void release_minimap();

253 254 255 256 257 258 259 260 261 262 263
public:

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

    /*!
     * \brief The default constructor
     */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
264
    Render_opengl(Core* core, QWidget *parent, const QGLFormat& format);
265 266

    /*!
267
     * \brief The destructor (~Render_opengl will never be called, so use another method to release memory)
268
     */
269
    void release();
270 271 272 273 274 275 276 277 278 279 280 281

    /*!
     * \brief Set Statistics and Informations about input trace
     */
    void set_total_width(Element_pos){}

    /*!
     * \brief Set Statistics and Informations about input trace
     */
    void set_total_time(Times){}

    /*!
Mathieu Faverge's avatar
Mathieu Faverge committed
282
     * \brief display the scale
283 284 285
     */
    void display_time_scale(){}

Mathieu Faverge's avatar
Mathieu Faverge committed
286 287
    //    void set_vertical_line(int l){}
    //  void draw_vertical_line();
288 289 290 291 292
    /***********************************
     *
     * Default QGLWidget functions.
     *
     **********************************/
Mathieu Faverge's avatar
Mathieu Faverge committed
293

294 295 296
    /*!
     * \brief Call by the system to initialize the OpenGL render area.
     */
Mathieu Faverge's avatar
Mathieu Faverge committed
297
    void initializeGL();
Mathieu Faverge's avatar
Mathieu Faverge committed
298

299 300 301
    /*!
     * \brief Call by the system when the render area was resized (occurs during a window resizement).
     * \param width : the new width of the render area.
Mathieu Faverge's avatar
Mathieu Faverge committed
302
     * \param height : the new height of the render area.
303 304
     */
    void resizeGL(int width, int height);
Mathieu Faverge's avatar
Mathieu Faverge committed
305

306 307 308
    /*!
     * \brief Call by the system each time the render area need to be updated.
     */
309
    void paintGL();
Mathieu Faverge's avatar
Mathieu Faverge committed
310

311
    //void paintEvent(QPaintEvent *event);
312

313
    /* void initializeOverlayGL();
Mathieu Faverge's avatar
Mathieu Faverge committed
314 315
     void resizeOverlayGL(int width, int height);
     void paintOverlayGL();*/
Mathieu Faverge's avatar
Mathieu Faverge committed
316

317 318 319 320 321 322 323 324 325 326

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

    /*!
     * \brief This function constructs the trace.
     */
327
    //  bool display_build() ;
328 329 330 331

    /*!
     * \brief This function releases the trace.
     */
332
    //   bool display_unbuild() ;
333 334 335 336

    /*!
     * \brief Proceeds with the initialization of the OpenGL draw functions.
     */
337
    void start_draw();
338 339 340 341

    /*!
     * \brief Creates and opens the display list for container draws.
     */
342
    void start_draw_containers();
343 344 345 346 347 348 349 350

    /*!
     * \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
     */
351
    void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h);
352 353 354 355 356 357 358 359 360

    /*!
     * \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.
     */
361
    void draw_container_text(const Element_pos x, const Element_pos y, const std::string value);
362 363 364 365

    /*!
     * \brief Closes the container display list.
     */
366
    void end_draw_containers();
Mathieu Faverge's avatar
Mathieu Faverge committed
367

368 369 370
    /*!
     * \brief Creates and opens the display list for stater draws.
     */
371
    void start_draw_states();
372 373 374 375 376 377 378 379 380 381 382

    /*!
     * \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.
     */
383
    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);
384 385 386 387

    /*!
     * \brief Closes the state display list.
     */
388
    void end_draw_states();
389 390 391 392

    /*!
     * \brief Open the arrow display list.
     */
393
    void start_draw_arrows();
394 395 396 397 398 399 400 401 402 403

    /*!
     * \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.
     */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
404
    void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height,const Element_col red, const Element_col green, const Element_col blue);
405 406 407 408

    /*!
     * \brief Closes the arrow display list.
     */
409
    void end_draw_arrows();
410 411 412 413 414

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

417 418
    void start_draw_events();

419 420 421 422 423 424
    /*!
     * \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.
     *
425 426 427
     *
     * \brief Creates and opens the display list for container draws.
     *
428 429
     * This function stores all the information of the event to display it each time the render area need to be updated.
     */
430
    void draw_event(const Element_pos time, const Element_pos height,  const Element_pos container_height);
431

432 433 434
    void end_draw_events();


435 436 437 438
    /*!
     * \brief Draw events contained in the Event_ vector
     * \param events An event vector.
     */
439
    //  void draw_stored_events(std::vector<Event_> &events);
440 441 442 443

    /*!
     * \brief Creates and opens the display list for counter draws.
     */
444
    void start_draw_counter();
Mathieu Faverge's avatar
Mathieu Faverge committed
445

446 447 448 449 450 451 452

    /*!
     * \brief Draw a text with the value of a variable
     * \param text text to draw.
     * \param y y position of the point.
     */
    void draw_text_value(long int id,double text, double y);
453 454 455 456 457 458 459
    /*!
     * \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.
     */
460
    void draw_counter(const Element_pos x, const Element_pos y);
Mathieu Faverge's avatar
Mathieu Faverge committed
461

462 463 464
    /*!
     * \brief Closes the counter display list.
     */
465
    void end_draw_counter();
466

Olivier Lagrasse's avatar
Olivier Lagrasse committed
467 468 469 470
    /*!
     * \brief Called before ruler drawing.
     */
    void start_ruler();
Mathieu Faverge's avatar
Mathieu Faverge committed
471

Olivier Lagrasse's avatar
Olivier Lagrasse committed
472 473 474 475
    /*!
     * \brief Called after ruler drawing.
     */
    void end_ruler();
Mathieu Faverge's avatar
Mathieu Faverge committed
476

Olivier Lagrasse's avatar
Olivier Lagrasse committed
477

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

Mathieu Faverge's avatar
Mathieu Faverge committed
483

484

485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
    /***********************************
     *
     * Render OpenGL drawing functions.
     *
     **********************************/

    /*!
     * \brief Display a wait on the screen if there is no file opened.
     * \return Asset value of the wait.
     */
    GLuint draw_wait();

    /*!
     * \brief Draw the ruler display list.
     */
    void call_ruler();



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

    /*!
     * \brief This function draws the trace.
     */
    bool build();

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

520 521 522 523 524 525
    /***********************************
     *
     * Displaying functions.
     *
     **********************************/

Mathieu Faverge's avatar
Mathieu Faverge committed
526 527 528 529 530 531 532 533 534 535 536 537 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 580 581 582 583
    //    /*!
    //      * \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) =0;

    //     /*!
    //      * \brief Display on screen states between timer_begin and time_end,
    //      * 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.
    //      */
    //        void display_state(Element_pos time_begin, Element_pos time_end,
    //                        Element_count container_begin, Element_count container_end,
    //                        Element_pos depth_begin, Element_pos depth_end) =0;

    //     /*!
    //      * \brief Display on screen arrows between timer_begin and time_end,
    //      * 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.
    //      * \param depth_begin floating point value : the narrowest difference between
    //      * 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.
    //      */
    //     virtual void display_arrow(Element_pos time_begin, Element_pos time_end,
    //                        Element_count container_begin, Element_count container_end,
    //                        Element_pos depth_begin, Element_pos depth_end) =0;

    //     /*!
    //      * \brief Display on screen events between timer_begin and time_end,
    //      * 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.
    //      */
    //     virtual void display_event(Element_pos time_begin, Element_pos time_end,
    //                        Element_count container_begin, Element_count container_end) =0;

    //     /*!
    //      * \brief Display on screen counters between timer_begin and time_end,
    //      * 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.
    //      */
    //     virtual void display_counter(Element_pos time_begin, Element_pos time_end,
    //                          Element_count container_begin, Element_count container_end) =0;
Mathieu Faverge's avatar
Mathieu Faverge committed
584

585
    /*!
586 587 588
     * \brief Set the color for the further drawings.
     * \param r the red value. Within [0 ; 1].
     * \param g the green value. Within [0 ; 1].
Mathieu Faverge's avatar
Mathieu Faverge committed
589
     * \param b the blue value. Within [0 ; 1].
590
     */
591
    void set_color(float r, float g, float b);
592 593

    /*!
594 595 596 597 598
     * \brief Draw a text.
     * \param x the horizontal position of the left bottom corner of the text.
     * \param y the vertical position of the left bottom corner of the text.
     * \param z the deep position of the text.
     * \param s the text.
599
     */
600
    virtual void draw_text(const Element_pos x, const Element_pos y, const Element_pos z, const std::string s);
601 602

    /*!
603 604 605 606 607 608
     * \brief Draw a quad.
     * \param x the horizontal position of the left bottom corner of the quad.
     * \param y the vertical position of the left bottom corner of the quad.
     * \param z the deep position of the quad.
     * \param w the width of the quad.
     * \param h the height of the quad.
609
     */
610
    void draw_quad(Element_pos x, Element_pos y, Element_pos z, Element_pos w, Element_pos h);
611 612

    /*!
613 614 615 616 617
     * \brief Draw a triangle.
     * \param x the horizontal position of the triangle center.
     * \param y the vertical position of the triangle center.
     * \param size the edge size.
     * \param r the rotation of triangle. (clockwise and in degree)
618
     */
619 620
    void draw_triangle(Element_pos x, Element_pos y,
                       Element_pos size, Element_pos r);
Mathieu Faverge's avatar
Mathieu Faverge committed
621

622 623 624 625 626 627 628 629 630
    /*!
     * \brief Draw a line.
     * \param x1 the horizontal position of the first point.
     * \param y1 the vertical position of the firt point.
     * \param x2 the horizontal position of the second point.
     * \param y2 the vertical position of the second point.
     * \param z the deep position of the triangle.
     */
    void draw_line(Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2, Element_pos z);
631 632

    /*!
633 634 635 636 637
     * \brief Draw a circle.
     * \param x the horizontal position of the circle center.
     * \param y the vertical position of the circle center.
     * \param z the deep position of the circle.
     * \param r the circle radius.
638
     */
639
    void draw_circle(Element_pos x, Element_pos y, Element_pos z, Element_pos r);
640 641
    template <int N> void cos_table_builder(double table[]);
    template <int N> void sin_table_builder(double table[]);
642 643 644 645 646
    /* Temporary methods. Use to draw stored arrows and circles. It is to prevent scaling */
    void draw_stored_arrows();
    void draw_stored_circles();

    void draw_stored_texts();
647

648 649 650 651 652 653
    /*!
     * \brief Show the minimap.
     */
    void show_minimap();

    /*! Function that only delete the arrows of the screen */
654
    void clear_arrow ();
655
    /*! Function that only delete the text of the screen */
656
    void clear_text ();
Mathieu Faverge's avatar
Mathieu Faverge committed
657 658


659 660 661
    /*!
     * \brief returns the offset of the vertical helper line
     */
Mathieu Faverge's avatar
Mathieu Faverge committed
662
    Element_pos get_vertical_line();
Mathieu Faverge's avatar
Mathieu Faverge committed
663

664 665 666 667
    /*!
     * \brief set the vertical line offset
     * \param l the line offset.
     */
Mathieu Faverge's avatar
Mathieu Faverge committed
668
    void set_vertical_line(Element_pos l);
Mathieu Faverge's avatar
Mathieu Faverge committed
669

670 671
    /*!
     * \brief draws the vertical helper line
Mathieu Faverge's avatar
Mathieu Faverge committed
672
     */
673
    void draw_vertical_line();
Mathieu Faverge's avatar
Mathieu Faverge committed
674 675


Mathieu Faverge's avatar
Mathieu Faverge committed
676
public slots:
677 678
    /*!
     * \brief slot connected to the simple click event
Mathieu Faverge's avatar
Mathieu Faverge committed
679
     */
680
    void update_vertical_line();
681 682 683
};

#endif