#ifndef RENDER_SVG #define RENDER_SVG #include #include #include #define BUFFER_SIZE 2048 //character number stored before flush the _buffer #define LEVEL 110 //distance between two containers #define MARGIN 10 //distance between two object #define ARROWSIZE 4 //spike size #include "render.hpp" #include "resource.hpp" /*typedef unsigned long Element_count ; typedef double Element_pos; typedef unsigned char Element_col; */ class Svg : public Render{ private: std::ostringstream _buffer; std::ofstream _svg_file; inline void print(); inline void rectangle(unsigned long w, unsigned long h,unsigned long x1,unsigned long y1, unsigned int r, unsigned int g, unsigned int b ); inline void line( long unsigned int x1, long unsigned int y1, long unsigned int x2, long unsigned int y2); inline void triangle(unsigned long x1,unsigned long y1,unsigned long x2,unsigned long y2, unsigned long x3,unsigned long 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(); }; /*********************************** * * * * 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){ } 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(){ } inline void Svg::draw_counter(const Element_pos x, const Element_pos y){ } inline void Svg::end_draw_counter(){ } inline void Svg::end_draw(){ } void Svg::rectangle(unsigned long w, unsigned long h,unsigned long x1,unsigned long y1, unsigned int r, unsigned int g, unsigned int b ){ _buffer << ""; print(); } void Svg::triangle(unsigned long x1,unsigned long y1,unsigned long x2,unsigned long y2, unsigned long x3,unsigned long y3){ _buffer << ""; print(); } void Svg::print(){ if (_buffer.str().size()>BUFFER_SIZE){ _svg_file.write(_buffer.str().c_str(), _buffer.str().size()); _buffer.flush(); } } inline void Svg::line( long unsigned int x1, long unsigned int y1, long unsigned int x2, long unsigned int y2){ _buffer << ""; 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){ Svg::line(start_time,start_height,end_time,end_height); Svg::triangle(end_time,end_height+ARROWSIZE,end_time,end_height-ARROWSIZE,end_time+ARROWSIZE,end_height);//spike } inline void Svg::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h){ Svg::rectangle(w, h, x, y, 0xff, 0x44, 0xcc); } 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){ Svg::rectangle(end-start,LEVEL - MARGIN, start,level*LEVEL,r , g, b); } inline void Svg::draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height){ rectangle(1,container_height*LEVEL, time, container_height, 0xff, 0x44, 0xcc); } #endif // RENDER_SVG