Open
Graph Drawing
Framework

 v.2012.07
 

GraphAttributes.h
Go to the documentation of this file.
1 /*
2  * $Revision: 2585 $
3  *
4  * last checkin:
5  * $Author: klein $
6  * $Date: 2012-07-12 03:46:50 +0200 (Do, 12. Jul 2012) $
7  ***************************************************************/
8 
47 #ifdef _MSC_VER
48 #pragma once
49 #endif
50 
51 #ifndef OGDF_ATTRIBUTED_GRAPH_H
52 #define OGDF_ATTRIBUTED_GRAPH_H
53 
54 #include <ogdf/basic/NodeArray.h>
55 #include <ogdf/basic/EdgeArray.h>
56 #include <ogdf/basic/String.h>
57 #include <ogdf/basic/geometry.h>
58 
59 namespace ogdf {
60 
61 //---------------------------------------------------------
62 // GraphAttributes
63 // graph topology + graphical attributes
64 //---------------------------------------------------------
66 
86 public:
88  enum EdgeArrow {
89  none,
90  last,
92  both,
93  undefined
94  };
95 
97 
100  enum EdgeStyle {
101  esNoPen = 0,
102  esSolid = 1,
103  esDash = 2,
104  esDot = 3,
105  esDashdot = 4,
106  esDashdotdot = 5
108  };
109 
111  static EdgeStyle intToStyle(int i) {
112  switch (i) {
113  case 0:
114  return esNoPen;
115  case 1:
116  return esSolid;
117  case 2:
118  return esDash;
119  case 3:
120  return esDot;
121  case 4:
122  return esDashdot;
123  case 5:
124  return esDashdotdot;
125  default:
126  return esNoPen;
127 
128  }
129  }
130 
132 
136  bpNone = 0,
137  bpSolid = 1,
138  bpDense1 = 2,
139  bpDense2 = 3,
140  bpDense3 = 4,
141  bpDense4 = 5,
142  bpDense5 = 6,
143  bpDense6 = 7,
144  bpDense7 = 8,
145  bpHorizontal = 9,
146  bpVertical = 10,
147  bpCross = 11,
148  BackwardDiagonal = 12,
149  ForwardDiagonal = 13,
150  DiagonalCross = 14
151  };
152 
154  static BrushPattern intToPattern(int i) {
155  switch (i) {
156  case 0:
157  return bpNone;
158  break;
159  case 1:
160  return bpSolid;
161  break;
162  case 2:
163  return bpDense1;
164  break;
165  case 3:
166  return bpDense2;
167  break;
168  case 4:
169  return bpDense3;
170  break;
171  case 5:
172  return bpDense4;
173  break;
174  case 6:
175  return bpDense5;
176  break;
177  case 7:
178  return bpDense6;
179  break;
180  case 8:
181  return bpDense7;
182  break;
183  case 9:
184  return bpHorizontal;
185  break;
186  case 10:
187  return bpVertical;
188  break;
189  case 11:
190  return bpCross;
191  break;
192  case 12:
193  return BackwardDiagonal;
194  break;
195  case 13:
196  return ForwardDiagonal;
197  break;
198  case 14:
199  return DiagonalCross;
200  break;
201  default:
202  return bpNone;
203  break;
204  }
205  }
206 
208  enum ImageStyle {
209  FreeScale = 0, FixScale = 1
210  };
213  TopLeft = 0, TopCenter, TopRight, CenterLeft, Center, CenterRight, BottomLeft, BottomCenter, BottomRight
214  };
215 
217  static ImageStyle intToImageStyle(int i) {
218  switch (i) {
219  case 0:
220  return FreeScale;
221  break;
222  case 1:
223  return FixScale;
224  break;
225  default:
226  return FreeScale;
227  }//switch
228  }//intToStyle
229 
232  switch (i) {
233  case 0:
234  return TopLeft;
235  break;
236  case 1:
237  return TopCenter;
238  break;
239  case 2:
240  return TopRight;
241  break;
242  case 3:
243  return CenterLeft;
244  break;
245  case 4:
246  return Center;
247  break;
248  case 5:
249  return CenterRight;
250  break;
251  case 6:
252  return BottomLeft;
253  break;
254  case 7:
255  return BottomCenter;
256  break;
257  case 8:
258  return BottomRight;
259  break;
260  default:
261  return TopLeft;
262  }//switch
263  }//intToAlignment
264 
265 protected:
270  void writeLongString(ostream &os, const String &str) const;
271 
272  /* Methods for OGML serialization */
273 
275  static const char * edgeStyleToOGML(const GraphAttributes::EdgeStyle & edgeStyle);
276 
278  static const char * imageAlignmentToOGML(const GraphAttributes::ImageAlignment &imgAlign);
279 
281  static const char * imageStyleToOGML(const GraphAttributes::ImageStyle &imgStyle);
282 
284  static const char * brushPatternToOGML(const GraphAttributes::BrushPattern & brushPattern);
285 
286  //static void generateIndent(char ** indent, const int & indentSize);
287 
289  String formatLabel(const String & labelText);
290 
291  /* End methods for OGML serialization */
292 
293  const Graph *m_pGraph;
294 
295  bool m_directed;
296 
297  // graphical representation of nodes
310 
311  // images
318 
319  // other node attributes
323  NodeArray<Graph::NodeType> m_vType; // type (vertex, dummy, generalizationMerger)
324 
325  // graphical representation of edges
333 
334  // other edge attributes
338 
340 
341 public:
343  enum {
344  nodeGraphics = 0x00001,
345  edgeGraphics = 0x00002,
346  nodeLevel = 0x00004,
347  edgeIntWeight = 0x00008,
348  edgeDoubleWeight = 0x00010,
349  edgeLabel = 0x00020,
350  nodeLabel = 0x00040,
351  edgeType = 0x00080,
352  nodeType = 0x00100,
353  nodeColor = 0x00200,
354  nodeId = 0x00400,
355  edgeArrow = 0x00800,
356  edgeColor = 0x01000,
357  edgeStyle = 0x02000,
358  nodeStyle = 0x04000,
359 
360 
361  nodeTemplate = 0x08000,
362  edgeSubGraph = 0x10000,
363  nodeWeight = 0x20000
365  };
366 
368  enum {
369  oval = 0x8001, rectangle = 0x8002
370  };
371 
373 
376  GraphAttributes();
377 
379 
383  GraphAttributes(const Graph &G, long initAttributes = nodeGraphics | edgeGraphics);
384 
385  virtual ~GraphAttributes() {
386  }
387 
389 
396  virtual void init(const Graph &G, long initAttr);
397 
399  long attributes() const {
400  return m_attributes;
401  }
402 
404  void initAttributes(long attr);
405 
407  void destroyAttributes(long attr);
408 
410  const Graph& constGraph() const {
411  return *m_pGraph;
412  }
413 
415  bool directed() {
416  return m_directed;
417  }
418 
420  void directed(bool directed) {
421  m_directed = directed;
422  }
423 
425  const String &templateNode(node v) const {
426  return m_nodeTemplate[v];
427  }
430  return m_nodeTemplate[v];
431  }
432 
434  const double &x(node v) const {
435  return m_x[v];
436  }
438  double &x(node v) {
439  return m_x[v];
440  }
441 
443  const double &y(node v) const {
444  return m_y[v];
445  }
447  double &y(node v) {
448  return m_y[v];
449  }
450 
452  const NodeArray<double> &width() const {
453  return m_width;
454  }
457  return m_width;
458  }
459 
461  const double &width(node v) const {
462  return m_width[v];
463  }
465  double &width(node v) {
466  return m_width[v];
467  }
468 
470  const NodeArray<double> &height() const {
471  return m_height;
472  }
475  return m_height;
476  }
477 
479  const double &height(node v) const {
480  return m_height[v];
481  }
483  double &height(node v) {
484  return m_height[v];
485  }
486 
488  const int &level(node v) const {
489  return m_level[v];
490  }
492  int &level(node v) {
493  return m_level[v];
494  }
495 
497  const int &weight(node v) const {
498  return m_nodeIntWeight[v];
499  }
501  int &weight(node v) {
502  return m_nodeIntWeight[v];
503  }
504 
506  const BrushPattern &nodePattern(node v) const {
507  return m_nodePattern[v];
508  }
511  return m_nodePattern[v];
512  }
513 
515  const EdgeStyle &styleNode(node v) const {
516  return m_nodeStyle[v];
517  }
520  return m_nodeStyle[v];
521  }
522 
524  const double &lineWidthNode(node v) const {
525  return m_nodeLineWidth[v];
526  }
528  double &lineWidthNode(node v) {
529  return m_nodeLineWidth[v];
530  }
531 
533  const String &nodeLine(node v) const {
534  return m_nodeLine[v];
535  }
538  return m_nodeLine[v];
539  }
540 
542  const DPolyline &bends(edge e) const {
543  return m_bends[e];
544  }
547  return m_bends[e];
548  }
549 
551  const int &intWeight(edge e) const {
552  return m_intWeight[e];
553  }
555  int &intWeight(edge e) {
556  return m_intWeight[e];
557  }
558 
560  const double &doubleWeight(edge e) const {
561  return m_doubleWeight[e];
562  }
564  double &doubleWeight(edge e) {
565  return m_doubleWeight[e];
566  }
567 
569  const double &edgeWidth(edge e) const {
570  return m_edgeWidth[e];
571  }
573  double &edgeWidth(edge e) {
574  return m_edgeWidth[e];
575  }
576 
578  const String &colorNode(node v) const {
579  return m_nodeColor[v];
580  }
583  return m_nodeColor[v];
584  }
585 
587  int shapeNode(node v) const {
588  return m_nodeShape[v];
589  }
591  int &shapeNode(node v) {
592  return m_nodeShape[v];
593  }
594 
596  const String &labelNode(node v) const {
597  return m_nodeLabel[v];
598  }
601  return m_nodeLabel[v];
602  }
603 
605  const String &labelEdge(edge e) const {
606  return m_edgeLabel[e];
607  }
610  return m_edgeLabel[e];
611  }
612 
615  return m_eType.valid() ? m_eType[e] : Graph::association;
616  }
619  return m_eType[e];
620  }
621 
624  return m_vType.valid() ? m_vType[v] : Graph::vertex;
625  }
628  return m_vType[v];
629  }
630 
632  const int &idNode(node v) const {
633  return m_nodeId[v];
634  }
636  int &idNode(node v) {
637  return m_nodeId[v];
638  }
639 
641  const EdgeArrow &arrowEdge(edge e) const {
642  return m_edgeArrow[e];
643  }
646  return m_edgeArrow[e];
647  }
648 
650  const EdgeStyle &styleEdge(edge e) const {
651  return m_edgeStyle[e];
652  }
655  return m_edgeStyle[e];
656  }
657 
659  const String &colorEdge(edge e) const {
660  return m_edgeColor[e];
661  }
664  return m_edgeColor[e];
665  }
666 
667  // Images:
669  const String &imageUriNode(node v) const {
670  return m_imageUri[v];
671  }
674  return m_imageUri[v];
675  }
677  const ImageStyle &imageStyleNode(node v) const {
678  return m_imageStyle[v];
679  }
682  return m_imageStyle[v];
683  }
684  // Returns image alignment of node v.
686  return m_imageAlign[v];
687  }
688  // Returns image alignment of node v.
690  return m_imageAlign[v];
691  }
693  const bool &imageDrawLineNode(node v) const {
694  return m_imageDrawLine[v];
695  }
698  return m_imageDrawLine[v];
699  }
701  const double &imageWidthNode(node v) const {
702  return m_imageWidth[v];
703  }
705  double &imageWidthNode(node v) {
706  return m_imageWidth[v];
707  }
708  // Returns image height of node v.
709  const double &imageHeightNode(node v) const {
710  return m_imageHeight[v];
711  }
712  // Returns image height of node v.
713  double &imageHeightNode(node v) {
714  return m_imageHeight[v];
715  }
716 
718  const unsigned int &subGraphBits(edge e) const {
719  return m_subGraph[e];
720  }
722  unsigned int &subGraphBits(edge e) {
723  return m_subGraph[e];
724  }
725 
727  bool inSubGraph(edge e, int n) const {
728  OGDF_ASSERT( n>=0 && n<32 );
729  return (m_subGraph[e] & (1 << n)) != 0;
730  }
732  void addSubGraph(edge e, int n) {
733  OGDF_ASSERT( n>=0 && n<32 );
734  m_subGraph[e] |= (1 << n);
735  }
737  void removeSubGraph(edge e, int n) {
738  OGDF_ASSERT( n>=0 && n<32 );
739  m_subGraph[e] &= ~(1 << n);
740  }
741 
743  const DRect boundingBox() const;
744 
751  bool isAssociationClass(node v) const {
752  return (type(v) == Graph::associationClass);
753  }
754 
764  void addNodeCenter2Bends(int mode = 1);
765 
766  void clearAllBends();
767 
769 
777  int hierarchyList(List<List<node>*> &list) const;
778 
780 
788  int hierarchyList(List<List<edge>*> &list) const;
789 
791  void setAllWidth(double w);
793  void setAllHeight(double h);
794 
796  bool readGML(Graph &G, const String &fileName);
797 
799  bool readGML(Graph &G, istream &is);
800 
802  void writeGML(const String &fileName) const;
803 
805  void writeGML(ostream &os) const;
806 
808 
813  void writeSVG(const String &fileName, int fontSize = 3, const String &fontColor = "#000000") const;
814 
816 
821  void writeSVG(ostream &os, int fontSize, const String &fontColor) const;
822 
824  bool readXML(Graph &G, const String &fileName);
825 
827  bool readXML(Graph &G, istream &is);
828 
830  void writeXML(const String &fileName, const char* delimiter = "", const char* offset = "") const;
831 
833  virtual void writeXML(ostream &os, const char* delimiter = "", const char* offset = "") const;
834 
836  bool readRudy(Graph &G, const String &fileName);
837 
839  bool readRudy(Graph &G, istream &is);
840 
842  void writeRudy(const String &fileName) const;
843 
845  void writeRudy(ostream &os) const;
846 
848 
854  void removeUnnecessaryBendsHV();
855 };
856 
857 } // end namespace ogdf
858 
859 
860 #endif