lemon/eps.h
author deba
Fri, 03 Mar 2006 12:35:32 +0000
changeset 1996 5dc13b93f8b4
child 2008 0820d8168cbb
permissions -rw-r--r--
Some documentation arrangement modification
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #ifndef LEMON_EPS_H
    20 #define LEMON_EPS_H
    21 
    22 #include<string>
    23 #include<iostream>
    24 #include<fstream>
    25 #include<sstream>
    26 #include<lemon/color.h>
    27 #include<lemon/xy.h>
    28 
    29   ///\ingroup io_group
    30   ///\file
    31   ///\brief Simple tool to create \c .eps files
    32   ///
    33   ///\author Alpar Juttner
    34 
    35 namespace lemon {
    36   
    37   ///\ingroup io_group
    38   ///\brief A simple tool to create \c .eps files
    39   ///
    40   ///A simple tool to create \c .eps files
    41   ///\author Alpar Juttner
    42   class EpsDrawer
    43   {
    44     void defMacros();
    45     void init(int x1,int y1,int x2,int y2);
    46     void init(double x1,double y1,double x2,double y2);
    47     bool local_stream;
    48   public:
    49     
    50     std::ostream &out;
    51     
    52     ///\e 
    53 
    54     ///The generated file is put to \c os.
    55     ///
    56     /// \c x and \c y determine the upper
    57     ///right corner of the bounding box. The lower left corner is (0,0).
    58     EpsDrawer(std::ostream &os,int x,int y);
    59     ///\e
    60 
    61     ///The generated file is put to \c os.
    62     ///
    63     ///(x1,y1) and (x2,y2)
    64     /// determine the lower left and the upper right corners of
    65     ///the bounding box, respectively.
    66     EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2);
    67     ///\e
    68 
    69     ///The generated file is put to \c os.
    70     ///
    71     ///\c s determines the upper
    72     ///right corner of the bounding box. The lower left corner is (0,0).
    73     EpsDrawer(std::ostream &os,xy<double> s);
    74     ///\e
    75 
    76     ///The generated file is put to \c os.
    77     ///
    78     ///\c a and \c b
    79     /// determine the lower left and the upper right corners of
    80     ///the bounding box, respectively.
    81     EpsDrawer(std::ostream &os,xy<double> a, xy<double> b);
    82     ///\e
    83 
    84     ///The generated picture is put to the file \c name.
    85     ///
    86     ///\c x and \c y determine the upper
    87     ///right corner of the bounding box. The lower left corner is (0,0).
    88     EpsDrawer(const std::string &name,int x,int y);
    89     ///\e
    90 
    91     ///The generated picture is put to the file \c name.
    92     ///
    93     ///(x1,y1) and (x2,y2)
    94     /// determine the lower left and the upper right corners of
    95     ///the bounding box, respectively.
    96     EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2);
    97     ///\e
    98 
    99     ///The generated picture is put to the file \c name.
   100     ///
   101     ///\c s determines the upper
   102     ///right corner of the bounding box. The lower left corner is (0,0).
   103     EpsDrawer(const std::string &name,xy<double> s);
   104     ///\e
   105 
   106     ///The generated picture is put to the file \c name.
   107     ///
   108     ///\c a and \c b
   109     /// determine the lower left and the upper right corners of
   110     ///the bounding box, respectively.
   111     EpsDrawer(const std::string &name,xy<double> a, xy<double> b);
   112 
   113 //     template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b) 
   114 //     template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b);
   115     
   116     ~EpsDrawer();
   117     
   118     ///Save the current graphic state.
   119 
   120     ///This function saves the current coordinate system, and the parameters
   121     ///set by \ref color(), \ref lineWidth() etc.
   122     ///The can be \ref restore "restore()"d later.
   123     ///
   124     ///The \ref save() - \ref restore() pairs can be nested.
   125     ///
   126     EpsDrawer &save();
   127     ///Restore the saves graphic state.
   128 
   129     EpsDrawer &restore();
   130     
   131     ///Draw a line
   132     EpsDrawer &line(double x1,double y1,double x2,double y2);
   133     ///Draw a line from the current point
   134     EpsDrawer &lineTo(double x1,double y1);
   135     ///Move the current point
   136     EpsDrawer &moveTo(double x1,double y1);
   137     ///Draw a circle
   138     EpsDrawer &circle(double x,double y, double r);
   139     
   140     ///Draw a line
   141     template<class T> EpsDrawer &line(xy<T> p1,xy<T> p2) 
   142     {
   143       return line(p1.x,p1.y,p2.x,p2.y);
   144     }
   145     ///Draw a line from the current point
   146     template<class T> EpsDrawer &lineTo(xy<T> p)
   147     {
   148       return lineTo(p.x,p.y);
   149     }
   150     ///Move the current point
   151     template<class T> EpsDrawer &moveTo(xy<T> p)
   152     {
   153       return moveTo(p.x,p.y);
   154     }
   155     ///Draw a circle
   156     template<class T> EpsDrawer &circle(xy<T> p, double r)
   157     {
   158       return circle(p.x,p.y,r);
   159     }
   160     
   161     ///Set the font size
   162     EpsDrawer &fontSize(double si);
   163     ///Set the fint type
   164     EpsDrawer &font(std::string );
   165     ///Sets whether text output is centerized of not
   166 
   167     ///Sets whether text output is centerized of not.
   168     ///
   169     ///\warning \ref save() doesn't save this setting.
   170     ///
   171     EpsDrawer &centerMode(bool m);
   172     ///Turn to collect mode.
   173 
   174     ///If you call this function, then the drawing operations like \ref line(),
   175     ///\ref lineTo(), \ref moveTo() will not take place immediately, but istead
   176     ///they
   177     ///are collected. These operations form a \e path.
   178     ///Then you can \ref stroke(), \ref fill(), \ref eofill(), \ref clip() or
   179     ///\ref eoclip() it.
   180     ///When drawing, you can also use \ref closePath() to - surprise - close the
   181     ///current path.
   182     ///
   183     ///This example draws a red filled diamond.
   184     ///\code
   185     ///  EpsDraw ed("diamond.eps",-1,-1,1,1);
   186     ///  ed.color(1,0,0,).collect().line(0,-1,1,0).lineTo(0,1)
   187     ///    .lineTo(-1,0).closePath().fill();
   188     ///\endcode
   189     EpsDrawer &collect();
   190     ///Close the current drawing path
   191     EpsDrawer &closePath();
   192     ///Stroke (draw) a path
   193 
   194     ///Stroke (draw) a path.
   195     ///\sa collect
   196     ///
   197     EpsDrawer &stroke();
   198     ///Fill a path
   199 
   200     ///Fill a path.
   201     ///\sa collect
   202     ///
   203     EpsDrawer &fill();
   204     ///Even-odd fill a path
   205 
   206     ///Even-odd fill a path.
   207     ///\sa collect
   208     ///
   209     EpsDrawer &eoFill();
   210     ///Set a clipping area.
   211 
   212     ///This function sets a clipping area. After that, the drawing operations
   213     ///will affect only this area.
   214     ///\sa collect
   215     ///
   216     EpsDrawer &clip();
   217     ///Set a clipping area using even-odd rule.
   218 
   219     ///This function sets a clipping area using even-odd rule.
   220     ///After that, the drawing operations
   221     ///will affect only this area.
   222     ///\sa collect
   223     ///
   224     EpsDrawer &eoClip();
   225     
   226     ///Set the line width.
   227     EpsDrawer &lineWidth(double w);
   228     ///Set the style of the line ends
   229 
   230     ///\param i It can be 0, 1 or 2
   231     ///
   232     EpsDrawer &lineCap(int i);
   233     ///Set the style of the line joins
   234 
   235     ///\param i It can be 0, 1 or 2
   236     ///
   237     EpsDrawer &lineJoin(int i);
   238     ///Set the cut length of near parallel joining lines.
   239     EpsDrawer &miterLimit(double w);
   240     
   241     ///Set the drawing color
   242     EpsDrawer &color(double r, double g, double b);
   243     ///Set the drawing color
   244     EpsDrawer &color(Color c)
   245     {
   246       return color(c.red(),c.green(),c.blue());
   247     }
   248     
   249     ///Translate the coordinate system
   250     EpsDrawer &translate(double x,double y);
   251     ///Translate the coordinate system
   252     template<class T> EpsDrawer &translate(xy<T> p)
   253     {
   254       return translate(p.x,p.y);
   255     }
   256     ///Rotate the coordinate system
   257     EpsDrawer &rotate(double r);
   258     ///Scale the coordinate system
   259     EpsDrawer &scale(double sx, double sy);
   260     ///Scale the coordinate system
   261     EpsDrawer &scale(double s) { return scale(s,s); }
   262     ///Scale the coordinate system
   263     template<class T> EpsDrawer &scale(xy<T> p)
   264     {
   265       return scale(p.x,p.y);
   266     }
   267     
   268     ///\e
   269     EpsDrawer &flush();
   270     ///Clear the image
   271     EpsDrawer &clear();
   272     
   273     ///Print a text at the current point
   274     EpsDrawer &operator<<(const std::string &s);
   275     ///Print a text at the current point
   276     EpsDrawer &operator<<(const char *s);
   277     ///Print a number at the current point
   278     EpsDrawer &operator<<(int i);
   279     ///Print a number at the current point
   280     EpsDrawer &operator<<(double d);
   281     ///Print a coordinate at the current point
   282     template<class T>
   283     EpsDrawer &operator<<(xy<T> p) 
   284     {
   285       out << "((" << p.x << ',' << p.y <<")) show\n";
   286       return *this;
   287     }
   288     
   289   };
   290   
   291 }
   292 
   293 #endif