alpar@1971: /* -*- C++ -*- alpar@1971: * alpar@1971: * This file is a part of LEMON, a generic C++ optimization library alpar@1971: * alpar@1971: * Copyright (C) 2003-2006 alpar@1971: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1971: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@1971: * alpar@1971: * Permission to use, modify and distribute this software is granted alpar@1971: * provided that this copyright notice appears in all copies. For alpar@1971: * precise terms see the accompanying LICENSE file. alpar@1971: * alpar@1971: * This software is provided "AS IS" with no warranty of any kind, alpar@1971: * express or implied, and with no claim as to its suitability for any alpar@1971: * purpose. alpar@1971: * alpar@1971: */ alpar@1971: alpar@1971: #ifndef LEMON_EPS_H alpar@1971: #define LEMON_EPS_H alpar@1971: alpar@1971: #include alpar@1971: #include alpar@1971: #include alpar@1971: #include alpar@1971: #include alpar@1971: #include alpar@1971: alpar@1971: ///\ingroup io_group alpar@1971: ///\file alpar@1971: ///\brief Simple tool to create \c .eps files alpar@1971: /// alpar@1971: ///\author Alpar Juttner alpar@1971: alpar@1971: namespace lemon { alpar@1971: alpar@1971: ///\ingroup io_group alpar@1971: ///\brief A simple tool to create \c .eps files alpar@1971: /// alpar@1971: ///A simple tool to create \c .eps files alpar@1971: ///\author Alpar Juttner alpar@1971: class EpsDrawer alpar@1971: { alpar@1971: void defMacros(); alpar@1971: void init(int x1,int y1,int x2,int y2); alpar@1971: void init(double x1,double y1,double x2,double y2); alpar@1971: bool local_stream; alpar@1971: public: alpar@1971: alpar@1971: std::ostream &out; alpar@1971: alpar@1971: ///\e alpar@1971: alpar@1971: ///The generated file is put to \c os. alpar@1971: /// alpar@1971: /// \c x and \c y determine the upper alpar@1971: ///right corner of the bounding box. The lower left corner is (0,0). alpar@1971: EpsDrawer(std::ostream &os,int x,int y); alpar@1971: ///\e alpar@1971: alpar@1971: ///The generated file is put to \c os. alpar@1971: /// alpar@1971: ///(x1,y1) and (x2,y2) alpar@1971: /// determine the lower left and the upper right corners of alpar@1971: ///the bounding box, respectively. alpar@1971: EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2); alpar@1971: ///\e alpar@1971: alpar@1971: ///The generated file is put to \c os. alpar@1971: /// alpar@1971: ///\c s determines the upper alpar@1971: ///right corner of the bounding box. The lower left corner is (0,0). alpar@1971: EpsDrawer(std::ostream &os,xy s); alpar@1971: ///\e alpar@1971: alpar@1971: ///The generated file is put to \c os. alpar@1971: /// alpar@1971: ///\c a and \c b alpar@1971: /// determine the lower left and the upper right corners of alpar@1971: ///the bounding box, respectively. alpar@1971: EpsDrawer(std::ostream &os,xy a, xy b); alpar@1971: ///\e alpar@1971: alpar@1971: ///The generated picture is put to the file \c name. alpar@1971: /// alpar@1971: ///\c x and \c y determine the upper alpar@1971: ///right corner of the bounding box. The lower left corner is (0,0). alpar@1971: EpsDrawer(const std::string &name,int x,int y); alpar@1971: ///\e alpar@1971: alpar@1971: ///The generated picture is put to the file \c name. alpar@1971: /// alpar@1971: ///(x1,y1) and (x2,y2) alpar@1971: /// determine the lower left and the upper right corners of alpar@1971: ///the bounding box, respectively. alpar@1971: EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2); alpar@1971: ///\e alpar@1971: alpar@1971: ///The generated picture is put to the file \c name. alpar@1971: /// alpar@1971: ///\c s determines the upper alpar@1971: ///right corner of the bounding box. The lower left corner is (0,0). alpar@1971: EpsDrawer(const std::string &name,xy s); alpar@1971: ///\e alpar@1971: alpar@1971: ///The generated picture is put to the file \c name. alpar@1971: /// alpar@1971: ///\c a and \c b alpar@1971: /// determine the lower left and the upper right corners of alpar@1971: ///the bounding box, respectively. alpar@1971: EpsDrawer(const std::string &name,xy a, xy b); alpar@1971: alpar@1971: // template EpsDrawer(std::ostream &os,BoundingBox b) alpar@1971: // template EpsDrawer(std::ostream &os,BoundingBox b); alpar@1971: alpar@1971: ~EpsDrawer(); alpar@1971: alpar@1971: ///Save the current graphic state. alpar@1971: alpar@1971: ///This function saves the current coordinate system, and the parameters alpar@1971: ///set by \ref color(), \ref lineWidth() etc. alpar@1971: ///The can be \ref restore "restore()"d later. alpar@1971: /// alpar@1971: ///The \ref save() - \ref restore() pairs can be nested. alpar@1971: /// alpar@1971: EpsDrawer &save(); alpar@1971: ///Restore the saves graphic state. alpar@1971: alpar@1971: EpsDrawer &restore(); alpar@1971: alpar@1971: ///Draw a line alpar@1971: EpsDrawer &line(double x1,double y1,double x2,double y2); alpar@1971: ///Draw a line from the current point alpar@1971: EpsDrawer &lineTo(double x1,double y1); alpar@1971: ///Move the current point alpar@1971: EpsDrawer &moveTo(double x1,double y1); alpar@1971: ///Draw a circle alpar@1971: EpsDrawer &circle(double x,double y, double r); alpar@1971: alpar@1971: ///Draw a line alpar@1971: template EpsDrawer &line(xy p1,xy p2) alpar@1971: { alpar@1971: return line(p1.x,p1.y,p2.x,p2.y); alpar@1971: } alpar@1971: ///Draw a line from the current point alpar@1971: template EpsDrawer &lineTo(xy p) alpar@1971: { alpar@1971: return lineTo(p.x,p.y); alpar@1971: } alpar@1971: ///Move the current point alpar@1971: template EpsDrawer &moveTo(xy p) alpar@1971: { alpar@1971: return moveTo(p.x,p.y); alpar@1971: } alpar@1971: ///Draw a circle alpar@1971: template EpsDrawer &circle(xy p, double r) alpar@1971: { alpar@1971: return circle(p.x,p.y,r); alpar@1971: } alpar@1971: alpar@1971: ///Set the font size alpar@1971: EpsDrawer &fontSize(double si); alpar@1971: ///Set the fint type alpar@1971: EpsDrawer &font(std::string ); alpar@1971: ///Sets whether text output is centerized of not alpar@1971: alpar@1971: ///Sets whether text output is centerized of not. alpar@1971: /// alpar@1971: ///\warning \ref save() doesn't save this setting. alpar@1971: /// alpar@1971: EpsDrawer ¢erMode(bool m); alpar@1971: ///Turn to collect mode. alpar@1971: alpar@1971: ///If you call this function, then the drawing operations like \ref line(), alpar@1971: ///\ref lineTo(), \ref moveTo() will not take place immediately, but istead alpar@1971: ///they alpar@1971: ///are collected. These operations form a \e path. alpar@1971: ///Then you can \ref stroke(), \ref fill(), \ref eofill(), \ref clip() or alpar@1971: ///\ref eoclip() it. alpar@1971: ///When drawing, you can also use \ref closePath() to - surprise - close the alpar@1971: ///current path. alpar@1971: /// alpar@1971: ///This example draws a red filled diamond. alpar@1971: ///\code alpar@1971: /// EpsDraw ed("diamond.eps",-1,-1,1,1); alpar@1971: /// ed.color(1,0,0,).collect().line(0,-1,1,0).lineTo(0,1) alpar@1971: /// .lineTo(-1,0).closePath().fill(); alpar@1971: ///\endcode alpar@1971: EpsDrawer &collect(); alpar@1971: ///Close the current drawing path alpar@1971: EpsDrawer &closePath(); alpar@1971: ///Stroke (draw) a path alpar@1971: alpar@1971: ///Stroke (draw) a path. alpar@1971: ///\sa collect alpar@1971: /// alpar@1971: EpsDrawer &stroke(); alpar@1971: ///Fill a path alpar@1971: alpar@1971: ///Fill a path. alpar@1971: ///\sa collect alpar@1971: /// alpar@1971: EpsDrawer &fill(); alpar@1971: ///Even-odd fill a path alpar@1971: alpar@1971: ///Even-odd fill a path. alpar@1971: ///\sa collect alpar@1971: /// alpar@1971: EpsDrawer &eoFill(); alpar@1971: ///Set a clipping area. alpar@1971: alpar@1971: ///This function sets a clipping area. After that, the drawing operations alpar@1971: ///will affect only this area. alpar@1971: ///\sa collect alpar@1971: /// alpar@1971: EpsDrawer &clip(); alpar@1971: ///Set a clipping area using even-odd rule. alpar@1971: alpar@1971: ///This function sets a clipping area using even-odd rule. alpar@1971: ///After that, the drawing operations alpar@1971: ///will affect only this area. alpar@1971: ///\sa collect alpar@1971: /// alpar@1971: EpsDrawer &eoClip(); alpar@1971: alpar@1971: ///Set the line width. alpar@1971: EpsDrawer &lineWidth(double w); alpar@1971: ///Set the style of the line ends alpar@1971: alpar@1971: ///\param i It can be 0, 1 or 2 alpar@1971: /// alpar@1971: EpsDrawer &lineCap(int i); alpar@1971: ///Set the style of the line joins alpar@1971: alpar@1971: ///\param i It can be 0, 1 or 2 alpar@1971: /// alpar@1971: EpsDrawer &lineJoin(int i); alpar@1971: ///Set the cut length of near parallel joining lines. alpar@1971: EpsDrawer &miterLimit(double w); alpar@1971: alpar@1971: ///Set the drawing color alpar@1971: EpsDrawer &color(double r, double g, double b); alpar@1971: ///Set the drawing color alpar@1971: EpsDrawer &color(Color c) alpar@1971: { alpar@1971: return color(c.red(),c.green(),c.blue()); alpar@1971: } alpar@1971: alpar@1971: ///Translate the coordinate system alpar@1971: EpsDrawer &translate(double x,double y); alpar@1971: ///Translate the coordinate system alpar@1971: template EpsDrawer &translate(xy p) alpar@1971: { alpar@1971: return translate(p.x,p.y); alpar@1971: } alpar@1971: ///Rotate the coordinate system alpar@1971: EpsDrawer &rotate(double r); alpar@1971: ///Scale the coordinate system alpar@1971: EpsDrawer &scale(double sx, double sy); alpar@1971: ///Scale the coordinate system alpar@1971: EpsDrawer &scale(double s) { return scale(s,s); } alpar@1971: ///Scale the coordinate system alpar@1971: template EpsDrawer &scale(xy p) alpar@1971: { alpar@1971: return scale(p.x,p.y); alpar@1971: } alpar@1971: alpar@1971: ///\e alpar@1971: EpsDrawer &flush(); alpar@1971: ///Clear the image alpar@1971: EpsDrawer &clear(); alpar@1971: alpar@1971: ///Print a text at the current point alpar@1971: EpsDrawer &operator<<(const std::string &s); alpar@1971: ///Print a text at the current point alpar@1971: EpsDrawer &operator<<(const char *s); alpar@1971: ///Print a number at the current point alpar@1971: EpsDrawer &operator<<(int i); alpar@1971: ///Print a number at the current point alpar@1971: EpsDrawer &operator<<(double d); alpar@1971: ///Print a coordinate at the current point alpar@1971: template alpar@1971: EpsDrawer &operator<<(xy p) alpar@1971: { alpar@1971: out << "((" << p.x << ',' << p.y <<")) show\n"; alpar@1971: return *this; alpar@1971: } alpar@1971: alpar@1971: }; alpar@1971: alpar@1971: } alpar@1971: alpar@1971: #endif