Changeset 1085:5b7ca75297b5 in lemon-0.x
- Timestamp:
- 01/16/05 23:34:51 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1481
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/lemon/graph_to_eps.h
r1073 r1085 106 106 double _nodeTextSize; 107 107 108 bool _showNodePsText; 109 ConstMap<typename Graph::Node,bool > _nodePsTexts; 110 char *_nodePsTextsPreamble; 111 108 112 bool _undir; 109 113 bool _pleaseRemoveOsStream; … … 129 133 _enableParallel(false), _parEdgeDist(1), 130 134 _showNodeText(false), _nodeTexts(false), _nodeTextSize(1), 135 _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0), 131 136 _undir(false), 132 137 _pleaseRemoveOsStream(_pros) {} … … 225 230 return GraphToEps<NodeTextsTraits<X> >(NodeTextsTraits<X>(*this,x)); 226 231 } 227 template<class X> struct EdgeWidthsTraits : public T { 232 template<class X> struct NodePsTextsTraits : public T { 233 const X &_nodePsTexts; 234 NodePsTextsTraits(const T &t,const X &x) : T(t), _nodePsTexts(x) {} 235 }; 236 ///Inserts a PostScript block to the nodes 237 238 ///With this command it is possible to insert a verbatim PostScript 239 ///block to the nodes. 240 ///The PS current point will be moved to the centre of the node before 241 ///the PostScript block inserted. 242 /// 243 ///Before and after the block a newline character is inserted to you 244 ///don't have to bother with the separators. 245 /// 246 ///\param x must be a node map with type that can be pushed to a standard 247 ///ostream. 248 /// 249 ///\sa nodePsTextsPreamble() 250 ///\todo Offer the choise not to move to the centre but pass the coordinates 251 ///to the Postscript block inserted. 252 template<class X> GraphToEps<NodePsTextsTraits<X> > nodePsTexts(const X &x) 253 { 254 dontPrint=true; 255 _showNodePsText=true; 256 return GraphToEps<NodePsTextsTraits<X> >(NodePsTextsTraits<X>(*this,x)); 257 } 258 template<class X> struct EdgeWidthsTraits : public T { 228 259 const X &_edgeWidths; 229 260 EdgeWidthsTraits(const T &t,const X &x) : T(t), _edgeWidths(x) {} … … 338 369 /// 339 370 GraphToEps<T> &nodeTextSize(double d) {_nodeTextSize=d;return *this;} 371 ///Gives a preamble block for node Postscript block. 372 373 ///Gives a preamble block for node Postscript block. 374 /// 375 ///\sa nodePsTexts() 376 GraphToEps<T> & nodePsTextsPreamble(const char *str) { 377 _nodePsTextsPreamble=s ;return *this; 378 } 340 379 ///Sets whether the the graph is undirected 341 380 … … 402 441 if(_scale!=1.0) os << _scale << " dup scale\n"; 403 442 404 os << "%Edges:\ngsave\n"; 405 406 if(_showEdges) 443 if(_showEdges) { 444 os << "%Edges:\ngsave\n"; 407 445 if(_enableParallel) { 408 446 std::vector<Edge> el; … … 420 458 sw-=_parEdgeDist; 421 459 sw/=-2.0; 422 xy<double> d(_coords[g.target(*i)]-_coords[g.source(*i)]); 423 double l=sqrt(d.normSquare()); 424 d/=l; 425 460 xy<double> dvec(_coords[g.target(*i)]-_coords[g.source(*i)]); 461 double l=sqrt(dvec.normSquare()); 462 xy<double> d(dvec/l); 463 xy<double> m; 464 // m=xy<double>(_coords[g.target(*i)]+_coords[g.source(*i)])/2.0; 465 466 // m=xy<double>(_coords[g.source(*i)])+ 467 // dvec*(double(_nodeSizes[g.source(*i)])/ 468 // (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)])); 469 470 m=xy<double>(_coords[g.source(*i)])+ 471 d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0; 472 426 473 for(typename std::vector<Edge>::iterator e=i;e!=j;++e) { 427 474 sw+=_edgeWidths[*e]*_edgeWidthScale/2.0; 428 xy<double> m(_coords[g.target(*e)]+_coords[g.source(*e)]); 429 m=m/2.0+rot(d)*sw/.75; 475 xy<double> mm=m+rot(d)*sw/.75; 430 476 if(_drawArrows) { 431 477 const int INERPOL_PREC=20; … … 434 480 double rn=_nodeSizes[g.target(*e)]*_nodeScale; 435 481 rn*=rn; 436 Bezier3 bez(s,m ,m,t);482 Bezier3 bez(s,mm,mm,t); 437 483 double t1=0,t2=1; 438 484 for(int i=0;i<INERPOL_PREC;++i) … … 473 519 os << _coords[g.source(*e)].x << ' ' 474 520 << _coords[g.source(*e)].y << ' ' 475 << m .x << ' ' <<m.y << ' '521 << mm.x << ' ' << mm.y << ' ' 476 522 << _coords[g.target(*e)].x << ' ' 477 523 << _coords[g.target(*e)].y << ' ' … … 510 556 << _edgeColors[e].getB() << ' ' 511 557 << _edgeWidths[e]*_edgeWidthScale << " l\n"; 512 os << "grestore\n%Nodes:\ngsave\n"; 513 if(_showNodes) 558 os << "grestore\n"; 559 } 560 if(_showNodes) { 561 os << "%Nodes:\ngsave\n"; 514 562 for(NodeIt n(g);n!=INVALID;++n) 515 563 os << _coords[n].x << ' ' << _coords[n].y << ' ' … … 517 565 << _nodeColors[n].getR() << ' ' 518 566 << _nodeColors[n].getG() << ' ' 519 << _nodeColors[n].getB() << " n\n"; 567 << _nodeColors[n].getB() << " n\n"; 568 os << "grestore\n"; 569 } 520 570 if(_showNodeText) { 521 os << " grestore\n%Node texts:\ngsave\n";571 os << "%Node texts:\ngsave\n"; 522 572 os << "/fosi " << _nodeTextSize << " def\n"; 523 573 os << "(Helvetica) findfont fosi scalefont setfont\n"; … … 526 576 os << _coords[n].x << ' ' << _coords[n].y 527 577 << " (" << _nodeTexts[n] << ") cshow\n"; 578 os << "grestore\n"; 528 579 } 529 os << "grestore\ngrestore\n"; 580 if(_showNodePsText) { 581 os << "%Node PS blocks:\ngsave\n"; 582 for(NodeIt n(g);n!=INVALID;++n) 583 os << _coords[n].x << ' ' << _coords[n].y 584 << " moveto\n" << _nodePsTexts[n] << "\n"; 585 os << "grestore\n"; 586 } 587 588 os << "grestore\n"; 530 589 531 590 //CleanUp: … … 577 636 } 578 637 579 //Generates an EPS file from a graph.580 //\param g is a reference to the graph to be printed581 //\param file_name is the output file_name.582 //583 //This function also has a lot of \ref named-templ-param "named parameters",584 //they are declared as the members of class \ref GraphToEps. The following585 //example shows how to use these parameters.586 //\code587 // graphToEps(g).scale(10).coords(coords)588 // .nodeScale(2).nodeSizes(sizes)589 // .edgeWidthScale(.4);590 //\endcode591 //\sa GraphToEps592 //\todo Avoid duplicated documentation593 //\bug Exception handling is missing? (Or we can just ignore it?)594 595 638 } //END OF NAMESPACE LEMON 596 639
Note: See TracChangeset
for help on using the changeset viewer.