# HG changeset patch # User alpar # Date 1142415959 0 # Node ID 0820d8168cbba966a86e6606ccd7ec548b146fa0 # Parent a9959afc29a30199d89085db171209efb71a8e9b "Node shapes" added diff -r a9959afc29a3 -r 0820d8168cbb demo/eps_demo.cc --- a/demo/eps_demo.cc Wed Mar 15 09:45:10 2006 +0000 +++ b/demo/eps_demo.cc Wed Mar 15 09:45:59 2006 +0000 @@ -106,5 +106,10 @@ fonts(ed.color(.7,.7,.7)); ed.color(0,1,0); + + ed.node(ed.CIRCLE,128,333,25); + ed.node(ed.SQUARE,256,333,25); + ed.node(ed.DIAMOND,128+256,333,25); + kosar(ed); } diff -r a9959afc29a3 -r 0820d8168cbb lemon/eps.cc --- a/lemon/eps.cc Wed Mar 15 09:45:10 2006 +0000 +++ b/lemon/eps.cc Wed Mar 15 09:45:59 2006 +0000 @@ -298,4 +298,66 @@ return *this; } + EpsDrawer &EpsDrawer::node(NodeShapes t, double x, double y, double r, + Color col, Color brd) + { + out << "gsave\n" + << brd.red() << ' ' << brd.green() << ' ' << brd.blue() + << " setrgbcolor\n"; + switch(t) { + case CIRCLE: + out << "newpath " << x << ' ' << y << ' ' << r + << " dup 3 index add 2 index moveto 0 360 arc fill\n"; + break; + case SQUARE: + out << "newpath\n" + << x-r << ' ' << y-r << " moveto\n" + << x-r << ' ' << y+r << " lineto\n" + << x+r << ' ' << y+r << " lineto\n" + << x+r << ' ' << y-r << " lineto closepath fill\n"; + break; + case DIAMOND: + out << "newpath\n" + << x-r << ' ' << y << " moveto\n" + << x << ' ' << y+r << " lineto\n" + << x+r << ' ' << y << " lineto\n" + << x << ' ' << y-r << " lineto closepath fill\n"; + break; + case MALE: + break; + case FEMALE: + break; + } + r/=1.1; + out << col.red() << ' ' << col.green() << ' ' << col.blue() + << " setrgbcolor\n"; + switch(t) { + case CIRCLE: + out << "newpath " << x << ' ' << y << ' ' << r + << " dup 3 index add 2 index moveto 0 360 arc fill\n"; + break; + case SQUARE: + out << "newpath\n" + << x-r << ' ' << y-r << " moveto\n" + << x-r << ' ' << y+r << " lineto\n" + << x+r << ' ' << y+r << " lineto\n" + << x+r << ' ' << y-r << " lineto closepath fill\n"; + break; + case DIAMOND: + out << "newpath\n" + << x-r << ' ' << y << " moveto\n" + << x << ' ' << y+r << " lineto\n" + << x+r << ' ' << y << " lineto\n" + << x << ' ' << y-r << " lineto closepath fill\n"; + break; + case MALE: + break; + case FEMALE: + break; + } + + out << "grestore\n"; + return *this; + } + } diff -r a9959afc29a3 -r 0820d8168cbb lemon/eps.h --- a/lemon/eps.h Wed Mar 15 09:45:10 2006 +0000 +++ b/lemon/eps.h Wed Mar 15 09:45:59 2006 +0000 @@ -49,6 +49,36 @@ std::ostream &out; + ///Node shapes + /// + enum NodeShapes { + /// = 0 + ///\image html nodeshape_0.png + ///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm + CIRCLE=0, + /// = 1 + ///\image html nodeshape_1.png + ///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm + /// + SQUARE=1, + /// = 2 + ///\image html nodeshape_2.png + ///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm + /// + DIAMOND=2, + /// = 3 + ///\image html nodeshape_3.png + ///\image latex nodeshape_2.eps "MALE shape (4)" width=2cm + /// + ///\warning Not implemented + MALE=3, + /// = 4 + ///\image html nodeshape_4.png + ///\image latex nodeshape_2.eps "FEMALE shape (4)" width=2cm + /// + ///\warning Not implemented + FEMALE=4 + }; ///\e ///The generated file is put to \c os. @@ -246,6 +276,32 @@ return color(c.red(),c.green(),c.blue()); } + ///Draw a node shape + + ///Draw a node shape. + /// + ///\param t The shape of the drawn object + ///\param x The \c x coordinate of the node + ///\param y The \c y coordinate of the node + ///\param col Color of the node. The default color is white + ///\param brd Color of the node border. The default color is black + EpsDrawer &node(NodeShapes t, double x, double y, double r, + Color col=Color(1,1,1), Color brd=Color(0,0,0)); + ///Draw a node shape + + ///Draw a node shape. + /// + ///\param t The shape of the drawn object + ///\param pos Position of the node + ///\param col Color of the node. The default color is white + ///\param brd Color of the node border. The default color is black + template + EpsDrawer &node(NodeShapes t, xy pos, double r, + Color col=Color(1,1,1), Color brd=Color(0,0,0)) + { + return node(t,pos.x,pos.y,r,col,brd); + } + ///Translate the coordinate system EpsDrawer &translate(double x,double y); ///Translate the coordinate system