From b22ce8f8f35a4e78f2d5475eff8b1497b54cc73f Mon Sep 17 00:00:00 2001 From: Pascal Noisette Date: Thu, 26 Feb 2009 11:18:08 +0000 Subject: [PATCH] a pretty arrow --- interface/src/render_svg.cpp | 80 ++++++++++++++++++++++++++++++++---- interface/src/render_svg.hpp | 23 ++++++++--- interface/test/test_svg.cpp | 2 + 3 files changed, 92 insertions(+), 13 deletions(-) diff --git a/interface/src/render_svg.cpp b/interface/src/render_svg.cpp index 1b074b1..33bb686 100644 --- a/interface/src/render_svg.cpp +++ b/interface/src/render_svg.cpp @@ -6,14 +6,39 @@ using namespace std; void Svg::rectangle(){ _buffer << ""; print(); } +void Svg::line(){ + + _buffer << ""; + print(); +} + + +void Svg::triangle(){ + + + + _buffer << ""; + print(); + + +} + void Svg::print(){ if (_buffer.str().size()>BUFFER_SIZE){ @@ -31,7 +56,25 @@ void Svg::init(const char *path){ if (_svg_file.is_open()==false){ std::cerr<<"unable to open file"; } - _buffer << "\n\n\n\t\n\tRectangles\n"; + _buffer << "\n" + << "\n" + << "\n" + << "\t\n" + << "\tRectangles\n"; + print(); } @@ -49,20 +92,41 @@ void Svg::draw_container(const Element_pos x, const Element_pos y, const Element _b=0xcc; _w=(unsigned long)w; _h=(unsigned long)h; - _x=(unsigned long)x; - _y=(unsigned long)y; + _x1=(unsigned long)x; + _y1=(unsigned long)y; rectangle(); } +void Svg::draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height){ + + _x1=(unsigned long)start_time; + _x2=(unsigned long)end_time; + _y1=(unsigned long)start_height; + _y2=(unsigned long)end_height; + line(); + + + _x1=(unsigned long)end_time; + _x2=(unsigned long)end_time; + _x3=(unsigned long)end_time+ARROWSIZE; + _y1=(unsigned long)end_height+ARROWSIZE; + _y2=(unsigned long)end_height-ARROWSIZE; + _y3=(unsigned long)end_height; + triangle();//spike + + +} + + void Svg::draw_state(const Element_pos start , const Element_pos end, const Element_count level, const Element_col r, const Element_col g, const Element_col b){ _r=(unsigned char)r; _g=(unsigned char)g; _b=(unsigned char)b; _w=(unsigned long)(end-start); - _h=(unsigned long)LEVEL - 10; - _x=(unsigned long)start; - _y=(unsigned long)level*LEVEL; + _h=(unsigned long)LEVEL - MARGIN; + _x1=(unsigned long)start; + _y1=(unsigned long)level*LEVEL; rectangle(); } diff --git a/interface/src/render_svg.hpp b/interface/src/render_svg.hpp index 0e6f0df..6534a38 100644 --- a/interface/src/render_svg.hpp +++ b/interface/src/render_svg.hpp @@ -2,17 +2,18 @@ #define RENDER_SVG -#include #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 typedef unsigned long Element_count ; typedef double Element_pos; -typedef unsigned int Element_col; +typedef unsigned char Element_col; class Svg{ @@ -20,11 +21,16 @@ class Svg{ private: std::ostringstream _buffer; + std::string _object_class; std::ofstream _svg_file; - unsigned int _r,_g,_b; - unsigned long _x,_y,_w,_h; - void print(); + unsigned int _r,_g,_b; // 0 < _r,_g,_b < 255 and displayed as int + unsigned long _w,_h; + unsigned long _x1,_y1,_x2,_y2,_x3,_y3; + + inline void print(); inline void rectangle(); + inline void line(); + inline void triangle(); public: /*! * \brief SVG header buiding @@ -56,6 +62,13 @@ public: * \param level refer to the container which state belongs to. */ void draw_state(const Element_pos start , const Element_pos end, const Element_count level, 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); + }; #endif // RENDER_SVG diff --git a/interface/test/test_svg.cpp b/interface/test/test_svg.cpp index a3eecc9..f5b2377 100644 --- a/interface/test/test_svg.cpp +++ b/interface/test/test_svg.cpp @@ -17,6 +17,8 @@ int main() s.draw_state(400, 750, 2, 0xff,0xcc,33); s.draw_state(70, 300, 3, 0xff,0xcc,33); + s.draw_arrow(100,700,LEVEL*1,LEVEL*3); + s.draw_arrow(200,400,LEVEL*2,LEVEL*2); s.end(); return 0; -- GitLab