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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
/******************************************************************************
*
*
*
*
* Copyright (C) 1997-2010 by Dimitri van Heesch.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation under the terms of the GNU General Public License is hereby
* granted. No representations are made about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
* See the GNU General Public License for more details.
*
* Documents produced by Doxygen are derivative works derived from the
* input used in their production; they are not affected by this license.
*
*/
#ifndef _DOT_H
#define _DOT_H
#include "qtbc.h"
#include <qlist.h>
#include <qdict.h>
#include <qwaitcondition.h>
#include <qmutex.h>
#include <qqueue.h>
#include <qthread.h>
#include "sortdict.h"
class ClassDef;
class FileDef;
class FTextStream;
class DotNodeList;
class ClassSDict;
class MemberDef;
class Definition;
class DirDef;
class GroupDef;
class DotGroupCollaboration;
class DotRunnerQueue;
enum GraphOutputFormat { BITMAP , EPS };
/** @brief Attributes of an edge of a dot graph */
struct EdgeInfo
{
enum Colors { Blue=0, Green=1, Red=2, Purple=3, Grey=4, Orange=5 };
enum Styles { Solid=0, Dashed=1 };
EdgeInfo() : m_color(0), m_style(0), m_labColor(0) {}
~EdgeInfo() {}
int m_color;
int m_style;
QCString m_label;
QCString m_url;
int m_labColor;
};
/** @brief A node in a dot graph */
class DotNode
{
public:
enum GraphType { Dependency, Inheritance, Collaboration, Hierarchy, CallGraph };
enum TruncState { Unknown, Truncated, Untruncated };
DotNode(int n,const char *lab,const char *tip,const char *url,
bool rootNode=FALSE,ClassDef *cd=0);
~DotNode();
void addChild(DotNode *n,
int edgeColor=EdgeInfo::Purple,
int edgeStyle=EdgeInfo::Solid,
const char *edgeLab=0,
const char *edgeURL=0,
int edgeLabCol=-1
);
void addParent(DotNode *n);
void deleteNode(DotNodeList &deletedList,SDict<DotNode> *skipNodes=0);
void removeChild(DotNode *n);
void removeParent(DotNode *n);
int findParent( DotNode *n );
void write(FTextStream &t,GraphType gt,GraphOutputFormat f,
bool topDown,bool toChildren,bool backArrows,bool reNumber);
int m_subgraphId;
void clearWriteFlag();
void writeXML(FTextStream &t,bool isClassGraph);
void writeDEF(FTextStream &t);
QCString label() const { return m_label; }
int number() const { return m_number; }
bool isVisible() const { return m_visible; }
TruncState isTruncated() const { return m_truncated; }
int distance() const { return m_distance; }
private:
void colorConnectedNodes(int curColor);
void writeBox(FTextStream &t,GraphType gt,GraphOutputFormat f,
bool hasNonReachableChildren, bool reNumber=FALSE);
void writeArrow(FTextStream &t,GraphType gt,GraphOutputFormat f,DotNode *cn,
EdgeInfo *ei,bool topDown, bool pointBack=TRUE, bool reNumber=FALSE);
void setDistance(int distance);
const DotNode *findDocNode() const; // only works for acyclic graphs!
void markAsVisible(bool b=TRUE) { m_visible=b; }
void markAsTruncated(bool b=TRUE) { m_truncated=b ? Truncated : Untruncated; }
int m_number;
QCString m_label; //!< label text
QCString m_tooltip; //!< node's tooltip
QCString m_url; //!< url of the node (format: remote$local)
QList<DotNode> *m_parents; //!< list of parent nodes (incoming arrows)
QList<DotNode> *m_children; //!< list of child nodes (outgoing arrows)
QList<EdgeInfo> *m_edgeInfo; //!< edge info for each child
bool m_deleted; //!< used to mark a node as deleted
bool m_written; //!< used to mark a node as written
bool m_hasDoc; //!< used to mark a node as documented
bool m_isRoot; //!< indicates if this is a root node
ClassDef * m_classDef; //!< class representing this node (can be 0)
bool m_visible; //!< is the node visible in the output
TruncState m_truncated; //!< does the node have non-visible children/parents
int m_distance; //!< shortest path to the root node
friend class DotGfxHierarchyTable;
friend class DotClassGraph;
friend class DotInclDepGraph;
friend class DotNodeList;
friend class DotCallGraph;
friend class DotGroupCollaboration;
friend QCString computeMd5Signature(
DotNode *root, GraphType gt,
GraphOutputFormat f,
bool lrRank, bool renderParents,
bool backArrows,
QCString &graphStr
);
};
inline int DotNode::findParent( DotNode *n )
{
if( !m_parents )
return -1;
return m_parents->find(n);
}
/** @brief Represents a graphical class hierarchy */
class DotGfxHierarchyTable
{
public:
DotGfxHierarchyTable();
~DotGfxHierarchyTable();
void writeGraph(FTextStream &t,const char *path,const char *fileName) const;
private:
void addHierarchy(DotNode *n,ClassDef *cd,bool hide);
void addClassList(ClassSDict *cl);
QList<DotNode> *m_rootNodes;
QDict<DotNode> *m_usedNodes;
static int m_curNodeNumber;
DotNodeList *m_rootSubgraphs;
};
/** @brief Representation of a class inheritance or dependency graph */
class DotClassGraph
{
public:
DotClassGraph(ClassDef *cd,DotNode::GraphType t);
~DotClassGraph();
bool isTrivial() const;
bool isTooBig() const;
QCString writeGraph(FTextStream &t,GraphOutputFormat f,const char *path,
const char *fileName, const char *relPath,
bool TBRank=TRUE,bool imageMap=TRUE) const;
void writeXML(FTextStream &t);
void writeDEF(FTextStream &t);
QCString diskName() const;
private:
void buildGraph(ClassDef *cd,DotNode *n,bool base,int distance);
bool determineVisibleNodes(DotNode *rootNode,int maxNodes,bool includeParents);
void determineTruncatedNodes(QList<DotNode> &queue,bool includeParents);
void addClass(ClassDef *cd,DotNode *n,int prot,const char *label,
const char *usedName,const char *templSpec,
bool base,int distance);
DotNode * m_startNode;
QDict<DotNode> * m_usedNodes;
static int m_curNodeNumber;
DotNode::GraphType m_graphType;
QCString m_diskName;
bool m_lrRank;
};
/** @brief Representation of an include dependency graph */
class DotInclDepGraph
{
public:
DotInclDepGraph(FileDef *fd,bool inverse);
~DotInclDepGraph();
QCString writeGraph(FTextStream &t, GraphOutputFormat f,
const char *path,const char *fileName,const char *relPath,
bool writeImageMap=TRUE) const;
bool isTrivial() const;
bool isTooBig() const;
QCString diskName() const;
void writeXML(FTextStream &t);
private:
void buildGraph(DotNode *n,FileDef *fd,int distance);
void determineVisibleNodes(QList<DotNode> &queue,int &maxNodes);
void determineTruncatedNodes(QList<DotNode> &queue);
DotNode *m_startNode;
QDict<DotNode> *m_usedNodes;
static int m_curNodeNumber;
QCString m_diskName;
int m_maxDistance;
bool m_inverse;
};
/** @brief Representation of an call graph */
class DotCallGraph
{
public:
DotCallGraph(MemberDef *md,bool inverse);
~DotCallGraph();
QCString writeGraph(FTextStream &t, GraphOutputFormat f,
const char *path,const char *fileName,
const char *relPath,bool writeImageMap=TRUE) const;
void buildGraph(DotNode *n,MemberDef *md,int distance);
bool isTrivial() const;
bool isTooBig() const;
void determineVisibleNodes(QList<DotNode> &queue, int &maxNodes);
void determineTruncatedNodes(QList<DotNode> &queue);
private:
DotNode *m_startNode;
static int m_curNodeNumber;
QDict<DotNode> *m_usedNodes;
int m_maxDistance;
int m_recDepth;
bool m_inverse;
QCString m_diskName;
Definition * m_scope;
};
/** @brief Representation of an directory dependency graph */
class DotDirDeps
{
public:
DotDirDeps(DirDef *dir);
~DotDirDeps();
bool isTrivial() const;
QCString writeGraph(FTextStream &out,
GraphOutputFormat format,
const char *path,
const char *fileName,
const char *relPath,
bool writeImageMap=TRUE) const;
private:
DirDef *m_dir;
};
/** @brief Representation of a group collaboration graph */
class DotGroupCollaboration
{
public :
enum EdgeType
{ tmember = 0,
tclass,
tnamespace,
tfile,
tpages,
tdir,
thierarchy
};
class Link
{
public:
Link(const QCString lab,const QCString &u) : label(lab), url(u) {}
QCString label;
QCString url;
};
class Edge
{
public :
Edge(DotNode *start,DotNode *end,EdgeType type)
: pNStart(start), pNEnd(end), eType(type)
{ links.setAutoDelete(TRUE); }
DotNode* pNStart;
DotNode* pNEnd;
EdgeType eType;
QList<Link> links;
void write( FTextStream &t ) const;
};
DotGroupCollaboration(GroupDef* gd);
~DotGroupCollaboration();
QCString writeGraph(FTextStream &t, GraphOutputFormat format,
const char *path,const char *fileName,const char *relPath,
bool writeImageMap=TRUE) const;
void buildGraph(GroupDef* gd);
bool isTrivial() const;
private :
void addCollaborationMember( Definition* def, QCString& url, EdgeType eType );
void addMemberList( class MemberList* ml );
void writeGraphHeader(FTextStream &t) const;
Edge* addEdge( DotNode* _pNStart, DotNode* _pNEnd, EdgeType _eType,
const QCString& _label, const QCString& _url );
DotNode *m_rootNode;
int m_curNodeId;
QDict<DotNode> *m_usedNodes;
QCString m_diskName;
QList<Edge> m_edges;
};
/** @brief Helper class to run dot from doxygen.
*/
class DotRunner
{
public:
struct CleanupItem
{
QCString path;
QCString file;
};
/** Creates a runner for a dot \a file. */
DotRunner(const QCString &file,const QCString &fontPath,bool checkResult,
const QCString &imageName = QCString());
/** Adds an additional job to the run.
* Performing multiple jobs one file can be faster.
*/
void addJob(const char *format,const char *output);
void addPostProcessing(const char *cmd,const char *args);
void preventCleanUp() { m_cleanUp = FALSE; }
/** Runs dot for all jobs added. */
bool run();
CleanupItem cleanup() const { return m_cleanupItem; }
private:
QList<QCString> m_jobs;
QCString m_postArgs;
QCString m_postCmd;
QCString m_file;
QCString m_path;
bool m_checkResult;
QCString m_imageName;
bool m_cleanUp;
CleanupItem m_cleanupItem;
};
/** @brief Helper class to insert a set of map file into an output file */
class DotMapConverter
{
public:
struct Map
{
QCString mapFile;
QCString relPath;
bool urlOnly;
QCString context;
QCString label;
};
DotMapConverter(const char *patchFile);
int addMap(const QCString &mapFile,const QCString &relPath,
bool urlOnly,const QCString &context,const QCString &label);
int addFigure(const QCString &baseName,
const QCString &figureName,bool heightCheck);
bool run();
private:
QList<Map> m_maps;
QCString m_patchFile;
};
class DotRunnerQueue
{
public:
void enqueue(DotRunner *runner);
DotRunner *dequeue();
uint count() const;
private:
QWaitCondition m_bufferNotEmpty;
QQueue<DotRunner> m_queue;
mutable QMutex m_mutex;
};
class DotWorkerThread : public QThread
{
public:
DotWorkerThread(int id,DotRunnerQueue *queue);
void run();
void cleanup();
private:
int m_id;
DotRunnerQueue *m_queue;
QList<DotRunner::CleanupItem> m_cleanupItems;
};
/** @brief singleton that manages dot relation actions */
class DotManager
{
public:
static DotManager *instance();
void addRun(DotRunner *run);
int addMap(const QCString &file,const QCString &mapFile,
const QCString &relPath,bool urlOnly,
const QCString &context,const QCString &label);
int addFigure(const QCString &file,const QCString &baseName,
const QCString &figureName,bool heightCheck);
bool run();
private:
DotManager();
virtual ~DotManager();
QList<DotRunner> m_dotRuns;
SDict<DotMapConverter> m_dotMaps;
static DotManager *m_theInstance;
DotRunnerQueue *m_queue;
QList<DotWorkerThread> m_workers;
};
/** Generated a graphs legend page */
void generateGraphLegend(const char *path);
void writeDotGraphFromFile(const char *inFile,const char *outDir,
const char *outFile,GraphOutputFormat format);
QCString getDotImageMapFromFile(const QCString& inFile, const QCString& outDir,
const QCString& relPath,const QCString& context);
void writeDotDirDepGraph(FTextStream &t,DirDef *dd);
#endif
|