"Node shapes" added
authoralpar
Wed, 15 Mar 2006 09:45:59 +0000
changeset 20080820d8168cbb
parent 2007 a9959afc29a3
child 2009 de287863cc98
"Node shapes" added
demo/eps_demo.cc
lemon/eps.cc
lemon/eps.h
     1.1 --- a/demo/eps_demo.cc	Wed Mar 15 09:45:10 2006 +0000
     1.2 +++ b/demo/eps_demo.cc	Wed Mar 15 09:45:59 2006 +0000
     1.3 @@ -106,5 +106,10 @@
     1.4    
     1.5    fonts(ed.color(.7,.7,.7));
     1.6    ed.color(0,1,0);
     1.7 +
     1.8 +  ed.node(ed.CIRCLE,128,333,25);
     1.9 +  ed.node(ed.SQUARE,256,333,25);
    1.10 +  ed.node(ed.DIAMOND,128+256,333,25);
    1.11 +
    1.12    kosar(ed);
    1.13  }
     2.1 --- a/lemon/eps.cc	Wed Mar 15 09:45:10 2006 +0000
     2.2 +++ b/lemon/eps.cc	Wed Mar 15 09:45:59 2006 +0000
     2.3 @@ -298,4 +298,66 @@
     2.4      return *this;
     2.5    }
     2.6  
     2.7 +  EpsDrawer &EpsDrawer::node(NodeShapes t, double x, double y, double r,
     2.8 +			     Color col, Color brd)
     2.9 +  {
    2.10 +    out << "gsave\n"
    2.11 +	<< brd.red() << ' ' << brd.green() << ' ' << brd.blue() 
    2.12 +	<< " setrgbcolor\n";
    2.13 +    switch(t) {
    2.14 +    case CIRCLE:
    2.15 +      out << "newpath " << x << ' ' << y << ' ' << r 
    2.16 +	  << " dup 3 index add 2 index moveto 0 360 arc fill\n";
    2.17 +      break;
    2.18 +    case SQUARE:
    2.19 +      out << "newpath\n"
    2.20 +	  << x-r << ' ' << y-r << " moveto\n"
    2.21 +	  << x-r << ' ' << y+r << " lineto\n"
    2.22 +	  << x+r << ' ' << y+r << " lineto\n"
    2.23 +	  << x+r << ' ' << y-r << " lineto closepath fill\n";
    2.24 +      break;
    2.25 +    case DIAMOND:
    2.26 +      out << "newpath\n"
    2.27 +	  << x-r << ' ' << y   << " moveto\n"
    2.28 +	  << x   << ' ' << y+r << " lineto\n"
    2.29 +	  << x+r << ' ' << y   << " lineto\n"
    2.30 +	  << x   << ' ' << y-r << " lineto closepath fill\n";
    2.31 +      break;
    2.32 +    case MALE:
    2.33 +      break;
    2.34 +    case FEMALE:
    2.35 +      break;
    2.36 +    }
    2.37 +    r/=1.1;
    2.38 +    out << col.red() << ' ' << col.green() << ' ' << col.blue() 
    2.39 +	<< " setrgbcolor\n";
    2.40 +    switch(t) {
    2.41 +    case CIRCLE:
    2.42 +      out << "newpath " << x << ' ' << y << ' ' << r 
    2.43 +	  << " dup 3 index add 2 index moveto 0 360 arc fill\n";
    2.44 +      break;
    2.45 +    case SQUARE:
    2.46 +      out << "newpath\n"
    2.47 +	  << x-r << ' ' << y-r << " moveto\n"
    2.48 +	  << x-r << ' ' << y+r << " lineto\n"
    2.49 +	  << x+r << ' ' << y+r << " lineto\n"
    2.50 +	  << x+r << ' ' << y-r << " lineto closepath fill\n";
    2.51 +      break;
    2.52 +    case DIAMOND:
    2.53 +      out << "newpath\n"
    2.54 +	  << x-r << ' ' << y   << " moveto\n"
    2.55 +	  << x   << ' ' << y+r << " lineto\n"
    2.56 +	  << x+r << ' ' << y   << " lineto\n"
    2.57 +	  << x   << ' ' << y-r << " lineto closepath fill\n";
    2.58 +      break;
    2.59 +    case MALE:
    2.60 +      break;
    2.61 +    case FEMALE:
    2.62 +      break;
    2.63 +    }
    2.64 +
    2.65 +    out << "grestore\n";
    2.66 +    return *this;
    2.67 +  }
    2.68 +  
    2.69  }
     3.1 --- a/lemon/eps.h	Wed Mar 15 09:45:10 2006 +0000
     3.2 +++ b/lemon/eps.h	Wed Mar 15 09:45:59 2006 +0000
     3.3 @@ -49,6 +49,36 @@
     3.4      
     3.5      std::ostream &out;
     3.6      
     3.7 +    ///Node shapes
     3.8 +    ///
     3.9 +    enum NodeShapes { 
    3.10 +      /// = 0
    3.11 +      ///\image html nodeshape_0.png
    3.12 +      ///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm
    3.13 +      CIRCLE=0, 
    3.14 +      /// = 1
    3.15 +      ///\image html nodeshape_1.png
    3.16 +      ///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm
    3.17 +      ///
    3.18 +      SQUARE=1, 
    3.19 +      /// = 2
    3.20 +      ///\image html nodeshape_2.png
    3.21 +      ///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm
    3.22 +      ///
    3.23 +      DIAMOND=2,
    3.24 +      /// = 3
    3.25 +      ///\image html nodeshape_3.png
    3.26 +      ///\image latex nodeshape_2.eps "MALE shape (4)" width=2cm
    3.27 +      ///
    3.28 +      ///\warning Not implemented
    3.29 +      MALE=3,
    3.30 +      /// = 4
    3.31 +      ///\image html nodeshape_4.png
    3.32 +      ///\image latex nodeshape_2.eps "FEMALE shape (4)" width=2cm
    3.33 +      ///
    3.34 +      ///\warning Not implemented
    3.35 +      FEMALE=4
    3.36 +    };
    3.37      ///\e 
    3.38  
    3.39      ///The generated file is put to \c os.
    3.40 @@ -246,6 +276,32 @@
    3.41        return color(c.red(),c.green(),c.blue());
    3.42      }
    3.43      
    3.44 +    ///Draw a node shape
    3.45 +
    3.46 +    ///Draw a node shape.
    3.47 +    ///
    3.48 +    ///\param t The shape of the drawn object
    3.49 +    ///\param x The \c x coordinate of the node
    3.50 +    ///\param y The \c y coordinate of the node
    3.51 +    ///\param col Color of the node. The default color is white
    3.52 +    ///\param brd Color of the node border. The default color is black
    3.53 +    EpsDrawer &node(NodeShapes t, double x, double y, double r,
    3.54 +		    Color col=Color(1,1,1), Color brd=Color(0,0,0));
    3.55 +    ///Draw a node shape
    3.56 +    
    3.57 +    ///Draw a node shape.
    3.58 +    ///
    3.59 +    ///\param t The shape of the drawn object
    3.60 +    ///\param pos Position of the node
    3.61 +    ///\param col Color of the node. The default color is white
    3.62 +    ///\param brd Color of the node border. The default color is black
    3.63 +    template<class T>
    3.64 +    EpsDrawer &node(NodeShapes t, xy<T> pos, double r,
    3.65 +		    Color col=Color(1,1,1), Color brd=Color(0,0,0))
    3.66 +    {
    3.67 +      return node(t,pos.x,pos.y,r,col,brd);
    3.68 +    }
    3.69 +
    3.70      ///Translate the coordinate system
    3.71      EpsDrawer &translate(double x,double y);
    3.72      ///Translate the coordinate system