-
Notifications
You must be signed in to change notification settings - Fork 1
/
OgdfScene.h
217 lines (185 loc) · 5.76 KB
/
OgdfScene.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
* ogdf-qt-intro
* @ CapelliC 2017
*/
#ifndef OGDFSCENE_H
#define OGDFSCENE_H
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <ogdf/fileformats/GraphIO.h>
#include "OgdfSettings.h"
using namespace ogdf;
class OgdfScene : public QGraphicsScene
{
Q_OBJECT
public:
OgdfScene(const GraphAttributes &attr, const OgdfSettings &settings)
: m_attr(attr)
, m_clsAttr(nullptr)
, m_settings(settings)
{
}
OgdfScene(const ClusterGraphAttributes &attr, const OgdfSettings &settings)
: m_attr(attr)
, m_clsAttr(&attr)
, m_settings(settings)
{
}
void draw();
private:
//! attributes of the graph to be visualized
const GraphAttributes &m_attr;
//! attributes of the cluster graph (\a nullptr if no cluster graph)
const ClusterGraphAttributes *m_clsAttr;
//! SVG configuration
const OgdfSettings &m_settings;
/**
* Draws a rectangle for each cluster in the ogdf::ClusterGraph.
*
* \param xmlNode the XML-node to print to
*/
void drawClusters(QGraphicsItem* xmlNode);
/**
* Draws a sequence of lines for each edge in the graph.
*
* \param xmlNode the XML-node to print to
*/
void drawEdges(QGraphicsItem* xmlNode);
/**
* Draws a sequence of lines for an edge.
* Arrow heads are added if requested.
*
* \param xmlNode the XML-node to print to
* \param e the edge to be visualized
*/
void drawEdge(QGraphicsItem* xmlNode, edge e);
/**
* Draws the curve depicting a particular edge.
* Draws a sequence of cubic Bézier curves if requested.
* Falls back to straight lines if there are exactly two points or the curviness is set to 0.
*
* Note that this method clears the list of points.
*
* \param xmlNode the XML-node to print to
* \param points the points along the curve
* \param e the edge depicted by the curve
* \return the XML-node of the curve
*/
QGraphicsItem* drawCurve(QGraphicsItem* xmlNode, edge e, List<DPoint> &points);
/**
* Draws the path corresponding to a single line to the stream.
*
* \param ss the output stream
* \param p1 the first point of the line
* \param p2 the second point of the line
*/
void drawLine(QGraphicsItem* xmlNode, const DPoint &p1, const DPoint &p2);
/**
* Draws a list of points using cubic Bézier interpolation.
*
* \param ss the output stream
* \param points the points to be connected by lines
*/
void drawBezierPath(QGraphicsItem* xmlNode, List<DPoint> &points);
/**
* Draws a list of points as straight lines connected by circular arcs.
*
* \param ss the output stream
* \param points the points to be connected by lines
*/
void drawRoundPath(QGraphicsItem* xmlNode, List<DPoint> &points);
/**
* Draws a list of points as straight lines.
*
* \param ss the output stream
* \param points the points to be connected by lines
*/
void drawLines(QGraphicsItem* xmlNode, List<DPoint> &points);
/**
* Draws a cubic Bezíer path.
*
* \param ss the output stream
* \param p1 the first point of the line
* \param p2 the second point of the line
* \param c1 the first control point of the line
* \param c2 the second control point of the line
*/
void drawBezier(QGraphicsItem* xmlNode, const DPoint &p1, const DPoint &p2, const DPoint &c1, const DPoint &c2);
/**
* Draws all nodes of the graph.
*
* \param xmlNode the XML-node to print to
*/
void drawNodes(QGraphicsItem* xmlNode);
/**
* Writes the header including the bounding box as the viewport.
*
* \param doc the XML-document
* \return the root SVG-node
*/
QGraphicsItem* writeHeader();
/**
* Generates a string that describes the requested dash type.
*
* \param xmlNode the node to append the XML-attribute to
* \param lineStyle specifies the style of the dashes
* \param lineWidth the stroke width of the respective edge
*/
void writeDashArray(QGraphicsItem* xmlNode, StrokeType lineStyle, double lineWidth);
/**
* Draws a single node.
*
* \param xmlNode the XML-node to print to
* \param v the node to be printed
*/
void drawNode(QGraphicsItem* xmlNode, node v);
/**
* Draws a single cluster as a rectangle.
*
* \param xmlNode the XML-node to print to
* \param c the cluster to be printed
*/
void drawCluster(QGraphicsItem* xmlNode, cluster c);
/**
* Determines whether a candidate arrow tip lies inside the rectangle of the node.
*
* \param point the candidate arrow tip
* \param e the edge of the arrow head
* \param v the node the arrow is facing
*/
bool isCoveredBy(const DPoint &point, edge e, node v);
/**
* Draws an arrow head at the end of the edge.
* Sets the end point of the respective edge segment to the arrow head's tip.
*
* \param xmlNode the XML-node to print to
* \param start the start point of the edge segment the arrow head will be placed on
* \param end the end point of the edge segment the arrow head will be placed on, this will usually be modified
* \param v the node that the arrow is facing
* \param e the edge that the arrow belongs to
*/
void drawArrowHead(QGraphicsItem* xmlNode, const DPoint &start, DPoint &end, node v, edge e);
/**
* Returns the size of the arrow.
*
* \param e the edge that the arrow belongs to
* \param v the node that the arrow is facing
*/
double getArrowSize(edge e, node v);
/**
* Writes the requested line style to the line's XML-node.
*
* \param line the XML-node depicting the line
* \param e the edge associated with that line
*/
void appendLineStyle(QGraphicsItem* line, edge e);
/**
* Draws a polygon with the respective points.
*
* \param xmlNode the XML-node to print to
* \param points the list of coordinates
* \return The generated XML-node
*/
QAbstractGraphicsShapeItem* drawPolygon(QGraphicsItem* xmlNode, const std::list<double> points);
};
#endif // OGDFSCENE_H