From d70b6dae4da95817d24b1405151b08f8337c743f Mon Sep 17 00:00:00 2001 From: Pascal Noisette Date: Wed, 4 Mar 2009 18:47:02 +0000 Subject: [PATCH] makefile test svg --- src/interface/render_svg.cpp | 53 +---------------------------- src/interface/render_svg.hpp | 66 ++++++++++++++++++++++++++++++++++-- tests/interface/makefile | 7 ++++ tests/interface/test_svg.cpp | 8 ++--- 4 files changed, 75 insertions(+), 59 deletions(-) create mode 100755 tests/interface/makefile diff --git a/src/interface/render_svg.cpp b/src/interface/render_svg.cpp index ffa2f52..19ad923 100644 --- a/src/interface/render_svg.cpp +++ b/src/interface/render_svg.cpp @@ -2,46 +2,8 @@ using namespace std; -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::line(unsigned long x1,unsigned long y1,unsigned long x2,unsigned long y2){ - _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(); - } -} - - void Svg::init(const char *path){ - _svg_file.open(path , ofstream::out | ofstream::trunc); + _svg_file.open(path , std::ofstream::out | std::ofstream::trunc); if (_svg_file.is_open()==false){ std::cerr<<"unable to open file"; } @@ -73,16 +35,3 @@ void Svg::end(){ _buffer.flush(); _svg_file.close(); } - -void Svg::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h){ - rectangle(w, h, x, y, 0xff, 0x44, 0xcc); -} - -void Svg::draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height){ - line(start_time,start_height,end_time,end_height); - triangle(end_time,end_height+ARROWSIZE,end_time,end_height-ARROWSIZE,end_time+ARROWSIZE,end_height);//spike -} - -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){ - rectangle(end-start,LEVEL - MARGIN, start,level*LEVEL,r , g, b); -} diff --git a/src/interface/render_svg.hpp b/src/interface/render_svg.hpp index acad38f..1be7247 100644 --- a/src/interface/render_svg.hpp +++ b/src/interface/render_svg.hpp @@ -29,7 +29,7 @@ private: 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(unsigned long x1,unsigned long y1,unsigned long x2,unsigned long y2); + 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: /*! @@ -80,6 +80,7 @@ public: void draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height); + void end_draw(); }; @@ -114,11 +115,70 @@ inline void Svg::start_draw_states(){ inline void Svg::end_draw_states(){ } -inline void Svg::draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height){ -} + 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 diff --git a/tests/interface/makefile b/tests/interface/makefile new file mode 100755 index 0000000..2aa6c84 --- /dev/null +++ b/tests/interface/makefile @@ -0,0 +1,7 @@ +test_svg.o : test_svg.cpp + +render_svg.o: ../../src/interface/render_svg.cpp ../../src/interface/render_svg.hpp + g++ -g -c -Wall ../../src/interface/render_svg.cpp -o render_svg.o + +test_svg : render_svg.o test_svg.o + g++ -g -o test_svg render_svg.o test_svg.o \ No newline at end of file diff --git a/tests/interface/test_svg.cpp b/tests/interface/test_svg.cpp index f5b2377..7e3c67e 100644 --- a/tests/interface/test_svg.cpp +++ b/tests/interface/test_svg.cpp @@ -1,5 +1,5 @@ -#include "../src/render_svg.hpp" +#include "../../src/interface/render_svg.hpp" using namespace std; int main() @@ -13,9 +13,9 @@ int main() s.draw_container(0,LEVEL*2,50,100); s.draw_container(0,LEVEL*3,50,100); - s.draw_state(100, 750, 1, 0xff,0xcc,33); - s.draw_state(400, 750, 2, 0xff,0xcc,33); - s.draw_state(70, 300, 3, 0xff,0xcc,33); + s.draw_state(100, 750, 1,NULL, 0xff,0xcc,33); + s.draw_state(400, 750, 2,NULL, 0xff,0xcc,33); + s.draw_state(70, 300, 3,NULL, 0xff,0xcc,33); s.draw_arrow(100,700,LEVEL*1,LEVEL*3); s.draw_arrow(200,400,LEVEL*2,LEVEL*2); -- GitLab