lemon/eps.h
changeset 1971 9a59a6cacfd9
child 2008 0820d8168cbb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lemon/eps.h	Mon Feb 20 06:41:12 2006 +0000
     1.3 @@ -0,0 +1,293 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2006
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#ifndef LEMON_EPS_H
    1.23 +#define LEMON_EPS_H
    1.24 +
    1.25 +#include<string>
    1.26 +#include<iostream>
    1.27 +#include<fstream>
    1.28 +#include<sstream>
    1.29 +#include<lemon/color.h>
    1.30 +#include<lemon/xy.h>
    1.31 +
    1.32 +  ///\ingroup io_group
    1.33 +  ///\file
    1.34 +  ///\brief Simple tool to create \c .eps files
    1.35 +  ///
    1.36 +  ///\author Alpar Juttner
    1.37 +
    1.38 +namespace lemon {
    1.39 +  
    1.40 +  ///\ingroup io_group
    1.41 +  ///\brief A simple tool to create \c .eps files
    1.42 +  ///
    1.43 +  ///A simple tool to create \c .eps files
    1.44 +  ///\author Alpar Juttner
    1.45 +  class EpsDrawer
    1.46 +  {
    1.47 +    void defMacros();
    1.48 +    void init(int x1,int y1,int x2,int y2);
    1.49 +    void init(double x1,double y1,double x2,double y2);
    1.50 +    bool local_stream;
    1.51 +  public:
    1.52 +    
    1.53 +    std::ostream &out;
    1.54 +    
    1.55 +    ///\e 
    1.56 +
    1.57 +    ///The generated file is put to \c os.
    1.58 +    ///
    1.59 +    /// \c x and \c y determine the upper
    1.60 +    ///right corner of the bounding box. The lower left corner is (0,0).
    1.61 +    EpsDrawer(std::ostream &os,int x,int y);
    1.62 +    ///\e
    1.63 +
    1.64 +    ///The generated file is put to \c os.
    1.65 +    ///
    1.66 +    ///(x1,y1) and (x2,y2)
    1.67 +    /// determine the lower left and the upper right corners of
    1.68 +    ///the bounding box, respectively.
    1.69 +    EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2);
    1.70 +    ///\e
    1.71 +
    1.72 +    ///The generated file is put to \c os.
    1.73 +    ///
    1.74 +    ///\c s determines the upper
    1.75 +    ///right corner of the bounding box. The lower left corner is (0,0).
    1.76 +    EpsDrawer(std::ostream &os,xy<double> s);
    1.77 +    ///\e
    1.78 +
    1.79 +    ///The generated file is put to \c os.
    1.80 +    ///
    1.81 +    ///\c a and \c b
    1.82 +    /// determine the lower left and the upper right corners of
    1.83 +    ///the bounding box, respectively.
    1.84 +    EpsDrawer(std::ostream &os,xy<double> a, xy<double> b);
    1.85 +    ///\e
    1.86 +
    1.87 +    ///The generated picture is put to the file \c name.
    1.88 +    ///
    1.89 +    ///\c x and \c y determine the upper
    1.90 +    ///right corner of the bounding box. The lower left corner is (0,0).
    1.91 +    EpsDrawer(const std::string &name,int x,int y);
    1.92 +    ///\e
    1.93 +
    1.94 +    ///The generated picture is put to the file \c name.
    1.95 +    ///
    1.96 +    ///(x1,y1) and (x2,y2)
    1.97 +    /// determine the lower left and the upper right corners of
    1.98 +    ///the bounding box, respectively.
    1.99 +    EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2);
   1.100 +    ///\e
   1.101 +
   1.102 +    ///The generated picture is put to the file \c name.
   1.103 +    ///
   1.104 +    ///\c s determines the upper
   1.105 +    ///right corner of the bounding box. The lower left corner is (0,0).
   1.106 +    EpsDrawer(const std::string &name,xy<double> s);
   1.107 +    ///\e
   1.108 +
   1.109 +    ///The generated picture is put to the file \c name.
   1.110 +    ///
   1.111 +    ///\c a and \c b
   1.112 +    /// determine the lower left and the upper right corners of
   1.113 +    ///the bounding box, respectively.
   1.114 +    EpsDrawer(const std::string &name,xy<double> a, xy<double> b);
   1.115 +
   1.116 +//     template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b) 
   1.117 +//     template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b);
   1.118 +    
   1.119 +    ~EpsDrawer();
   1.120 +    
   1.121 +    ///Save the current graphic state.
   1.122 +
   1.123 +    ///This function saves the current coordinate system, and the parameters
   1.124 +    ///set by \ref color(), \ref lineWidth() etc.
   1.125 +    ///The can be \ref restore "restore()"d later.
   1.126 +    ///
   1.127 +    ///The \ref save() - \ref restore() pairs can be nested.
   1.128 +    ///
   1.129 +    EpsDrawer &save();
   1.130 +    ///Restore the saves graphic state.
   1.131 +
   1.132 +    EpsDrawer &restore();
   1.133 +    
   1.134 +    ///Draw a line
   1.135 +    EpsDrawer &line(double x1,double y1,double x2,double y2);
   1.136 +    ///Draw a line from the current point
   1.137 +    EpsDrawer &lineTo(double x1,double y1);
   1.138 +    ///Move the current point
   1.139 +    EpsDrawer &moveTo(double x1,double y1);
   1.140 +    ///Draw a circle
   1.141 +    EpsDrawer &circle(double x,double y, double r);
   1.142 +    
   1.143 +    ///Draw a line
   1.144 +    template<class T> EpsDrawer &line(xy<T> p1,xy<T> p2) 
   1.145 +    {
   1.146 +      return line(p1.x,p1.y,p2.x,p2.y);
   1.147 +    }
   1.148 +    ///Draw a line from the current point
   1.149 +    template<class T> EpsDrawer &lineTo(xy<T> p)
   1.150 +    {
   1.151 +      return lineTo(p.x,p.y);
   1.152 +    }
   1.153 +    ///Move the current point
   1.154 +    template<class T> EpsDrawer &moveTo(xy<T> p)
   1.155 +    {
   1.156 +      return moveTo(p.x,p.y);
   1.157 +    }
   1.158 +    ///Draw a circle
   1.159 +    template<class T> EpsDrawer &circle(xy<T> p, double r)
   1.160 +    {
   1.161 +      return circle(p.x,p.y,r);
   1.162 +    }
   1.163 +    
   1.164 +    ///Set the font size
   1.165 +    EpsDrawer &fontSize(double si);
   1.166 +    ///Set the fint type
   1.167 +    EpsDrawer &font(std::string );
   1.168 +    ///Sets whether text output is centerized of not
   1.169 +
   1.170 +    ///Sets whether text output is centerized of not.
   1.171 +    ///
   1.172 +    ///\warning \ref save() doesn't save this setting.
   1.173 +    ///
   1.174 +    EpsDrawer &centerMode(bool m);
   1.175 +    ///Turn to collect mode.
   1.176 +
   1.177 +    ///If you call this function, then the drawing operations like \ref line(),
   1.178 +    ///\ref lineTo(), \ref moveTo() will not take place immediately, but istead
   1.179 +    ///they
   1.180 +    ///are collected. These operations form a \e path.
   1.181 +    ///Then you can \ref stroke(), \ref fill(), \ref eofill(), \ref clip() or
   1.182 +    ///\ref eoclip() it.
   1.183 +    ///When drawing, you can also use \ref closePath() to - surprise - close the
   1.184 +    ///current path.
   1.185 +    ///
   1.186 +    ///This example draws a red filled diamond.
   1.187 +    ///\code
   1.188 +    ///  EpsDraw ed("diamond.eps",-1,-1,1,1);
   1.189 +    ///  ed.color(1,0,0,).collect().line(0,-1,1,0).lineTo(0,1)
   1.190 +    ///    .lineTo(-1,0).closePath().fill();
   1.191 +    ///\endcode
   1.192 +    EpsDrawer &collect();
   1.193 +    ///Close the current drawing path
   1.194 +    EpsDrawer &closePath();
   1.195 +    ///Stroke (draw) a path
   1.196 +
   1.197 +    ///Stroke (draw) a path.
   1.198 +    ///\sa collect
   1.199 +    ///
   1.200 +    EpsDrawer &stroke();
   1.201 +    ///Fill a path
   1.202 +
   1.203 +    ///Fill a path.
   1.204 +    ///\sa collect
   1.205 +    ///
   1.206 +    EpsDrawer &fill();
   1.207 +    ///Even-odd fill a path
   1.208 +
   1.209 +    ///Even-odd fill a path.
   1.210 +    ///\sa collect
   1.211 +    ///
   1.212 +    EpsDrawer &eoFill();
   1.213 +    ///Set a clipping area.
   1.214 +
   1.215 +    ///This function sets a clipping area. After that, the drawing operations
   1.216 +    ///will affect only this area.
   1.217 +    ///\sa collect
   1.218 +    ///
   1.219 +    EpsDrawer &clip();
   1.220 +    ///Set a clipping area using even-odd rule.
   1.221 +
   1.222 +    ///This function sets a clipping area using even-odd rule.
   1.223 +    ///After that, the drawing operations
   1.224 +    ///will affect only this area.
   1.225 +    ///\sa collect
   1.226 +    ///
   1.227 +    EpsDrawer &eoClip();
   1.228 +    
   1.229 +    ///Set the line width.
   1.230 +    EpsDrawer &lineWidth(double w);
   1.231 +    ///Set the style of the line ends
   1.232 +
   1.233 +    ///\param i It can be 0, 1 or 2
   1.234 +    ///
   1.235 +    EpsDrawer &lineCap(int i);
   1.236 +    ///Set the style of the line joins
   1.237 +
   1.238 +    ///\param i It can be 0, 1 or 2
   1.239 +    ///
   1.240 +    EpsDrawer &lineJoin(int i);
   1.241 +    ///Set the cut length of near parallel joining lines.
   1.242 +    EpsDrawer &miterLimit(double w);
   1.243 +    
   1.244 +    ///Set the drawing color
   1.245 +    EpsDrawer &color(double r, double g, double b);
   1.246 +    ///Set the drawing color
   1.247 +    EpsDrawer &color(Color c)
   1.248 +    {
   1.249 +      return color(c.red(),c.green(),c.blue());
   1.250 +    }
   1.251 +    
   1.252 +    ///Translate the coordinate system
   1.253 +    EpsDrawer &translate(double x,double y);
   1.254 +    ///Translate the coordinate system
   1.255 +    template<class T> EpsDrawer &translate(xy<T> p)
   1.256 +    {
   1.257 +      return translate(p.x,p.y);
   1.258 +    }
   1.259 +    ///Rotate the coordinate system
   1.260 +    EpsDrawer &rotate(double r);
   1.261 +    ///Scale the coordinate system
   1.262 +    EpsDrawer &scale(double sx, double sy);
   1.263 +    ///Scale the coordinate system
   1.264 +    EpsDrawer &scale(double s) { return scale(s,s); }
   1.265 +    ///Scale the coordinate system
   1.266 +    template<class T> EpsDrawer &scale(xy<T> p)
   1.267 +    {
   1.268 +      return scale(p.x,p.y);
   1.269 +    }
   1.270 +    
   1.271 +    ///\e
   1.272 +    EpsDrawer &flush();
   1.273 +    ///Clear the image
   1.274 +    EpsDrawer &clear();
   1.275 +    
   1.276 +    ///Print a text at the current point
   1.277 +    EpsDrawer &operator<<(const std::string &s);
   1.278 +    ///Print a text at the current point
   1.279 +    EpsDrawer &operator<<(const char *s);
   1.280 +    ///Print a number at the current point
   1.281 +    EpsDrawer &operator<<(int i);
   1.282 +    ///Print a number at the current point
   1.283 +    EpsDrawer &operator<<(double d);
   1.284 +    ///Print a coordinate at the current point
   1.285 +    template<class T>
   1.286 +    EpsDrawer &operator<<(xy<T> p) 
   1.287 +    {
   1.288 +      out << "((" << p.x << ',' << p.y <<")) show\n";
   1.289 +      return *this;
   1.290 +    }
   1.291 +    
   1.292 +  };
   1.293 +  
   1.294 +}
   1.295 +
   1.296 +#endif