... | ... |
@@ -594,195 +594,195 @@ |
594 | 594 |
{_nodeTextColorType=DIST_COL;return *this;} |
595 | 595 |
///Sets the color of the node texts to be black or white and always visible. |
596 | 596 |
|
597 | 597 |
///Sets the color of the node texts to be black or white according to |
598 | 598 |
///which is more different from the node color. |
599 | 599 |
GraphToEps<T> &distantBWNodeTexts() |
600 | 600 |
{_nodeTextColorType=DIST_BW;return *this;} |
601 | 601 |
|
602 | 602 |
///Gives a preamble block for node Postscript block. |
603 | 603 |
|
604 | 604 |
///Gives a preamble block for node Postscript block. |
605 | 605 |
/// |
606 | 606 |
///\sa nodePsTexts() |
607 | 607 |
GraphToEps<T> & nodePsTextsPreamble(const char *str) { |
608 | 608 |
_nodePsTextsPreamble=str ;return *this; |
609 | 609 |
} |
610 | 610 |
///Sets whether the graph is undirected |
611 | 611 |
|
612 | 612 |
///Sets whether the graph is undirected. |
613 | 613 |
/// |
614 | 614 |
///This setting is the default for undirected graphs. |
615 | 615 |
/// |
616 | 616 |
///\sa directed() |
617 | 617 |
GraphToEps<T> &undirected(bool b=true) {_undirected=b;return *this;} |
618 | 618 |
|
619 | 619 |
///Sets whether the graph is directed |
620 | 620 |
|
621 | 621 |
///Sets whether the graph is directed. |
622 | 622 |
///Use it to show the edges as a pair of directed ones. |
623 | 623 |
/// |
624 | 624 |
///This setting is the default for digraphs. |
625 | 625 |
/// |
626 | 626 |
///\sa undirected() |
627 | 627 |
GraphToEps<T> &directed(bool b=true) {_undirected=!b;return *this;} |
628 | 628 |
|
629 | 629 |
///Sets the title. |
630 | 630 |
|
631 | 631 |
///Sets the title of the generated image, |
632 | 632 |
///namely it inserts a <tt>%%Title:</tt> DSC field to the header of |
633 | 633 |
///the EPS file. |
634 | 634 |
GraphToEps<T> &title(const std::string &t) {_title=t;return *this;} |
635 | 635 |
///Sets the copyright statement. |
636 | 636 |
|
637 | 637 |
///Sets the copyright statement of the generated image, |
638 | 638 |
///namely it inserts a <tt>%%Copyright:</tt> DSC field to the header of |
639 | 639 |
///the EPS file. |
640 | 640 |
GraphToEps<T> ©right(const std::string &t) {_copyright=t;return *this;} |
641 | 641 |
|
642 | 642 |
protected: |
643 | 643 |
bool isInsideNode(dim2::Point<double> p, double r,int t) |
644 | 644 |
{ |
645 | 645 |
switch(t) { |
646 | 646 |
case CIRCLE: |
647 | 647 |
case MALE: |
648 | 648 |
case FEMALE: |
649 | 649 |
return p.normSquare()<=r*r; |
650 | 650 |
case SQUARE: |
651 | 651 |
return p.x<=r&&p.x>=-r&&p.y<=r&&p.y>=-r; |
652 | 652 |
case DIAMOND: |
653 | 653 |
return p.x+p.y<=r && p.x-p.y<=r && -p.x+p.y<=r && -p.x-p.y<=r; |
654 | 654 |
} |
655 | 655 |
return false; |
656 | 656 |
} |
657 | 657 |
|
658 | 658 |
public: |
659 | 659 |
~GraphToEps() { } |
660 | 660 |
|
661 | 661 |
///Draws the graph. |
662 | 662 |
|
663 | 663 |
///Like other functions using |
664 | 664 |
///\ref named-templ-func-param "named template parameters", |
665 | 665 |
///this function calls the algorithm itself, i.e. in this case |
666 | 666 |
///it draws the graph. |
667 | 667 |
void run() { |
668 | 668 |
const double EPSILON=1e-9; |
669 | 669 |
if(dontPrint) return; |
670 | 670 |
|
671 | 671 |
_graph_to_eps_bits::_NegY<typename T::CoordsMapType> |
672 | 672 |
mycoords(_coords,_negY); |
673 | 673 |
|
674 | 674 |
os << "%!PS-Adobe-2.0 EPSF-2.0\n"; |
675 | 675 |
if(_title.size()>0) os << "%%Title: " << _title << '\n'; |
676 | 676 |
if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n'; |
677 | 677 |
os << "%%Creator: LEMON, graphToEps()\n"; |
678 | 678 |
|
679 | 679 |
{ |
680 | 680 |
os << "%%CreationDate: "; |
681 | 681 |
#ifndef WIN32 |
682 | 682 |
timeval tv; |
683 | 683 |
gettimeofday(&tv, 0); |
684 | 684 |
|
685 | 685 |
char cbuf[26]; |
686 | 686 |
ctime_r(&tv.tv_sec,cbuf); |
687 | 687 |
os << cbuf; |
688 | 688 |
#else |
689 | 689 |
os << bits::getWinFormattedDate(); |
690 |
os << std::endl; |
|
690 | 691 |
#endif |
691 | 692 |
} |
692 |
os << std::endl; |
|
693 | 693 |
|
694 | 694 |
if (_autoArcWidthScale) { |
695 | 695 |
double max_w=0; |
696 | 696 |
for(ArcIt e(g);e!=INVALID;++e) |
697 | 697 |
max_w=std::max(double(_arcWidths[e]),max_w); |
698 | 698 |
if(max_w>EPSILON) { |
699 | 699 |
_arcWidthScale/=max_w; |
700 | 700 |
} |
701 | 701 |
} |
702 | 702 |
|
703 | 703 |
if (_autoNodeScale) { |
704 | 704 |
double max_s=0; |
705 | 705 |
for(NodeIt n(g);n!=INVALID;++n) |
706 | 706 |
max_s=std::max(double(_nodeSizes[n]),max_s); |
707 | 707 |
if(max_s>EPSILON) { |
708 | 708 |
_nodeScale/=max_s; |
709 | 709 |
} |
710 | 710 |
} |
711 | 711 |
|
712 | 712 |
double diag_len = 1; |
713 | 713 |
if(!(_absoluteNodeSizes&&_absoluteArcWidths)) { |
714 | 714 |
dim2::Box<double> bb; |
715 | 715 |
for(NodeIt n(g);n!=INVALID;++n) bb.add(mycoords[n]); |
716 | 716 |
if (bb.empty()) { |
717 | 717 |
bb = dim2::Box<double>(dim2::Point<double>(0,0)); |
718 | 718 |
} |
719 | 719 |
diag_len = std::sqrt((bb.bottomLeft()-bb.topRight()).normSquare()); |
720 | 720 |
if(diag_len<EPSILON) diag_len = 1; |
721 | 721 |
if(!_absoluteNodeSizes) _nodeScale*=diag_len; |
722 | 722 |
if(!_absoluteArcWidths) _arcWidthScale*=diag_len; |
723 | 723 |
} |
724 | 724 |
|
725 | 725 |
dim2::Box<double> bb; |
726 | 726 |
for(NodeIt n(g);n!=INVALID;++n) { |
727 | 727 |
double ns=_nodeSizes[n]*_nodeScale; |
728 | 728 |
dim2::Point<double> p(ns,ns); |
729 | 729 |
switch(_nodeShapes[n]) { |
730 | 730 |
case CIRCLE: |
731 | 731 |
case SQUARE: |
732 | 732 |
case DIAMOND: |
733 | 733 |
bb.add(p+mycoords[n]); |
734 | 734 |
bb.add(-p+mycoords[n]); |
735 | 735 |
break; |
736 | 736 |
case MALE: |
737 | 737 |
bb.add(-p+mycoords[n]); |
738 | 738 |
bb.add(dim2::Point<double>(1.5*ns,1.5*std::sqrt(3.0)*ns)+mycoords[n]); |
739 | 739 |
break; |
740 | 740 |
case FEMALE: |
741 | 741 |
bb.add(p+mycoords[n]); |
742 | 742 |
bb.add(dim2::Point<double>(-ns,-3.01*ns)+mycoords[n]); |
743 | 743 |
break; |
744 | 744 |
} |
745 | 745 |
} |
746 | 746 |
if (bb.empty()) { |
747 | 747 |
bb = dim2::Box<double>(dim2::Point<double>(0,0)); |
748 | 748 |
} |
749 | 749 |
|
750 | 750 |
if(_scaleToA4) |
751 | 751 |
os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n"; |
752 | 752 |
else { |
753 | 753 |
if(_preScale) { |
754 | 754 |
//Rescale so that BoundingBox won't be neither to big nor too small. |
755 | 755 |
while(bb.height()*_scale>1000||bb.width()*_scale>1000) _scale/=10; |
756 | 756 |
while(bb.height()*_scale<100||bb.width()*_scale<100) _scale*=10; |
757 | 757 |
} |
758 | 758 |
|
759 | 759 |
os << "%%BoundingBox: " |
760 | 760 |
<< int(floor(bb.left() * _scale - _xBorder)) << ' ' |
761 | 761 |
<< int(floor(bb.bottom() * _scale - _yBorder)) << ' ' |
762 | 762 |
<< int(ceil(bb.right() * _scale + _xBorder)) << ' ' |
763 | 763 |
<< int(ceil(bb.top() * _scale + _yBorder)) << '\n'; |
764 | 764 |
} |
765 | 765 |
|
766 | 766 |
os << "%%EndComments\n"; |
767 | 767 |
|
768 | 768 |
//x1 y1 x2 y2 x3 y3 cr cg cb w |
769 | 769 |
os << "/lb { setlinewidth setrgbcolor newpath moveto\n" |
770 | 770 |
<< " 4 2 roll 1 index 1 index curveto stroke } bind def\n"; |
771 | 771 |
os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke }" |
772 | 772 |
<< " bind def\n"; |
773 | 773 |
//x y r |
774 | 774 |
os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath }" |
775 | 775 |
<< " bind def\n"; |
776 | 776 |
//x y r |
777 | 777 |
os << "/sq { newpath 2 index 1 index add 2 index 2 index add moveto\n" |
778 | 778 |
<< " 2 index 1 index sub 2 index 2 index add lineto\n" |
779 | 779 |
<< " 2 index 1 index sub 2 index 2 index sub lineto\n" |
780 | 780 |
<< " 2 index 1 index add 2 index 2 index sub lineto\n" |
781 | 781 |
<< " closepath pop pop pop} bind def\n"; |
782 | 782 |
//x y r |
783 | 783 |
os << "/di { newpath 2 index 1 index add 2 index moveto\n" |
784 | 784 |
<< " 2 index 2 index 2 index add lineto\n" |
785 | 785 |
<< " 2 index 1 index sub 2 index lineto\n" |
786 | 786 |
<< " 2 index 2 index 2 index sub lineto\n" |
787 | 787 |
<< " closepath pop pop pop} bind def\n"; |
788 | 788 |
// x y r cr cg cb |
0 comments (0 inline)