Open
Graph Drawing
Framework

 v.2012.05
 

GraphAttributes.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008 
00046 #ifdef _MSC_VER
00047 #pragma once
00048 #endif
00049 
00050 #ifndef OGDF_ATTRIBUTED_GRAPH_H
00051 #define OGDF_ATTRIBUTED_GRAPH_H
00052 
00053 #include <ogdf/basic/NodeArray.h>
00054 #include <ogdf/basic/EdgeArray.h>
00055 #include <ogdf/basic/String.h>
00056 #include <ogdf/basic/geometry.h>
00057 
00058 namespace ogdf {
00059 
00060 //---------------------------------------------------------
00061 // GraphAttributes
00062 // graph topology + graphical attributes
00063 //---------------------------------------------------------
00065 
00084 class OGDF_EXPORT GraphAttributes {
00085 public:
00087     enum EdgeArrow {
00088         none, 
00089         last, 
00090         first, 
00091         both, 
00092         undefined
00093     };
00094 
00096 
00099     enum EdgeStyle {
00100         esNoPen = 0, 
00101         esSolid = 1, 
00102         esDash = 2, 
00103         esDot = 3, 
00104         esDashdot = 4, 
00105         esDashdotdot = 5
00107     };
00108 
00110     static EdgeStyle intToStyle(int i) {
00111         switch (i) {
00112         case 0:
00113             return esNoPen;
00114         case 1:
00115             return esSolid;
00116         case 2:
00117             return esDash;
00118         case 3:
00119             return esDot;
00120         case 4:
00121             return esDashdot;
00122         case 5:
00123             return esDashdotdot;
00124         default:
00125             return esNoPen;
00126 
00127         }
00128     }
00129 
00131 
00134     enum BrushPattern {
00135         bpNone = 0,
00136         bpSolid = 1,
00137         bpDense1 = 2,
00138         bpDense2 = 3,
00139         bpDense3 = 4,
00140         bpDense4 = 5,
00141         bpDense5 = 6,
00142         bpDense6 = 7,
00143         bpDense7 = 8,
00144         bpHorizontal = 9,
00145         bpVertical = 10,
00146         bpCross = 11,
00147         BackwardDiagonal = 12,
00148         ForwardDiagonal = 13,
00149         DiagonalCross = 14
00150     };
00151 
00153     static BrushPattern intToPattern(int i) {
00154         switch (i) {
00155         case 0:
00156             return bpNone;
00157             break;
00158         case 1:
00159             return bpSolid;
00160             break;
00161         case 2:
00162             return bpDense1;
00163             break;
00164         case 3:
00165             return bpDense2;
00166             break;
00167         case 4:
00168             return bpDense3;
00169             break;
00170         case 5:
00171             return bpDense4;
00172             break;
00173         case 6:
00174             return bpDense5;
00175             break;
00176         case 7:
00177             return bpDense6;
00178             break;
00179         case 8:
00180             return bpDense7;
00181             break;
00182         case 9:
00183             return bpHorizontal;
00184             break;
00185         case 10:
00186             return bpVertical;
00187             break;
00188         case 11:
00189             return bpCross;
00190             break;
00191         case 12:
00192             return BackwardDiagonal;
00193             break;
00194         case 13:
00195             return ForwardDiagonal;
00196             break;
00197         case 14:
00198             return DiagonalCross;
00199             break;
00200         default:
00201             return bpNone;
00202             break;
00203         }
00204     }
00205 
00207     enum ImageStyle {
00208         FreeScale = 0, FixScale = 1,
00209     };
00211     enum ImageAlignment {
00212         TopLeft = 0, TopCenter, TopRight, CenterLeft, Center, CenterRight, BottomLeft, BottomCenter, BottomRight
00213     };
00214 
00216     static ImageStyle intToImageStyle(int i) {
00217         switch (i) {
00218         case 0:
00219             return FreeScale;
00220             break;
00221         case 1:
00222             return FixScale;
00223             break;
00224         default:
00225             return FreeScale;
00226         }//switch
00227     }//intToStyle
00228 
00230     static ImageAlignment intToImageAlignment(int i) {
00231         switch (i) {
00232         case 0:
00233             return TopLeft;
00234             break;
00235         case 1:
00236             return TopCenter;
00237             break;
00238         case 2:
00239             return TopRight;
00240             break;
00241         case 3:
00242             return CenterLeft;
00243             break;
00244         case 4:
00245             return Center;
00246             break;
00247         case 5:
00248             return CenterRight;
00249             break;
00250         case 6:
00251             return BottomLeft;
00252             break;
00253         case 7:
00254             return BottomCenter;
00255             break;
00256         case 8:
00257             return BottomRight;
00258             break;
00259         default:
00260             return TopLeft;
00261         }//switch
00262     }//intToAlignment
00263 
00264 protected:
00269     void writeLongString(ostream &os, const String &str) const;
00270 
00271     /* Methods for OGML serialization */
00272 
00274     static const char * edgeStyleToOGML(const GraphAttributes::EdgeStyle & edgeStyle);
00275 
00277     static const char * imageAlignmentToOGML(const GraphAttributes::ImageAlignment &imgAlign);
00278 
00280     static const char * imageStyleToOGML(const GraphAttributes::ImageStyle &imgStyle);
00281 
00283     static const char * brushPatternToOGML(const GraphAttributes::BrushPattern & brushPattern);
00284 
00285     static void generateIndent(char ** indent, const int & indentSize);
00286 
00288     String formatLabel(const String & labelText);
00289 
00290     /* End methods for OGML serialization */
00291 
00292     const Graph *m_pGraph; 
00293 
00294     bool m_directed; 
00295 
00296     // graphical representation of nodes
00297     NodeArray<double> m_x; 
00298     NodeArray<double> m_y; 
00299     NodeArray<double> m_width; 
00300     NodeArray<double> m_height; 
00301     NodeArray<String> m_nodeLabel; 
00302     NodeArray<String> m_nodeColor; 
00303     NodeArray<String> m_nodeLine; 
00304     NodeArray<int> m_nodeShape; 
00305     NodeArray<double> m_nodeLineWidth; 
00306     NodeArray<BrushPattern> m_nodePattern; 
00307     NodeArray<EdgeStyle> m_nodeStyle; 
00308     NodeArray<String> m_nodeTemplate; 
00309 
00310     // images
00311     NodeArray<String> m_imageUri;
00312     NodeArray<ImageStyle> m_imageStyle;
00313     NodeArray<ImageAlignment> m_imageAlign;
00314     NodeArray<bool> m_imageDrawLine;
00315     NodeArray<double> m_imageWidth;
00316     NodeArray<double> m_imageHeight;
00317 
00318     // other node attributes
00319     NodeArray<int> m_nodeId; 
00320     NodeArray<int> m_level; 
00321     NodeArray<int> m_nodeIntWeight; 
00322     NodeArray<Graph::NodeType> m_vType; // type (vertex, dummy, generalizationMerger)
00323 
00324     // graphical representation of edges
00325     EdgeArray<DPolyline> m_bends; 
00326     EdgeArray<String> m_edgeLabel; 
00327     EdgeArray<EdgeArrow> m_edgeArrow; 
00328     EdgeArray<EdgeStyle> m_edgeStyle; 
00329     EdgeArray<String> m_edgeColor; 
00330     EdgeArray<double> m_edgeWidth; 
00331     EdgeArray<Graph::EdgeType> m_eType; 
00332 
00333     // other edge attributes
00334     EdgeArray<int> m_intWeight; 
00335     EdgeArray<double> m_doubleWeight; 
00336     EdgeArray<unsigned int> m_subGraph; 
00337 
00338     long m_attributes; 
00339 
00340 public:
00342     enum {
00343         nodeGraphics = 0x00001, 
00344         edgeGraphics = 0x00002, 
00345         nodeLevel = 0x00004, 
00346         edgeIntWeight = 0x00008, 
00347         edgeDoubleWeight = 0x00010, 
00348         edgeLabel = 0x00020, 
00349         nodeLabel = 0x00040, 
00350         edgeType = 0x00080, 
00351         nodeType = 0x00100, 
00352         nodeColor = 0x00200, 
00353         nodeId = 0x00400, 
00354         edgeArrow = 0x00800, 
00355         edgeColor = 0x01000, 
00356         edgeStyle = 0x02000, 
00357         nodeStyle = 0x04000, 
00358 
00359 
00360         nodeTemplate = 0x08000, 
00361         edgeSubGraph = 0x10000, 
00362         nodeWeight = 0x20000
00364     };
00365 
00367     enum {
00368         oval = 0x8001, rectangle = 0x8002
00369     };
00370 
00372 
00375     GraphAttributes();
00376 
00378 
00382     GraphAttributes(const Graph &G, long initAttributes = nodeGraphics | edgeGraphics);
00383 
00384     virtual ~GraphAttributes() {
00385     }
00386 
00388 
00395     virtual void init(const Graph &G, long initAttr);
00396 
00398     long attributes() const {
00399         return m_attributes;
00400     }
00401 
00403     void initAttributes(long attr);
00404 
00406     void destroyAttributes(long attr);
00407 
00409     const Graph& constGraph() const {
00410         return *m_pGraph;
00411     }
00412 
00414     bool directed() {
00415         return m_directed;
00416     }
00417     ;
00418 
00420     void directed(bool directed) {
00421         m_directed = directed;
00422     }
00423     ;
00424 
00426     const String &templateNode(node v) const {
00427         return m_nodeTemplate[v];
00428     }
00430     String &templateNode(node v) {
00431         return m_nodeTemplate[v];
00432     }
00433 
00435     const double &x(node v) const {
00436         return m_x[v];
00437     }
00439     double &x(node v) {
00440         return m_x[v];
00441     }
00442 
00444     const double &y(node v) const {
00445         return m_y[v];
00446     }
00448     double &y(node v) {
00449         return m_y[v];
00450     }
00451 
00453     const NodeArray<double> &width() const {
00454         return m_width;
00455     }
00457     NodeArray<double> &width() {
00458         return m_width;
00459     }
00460 
00462     const double &width(node v) const {
00463         return m_width[v];
00464     }
00466     double &width(node v) {
00467         return m_width[v];
00468     }
00469 
00471     const NodeArray<double> &height() const {
00472         return m_height;
00473     }
00475     NodeArray<double> &height() {
00476         return m_height;
00477     }
00478 
00480     const double &height(node v) const {
00481         return m_height[v];
00482     }
00484     double &height(node v) {
00485         return m_height[v];
00486     }
00487 
00489     const int &level(node v) const {
00490         return m_level[v];
00491     }
00493     int &level(node v) {
00494         return m_level[v];
00495     }
00496 
00498     const int &weight(node v) const {
00499         return m_nodeIntWeight[v];
00500     }
00502     int &weight(node v) {
00503         return m_nodeIntWeight[v];
00504     }
00505 
00507     const BrushPattern &nodePattern(node v) const {
00508         return m_nodePattern[v];
00509     }
00511     BrushPattern &nodePattern(node v) {
00512         return m_nodePattern[v];
00513     }
00514 
00516     const EdgeStyle &styleNode(node v) const {
00517         return m_nodeStyle[v];
00518     }
00520     EdgeStyle &styleNode(node v) {
00521         return m_nodeStyle[v];
00522     }
00523 
00525     const double &lineWidthNode(node v) const {
00526         return m_nodeLineWidth[v];
00527     }
00529     double &lineWidthNode(node v) {
00530         return m_nodeLineWidth[v];
00531     }
00532 
00534     const String &nodeLine(node v) const {
00535         return m_nodeLine[v];
00536     }
00538     String &nodeLine(node v) {
00539         return m_nodeLine[v];
00540     }
00541 
00543     const DPolyline &bends(edge e) const {
00544         return m_bends[e];
00545     }
00547     DPolyline &bends(edge e) {
00548         return m_bends[e];
00549     }
00550 
00552     const int &intWeight(edge e) const {
00553         return m_intWeight[e];
00554     }
00556     int &intWeight(edge e) {
00557         return m_intWeight[e];
00558     }
00559 
00561     const double &doubleWeight(edge e) const {
00562         return m_doubleWeight[e];
00563     }
00565     double &doubleWeight(edge e) {
00566         return m_doubleWeight[e];
00567     }
00568 
00570     const double &edgeWidth(edge e) const {
00571         return m_edgeWidth[e];
00572     }
00574     double &edgeWidth(edge e) {
00575         return m_edgeWidth[e];
00576     }
00577 
00579     const String &colorNode(node v) const {
00580         return m_nodeColor[v];
00581     }
00583     String &colorNode(node v) {
00584         return m_nodeColor[v];
00585     }
00586 
00588     int shapeNode(node v) const {
00589         return m_nodeShape[v];
00590     }
00592     int &shapeNode(node v) {
00593         return m_nodeShape[v];
00594     }
00595 
00597     const String &labelNode(node v) const {
00598         return m_nodeLabel[v];
00599     }
00601     String &labelNode(node v) {
00602         return m_nodeLabel[v];
00603     }
00604 
00606     const String &labelEdge(edge e) const {
00607         return m_edgeLabel[e];
00608     }
00610     String &labelEdge(edge e) {
00611         return m_edgeLabel[e];
00612     }
00613 
00615     Graph::EdgeType type(edge e) const {
00616         return m_eType.valid() ? m_eType[e] : Graph::association;
00617     }
00619     Graph::EdgeType &type(edge e) {
00620         return m_eType[e];
00621     }
00622 
00624     Graph::NodeType type(node v) const {
00625         return m_vType.valid() ? m_vType[v] : Graph::vertex;
00626     }
00628     Graph::NodeType &type(node v) {
00629         return m_vType[v];
00630     }
00631 
00633     const int &idNode(node v) const {
00634         return m_nodeId[v];
00635     }
00637     int &idNode(node v) {
00638         return m_nodeId[v];
00639     }
00640 
00642     const EdgeArrow &arrowEdge(edge e) const {
00643         return m_edgeArrow[e];
00644     }
00646     EdgeArrow &arrowEdge(edge e) {
00647         return m_edgeArrow[e];
00648     }
00649 
00651     const EdgeStyle &styleEdge(edge e) const {
00652         return m_edgeStyle[e];
00653     }
00655     EdgeStyle &styleEdge(edge e) {
00656         return m_edgeStyle[e];
00657     }
00658 
00660     const String &colorEdge(edge e) const {
00661         return m_edgeColor[e];
00662     }
00664     String &colorEdge(edge e) {
00665         return m_edgeColor[e];
00666     }
00667 
00668     // Images:
00670     const String &imageUriNode(node v) const {
00671         return m_imageUri[v];
00672     }
00674     String &imageUriNode(node v) {
00675         return m_imageUri[v];
00676     }
00678     const ImageStyle &imageStyleNode(node v) const {
00679         return m_imageStyle[v];
00680     }
00682     ImageStyle &imageStyleNode(node v) {
00683         return m_imageStyle[v];
00684     }
00685     // Returns image alignment of node v.
00686     const ImageAlignment &imageAlignmentNode(node v) const {
00687         return m_imageAlign[v];
00688     }
00689     // Returns image alignment of node v.
00690     ImageAlignment &imageAlignmentNode(node v) {
00691         return m_imageAlign[v];
00692     }
00694     const bool &imageDrawLineNode(node v) const {
00695         return m_imageDrawLine[v];
00696     }
00698     bool &imageDrawLineNode(node v) {
00699         return m_imageDrawLine[v];
00700     }
00702     const double &imageWidthNode(node v) const {
00703         return m_imageWidth[v];
00704     }
00706     double &imageWidthNode(node v) {
00707         return m_imageWidth[v];
00708     }
00709     // Returns image height of node v.
00710     const double &imageHeightNode(node v) const {
00711         return m_imageHeight[v];
00712     }
00713     // Returns image height of node v.
00714     double &imageHeightNode(node v) {
00715         return m_imageHeight[v];
00716     }
00717 
00719     const unsigned int &subGraphBits(edge e) const {
00720         return m_subGraph[e];
00721     }
00723     unsigned int &subGraphBits(edge e) {
00724         return m_subGraph[e];
00725     }
00726 
00728     bool inSubGraph(edge e, int n) const {
00729         OGDF_ASSERT( n>=0 && n<32 );
00730         return (m_subGraph[e] & (1 << n)) != 0;
00731     }
00733     void addSubGraph(edge e, int n) {
00734         OGDF_ASSERT( n>=0 && n<32 );
00735         m_subGraph[e] |= (1 << n);
00736     }
00738     void removeSubGraph(edge e, int n) {
00739         OGDF_ASSERT( n>=0 && n<32 );
00740         m_subGraph[e] &= ~(1 << n);
00741     }
00742 
00744     const DRect boundingBox() const;
00745 
00752     bool isAssociationClass(node v) const {
00753         return (type(v) == Graph::associationClass);
00754     }
00755 
00765     void addNodeCenter2Bends(int mode = 1);
00766 
00767     void clearAllBends();
00768 
00770 
00778     int hierarchyList(List<List<node>*> &list) const;
00779 
00781 
00789     int hierarchyList(List<List<edge>*> &list) const;
00790 
00792     void setAllWidth(double w);
00794     void setAllHeight(double h);
00795 
00797     bool readGML(Graph &G, const String &fileName);
00798 
00800     bool readGML(Graph &G, istream &is);
00801 
00803     void writeGML(const String &fileName) const;
00804 
00806     void writeGML(ostream &os) const;
00807 
00809 
00814     void writeSVG(const String &fileName, int fontSize = 3, const String &fontColor = "#000000") const;
00815 
00817 
00822     void writeSVG(ostream &os, int fontSize, const String &fontColor) const;
00823 
00825     bool readXML(Graph &G, const String &fileName);
00826 
00828     bool readXML(Graph &G, istream &is);
00829 
00831     void writeXML(const String &fileName, const char* delimiter = "", const char* offset = "") const;
00832 
00834     virtual void writeXML(ostream &os, const char* delimiter = "", const char* offset = "") const;
00835 
00837     bool readRudy(Graph &G, const String &fileName);
00838 
00840     bool readRudy(Graph &G, istream &is);
00841 
00843     void writeRudy(const String &fileName) const;
00844 
00846     void writeRudy(ostream &os) const;
00847 
00849 
00855     void removeUnnecessaryBendsHV();
00856 };
00857 
00858 } // end namespace ogdf
00859 
00860 
00861 #endif