#ifndef RENDER_SVG #define RENDER_SVG #include #include #include #define BUFFER_SIZE 10 //character number stored before flush the _buffer #define LEVEL 20 //distance between two containers #define MARGIN 10 //distance between two object #define ARROWSIZE 2 //spike size #define WIDE 20 #define MARGINSTATE 0.5 #define WAIT_NEW_CHRONO 0 #define INIT 1 #define WAIT_FOR_POINT 2 #include "render.hpp" #include "resource.hpp" #define max(a,b) (a>b?a:b); #define min(a,b) (a>b?b:a); class Svg : public Render{ private: std::ostringstream _buffer; std::ostringstream _thin_element_buffer; std::ostringstream _chronogramme; int _chronogramme_state; std::ofstream _svg_file; Element_pos _container_width_max; Element_pos _container_height_min; int _debug_counter; double _epsilon; inline void print(); 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 ); inline void line(const char* name, Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2); inline void triangle(const char* name,Element_pos x1,Element_pos y1,Element_pos x2,Element_pos y2, Element_pos x3,Element_pos y3); public: /*! * \brief SVG header buiding */ void init(const char *path); /*! * \brief SVG bottom file buiding */ void end(); void start_draw(); 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) ; void draw_container_text(const Element_pos x, const Element_pos y, const std::string value); void end_draw_containers(); void start_draw_states(); /*! * \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. */ 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) ; /*! * \brief Draw an arrow * */ void draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height); void end_draw_states(); void draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height); void start_draw_counter(); void draw_counter(const Element_pos x, const Element_pos y); void end_draw_counter(); void end_draw(); void set_accuracy(double epsilon); }; /*********************************** * * * * Drawing function for the trace. * * * **********************************/ inline void Svg::start_draw(){ } inline void Svg::draw_container_text(const Element_pos x, const Element_pos y, const std::string value){ Element_pos xprime,yprime; yprime = LEVEL*y; xprime = LEVEL*x; _thin_element_buffer << " "; _thin_element_buffer << value; _thin_element_buffer << ""; } inline void Svg::start_draw_containers(){ } inline void Svg::end_draw_containers(){ } inline void Svg::start_draw_states(){ } inline void Svg::end_draw_states(){ } /******************** * Counter *******************/ inline void Svg::start_draw_counter(){ _chronogramme_state=INIT; } inline void Svg::draw_counter(const Element_pos x, const Element_pos y){ std::cout<<"s.draw_counter("<"; _svg_file.write(_chronogramme.str().c_str(), _chronogramme.str().size()); _chronogramme.str(""); _chronogramme_state=WAIT_NEW_CHRONO; } else { _chronogramme << " L" << x << " " << y; } } else if (_chronogramme_state==WAIT_NEW_CHRONO) { if (x==0) { _chronogramme << "\n"; print(); } 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"; } void Svg::print(){ // if (_buffer.str().size()>BUFFER_SIZE){ _svg_file.write(_buffer.str().c_str(), _buffer.str().size()); _buffer.str(""); } inline void Svg::line(const char* name, Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2){ _thin_element_buffer << "\n"; print(); } 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){ //std::cout<<"s.draw_arrow("<