MAJ terminée. Nous sommes passés en version 14.6.2 . Pour consulter les "releases notes" associées c'est ici :

https://about.gitlab.com/releases/2022/01/11/security-release-gitlab-14-6-2-released/
https://about.gitlab.com/releases/2022/01/04/gitlab-14-6-1-released/

GanttDiagram.hpp 16.1 KB
Newer Older
1
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
43
44
45
46
47
48
/*
 ** 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
 **
 */
/*!
 *\file GanttDiagram.hpp
 */

#ifndef GANTTDIAGRAM_HPP
#define GANTTDIAGRAM_HPP
49
#include <iostream>
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "Render.hpp"

class Trace;
/*!
 * \brief Structure used to store container information.
 */
struct Container_{
    /*!
     * \brief Coordinates.
     */
    Element_pos x, y, w, h;
};

/*!
 * \brief Structure used to store container text.
 */
struct Container_text_{
    /*!
     * \brief Coordinates.
     */
Thibault Soucarre's avatar
Thibault Soucarre committed
70
    Element_pos x, y, size;
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    /*!
     * \brief Text.
     */
    std::string value;
};

/*!
 * \brief This class is used to called opengl or svg primitive functions to draw trace elements.
 */
class GanttDiagram : public Geometry
{
private:

    /*!
     * This attribute store the instance of a drawing class. (OpenGL or SVG for example)
     */
87
    Render *_render;
88
89
90
91
92
93
94

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


95
    std::vector<Container_>      _containers;
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
    std::vector<Container_text_> _container_texts;

    /*!
     * \brief The default constructor is in private scope to prevent Render instanciation without
     * provide a drawing instance.
     */
    GanttDiagram(){
    }

public:

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

    /*!
     * \brief The default constructor
     */
    GanttDiagram(Render* instance){
117
        _render = instance;
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
    }

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

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

    /*!
     * \brief Proceeds with the initialization of the draw functions.
     */
    inline void start_draw(){
        /* clear vectors */
        _containers.clear();
        _container_texts.clear();

140
        _render->start_draw();
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    }

    /*!
     * \brief Initialize container draws.
     */
    inline 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
     */
156
157
158
159
160
    inline void draw_container(const Element_pos x,
                               const Element_pos y,
                               const Element_pos w,
                               const Element_pos h,
                               const std::string &value)
Mathieu Faverge's avatar
Mathieu Faverge committed
161
162
163
        {
            Container_text_ buft;
            Container_      buf;
164

Mathieu Faverge's avatar
Mathieu Faverge committed
165
166
167
168
            buf.x = x;
            buf.y = y;
            buf.w = w;
            buf.h = h;
169

Mathieu Faverge's avatar
Mathieu Faverge committed
170
            _containers.push_back(buf);
171

Mathieu Faverge's avatar
Mathieu Faverge committed
172
173
174
            buft.x     = x + w/5;
            buft.y     = y + h/2;
            buft.value = value;
175

Mathieu Faverge's avatar
Mathieu Faverge committed
176
            _container_texts.push_back(buft);
177

Mathieu Faverge's avatar
Mathieu Faverge committed
178
179
            if ((x+w)>Info::Container::x_max)
                Info::Container::x_max = x+w;
180

Mathieu Faverge's avatar
Mathieu Faverge committed
181
182
            if ((y+h)>Info::Container::y_max)
                Info::Container::y_max = y+h;
183

Mathieu Faverge's avatar
Mathieu Faverge committed
184
185
            if (Info::Container::x_min > x)
                Info::Container::x_min = x;
186

Mathieu Faverge's avatar
Mathieu Faverge committed
187
188
            if (Info::Container::y_min > y)
                Info::Container::y_min = y;
189
190

#ifdef DEBUG_MODE_RENDER_AREA
Mathieu Faverge's avatar
Mathieu Faverge committed
191
192
193
            std::cerr << __FILE__ << " l." << __LINE__ << ":" << std::endl;
            std::cerr < "Container drawing:" << std::endl;
            std::cerr << "x: " << x << " y: " << y << " w: " << w << " h: " << h << " xmax-xmin: " << Info::Container::x_max << " - " << Info::Container::x_min << " ymax-ymin: " << Info::Container::y_max << " - " << Info::Container::y_min << std::endl;
194
195

#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
196
        }
197
198
199
200
201
202
203
204
205

    /*!
     * \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.
     */
206
    inline void draw_container_text(const Element_pos x, const Element_pos y, const std::string value)
Mathieu Faverge's avatar
Mathieu Faverge committed
207
208
209
        {
            return;
        }
210
211
212
213

    /*!
     * \brief Closes the container display list.
     */
214
    inline void end_draw_containers()
Mathieu Faverge's avatar
Mathieu Faverge committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
        {
            static float j = 0.6f;
            float coeffx =  (Info::Render::width                /Info::Container::x_max) * _x_scale_container_state;
            float coeffy = ((Info::Render::height-_ruler_height)/Info::Container::y_max) * _y_state_scale;

            /* Before calling start_draw_container(), Info::Container::y_max should have a correct value */
            _render->start_draw_containers();

            for (unsigned int i=0 ; i<_containers.size() ; i++){
                _render->set_color(0, 0, j);
                _render->draw_quad(_containers[i].x * coeffx,
                                   trace_to_render_y(_containers[i].y),
                                   _z_container,
                                   _containers[i].w * coeffx,
                                   _containers[i].h * coeffy);
            }
231

Mathieu Faverge's avatar
Mathieu Faverge committed
232
233
234
            for (unsigned int i=0 ; i<_container_texts.size() ; i++){
                _container_texts[i].x *= coeffx;
                _container_texts[i].y  = trace_to_render_y(_container_texts[i].y);
235

Mathieu Faverge's avatar
Mathieu Faverge committed
236
237
238
239
240
                _render->draw_text(_container_texts[i].x,
                                   _container_texts[i].y,
                                   _containers[i].w * coeffx,
                                   _container_texts[i].value);
            }
241

Mathieu Faverge's avatar
Mathieu Faverge committed
242
243
            _render->end_draw_containers();
        }
244
245
246
247

    /*!
     * \brief Creates and opens the display list for state draws.
     */
248
    inline void start_draw_states()
Mathieu Faverge's avatar
Mathieu Faverge committed
249
250
251
        {
            _render->start_draw_states();
        }
252
253
254
255
256
257
258
259
260
261
262

    /*!
     * \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.
     */
263
264
265
266
267
268
269
270
    inline 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,
                           EntityValue * value)
Mathieu Faverge's avatar
Mathieu Faverge committed
271
272
273
274
275
276
277
278
279
        {
            _render->set_color(r, g, b);
            _render->draw_state(trace_to_render_x(start - Info::Render::_x_min_visible),
                                trace_to_render_y(base),
                                _z_state,
                                (end-start)*coeff_trace_render_x(),
                                height     *coeff_trace_render_y(),
                                value);
        }
280
281
282
283

    /*!
     * \brief Closes the state display list.
     */
284
    inline void end_draw_states()
Mathieu Faverge's avatar
Mathieu Faverge committed
285
286
287
        {
            _render->end_draw_states();
        }
288
289
290
291

    /*!
     * \brief Open the arrow display list.
     */
292
    inline void start_draw_arrows()
Mathieu Faverge's avatar
Mathieu Faverge committed
293
294
295
        {
            _render->start_draw_arrows();
        }
296
297
298
299
300
301
302
303
304
305

    /*!
     * \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.
     */
306
307
308
309
310
311
312
313
    inline void draw_arrow(Element_pos start_time,
                           Element_pos end_time,
                           Element_pos start_height,
                           Element_pos end_height,
                           const Element_col r,
                           const Element_col g,
                           const Element_col b,
                           EntityValue* value)
Mathieu Faverge's avatar
Mathieu Faverge committed
314
315
        {
            _render->set_color(r, g, b);
316

Mathieu Faverge's avatar
Mathieu Faverge committed
317
318
319
320
            start_time   = trace_to_render_x(start_time - Info::Render::_x_min_visible);
            end_time     = trace_to_render_x(end_time   - Info::Render::_x_min_visible);
            start_height = trace_to_render_y(start_height);
            end_height   = trace_to_render_y(end_height);
321

Mathieu Faverge's avatar
Mathieu Faverge committed
322
323
324
            /* For OpenGL */
            _render->draw_arrow(start_time, end_time, start_height, end_height, r, g, b, value);
        }
325
326
327
328

    /*!
     * \brief Closes the arrow display list.
     */
329
    inline void end_draw_arrows()
Mathieu Faverge's avatar
Mathieu Faverge committed
330
331
332
        {
            _render->end_draw_arrows();
        }
333

334
    inline void start_draw_events()
Mathieu Faverge's avatar
Mathieu Faverge committed
335
336
337
        {
            _render->start_draw_events();
        }
338
339
340
341
342
343
344
345
346

    /*!
     * \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.
     */
347
348
349
350
351
352
353
    inline void draw_event(Element_pos time,
                           Element_pos height,
                           Element_pos container_height,
                           const Element_col r,
                           const Element_col g,
                           const Element_col b,
                           EntityValue* value)
Mathieu Faverge's avatar
Mathieu Faverge committed
354
355
356
        {
            /* For SVG */
            _render->set_color(r, g, b);
357

Mathieu Faverge's avatar
Mathieu Faverge committed
358
359
360
            time             = trace_to_render_x(time - Info::Render::_x_min_visible);
            height           = trace_to_render_y(height);
            container_height = container_height*coeff_trace_render_y();
361

Mathieu Faverge's avatar
Mathieu Faverge committed
362
363
364
            /* For OpenGL */
            _render->draw_event(time, height, container_height, value);
        }
365

366
    inline void end_draw_events()
Mathieu Faverge's avatar
Mathieu Faverge committed
367
368
369
        {
            _render->end_draw_events();
        }
370
371
372
373

    /*!
     * \brief Creates and opens the display list for counter draws.
     */
374
    inline void start_draw_counter()
Mathieu Faverge's avatar
Mathieu Faverge committed
375
376
377
378
379
380
381
        {
            _render->set_color(1.0, 1.0, 1.0);
            _counter_last_x=0.0;
            _counter_last_y=0.0;
            _render->start_draw_counter();
            _start_new_line = true;
        }
382
383
384
385
386
387
388

    /*!
     * \brief Draw a text with the value of a variable
     * \param text text to draw.
     * \param y y position of the point.
     *
     */
389
    inline void draw_text_value(long int id, double text, double y)
Mathieu Faverge's avatar
Mathieu Faverge committed
390
391
392
        {
            _render->draw_text_value(id,text,y);
        }
393

394
395
396
397
398
399
400
    /*!
     * \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.
     */
401
    inline void draw_counter(const Element_pos x, const Element_pos y)
Mathieu Faverge's avatar
Mathieu Faverge committed
402
403
        {
            if (_start_new_line){/* Start a new line */
404

Mathieu Faverge's avatar
Mathieu Faverge committed
405
406
407
                _counter_last_x = x;
                _counter_last_y = y;
                _start_new_line = false;
408

409
410
            }
            else
Mathieu Faverge's avatar
Mathieu Faverge committed
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
            {/* line is already started */

                if (x <= 0.0){/* convention: the line is over */
                    _render->draw_line( trace_to_render_x(_counter_last_x - Info::Render::_x_min_visible),
                                        trace_to_render_y(_counter_last_y),
                                        trace_to_render_x(Info::Entity::x_max),
                                        trace_to_render_y(_counter_last_y),
                                        _z_counter );
                    _start_new_line = true;
                }
                else
                {/* add new points to the line */

                    /* Each time, the method draw the line from the previous point to
                     the current point (x, y). This last is stored for the next line drawing. */
                    _render->draw_line( trace_to_render_x(_counter_last_x - Info::Render::_x_min_visible),
                                        trace_to_render_y(_counter_last_y),
                                        trace_to_render_x(x - Info::Render::_x_min_visible),
                                        trace_to_render_y(_counter_last_y),
                                        _z_counter );
                    _render->draw_line( trace_to_render_x(x - Info::Render::_x_min_visible),
                                        trace_to_render_y(_counter_last_y),
                                        trace_to_render_x(x - Info::Render::_x_min_visible),
                                        trace_to_render_y(y),
                                        _z_counter );
                    _counter_last_x = x;
                    _counter_last_y = y;
                }
439
440
441
442
443
444
            }
        }

    /*!
     * \brief Closes the counter display list.
     */
445
    inline void end_draw_counter()
Mathieu Faverge's avatar
Mathieu Faverge committed
446
447
448
449
450
451
452
453
454
455
        {
            if (!_start_new_line) {/* If a line was previously opened */
                /* Draw the last line */
                _render->draw_line( trace_to_render_x(_counter_last_x - Info::Render::_x_min_visible),
                                    trace_to_render_y(_counter_last_y),
                                    trace_to_render_x(Info::Entity::x_max),
                                    trace_to_render_y(_counter_last_y),
                                    _z_counter );
            }
            _render->end_draw_counter();
456
457
458
459
460
        }

    /*!
     * \brief Do nothing (it is present for compatibility of the Render class).
     */
461
    inline void end_draw()
462
        {
Mathieu Faverge's avatar
Mathieu Faverge committed
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
            std::ostringstream buf_txt;
            Element_pos graduation_diff;
            //Element_pos coeff_prefix;
            const Element_pos offset_x = 0;
            const Element_pos offset_y = 0;

            graduation_diff = Ruler::get_graduation_diff(Info::Render::_x_min_visible, Info::Render::_x_max_visible);

            /* Now, draw ruler */
            /*Rendering is done in paintGL because we need to recalculate graduations each time paintGL is called, not just when launching the program*/
            _render->start_ruler();
            {
                //_render->call_ruler();
            }
            _render->end_ruler();
478

Mathieu Faverge's avatar
Mathieu Faverge committed
479
480
481
482
            /* clear vectors */
            _containers.clear();
            _container_texts.clear();
            _render->end_draw();
483

Mathieu Faverge's avatar
Mathieu Faverge committed
484
        }
485
};
486
487

#endif