alpar@1971: /* -*- C++ -*- alpar@1971: * alpar@1971: * This file is a part of LEMON, a generic C++ optimization library alpar@1971: * alpar@2391: * Copyright (C) 2003-2007 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@2207: #include alpar@1971: deba@2084: ///\ingroup eps_io 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: deba@2084: ///\ingroup eps_io 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@2008: ///Node shapes alpar@2008: /// alpar@2008: enum NodeShapes { alpar@2008: /// = 0 alpar@2008: ///\image html nodeshape_0.png alpar@2008: ///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm alpar@2008: CIRCLE=0, alpar@2008: /// = 1 alpar@2008: ///\image html nodeshape_1.png alpar@2008: ///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm alpar@2008: /// alpar@2008: SQUARE=1, alpar@2008: /// = 2 alpar@2008: ///\image html nodeshape_2.png alpar@2008: ///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm alpar@2008: /// alpar@2008: DIAMOND=2, alpar@2008: /// = 3 alpar@2008: ///\image html nodeshape_3.png alpar@2008: ///\image latex nodeshape_2.eps "MALE shape (4)" width=2cm alpar@2008: /// alpar@2008: ///\warning Not implemented alpar@2008: MALE=3, alpar@2008: /// = 4 alpar@2008: ///\image html nodeshape_4.png alpar@2008: ///\image latex nodeshape_2.eps "FEMALE shape (4)" width=2cm alpar@2008: /// alpar@2008: ///\warning Not implemented alpar@2008: FEMALE=4 alpar@2008: }; 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@2207: EpsDrawer(std::ostream &os,dim2::Point 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@2207: EpsDrawer(std::ostream &os,dim2::Point a, dim2::Point 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@2207: EpsDrawer(const std::string &name,dim2::Point 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@2207: EpsDrawer(const std::string &name,dim2::Point a, dim2::Point 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@2207: template EpsDrawer &line(dim2::Point p1,dim2::Point 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@2207: template EpsDrawer &lineTo(dim2::Point p) alpar@1971: { alpar@1971: return lineTo(p.x,p.y); alpar@1971: } alpar@1971: ///Move the current point alpar@2207: template EpsDrawer &moveTo(dim2::Point p) alpar@1971: { alpar@1971: return moveTo(p.x,p.y); alpar@1971: } alpar@1971: ///Draw a circle alpar@2207: template EpsDrawer &circle(dim2::Point 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@2214: ///Then you can \ref stroke(), \ref fill(), \ref eoFill(), \ref clip() or alpar@2214: ///\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@2214: ///\sa collect() alpar@1971: /// alpar@1971: EpsDrawer &stroke(); alpar@1971: ///Fill a path alpar@1971: alpar@1971: ///Fill a path. alpar@2214: ///\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@2214: ///\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@2214: ///\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@2214: ///\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@2008: ///Draw a node shape alpar@2008: alpar@2008: ///Draw a node shape. alpar@2008: /// alpar@2008: ///\param t The shape of the drawn object alpar@2008: ///\param x The \c x coordinate of the node alpar@2008: ///\param y The \c y coordinate of the node alpar@2350: ///\param r The size (radius) of the node alpar@2008: ///\param col Color of the node. The default color is white alpar@2008: ///\param brd Color of the node border. The default color is black alpar@2008: EpsDrawer &node(NodeShapes t, double x, double y, double r, alpar@2174: Color col=WHITE, Color brd=BLACK); alpar@2008: ///Draw a node shape alpar@2008: alpar@2008: ///Draw a node shape. alpar@2008: /// alpar@2008: ///\param t The shape of the drawn object alpar@2008: ///\param pos Position of the node alpar@2350: ///\param r The size (radius) of the node alpar@2008: ///\param col Color of the node. The default color is white alpar@2008: ///\param brd Color of the node border. The default color is black alpar@2008: template alpar@2207: EpsDrawer &node(NodeShapes t, dim2::Point pos, double r, alpar@2174: Color col=WHITE, Color brd=BLACK) alpar@2008: { alpar@2008: return node(t,pos.x,pos.y,r,col,brd); alpar@2008: } alpar@2008: alpar@1971: ///Translate the coordinate system alpar@1971: EpsDrawer &translate(double x,double y); alpar@1971: ///Translate the coordinate system alpar@2207: template EpsDrawer &translate(dim2::Point 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@2207: template EpsDrawer &scale(dim2::Point 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@2207: EpsDrawer &operator<<(dim2::Point 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