Open
Graph Drawing
Framework

 v.2010.10
 

GraphAttributes.h

Go to the documentation of this file.
00001 /*
00002  * $Revision: 2044 $
00003  * 
00004  * last checkin:
00005  *   $Author: tschaefer $ 
00006  *   $Date: 2010-10-06 14:54:26 +0200 (Wed, 06 Oct 2010) $ 
00007  ***************************************************************/
00008  
00057 #ifdef _MSC_VER
00058 #pragma once
00059 #endif
00060 
00061 #ifndef OGDF_ATTRIBUTED_GRAPH_H
00062 #define OGDF_ATTRIBUTED_GRAPH_H
00063 
00064 
00065 #include <ogdf/basic/NodeArray.h>
00066 #include <ogdf/basic/EdgeArray.h>
00067 #include <ogdf/basic/String.h>
00068 #include <ogdf/basic/geometry.h>
00069 
00070 namespace ogdf {
00071 
00072 //---------------------------------------------------------
00073 // GraphAttributes
00074 // graph topology + graphical attributes
00075 //---------------------------------------------------------
00077 
00096 class OGDF_EXPORT GraphAttributes
00097 {
00098 public:
00100     enum EdgeArrow {
00101         none,      
00102         last,      
00103         first,     
00104         both,      
00105         undefined
00106     };
00107 
00109 
00112     enum EdgeStyle {
00113         esNoPen      = 0, 
00114         esSolid      = 1, 
00115         esDash       = 2, 
00116         esDot        = 3, 
00117         esDashdot    = 4, 
00118         esDashdotdot = 5  
00119     };
00120 
00122     static EdgeStyle intToStyle(int i)
00123     {
00124         switch (i)
00125         {
00126             case 0: return esNoPen;
00127             case 1: return esSolid;
00128             case 2: return esDash;
00129             case 3: return esDot;
00130             case 4: return esDashdot;
00131             case 5: return esDashdotdot;
00132             default: return esNoPen;
00133 
00134         }
00135     }
00136 
00138 
00141     enum BrushPattern {
00142         bpNone = 0,
00143         bpSolid = 1,
00144         bpDense1 = 2,
00145         bpDense2 = 3,
00146         bpDense3 = 4,
00147         bpDense4 = 5,
00148         bpDense5 = 6,
00149         bpDense6 = 7,
00150         bpDense7 = 8,
00151         bpHorizontal = 9,
00152         bpVertical = 10,
00153         bpCross = 11,
00154         BackwardDiagonal = 12,
00155         ForwardDiagonal = 13,
00156         DiagonalCross = 14
00157     };
00158 
00160     static BrushPattern intToPattern(int i)
00161     {
00162         switch (i)
00163         {
00164             case 0: return bpNone; break;
00165             case 1: return bpSolid; break;
00166             case 2: return bpDense1; break;
00167             case 3: return bpDense2; break;
00168             case 4: return bpDense3; break;
00169             case 5: return bpDense4; break;
00170             case 6: return bpDense5; break;
00171             case 7: return bpDense6; break;
00172             case 8: return bpDense7; break;
00173             case 9: return bpHorizontal; break;
00174             case 10: return bpVertical; break;
00175             case 11: return bpCross; break;
00176             case 12: return BackwardDiagonal; break;
00177             case 13: return ForwardDiagonal; break;
00178             case 14: return DiagonalCross; break;
00179             default: return bpNone; break;
00180         }
00181     }
00182 
00184     enum ImageStyle {
00185         FreeScale    = 0,
00186         FixScale   = 1,
00187     };
00189     enum ImageAlignment {
00190         TopLeft = 0,
00191         TopCenter,
00192         TopRight,
00193         CenterLeft,
00194         Center,
00195         CenterRight,
00196         BottomLeft,
00197         BottomCenter,
00198         BottomRight
00199     };
00200     
00202     static ImageStyle intToImageStyle(int i)
00203     {
00204         switch (i)
00205         {
00206             case  0:
00207                 return FreeScale;
00208                 break;
00209             case 1:
00210                 return FixScale;
00211                 break;
00212             default:
00213                 return FreeScale;
00214         }//switch
00215     }//intToStyle
00216     
00218     static ImageAlignment intToImageAlignment(int i)
00219     {
00220         switch (i)
00221         {
00222                 case  0:
00223                     return TopLeft;
00224                     break;
00225                 case 1:
00226                     return TopCenter;
00227                     break;
00228                 case 2:
00229                     return TopRight;
00230                     break;
00231                 case 3:
00232                     return CenterLeft;
00233                     break;
00234                 case 4:
00235                     return Center;
00236                     break;
00237                 case 5:
00238                     return CenterRight;
00239                     break;
00240                 case 6:
00241                     return BottomLeft;
00242                     break;
00243                 case 7:
00244                     return BottomCenter;
00245                     break;
00246                 case 8:
00247                     return BottomRight;
00248                     break;
00249                 default:
00250                     return TopLeft;
00251         }//switch
00252     }//intToAlignment
00253 
00254 protected:
00259     void writeLongString(ostream &os, const String &str) const;
00260 
00261     /* Methods for OGML serialization */
00262   
00264     static const char * edgeStyleToOGML(const GraphAttributes::EdgeStyle & edgeStyle);
00265 
00267     static const char * imageAlignmentToOGML(const GraphAttributes::ImageAlignment &imgAlign);
00268 
00270     static const char * imageStyleToOGML(const GraphAttributes::ImageStyle &imgStyle);
00271 
00273     static const char * brushPatternToOGML(const GraphAttributes::BrushPattern & brushPattern);
00274     
00275     static void generateIndent(char ** indent, const int & indentSize);
00276 
00278     String formatLabel(const String & labelText);
00279   
00280     /* End methods for OGML serialization */
00281 
00282     const Graph *m_pGraph; 
00283     
00284     bool m_directed;    
00285 
00286     // graphical representation of nodes
00287     NodeArray<double>       m_x;             
00288     NodeArray<double>       m_y;             
00289     NodeArray<double>       m_width;         
00290     NodeArray<double>       m_height;        
00291     NodeArray<String>       m_nodeLabel;     
00292     NodeArray<String>       m_nodeColor;     
00293     NodeArray<String>       m_nodeLine;      
00294     NodeArray<int>          m_nodeShape;     
00295     NodeArray<double>       m_nodeLineWidth; 
00296     NodeArray<BrushPattern> m_nodePattern;   
00297     NodeArray<EdgeStyle>    m_nodeStyle;     
00298     NodeArray<String>       m_nodeTemplate;  
00299     
00300     // images
00301     NodeArray<String>         m_imageUri;
00302     NodeArray<ImageStyle>     m_imageStyle;
00303     NodeArray<ImageAlignment> m_imageAlign;
00304     NodeArray<bool>           m_imageDrawLine;
00305     NodeArray<double>         m_imageWidth;
00306     NodeArray<double>         m_imageHeight;
00307     
00308     // other node attributes
00309     NodeArray<int>             m_nodeId; 
00310     NodeArray<int>             m_level;  
00311     NodeArray<int>             m_nodeIntWeight; 
00312     NodeArray<Graph::NodeType> m_vType;  // type (vertex, dummy, generalizationMerger)
00313     
00314     // graphical representation of edges
00315     EdgeArray<DPolyline>       m_bends;     
00316     EdgeArray<String>          m_edgeLabel; 
00317     EdgeArray<EdgeArrow>       m_edgeArrow; 
00318     EdgeArray<EdgeStyle>       m_edgeStyle; 
00319     EdgeArray<String>          m_edgeColor; 
00320     EdgeArray<double>          m_edgeWidth; 
00321     EdgeArray<Graph::EdgeType> m_eType;     
00322 
00323     // other edge attributes
00324     EdgeArray<int>          m_intWeight;    
00325     EdgeArray<double>       m_doubleWeight; 
00326     EdgeArray<unsigned int> m_subGraph;     
00327 
00328     long m_attributes; 
00329 
00330 public:
00332     enum {
00333         nodeGraphics     = 0x00001, 
00334         edgeGraphics     = 0x00002, 
00335         nodeLevel        = 0x00004, 
00336         edgeIntWeight    = 0x00008, 
00337         edgeDoubleWeight = 0x00010, 
00338         edgeLabel        = 0x00020, 
00339         nodeLabel        = 0x00040, 
00340         edgeType         = 0x00080, 
00341         nodeType         = 0x00100, 
00342         nodeColor        = 0x00200, 
00343         nodeId           = 0x00400, 
00344         edgeArrow        = 0x00800, 
00345         edgeColor        = 0x01000, 
00346         edgeStyle        = 0x02000, 
00347         nodeStyle        = 0x04000, 
00348         nodeTemplate     = 0x08000, 
00349         edgeSubGraph     = 0x10000, 
00350         nodeWeight       = 0x20000  
00351     };
00352 
00354     enum {
00355         oval      = 0x8001,
00356         rectangle = 0x8002
00357     };
00358 
00360 
00363     GraphAttributes();
00364 
00365 
00367 
00371     GraphAttributes(const Graph &G, long initAttributes = nodeGraphics | edgeGraphics);
00372 
00373     virtual ~GraphAttributes() {}
00374 
00376 
00383     virtual void init(const Graph &G, long initAttr);
00384 
00386     long attributes() const { return m_attributes; }
00387 
00389     void initAttributes(long attr);
00390 
00392     void destroyAttributes(long attr);
00393 
00395     const Graph& constGraph() const { return *m_pGraph; }
00396     
00398     bool directed() { return m_directed; };
00399     
00401     void directed(bool directed) { m_directed = directed; };
00402     
00404     const String &templateNode(node v) const { return m_nodeTemplate[v]; }
00406     String &templateNode(node v) { return m_nodeTemplate[v]; }
00407 
00409     const double &x(node v) const { return m_x[v]; }
00411     double &x(node v) { return m_x[v]; }
00412 
00414     const double &y(node v) const { return m_y[v]; }
00416     double &y(node v) { return m_y[v]; }
00417 
00418 
00420     const NodeArray<double> &width() const { return m_width; }
00422     NodeArray<double> &width() { return m_width; }
00423 
00425     const double &width(node v) const { return m_width[v]; }
00427     double &width(node v) { return m_width[v]; }
00428 
00430     const NodeArray<double> &height() const { return m_height; }
00432     NodeArray<double> &height() { return m_height; }
00433 
00435     const double &height(node v) const { return m_height[v]; }
00437     double &height(node v) { return m_height[v]; }
00438 
00440     const int &level(node v) const { return m_level[v]; }
00442     int &level(node v) { return m_level[v]; }
00443 
00445     const int &weight(node v) const { return m_nodeIntWeight[v]; }
00447     int &weight(node v) { return m_nodeIntWeight[v]; }
00448     
00450     const BrushPattern &nodePattern(node v) const { return m_nodePattern[v]; }
00452     BrushPattern &nodePattern(node v) { return m_nodePattern[v]; }
00453 
00455     const EdgeStyle &styleNode(node v) const { return m_nodeStyle[v]; }
00457     EdgeStyle &styleNode(node v) { return m_nodeStyle[v]; }
00458 
00460     const double &lineWidthNode(node v) const { return m_nodeLineWidth[v]; }
00462     double &lineWidthNode(node v) { return m_nodeLineWidth[v]; }
00463 
00465     const String &nodeLine(node v) const { return m_nodeLine[v]; }
00467     String &nodeLine(node v) { return m_nodeLine[v]; }
00468 
00470     const DPolyline &bends(edge e) const { return m_bends[e]; }
00472     DPolyline &bends(edge e) { return m_bends[e]; }
00473 
00475     const int &intWeight(edge e) const { return m_intWeight[e]; }
00477     int &intWeight(edge e) { return m_intWeight[e]; }
00478 
00480     const double &doubleWeight(edge e) const { return m_doubleWeight[e]; }
00482     double &doubleWeight(edge e) { return m_doubleWeight[e]; }
00483 
00485     const double &edgeWidth(edge e) const { return m_edgeWidth[e]; }
00487     double &edgeWidth(edge e) { return m_edgeWidth[e]; }
00488 
00490     const String &colorNode(node v) const {return m_nodeColor[v];}
00492     String &colorNode(node v) {return m_nodeColor[v];}
00493 
00495     int shapeNode(node v) const {return m_nodeShape[v];}
00497     int &shapeNode(node v) {return m_nodeShape[v];}
00498 
00500     const String &labelNode(node v) const {return m_nodeLabel[v];}
00502     String &labelNode(node v) {return m_nodeLabel[v];}
00503 
00505     const String &labelEdge(edge e) const {return m_edgeLabel[e];}
00507     String &labelEdge(edge e) {return m_edgeLabel[e];}
00508 
00510     Graph::EdgeType type(edge e) const {
00511         return m_eType.valid() ? m_eType[e] : Graph::association;
00512     }
00514     Graph::EdgeType &type(edge e) { return m_eType[e]; }
00515 
00516 
00518     Graph::NodeType type(node v) const {
00519         return m_vType.valid() ? m_vType[v] : Graph::vertex;
00520     }
00522     Graph::NodeType &type(node v) { return m_vType[v]; }
00523 
00525     const int &idNode(node v) const { return m_nodeId[v]; }
00527     int &idNode(node v) { return m_nodeId[v]; }
00528 
00530     const EdgeArrow &arrowEdge(edge e) const { return m_edgeArrow[e]; }
00532     EdgeArrow &arrowEdge(edge e) { return m_edgeArrow[e]; }
00533 
00535     const EdgeStyle &styleEdge(edge e) const { return m_edgeStyle[e]; }
00537     EdgeStyle &styleEdge(edge e) { return m_edgeStyle[e]; }
00538 
00540     const String &colorEdge(edge e) const {return m_edgeColor[e];}
00542     String &colorEdge(edge e) {return m_edgeColor[e];}
00543 
00544     // Images:
00546     const String &imageUriNode(node v) const { return m_imageUri[v]; }
00548     String &imageUriNode(node v) { return m_imageUri[v]; }
00550     const ImageStyle &imageStyleNode(node v) const { return m_imageStyle[v]; }
00552     ImageStyle &imageStyleNode(node v) { return m_imageStyle[v]; }
00553     // Returns image alignment of node v.
00554     const ImageAlignment &imageAlignmentNode(node v) const { return m_imageAlign[v]; }
00555     // Returns image alignment of node v.
00556     ImageAlignment &imageAlignmentNode(node v) { return m_imageAlign[v]; }
00558     const bool &imageDrawLineNode(node v) const { return m_imageDrawLine[v]; }
00560     bool &imageDrawLineNode(node v) { return m_imageDrawLine[v]; }
00562     const double &imageWidthNode(node v) const { return m_imageWidth[v]; }
00564     double &imageWidthNode(node v) { return m_imageWidth[v]; }
00565     // Returns image height of node v.
00566     const double &imageHeightNode(node v) const { return m_imageHeight[v]; }
00567     // Returns image height of node v.
00568     double &imageHeightNode(node v) { return m_imageHeight[v]; }
00569     
00571     const unsigned int &subGraphBits(edge e) const { return m_subGraph[e]; }
00573     unsigned int &subGraphBits(edge e) { return m_subGraph[e]; }
00574 
00576     bool inSubGraph(edge e, int n) const { OGDF_ASSERT( n>=0 && n<32 ); return (m_subGraph[e] & (1 << n)) != 0; }
00578     void addSubGraph(edge e, int n) { OGDF_ASSERT( n>=0 && n<32 ); m_subGraph[e] |= (1 << n); }
00580     void removeSubGraph(edge e, int n) { OGDF_ASSERT( n>=0 && n<32 ); m_subGraph[e] &= ~(1 << n); }
00581 
00583     const DRect boundingBox() const;
00584 
00591     bool isAssociationClass(node v) const
00592     {
00593         return (type(v) == Graph::associationClass);
00594     }
00595 
00605     void addNodeCenter2Bends(int mode = 1);
00606 
00607     void clearAllBends();
00608 
00610 
00618     int hierarchyList(List<List<node>* > &list) const;
00619 
00621 
00629     int hierarchyList(List<List<edge>* > &list) const;
00630 
00632     void setAllWidth(double w);
00634     void setAllHeight(double h);
00635     
00637     bool readGML(Graph &G, const String &fileName);
00638 
00640     bool readGML(Graph &G, istream &is);
00641 
00643     void writeGML(const String &fileName) const;
00644 
00646     void writeGML(ostream &os) const;
00647 
00649     bool readXML(Graph &G, const String &fileName);
00650 
00652     bool readXML(Graph &G, istream &is);
00653 
00655     void writeXML(const String &fileName,const char* delimiter = "",const char* offset = "") const;
00656 
00658     virtual void writeXML(ostream &os,const char* delimiter = "",const char* offset = "") const;
00659 
00661     bool readRudy(Graph &G, const String &fileName);
00662 
00664     bool readRudy(Graph &G, istream &is);
00665 
00667     void writeRudy(const String &fileName) const;
00668 
00670     void writeRudy(ostream &os) const;
00671 
00672 
00673 
00675 
00681     void removeUnnecessaryBendsHV();
00682 };
00683 
00684 
00685 
00686 } // end namespace ogdf
00687 
00688 
00689 #endif