1 /******************************************************************************
3 * $Id: dot.h,v 1.14 2001/03/19 19:27:40 root Exp $
6 * Copyright (C) 1997-2012 by Dimitri van Heesch.
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation under the terms of the GNU General Public License is hereby
10 * granted. No representations are made about the suitability of this software
11 * for any purpose. It is provided "as is" without express or implied warranty.
12 * See the GNU General Public License for more details.
14 * Documents produced by Doxygen are derivative works derived from the
15 * input used in their production; they are not affected by this license.
25 #include <qwaitcondition.h>
40 class DotGroupCollaboration;
43 enum GraphOutputFormat { BITMAP , EPS };
45 /** Attributes of an edge of a dot graph */
48 enum Colors { Blue=0, Green=1, Red=2, Purple=3, Grey=4, Orange=5 };
49 enum Styles { Solid=0, Dashed=1 };
50 EdgeInfo() : m_color(0), m_style(0), m_labColor(0) {}
59 /** A node in a dot graph */
63 enum GraphType { Dependency, Inheritance, Collaboration, Hierarchy, CallGraph };
64 enum TruncState { Unknown, Truncated, Untruncated };
65 DotNode(int n,const char *lab,const char *tip,const char *url,
66 bool rootNode=FALSE,ClassDef *cd=0);
68 void addChild(DotNode *n,
69 int edgeColor=EdgeInfo::Purple,
70 int edgeStyle=EdgeInfo::Solid,
71 const char *edgeLab=0,
72 const char *edgeURL=0,
75 void addParent(DotNode *n);
76 void deleteNode(DotNodeList &deletedList,SDict<DotNode> *skipNodes=0);
77 void removeChild(DotNode *n);
78 void removeParent(DotNode *n);
79 int findParent( DotNode *n );
80 void write(FTextStream &t,GraphType gt,GraphOutputFormat f,
81 bool topDown,bool toChildren,bool backArrows,bool reNumber);
83 void clearWriteFlag();
84 void writeXML(FTextStream &t,bool isClassGraph);
85 void writeDEF(FTextStream &t);
86 QCString label() const { return m_label; }
87 int number() const { return m_number; }
88 bool isVisible() const { return m_visible; }
89 TruncState isTruncated() const { return m_truncated; }
90 int distance() const { return m_distance; }
93 void colorConnectedNodes(int curColor);
94 void writeBox(FTextStream &t,GraphType gt,GraphOutputFormat f,
95 bool hasNonReachableChildren, bool reNumber=FALSE);
96 void writeArrow(FTextStream &t,GraphType gt,GraphOutputFormat f,DotNode *cn,
97 EdgeInfo *ei,bool topDown, bool pointBack=TRUE, bool reNumber=FALSE);
98 void setDistance(int distance);
99 const DotNode *findDocNode() const; // only works for acyclic graphs!
100 void markAsVisible(bool b=TRUE) { m_visible=b; }
101 void markAsTruncated(bool b=TRUE) { m_truncated=b ? Truncated : Untruncated; }
103 QCString m_label; //!< label text
104 QCString m_tooltip; //!< node's tooltip
105 QCString m_url; //!< url of the node (format: remote$local)
106 QList<DotNode> *m_parents; //!< list of parent nodes (incoming arrows)
107 QList<DotNode> *m_children; //!< list of child nodes (outgoing arrows)
108 QList<EdgeInfo> *m_edgeInfo; //!< edge info for each child
109 bool m_deleted; //!< used to mark a node as deleted
110 bool m_written; //!< used to mark a node as written
111 bool m_hasDoc; //!< used to mark a node as documented
112 bool m_isRoot; //!< indicates if this is a root node
113 ClassDef * m_classDef; //!< class representing this node (can be 0)
114 bool m_visible; //!< is the node visible in the output
115 TruncState m_truncated; //!< does the node have non-visible children/parents
116 int m_distance; //!< shortest path to the root node
118 friend class DotGfxHierarchyTable;
119 friend class DotClassGraph;
120 friend class DotInclDepGraph;
121 friend class DotNodeList;
122 friend class DotCallGraph;
123 friend class DotGroupCollaboration;
125 friend QCString computeMd5Signature(
126 DotNode *root, GraphType gt,
128 bool lrRank, bool renderParents,
130 const QCString &title,
135 inline int DotNode::findParent( DotNode *n )
139 return m_parents->find(n);
142 /** Represents a graphical class hierarchy */
143 class DotGfxHierarchyTable
146 DotGfxHierarchyTable();
147 ~DotGfxHierarchyTable();
148 void writeGraph(FTextStream &t,const char *path, const char *fileName) const;
151 void addHierarchy(DotNode *n,ClassDef *cd,bool hide);
152 void addClassList(ClassSDict *cl);
154 QList<DotNode> *m_rootNodes;
155 QDict<DotNode> *m_usedNodes;
156 static int m_curNodeNumber;
157 DotNodeList *m_rootSubgraphs;
160 /** Representation of a class inheritance or dependency graph */
164 DotClassGraph(ClassDef *cd,DotNode::GraphType t);
166 bool isTrivial() const;
167 bool isTooBig() const;
168 QCString writeGraph(FTextStream &t,GraphOutputFormat f,const char *path,
169 const char *fileName, const char *relPath,
170 bool TBRank=TRUE,bool imageMap=TRUE,int graphId=-1) const;
172 void writeXML(FTextStream &t);
173 void writeDEF(FTextStream &t);
174 QCString diskName() const;
177 void buildGraph(ClassDef *cd,DotNode *n,bool base,int distance);
178 bool determineVisibleNodes(DotNode *rootNode,int maxNodes,bool includeParents);
179 void determineTruncatedNodes(QList<DotNode> &queue,bool includeParents);
180 void addClass(ClassDef *cd,DotNode *n,int prot,const char *label,
181 const char *usedName,const char *templSpec,
182 bool base,int distance);
184 DotNode * m_startNode;
185 QDict<DotNode> * m_usedNodes;
186 static int m_curNodeNumber;
187 DotNode::GraphType m_graphType;
192 /** Representation of an include dependency graph */
193 class DotInclDepGraph
196 DotInclDepGraph(FileDef *fd,bool inverse);
198 QCString writeGraph(FTextStream &t, GraphOutputFormat f,
199 const char *path,const char *fileName,const char *relPath,
200 bool writeImageMap=TRUE,int graphId=-1) const;
201 bool isTrivial() const;
202 bool isTooBig() const;
203 QCString diskName() const;
204 void writeXML(FTextStream &t);
207 void buildGraph(DotNode *n,FileDef *fd,int distance);
208 void determineVisibleNodes(QList<DotNode> &queue,int &maxNodes);
209 void determineTruncatedNodes(QList<DotNode> &queue);
211 DotNode *m_startNode;
212 QDict<DotNode> *m_usedNodes;
213 static int m_curNodeNumber;
219 /** Representation of an call graph */
223 DotCallGraph(MemberDef *md,bool inverse);
225 QCString writeGraph(FTextStream &t, GraphOutputFormat f,
226 const char *path,const char *fileName,
227 const char *relPath,bool writeImageMap=TRUE,
228 int graphId=-1) const;
229 void buildGraph(DotNode *n,MemberDef *md,int distance);
230 bool isTrivial() const;
231 bool isTooBig() const;
232 void determineVisibleNodes(QList<DotNode> &queue, int &maxNodes);
233 void determineTruncatedNodes(QList<DotNode> &queue);
236 DotNode *m_startNode;
237 static int m_curNodeNumber;
238 QDict<DotNode> *m_usedNodes;
243 Definition * m_scope;
246 /** Representation of an directory dependency graph */
250 DotDirDeps(DirDef *dir);
252 bool isTrivial() const;
253 QCString writeGraph(FTextStream &out,
254 GraphOutputFormat format,
256 const char *fileName,
258 bool writeImageMap=TRUE,
259 int graphId=-1) const;
264 /** Representation of a group collaboration graph */
265 class DotGroupCollaboration
281 Link(const QCString lab,const QCString &u) : label(lab), url(u) {}
289 Edge(DotNode *start,DotNode *end,EdgeType type)
290 : pNStart(start), pNEnd(end), eType(type)
291 { links.setAutoDelete(TRUE); }
298 void write( FTextStream &t ) const;
301 DotGroupCollaboration(GroupDef* gd);
302 ~DotGroupCollaboration();
303 QCString writeGraph(FTextStream &t, GraphOutputFormat format,
304 const char *path,const char *fileName,const char *relPath,
305 bool writeImageMap=TRUE,int graphId=-1) const;
306 void buildGraph(GroupDef* gd);
307 bool isTrivial() const;
309 void addCollaborationMember( Definition* def, QCString& url, EdgeType eType );
310 void addMemberList( class MemberList* ml );
311 void writeGraphHeader(FTextStream &t,const QCString &title) const;
312 Edge* addEdge( DotNode* _pNStart, DotNode* _pNEnd, EdgeType _eType,
313 const QCString& _label, const QCString& _url );
317 QDict<DotNode> *m_usedNodes;
322 /** Helper class to run dot from doxygen.
333 /** Creates a runner for a dot \a file. */
334 DotRunner(const QCString &file,const QCString &fontPath,bool checkResult,
335 const QCString &imageName = QCString());
337 /** Adds an additional job to the run.
338 * Performing multiple jobs one file can be faster.
340 void addJob(const char *format,const char *output);
342 void addPostProcessing(const char *cmd,const char *args);
344 void preventCleanUp() { m_cleanUp = FALSE; }
346 /** Runs dot for all jobs added. */
348 CleanupItem cleanup() const { return m_cleanupItem; }
351 QList<QCString> m_jobs;
357 QCString m_imageName;
359 CleanupItem m_cleanupItem;
362 /** Helper class to insert a set of map file into an output file */
376 DotFilePatcher(const char *patchFile);
377 int addMap(const QCString &mapFile,const QCString &relPath,
378 bool urlOnly,const QCString &context,const QCString &label);
379 int addFigure(const QCString &baseName,
380 const QCString &figureName,bool heightCheck);
381 int addSVGConversion(const QCString &relPath,bool urlOnly,
382 const QCString &context,bool zoomable,int graphId);
383 int addSVGObject(const QCString &baseName, const QCString &figureName,
384 const QCString &relPath);
386 QCString file() const;
390 QCString m_patchFile;
393 /** Queue of dot jobs to run. */
397 void enqueue(DotRunner *runner);
398 DotRunner *dequeue();
401 QWaitCondition m_bufferNotEmpty;
402 QQueue<DotRunner> m_queue;
403 mutable QMutex m_mutex;
406 /** Worker thread to execute a dot run */
407 class DotWorkerThread : public QThread
410 DotWorkerThread(int id,DotRunnerQueue *queue);
415 DotRunnerQueue *m_queue;
416 QList<DotRunner::CleanupItem> m_cleanupItems;
419 /** Singleton that manages dot relation actions */
423 static DotManager *instance();
424 void addRun(DotRunner *run);
425 int addMap(const QCString &file,const QCString &mapFile,
426 const QCString &relPath,bool urlOnly,
427 const QCString &context,const QCString &label);
428 int addFigure(const QCString &file,const QCString &baseName,
429 const QCString &figureName,bool heightCheck);
430 int addSVGConversion(const QCString &file,const QCString &relPath,
431 bool urlOnly,const QCString &context,bool zoomable,int graphId);
432 int addSVGObject(const QCString &file,const QCString &baseName,
433 const QCString &figureNAme,const QCString &relPath);
438 virtual ~DotManager();
439 QList<DotRunner> m_dotRuns;
440 SDict<DotFilePatcher> m_dotMaps;
441 static DotManager *m_theInstance;
442 DotRunnerQueue *m_queue;
443 QList<DotWorkerThread> m_workers;
447 /** Generated a graphs legend page */
448 void generateGraphLegend(const char *path);
450 void writeDotGraphFromFile(const char *inFile,const char *outDir,
451 const char *outFile,GraphOutputFormat format);
452 void writeDotImageMapFromFile(FTextStream &t,
453 const QCString& inFile, const QCString& outDir,
454 const QCString& relPath,const QCString& baseName,
455 const QCString& context,int graphId=-1);
457 void writeDotDirDepGraph(FTextStream &t,DirDef *dd);