render_svg.hpp 20.2 KB
Newer Older
1 2 3
/*!
 *\file render_svg.hpp
 */
4
#ifndef RENDER_SVG
5
#define RENDER_SVG
6 7


Pascal Noisette's avatar
Pascal Noisette committed
8 9 10
#include <iostream>
#include <sstream>
#include <fstream>
11

Pascal Noisette's avatar
Pascal Noisette committed
12

13 14
#include "render.hpp"
#include "resource.hpp"
Pascal Noisette's avatar
Pascal Noisette committed
15

16 17 18
/*!
 * \brief This class provides a SVG display ,it inherited from the Render interface.
 */
19
class Svg : public Render{
20 21


22
private:
23
  
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
24 25 26
    /*!
     * \brief buffer containing the main objets to be displayed
     */
27
    std::ostringstream _buffer;
Pascal Noisette's avatar
Pascal Noisette committed
28

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
29 30 31
    /*!
     * \brief buffer containning the smallest objet which must be display over main objet to be visible
     */
32
    std::ostringstream _thin_element_buffer;
Pascal Noisette's avatar
Pascal Noisette committed
33

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
34 35 36
    /*!
     * \brief buffer containning each counters values
     */
37
    std::ostringstream _chronogramme;
Pascal Noisette's avatar
Pascal Noisette committed
38

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
39 40 41
    /*!
     * \brief buffer containning the scale
     */
42
    std::ostringstream _time_scale;
Pascal Noisette's avatar
Pascal Noisette committed
43

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
44 45
    /*!
     * \brief State of the chronogramme drawer automaton
Johnny Jazeix's avatar
Johnny Jazeix committed
46
     * the automaton can be _INIT, _WAIT_FOR_POINT and _WAIT_NEW_CHRONO
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
47
     */
Pascal Noisette's avatar
Pascal Noisette committed
48
    int _chronogramme_state;
Pascal Noisette's avatar
Pascal Noisette committed
49

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
50 51 52
    /*!
     * \brief output svg file
     */
53
    std::ofstream _svg_file;
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
54 55 56
    /*!
     * \brief width container sum which is the abscisse of the beginnig of the events display
     */
Pascal Noisette's avatar
Pascal Noisette committed
57
    Element_pos _container_width_max;
Pascal Noisette's avatar
Pascal Noisette committed
58

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
59 60 61
    /*!
     * \brief minimum container height which is the height of any event
     */
Pascal Noisette's avatar
Pascal Noisette committed
62
    Element_pos _container_height_min;
Pascal Noisette's avatar
Pascal Noisette committed
63

Pascal Noisette's avatar
Pascal Noisette committed
64

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
65 66 67
    /*!
     * \brief Statistics and Informations about input trace computed in live
     */
Pascal Noisette's avatar
Pascal Noisette committed
68 69 70
    Element_pos _total_width;
   

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
71 72 73
    /*!
     * \brief Statistics and Informations about input trace computed in live
     */
Pascal Noisette's avatar
Pascal Noisette committed
74 75
    Times _total_time;

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
76 77 78 79
    /*!
     * \brief Statistics and Informations about input trace computed in live
     */
    bool _debug_svg_already_closed_once;
80

Pascal Noisette's avatar
Pascal Noisette committed
81 82


83

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
84 85 86
    /*!
     * \brief flush the buffer containing svg element on the file
     */
Pascal Noisette's avatar
Pascal Noisette committed
87
    inline void print();
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
88 89 90 91
    /*!
     * \brief add a rectangle to the buffer of drawing
     */   
    inline void rectangle(const char* name,Element_pos w, Element_pos h,Element_pos x1,Element_pos y1, unsigned int r, unsigned int g, unsigned int b);
92

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
93 94 95
    /*!
     * \brief add a line to the buffer of drawing
     */   
Pascal Noisette's avatar
Pascal Noisette committed
96
    inline void line(const char* name, Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2);
97 98


Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
99 100 101
    /*!
     * \brief add a triangle shape to the buffer of drawing
     */ 
Pascal Noisette's avatar
Pascal Noisette committed
102
    inline void triangle(const char* name,Element_pos x1,Element_pos y1,Element_pos x2,Element_pos y2, Element_pos x3,Element_pos y3);
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
103

104
public:
Pascal Noisette's avatar
Pascal Noisette committed
105

106

107
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
108 109
     * \brief Distance between two container
     */
Johnny Jazeix's avatar
Johnny Jazeix committed
110
    static const int _MARGIN = 10;
Pascal Noisette's avatar
Pascal Noisette committed
111

112
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
113 114
     * \brief Spike size
     */
Johnny Jazeix's avatar
Johnny Jazeix committed
115
    static const int _ARROWSIZE = 2;
Pascal Noisette's avatar
Pascal Noisette committed
116 117


118
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
119 120
     * \brief Distance between two states
     */
Johnny Jazeix's avatar
Johnny Jazeix committed
121 122
    static const double _MARGINSTATE;
    
123
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
124 125
     * \brief offset between the top and the picture due to the scale
     */
Johnny Jazeix's avatar
Johnny Jazeix committed
126
    static const int _MARGINTOP = 20;
Pascal Noisette's avatar
Pascal Noisette committed
127

128
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
129 130
     * \brief a State of chronogramme drawer automaton 
     */
Johnny Jazeix's avatar
Johnny Jazeix committed
131
    static const int _WAIT_NEW_CHRONO = 0;
Pascal Noisette's avatar
Pascal Noisette committed
132

133
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
134 135
     * \brief a State of chronogramme drawer automaton
     */
Johnny Jazeix's avatar
Johnny Jazeix committed
136
    static const int _INIT = 1;
Pascal Noisette's avatar
Pascal Noisette committed
137

138
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
139 140
     * \brief a State of chronogramme drawer automaton
     */
Johnny Jazeix's avatar
Johnny Jazeix committed
141
    static const int _WAIT_FOR_POINT = 2;
Pascal Noisette's avatar
Pascal Noisette committed
142

Johnny Jazeix's avatar
Johnny Jazeix committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160

    /*!
     * \brief Trace can be exported on a selected period of time, beginning with _start_interval_time, default 0 and command line changed with -t _start_interval_time _end_interval_time or the static svg::set_interval(Times t1,Times t2)
     */
    static Times _start_interval_time;

  
    /*!
     * \brief Trace can be exported on a selected period of time, endding with _end_interval_time, default 0 (no upper selection) and command line changed with -t _start_interval_time _end_interval_time  or the static svg::set_interval(Times t1,Times t2)
     */   
    static Times _end_interval_time;


    /*!
     * \brief Svg display is widden by _wide_factor (in pixel/second), default 100, and command line changed with -w _wide_factor
     */   
    static  Element_pos _wide_factor;

161
    /*!
Johnny Jazeix's avatar
Johnny Jazeix committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
     *\brief Svg display is grown by _height_factor (in pixel/second), default 20, and command line changed with -w _wide_factor
     It corresponds to the height of a containers in pixel
    */

    static  Element_pos _height_factor;

    /*!
     * \brief accuracy required : an element less wide than  _epsilon will not be printed
     */
    static double _epsilon;


    /*!
     * \brief the scale can be more accurate by increasing the _scale_frequency
     */
    static double _scale_frequency;

179 180
    /*STATIC : allows commands line parameter*/

Pascal Noisette's avatar
Pascal Noisette committed
181
    /*!
182
     * \brief Trace can be exported on a selected period of time, starting with  _start_interval_time and endding with _end_interval_time, default 0 (no upper selection) and command line changed with -t _start_interval_time _end_interval_time  or the static svg::set_interval(Times t1,Times t2)
Pascal Noisette's avatar
Pascal Noisette committed
183
     */
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
184
    static void set_interval(Times t1, Times t2);
185
    /*!
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
186 187 188
     * \brief Set the precision of SVG display.
     * \param epsilon Precision
     */
189 190 191
    static void set_accuracy(double epsilon);
    /*!
     * \brief Svg display is widden by _wide_factor (in pixel/second), default 100, and command line changed with -w _wide_factor
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
192
     */
193 194 195
    static void set_wide_factor (Element_pos w);
    /*!
     * \brief Svg display is grown by _height
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
196
     */
197
    static void set_height_factor (Element_pos w);
Pascal Noisette's avatar
Pascal Noisette committed
198

199 200 201 202 203 204 205 206 207 208 209 210
    /*!
     * \brief Return the height factor.
     * \return The height factor.
     */
    static Element_pos get_height_factor();

    /*!
     * \brief Return the widet factor.
     * \return The wide factor.
     */
    static Element_pos get_wide_factor();

211 212
    /*!
     * \brief the scale can be more accurate by increasing the _scale_frequency
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
213
     */
214 215 216
    static void set_scale_frequency(Element_pos w);


217 218


Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
219
    /*Statistics : not yet implemented*/
220
    
Pascal Noisette's avatar
Pascal Noisette committed
221
    /*!
222
     * \brief The width of the trace
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
223 224
     */
    void set_total_width(Element_pos);
225 226
    /*!
     * \brief The time span of the trace
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
227 228
     */
    void set_total_time(Times);
229 230 231 232 233




    /*drawing functions*/
Pascal Noisette's avatar
Pascal Noisette committed
234

235
    /*!
236 237
     * \brief SVG header buiding
     */
238
    void init(const char *path);
239

240
    /*!
241 242
     * \brief SVG bottom file buiding
     */
243
    void end();
244

Pascal Noisette's avatar
Pascal Noisette committed
245

246
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
247 248
     * \brief unused
     */
249
    void start_draw();
Pascal Noisette's avatar
Pascal Noisette committed
250

251
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
252 253
     * \brief unused
     */
254
    void start_draw_containers();
255

256
    /*!
257 258 259 260 261 262
     * \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
     */
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
263
    void draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h);
264

Pascal Noisette's avatar
Pascal Noisette committed
265 266 267
    /*!
     * \brief Draw associated container name
     */
268
    void draw_container_text(const Element_pos x, const Element_pos y, const std::string value);
269
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
270 271
     * \brief unused
     */
272
    void end_draw_containers();
Pascal Noisette's avatar
Pascal Noisette committed
273

274
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
275 276
     * \brief unused
     */
277 278
    void start_draw_states();

279 280 281 282 283 284 285 286
    /*!
     * \brief Draw a state of the trace.
     * \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.
     * \param start the beginning time of the state.
     * \param end the ending time of the state.
     * \param level refer to the container which state belongs to.
287
     * \param height Unused parameter yet.
288
     */
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
289
    void draw_state(const Element_pos start , const Element_pos end, const Element_pos level, const Element_pos height, const Element_col r, const Element_col g, const Element_col b);
Pascal Noisette's avatar
Pascal Noisette committed
290

Olivier Lagrasse's avatar
Olivier Lagrasse committed
291 292 293 294 295
    /*!
     * \brief unused
     */
    void start_draw_arrows();

Pascal Noisette's avatar
Pascal Noisette committed
296
    /*!
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
297 298 299
     * \brief Draw an arrow
     *
     */
Pascal Noisette's avatar
Pascal Noisette committed
300 301
    void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height);

Olivier Lagrasse's avatar
Olivier Lagrasse committed
302 303 304 305
    /*!
     * \brief unused
     */
    void end_draw_arrows();
Pascal Noisette's avatar
Pascal Noisette committed
306

307
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
308 309
     * \brief unused
     */
310 311
    void end_draw_states();

312 313
    /*!
     * \brief warning : not yet implemented
Pascal Noisette's avatar
Pascal Noisette committed
314
     */
315 316
    void draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height);

Pascal Noisette's avatar
Pascal Noisette committed
317

318
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
319 320
     * \brief initialise drawer automaton
     */
321 322
    void start_draw_counter();
    
Pascal Noisette's avatar
Pascal Noisette committed
323

324
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
325 326
     * \brief add a point or switch chronogramme drawing
     */
Pascal Noisette's avatar
Pascal Noisette committed
327
    void draw_counter(const Element_pos x, const Element_pos y);
328
    
329
    /*!
Pascal Noisette's avatar
Pascal Noisette committed
330 331
     * \brief close drawer automaton
     */
332 333
    void end_draw_counter();

334 335 336 337

    /*!
     * \brief display the scale 
     */
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
338
    void display_time_scale();
339 340 341


    /*!
Pascal Noisette's avatar
Pascal Noisette committed
342 343
     * \brief unused
     */
344
    void end_draw();
345
  
346
    
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
347
    ~Svg();
348

349

350 351
};

352 353 354 355 356 357 358 359 360 361 362 363 364 365


/***********************************
 *
 *
 *
 * Drawing function for the trace.
 *
 *
 *
 **********************************/


inline void Svg::start_draw(){
366
 
367 368 369
}

inline void Svg::draw_container_text(const Element_pos x, const Element_pos y, const std::string value){
Pascal Noisette's avatar
Pascal Noisette committed
370
  
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
371
    Element_pos xprime,yprime;
372

Johnny Jazeix's avatar
Johnny Jazeix committed
373
    /*positions are translated to _MARGINTOP            : the upper region reserved for scale*/
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
374
    /*heights are grown by _height_factor              : conversion from time in ms to pixel*/
Johnny Jazeix's avatar
Johnny Jazeix committed
375
    yprime =  _height_factor*y + _MARGINTOP;
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
376
    xprime =  _height_factor*x;
Pascal Noisette's avatar
Pascal Noisette committed
377

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
378 379 380
    _thin_element_buffer << "<text x='" << xprime <<"' y='" << yprime << "'> ";
    _thin_element_buffer << value;
    _thin_element_buffer << "</text>";
Pascal Noisette's avatar
Pascal Noisette committed
381 382

} 
383 384

inline void Svg::start_draw_containers(){
Pascal Noisette's avatar
Pascal Noisette committed
385

386 387 388 389 390 391 392 393 394 395 396
}

inline void Svg::end_draw_containers(){
}

inline void Svg::start_draw_states(){
}

inline void Svg::end_draw_states(){
}

Pascal Noisette's avatar
Pascal Noisette committed
397

398 399 400 401 402
/********************
 * Counter
 *******************/

inline void Svg::start_draw_counter(){
Johnny Jazeix's avatar
Johnny Jazeix committed
403
    _chronogramme_state = _INIT;
Pascal Noisette's avatar
Pascal Noisette committed
404
 
405 406 407
}

inline void Svg::draw_counter(const Element_pos x, const Element_pos y){
408
 
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
409 410 411 412
    /*computed position according to adjusted parameters*/
    /*widths are widen by _wide_factor                 : conversion from time in ms to pixel*/
    /*heights are grown by _height_factor              : conversion from time in ms to pixel*/
    /*positions are translated to _container_width_max : the left region occupied by containers*/
Johnny Jazeix's avatar
Johnny Jazeix committed
413
    /*positions are translated to _MARGINTOP            : the upper region reserved for scale*/
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
414
    /*whenever a time selection is set                 : positions are translated to -_start_interval_time (in ms, ie  -_start_interval_time*_wide_factor pixel)*/
415

Johnny Jazeix's avatar
Johnny Jazeix committed
416 417
    Element_pos xprime = x*_wide_factor +  _container_width_max;
    Element_pos yprime = y* _height_factor + _MARGINTOP;
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
418
    Element_pos switchvalue = _container_width_max;
Pascal Noisette's avatar
wide  
Pascal Noisette committed
419

420
 
Pascal Noisette's avatar
Pascal Noisette committed
421
  
Johnny Jazeix's avatar
Johnny Jazeix committed
422
    if (_chronogramme_state == _INIT) {
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
423
        if (xprime == switchvalue) {
424
           
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
425
            _chronogramme << "\n<path d='M"<< xprime +  _start_interval_time*_wide_factor << " " << yprime;
Johnny Jazeix's avatar
Johnny Jazeix committed
426
            _chronogramme_state=_WAIT_FOR_POINT;
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
427 428 429
        }
        else
            std::cerr<<"draw_counter not initialised";
Pascal Noisette's avatar
Pascal Noisette committed
430 431
	  
    }
Johnny Jazeix's avatar
Johnny Jazeix committed
432
    else if (_chronogramme_state == _WAIT_FOR_POINT) {
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
433
        if (xprime == switchvalue) {
Pascal Noisette's avatar
Pascal Noisette committed
434
           
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
435 436 437
            _chronogramme << "'/>";
            _svg_file.write(_chronogramme.str().c_str(), _chronogramme.str().size());
            _chronogramme.str("");
Johnny Jazeix's avatar
Johnny Jazeix committed
438
            _chronogramme_state=_WAIT_NEW_CHRONO;
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
439 440 441 442
        }
        else {
            if (_end_interval_time && x > _end_interval_time)
                return;
443
	  
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
444 445
            if (x<_start_interval_time)	
                return;
446
	  
447 448

	  _total_time = std::max( _total_time,x);
449
	  
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
450 451
            _chronogramme << " L" << xprime << " " << yprime;
        }
Pascal Noisette's avatar
Pascal Noisette committed
452 453 454
      
    }
  
Johnny Jazeix's avatar
Johnny Jazeix committed
455
    else  if (_chronogramme_state==_WAIT_NEW_CHRONO) {
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
456 457
        if (xprime==switchvalue) {
            _chronogramme << "\n<path d='M"<< xprime +  _start_interval_time*_wide_factor<< " " << yprime;
Johnny Jazeix's avatar
Johnny Jazeix committed
458
            _chronogramme_state=_WAIT_FOR_POINT;
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
459 460 461
        }
        else
            std::cerr<<"draw_counter not initialised";
Pascal Noisette's avatar
Pascal Noisette committed
462 463 464 465 466
	  

    }
  

467 468
}

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
469
inline void Svg::end_draw_counter() {
Johnny Jazeix's avatar
Johnny Jazeix committed
470
    if (_chronogramme_state!=_WAIT_NEW_CHRONO && _chronogramme_state!=_INIT)
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
471
        std::cerr<<"draw_counter not un-initialised";
472 473
}

474 475

inline void Svg::end_draw(){
476
    
477 478
}

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
479 480
void Svg::rectangle(const char* name,Element_pos w, Element_pos h,Element_pos x1,Element_pos y1, unsigned int r, unsigned int g, unsigned int b) {
    _buffer << "\n<rect class='"<<name<<"' title='"<<name<<"' width='" << w
Pascal Noisette's avatar
Pascal Noisette committed
481 482 483 484
            <<"' height='"<< h
            <<"' x='"     << x1
            <<"' y='"     << y1
            <<"' fill='rgb("<<r<<","<<g<<","<<b
Pascal Noisette's avatar
Pascal Noisette committed
485
            <<")'/>";
Pascal Noisette's avatar
Pascal Noisette committed
486 487 488 489 490 491 492
    print();
}





Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
493 494 495 496 497 498
void Svg::triangle(const char* name,Element_pos x1,Element_pos y1,Element_pos x2,Element_pos y2, Element_pos x3,Element_pos y3) {
    _thin_element_buffer << "\n<polyline title='"<<name<<"' class='triangle' points='"
                         <<        x1 << "," << y1
                         << " " << x2 << "," << y2
                         << " " << x3 << "," << y3
                         <<"' />";
499
    
Pascal Noisette's avatar
Pascal Noisette committed
500 501
}

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
502 503 504
void Svg::print() {
    _svg_file.write(_buffer.str().c_str(),  _buffer.str().size());
    _buffer.str("");
Pascal Noisette's avatar
Pascal Noisette committed
505 506 507 508 509
}




Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
510 511 512 513 514 515
inline void Svg::line(const char* name, Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2) {
    _thin_element_buffer << "\n<line title='"<<name<<"' x1='" << x1
                         <<"' y1='"     << y1
                         <<"' x2='"     << x2
                         <<"' y2='"     << y2
                         <<"' />";
Pascal Noisette's avatar
Pascal Noisette committed
516 517 518
    print();
}

Olivier Lagrasse's avatar
Olivier Lagrasse committed
519 520 521
inline void Svg::start_draw_arrows(){
}

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
522
inline void Svg::draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height) {
Pascal Noisette's avatar
Pascal Noisette committed
523

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
524
    /*selection*/
525
    /*may be outofrange*/
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
    if ((_end_interval_time && start_time>_end_interval_time) || (end_time < _start_interval_time))
        return;

    /*arrow line equation y = a*x+b  */
    Element_pos a =  (1.0*(end_height - start_height))/(end_time - start_time);
    Element_pos b = start_height - a*(start_time);


    /*parameter to be adjusted to the time selection*/
    Element_pos start_timeprime;
    Element_pos end_timeprime;
    Element_pos start_heightprime;
    Element_pos end_heightprime;

    bool trunc = false;

    /*begining : left adjustement*/
    if (start_time<_start_interval_time) {
        start_timeprime =  _start_interval_time ;
        start_heightprime = a*start_timeprime+b;
546
    }
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
547 548 549
    else {
        start_timeprime =  start_time ;
        start_heightprime =  start_height;
550 551
    }

552

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
553 554 555
    /*endding as specified parameter*/
    end_timeprime =  end_time ;
    end_heightprime =  end_height;
556

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
557 558 559 560 561 562 563 564
    /*except if an _end_interval_time is set */
    if (_end_interval_time) {
        if (end_time>_end_interval_time) {      
            /*adjustement on the right and no spike !*/
            trunc = true;
            end_timeprime = _end_interval_time;
            end_heightprime =  a*end_timeprime+b;
        }
565

566 567 568
    }


569 570 571

  /*update of the time*/
  _total_time = std::max( _total_time,end_timeprime);
Pascal Noisette's avatar
Pascal Noisette committed
572

573

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
574 575 576 577
    /*computed position according to adjusted parameters*/
    /*width are widen by _wide_factor                  : conversion from time in ms to pixel*/
    /*heights are grown by _height_factor              : conversion from time in ms to pixel*/
    /*positions are translated to _container_width_max : the left region occupied by containers*/
Johnny Jazeix's avatar
Johnny Jazeix committed
578
    /*positions are translated to _MARGINTOP            : the upper region reserved for scale*/
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
579
    /*whenever a time selection is set                 : states are translated to -_start_interval_time (in ms, ie  -_start_interval_time*_wide_factor pixel)*/
580 581

  
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
582
    Element_pos x1=start_timeprime*_wide_factor +  _container_width_max -_start_interval_time*_wide_factor ;
Johnny Jazeix's avatar
Johnny Jazeix committed
583
    Element_pos y1=start_heightprime* _height_factor + _MARGINTOP;
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
584
    Element_pos x2=end_timeprime*_wide_factor+  _container_width_max -_start_interval_time*_wide_factor;
Johnny Jazeix's avatar
Johnny Jazeix committed
585
    Element_pos y2=end_heightprime* _height_factor + _MARGINTOP;
586 587


Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
588 589
    /*an arrow :*/
    Svg::line("arrow",x1 ,y1 ,x2,y2);
Pascal Noisette's avatar
Pascal Noisette committed
590

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
591
    if (!trunc)
Johnny Jazeix's avatar
Johnny Jazeix committed
592
        Svg::triangle("arrow",x2 ,y2+_ARROWSIZE,x2 ,y2-_ARROWSIZE,x2+_ARROWSIZE,y2);
593
  
594
  
Pascal Noisette's avatar
Pascal Noisette committed
595 596
}

597

Olivier Lagrasse's avatar
Olivier Lagrasse committed
598 599 600
inline void Svg::end_draw_arrows(){
}

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
601
inline void Svg::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h) {
Pascal Noisette's avatar
Pascal Noisette committed
602

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
603
    Element_pos xprime,yprime,wprime,hprime;
Pascal Noisette's avatar
Pascal Noisette committed
604
  
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
605 606 607 608 609 610
    if (h<=0 || w<=0 || x<0 || y<0){
        std::cerr<<"draw_container : specified argument isn't positive double"<<std::endl;
        return;
    }

    /*parameters are grown                             : conversion from time in ms to pixel*/
Johnny Jazeix's avatar
Johnny Jazeix committed
611
    /*positions are translated to _MARGINTOP            : the upper region reserved for scale*/
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
612 613
    wprime =  _height_factor*w;
    hprime =  _height_factor*h;
Johnny Jazeix's avatar
Johnny Jazeix committed
614
    yprime =  _height_factor*y + _MARGINTOP;
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
615
    xprime =  _height_factor*x;
Pascal Noisette's avatar
Pascal Noisette committed
616

Pascal Noisette's avatar
Pascal Noisette committed
617
 
Pascal Noisette's avatar
Pascal Noisette committed
618

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
619
    Svg::rectangle("container",wprime, hprime, xprime, yprime, 0xbb, 0xbb, 0xbb);
620
  
621 622

  
Johnny Jazeix's avatar
Johnny Jazeix committed
623
  _container_width_max = std::max(wprime+xprime+ _MARGIN,_container_width_max);
624
  _container_height_min = std::min(hprime,_container_height_min);
Pascal Noisette's avatar
Pascal Noisette committed
625 626 627 628
}



Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
629
inline void Svg::draw_state(const Element_pos start , const Element_pos end, const Element_pos level, const Element_pos height, const Element_col r, const Element_col g, const Element_col b) {
630
  
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
631 632 633 634
    Element_pos w;
    Element_pos h;
    Element_pos x;
    Element_pos y;
Pascal Noisette's avatar
Pascal Noisette committed
635

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
636 637
    Element_pos startprime;
    Element_pos endprime;
638
 
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
639 640 641 642
    if (start<=0 || end <=0 || height<0 || level<0){
        std::cerr<<"draw_state : specified argument isn't positive double"<<std::endl;
        return;
    }
643

644
  
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
645
    /*selection*/
646
    /*an outofrange state will not be displayed*/
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
647 648
    if ((_end_interval_time && start>_end_interval_time) || end<_start_interval_time)
        return;
649
  
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
650 651 652 653 654 655 656 657 658 659
    /*a state may be shortenend on its left*/
    if (start < _start_interval_time)
        startprime = _start_interval_time;
    else
        startprime = start ;

    /*or on its end*/
    endprime = end;
    if (_end_interval_time && end>_end_interval_time) {
        endprime = _end_interval_time;
660
    }
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
661
    
662
  
663 664 665

  
  _total_time = std::max( _total_time,endprime);
666

667

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
668 669 670 671
    /*adjusted parameter to positions*/
    /*states are widen by _wide_factor              : conversion from time in ms to pixel*/
    /*states are grown by _height_factor            : conversion from time in ms to pixel*/
    /*states are translated to _container_width_max : the left region occupied by containers*/
Johnny Jazeix's avatar
Johnny Jazeix committed
672 673
    /*states are translated to _MARGINSTATE          : the margin between two container*/
    /*states are translated to _MARGINTOP            : the upper region reserved for scale*/
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
674 675
    /*states height is not the specified parameter  : container_height_min replaces height which enable the state to have an uniform size */
    /*whenever a time selection is set              : states are translated to -_start_interval_time (in ms, ie  -_start_interval_time*_wide_factor pixel)*/
676
  
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
677 678
    w = endprime*_wide_factor-startprime*_wide_factor;
    h = _container_height_min;
Johnny Jazeix's avatar
Johnny Jazeix committed
679 680
    x = (startprime )*_wide_factor + _container_width_max + _MARGINSTATE -_start_interval_time*_wide_factor;
    y = level* _height_factor + _MARGINTOP;
681

682

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
683 684 685
    if(w < _epsilon){
        return;
    }
Pascal Noisette's avatar
Pascal Noisette committed
686
  
687
 
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
688
    Svg::rectangle("state",w,h, x,y,r*255 , g*255,  b*255);
Pascal Noisette's avatar
Pascal Noisette committed
689 690
}

Pascal Noisette's avatar
Pascal Noisette committed
691

Pascal Noisette's avatar
Pascal Noisette committed
692

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
693 694 695 696
/*!
 * \brief not yet implemented
 */
inline  void Svg::draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height) {
Pascal Noisette's avatar
Pascal Noisette committed
697

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
698 699 700 701
    if (time<=0 || height <=0 || container_height <=0){
        std::cerr<<"draw_event : specified argument isn't positive double"<<std::endl;
        return;
    }
702
  
703
   
704
  
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
705 706 707
    /*an outofrange event will not be displayed*/
    if ((_end_interval_time && time > _end_interval_time) || time < _start_interval_time)
        return;
708
  
709 710 711 712 713
    _total_time = std::max(_total_time, time);


    _total_time = std::max( _total_time,time);

Johnny Jazeix's avatar
Johnny Jazeix committed
714
  Svg::rectangle("event",_MARGINSTATE,_container_height_min, time +  _container_width_max -_start_interval_time*_wide_factor, height + _MARGINTOP, 0x17, 0x60, 0xe7);
715
  
Pascal Noisette's avatar
Pascal Noisette committed
716
}
717

Pascal Noisette's avatar
Pascal Noisette committed
718 719


720
#endif // RENDER_SVG