gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Changes in interface and internals of graph_to_eps.h
0 1 0
default
1 file changed with 17 insertions and 14 deletions:
↑ Collapse diff ↑
Ignore white space 32 line context
... ...
@@ -36,43 +36,45 @@
36 36
#include<lemon/math.h>
37 37
#include<lemon/bits/invalid.h>
38 38
#include<lemon/dim2.h>
39 39
#include<lemon/maps.h>
40 40
#include<lemon/color.h>
41 41
#include<lemon/bits/bezier.h>
42 42

	
43 43

	
44 44
///\ingroup eps_io
45 45
///\file
46 46
///\brief Simple graph drawer
47 47
///
48 48
///\author Alpar Juttner
49 49

	
50 50
namespace lemon {
51 51

	
52
template<class MT>
53
class _NegY {
54
public:
55
  typedef typename MT::Key Key;
56
  typedef typename MT::Value Value;
57
  const MT &map;
58
  int yscale;
59
  _NegY(const MT &m,bool b) : map(m), yscale(1-b*2) {}
60
  Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);}
61
};
62

	
52
  namespace _graph_to_eps_bits {
53
    template<class MT>
54
    class _NegY {
55
    public:
56
      typedef typename MT::Key Key;
57
      typedef typename MT::Value Value;
58
      const MT &map;
59
      int yscale;
60
      _NegY(const MT &m,bool b) : map(m), yscale(1-b*2) {}
61
      Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);}
62
    };
63
  }
64
  
63 65
///Default traits class of \ref GraphToEps
64 66

	
65 67
///Default traits class of \ref GraphToEps
66 68
///
67 69
///\c G is the type of the underlying graph.
68 70
template<class G>
69 71
struct DefaultGraphToEpsTraits
70 72
{
71 73
  typedef G Graph;
72 74
  typedef typename Graph::Node Node;
73 75
  typedef typename Graph::NodeIt NodeIt;
74 76
  typedef typename Graph::Arc Arc;
75 77
  typedef typename Graph::ArcIt ArcIt;
76 78
  typedef typename Graph::InArcIt InArcIt;
77 79
  typedef typename Graph::OutArcIt OutArcIt;
78 80
  
... ...
@@ -145,33 +147,33 @@
145 147
  ///\param _pros If it is \c true, then the \c ostream referenced by \c _os
146 148
  ///will be explicitly deallocated by the destructor.
147 149
  ///By default it is <tt>std::cout</tt>
148 150
  DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout,
149 151
			  bool _pros=false) :
150 152
    g(_g), os(_os),
151 153
    _coords(dim2::Point<double>(1,1)), _nodeSizes(.01), _nodeShapes(0),
152 154
    _nodeColors(WHITE), _arcColors(BLACK),
153 155
    _arcWidths(1.0), _arcWidthScale(0.003),
154 156
    _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0),
155 157
    _nodeBorderQuotient(.1),
156 158
    _drawArrows(false), _arrowLength(1), _arrowWidth(0.3),
157 159
    _showNodes(true), _showArcs(true),
158 160
    _enableParallel(false), _parArcDist(1),
159 161
    _showNodeText(false), _nodeTexts(false), _nodeTextSize(1),
160 162
    _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
161
    _undirected(false),
163
    _undirected(lemon::UndirectedTagIndicator<G>::value),
162 164
    _pleaseRemoveOsStream(_pros), _scaleToA4(false),
163 165
    _nodeTextColorType(SAME_COL), _nodeTextColors(BLACK),
164 166
    _autoNodeScale(false),
165 167
    _autoArcWidthScale(false),
166 168
    _absoluteNodeSizes(false),
167 169
    _absoluteArcWidths(false),
168 170
    _negY(false),
169 171
    _preScale(true)
170 172
  {}
171 173
};
172 174

	
173 175
///Helper class to implement the named parameters of \ref graphToEps()
174 176

	
175 177
///Helper class to implement the named parameters of \ref graphToEps()
176 178
///\todo Is 'helper class' a good name for this?
177 179
///
... ...
@@ -655,33 +657,33 @@
655 657
  ///Gives a preamble block for node Postscript block.
656 658
  ///
657 659
  ///\sa nodePsTexts()
658 660
  GraphToEps<T> & nodePsTextsPreamble(const char *str) {
659 661
    _nodePsTextsPreamble=str ;return *this;
660 662
  }
661 663
  ///Sets whether the the graph is undirected
662 664

	
663 665
  ///Sets whether the the graph is undirected
664 666
  ///
665 667
  GraphToEps<T> &undirected(bool b=true) {_undirected=b;return *this;}
666 668

	
667 669
  ///Sets whether the the graph is directed
668 670

	
669 671
  ///Sets whether the the graph is directed.
670 672
  ///Use it to show the edges as a pair of directed ones.
671
  GraphToEps<T> &bidir(bool b=true) {_undirected=!b;return *this;}
673
  GraphToEps<T> &directed(bool b=true) {_undirected=!b;return *this;}
672 674

	
673 675
  ///Sets the title.
674 676

	
675 677
  ///Sets the title of the generated image,
676 678
  ///namely it inserts a <tt>%%Title:</tt> DSC field to the header of
677 679
  ///the EPS file.
678 680
  GraphToEps<T> &title(const std::string &t) {_title=t;return *this;}
679 681
  ///Sets the copyright statement.
680 682

	
681 683
  ///Sets the copyright statement of the generated image,
682 684
  ///namely it inserts a <tt>%%Copyright:</tt> DSC field to the header of
683 685
  ///the EPS file.
684 686
  ///\todo Multiline copyright notice could be supported.
685 687
  GraphToEps<T> &copyright(const std::string &t) {_copyright=t;return *this;}
686 688

	
687 689
protected:
... ...
@@ -701,33 +703,34 @@
701 703
  }
702 704

	
703 705
public:
704 706
  ~GraphToEps() { }
705 707
  
706 708
  ///Draws the graph.
707 709

	
708 710
  ///Like other functions using
709 711
  ///\ref named-templ-func-param "named template parameters",
710 712
  ///this function calles the algorithm itself, i.e. in this case
711 713
  ///it draws the graph.
712 714
  void run() {
713 715
    ///\todo better 'epsilon' would be nice here.
714 716
    const double EPSILON=1e-9;
715 717
    if(dontPrint) return;
716 718
    
717
    _NegY<typename T::CoordsMapType> mycoords(_coords,_negY);
719
    _graph_to_eps_bits::_NegY<typename T::CoordsMapType>
720
      mycoords(_coords,_negY);
718 721

	
719 722
    os << "%!PS-Adobe-2.0 EPSF-2.0\n";
720 723
    if(_title.size()>0) os << "%%Title: " << _title << '\n';
721 724
     if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n';
722 725
//        << "%%Copyright: XXXX\n"
723 726
    os << "%%Creator: LEMON, graphToEps()\n";
724 727
    
725 728
    {
726 729
      char cbuf[50];
727 730
      timeval tv;
728 731
      gettimeofday(&tv, 0);
729 732
      ctime_r(&tv.tv_sec,cbuf);
730 733
      os << "%%CreationDate: " << cbuf;
731 734
    }
732 735

	
733 736
    if (_autoArcWidthScale) {
0 comments (0 inline)