1 /** \file
2  * \brief Implementation of DOT string conversion functions.
3  *
4  * \author Łukasz Hanuszczak
5  *
6  * \par License:
7  * This file is part of the Open Graph Drawing Framework (OGDF).
8  *
9  * \par
10  * Copyright (C)<br>
11  * See README.md in the OGDF root directory for details.
12  *
13  * \par
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * Version 2 or 3 as published by the Free Software Foundation;
17  * see the file LICENSE.txt included in the packaging of this file
18  * for details.
19  *
20  * \par
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * \par
27  * You should have received a copy of the GNU General Public
28  * License along with this program; if not, see
29  * http://www.gnu.org/copyleft/gpl.html
30  */
31 
32 #include <ogdf/fileformats/DOT.h>
33 #include <ogdf/fileformats/Utils.h>
34 
35 namespace ogdf {
36 
37 namespace dot {
38 
39 
toString(const Attribute & attr)40 std::string toString(const Attribute &attr)
41 {
42 	switch(attr) {
43 		case Attribute::Id: return "id";
44 		case Attribute::Label: return "label";
45 		case Attribute::Template: return "comment";
46 		case Attribute::Width: return "width";
47 		case Attribute::Height: return "height";
48 		case Attribute::Shape: return "shape";
49 		case Attribute::Position: return "pos";
50 		case Attribute::LabelPosition: return "labelpos";
51 		case Attribute::Stroke: return "color";
52 		case Attribute::StrokeType: return "stroketype";
53 		case Attribute::Fill: return "fillcolor";
54 		case Attribute::Weight: return "weight";
55 		case Attribute::Arrow: return "arrow";
56 		case Attribute::StrokeWidth: return "strokewidth";
57 		case Attribute::FillPattern: return "fillpattern";
58 		case Attribute::FillBackground: return "fillbgcolor";
59 		case Attribute::Type: return "type";
60 		case Attribute::Dir: return "dir";
61 		case Attribute::SubGraphs: return "available_for";
62 		default: return "comment";
63 	}
64 }
65 
66 
toString(const Shape & shape)67 std::string toString(const Shape &shape)
68 {
69 	switch(shape) {
70 		case Shape::Rect:             return "rect";
71 		case Shape::RoundedRect:      return "roundedrect";
72 		case Shape::Ellipse:          return "ellipse";
73 		case Shape::Triangle:         return "triangle";
74 		case Shape::Pentagon:         return "pentagon";
75 		case Shape::Hexagon:          return "hexagon";
76 		case Shape::Octagon:          return "octagon";
77 		case Shape::Rhomb:            return "diamond";
78 		case Shape::Trapeze:          return "trapezium";
79 		case Shape::Parallelogram:    return "parallelogram";
80 		case Shape::InvTriangle:      return "invtriangle";
81 		case Shape::InvTrapeze:       return "invtrapezium";
82 		case Shape::InvParallelogram: return "invparallelogram";
83 		case Shape::Image:            return "image";
84 	}
85 	OGDF_ASSERT(false);
86 	return "UNKNOWN";
87 }
88 
89 
toString(const EdgeArrow & arrow)90 std::string toString(const EdgeArrow &arrow)
91 {
92 	switch(arrow) {
93 		case EdgeArrow::None:      return "none";
94 		case EdgeArrow::Last:      return "forward";
95 		case EdgeArrow::First:     return "back";
96 		case EdgeArrow::Both:      return "both";
97 		case EdgeArrow::Undefined: return "none"; // Not supported.
98 	}
99 	OGDF_ASSERT(false);
100 	return "UNKNOWN";
101 }
102 
103 
toString(const Graph::EdgeType & type)104 std::string toString(const Graph::EdgeType &type)
105 {
106 	switch(type) {
107 		case Graph::EdgeType::association:    return "association";
108 		case Graph::EdgeType::generalization: return "generalization";
109 		case Graph::EdgeType::dependency:     return "dependency";
110 	}
111 	OGDF_ASSERT(false);
112 	return "UNKNOWN";
113 }
114 
115 
toAttribute(const std::string & str)116 Attribute toAttribute(const std::string &str)
117 {
118 	return toEnum(str, toString, static_cast<Attribute>(0), Attribute::Unknown, Attribute::Unknown);
119 }
120 
toShape(const std::string & str)121 Shape toShape(const std::string &str) {
122 	return toEnum(str, toString, Shape::Rect, Shape::Image, Shape::Rect);
123 }
124 
toArrow(const std::string & str)125 EdgeArrow toArrow(const std::string &str)
126 {
127 	return toEnum(str, toString, EdgeArrow::None, EdgeArrow::Undefined, EdgeArrow::Undefined);
128 }
129 
toEdgeType(const std::string & str)130 Graph::EdgeType toEdgeType(const std::string &str) {
131 	return toEnum(str, toString, Graph::EdgeType::association, Graph::EdgeType::dependency, Graph::EdgeType::association);
132 }
133 
134 }
135 
136 }
137