dot.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  *
4  *
5  *
6  * Copyright (C) 1997-2015 by Dimitri van Heesch.
7  *
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.
13  *
14  * Documents produced by Doxygen are derivative works derived from the
15  * input used in their production; they are not affected by this license.
16  *
17  */
18 
19 #ifndef _DOT_H
20 #define _DOT_H
21 
22 #include <qlist.h>
23 #include <qdict.h>
24 #include <qwaitcondition.h>
25 #include <qmutex.h>
26 #include <qqueue.h>
27 #include <qthread.h>
28 #include "sortdict.h"
29 
30 class ClassDef;
31 class FileDef;
32 class FTextStream;
33 class DotNodeList;
34 class ClassSDict;
35 class MemberDef;
36 class Definition;
37 class DirDef;
38 class GroupDef;
40 class DotRunnerQueue;
41 
44 
45 /** Attributes of an edge of a dot graph */
46 struct EdgeInfo
47 {
48  enum Colors { Blue=0, Green=1, Red=2, Purple=3, Grey=4, Orange=5, Orange2=6 };
49  enum Styles { Solid=0, Dashed=1 };
50  EdgeInfo() : m_color(0), m_style(0), m_labColor(0) {}
51  ~EdgeInfo() {}
52  int m_color;
53  int m_style;
57 };
58 
59 /** A node in a dot graph */
60 class DotNode
61 {
62  public:
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);
67  ~DotNode();
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,
73  int edgeLabCol=-1
74  );
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 );
81  bool topDown,bool toChildren,bool backArrows,bool reNumber);
83  void clearWriteFlag();
84  void writeXML(FTextStream &t,bool isClassGraph);
85  void writeDocbook(FTextStream &t,bool isClassGraph);
86  void writeDEF(FTextStream &t);
87  QCString label() const { return m_label; }
88  int number() const { return m_number; }
89  bool isVisible() const { return m_visible; }
90  TruncState isTruncated() const { return m_truncated; }
91  int distance() const { return m_distance; }
92 
93  private:
94  void colorConnectedNodes(int curColor);
95  void writeBox(FTextStream &t,GraphType gt,GraphOutputFormat f,
96  bool hasNonReachableChildren, bool reNumber=FALSE);
97  void writeArrow(FTextStream &t,GraphType gt,GraphOutputFormat f,DotNode *cn,
98  EdgeInfo *ei,bool topDown, bool pointBack=TRUE, bool reNumber=FALSE);
99  void setDistance(int distance);
100  const DotNode *findDocNode() const; // only works for acyclic graphs!
101  void markAsVisible(bool b=TRUE) { m_visible=b; }
102  void markAsTruncated(bool b=TRUE) { m_truncated=b ? Truncated : Untruncated; }
103  int m_number;
104  QCString m_label; //!< label text
105  QCString m_tooltip; //!< node's tooltip
106  QCString m_url; //!< url of the node (format: remote$local)
107  QList<DotNode> *m_parents; //!< list of parent nodes (incoming arrows)
108  QList<DotNode> *m_children; //!< list of child nodes (outgoing arrows)
109  QList<EdgeInfo> *m_edgeInfo; //!< edge info for each child
110  bool m_deleted; //!< used to mark a node as deleted
111  bool m_written; //!< used to mark a node as written
112  bool m_hasDoc; //!< used to mark a node as documented
113  bool m_isRoot; //!< indicates if this is a root node
114  ClassDef * m_classDef; //!< class representing this node (can be 0)
115  bool m_visible; //!< is the node visible in the output
116  TruncState m_truncated; //!< does the node have non-visible children/parents
117  int m_distance; //!< shortest path to the root node
118 
119  friend class DotGfxHierarchyTable;
120  friend class DotClassGraph;
121  friend class DotInclDepGraph;
122  friend class DotNodeList;
123  friend class DotCallGraph;
124  friend class DotGroupCollaboration;
125  friend class DotInheritanceGraph;
126 
128  DotNode *root, GraphType gt,
130  bool lrRank, bool renderParents,
131  bool backArrows,
132  const QCString &title,
133  QCString &graphStr
134  );
135 };
136 
137 /** Class representing a list of DotNode objects. */
138 class DotNodeList : public QList<DotNode>
139 {
140  public:
143  private:
144  int compareValues(const DotNode *n1,const DotNode *n2) const;
145 };
146 
147 /** Represents a graphical class hierarchy */
149 {
150  public:
153  void writeGraph(FTextStream &t,const char *path, const char *fileName) const;
154  void createGraph(DotNode *rootNode,FTextStream &t,const char *path,const char *fileName,int id) const;
155  const DotNodeList *subGraphs() const { return m_rootSubgraphs; }
156 
157  private:
158  void addHierarchy(DotNode *n,ClassDef *cd,bool hide);
159  void addClassList(ClassSDict *cl);
160 
162  QDict<DotNode> *m_usedNodes;
163  static int m_curNodeNumber;
165 };
166 
167 /** Representation of a class inheritance or dependency graph */
169 {
170  public:
172  ~DotClassGraph();
173  bool isTrivial() const;
174  bool isTooBig() const;
176  const char *path, const char *fileName, const char *relPath,
177  bool TBRank=TRUE,bool imageMap=TRUE,int graphId=-1) const;
178 
179  void writeXML(FTextStream &t);
180  void writeDocbook(FTextStream &t);
181  void writeDEF(FTextStream &t);
182  QCString diskName() const;
183 
184  private:
185  void buildGraph(ClassDef *cd,DotNode *n,bool base,int distance);
186  bool determineVisibleNodes(DotNode *rootNode,int maxNodes,bool includeParents);
187  void determineTruncatedNodes(QList<DotNode> &queue,bool includeParents);
188  void addClass(ClassDef *cd,DotNode *n,int prot,const char *label,
189  const char *usedName,const char *templSpec,
190  bool base,int distance);
191 
193  QDict<DotNode> * m_usedNodes;
194  static int m_curNodeNumber;
197  bool m_lrRank;
198 };
199 
200 /** Representation of an include dependency graph */
202 {
203  public:
204  DotInclDepGraph(FileDef *fd,bool inverse);
205  ~DotInclDepGraph();
207  const char *path,const char *fileName,const char *relPath,
208  bool writeImageMap=TRUE,int graphId=-1) const;
209  bool isTrivial() const;
210  bool isTooBig() const;
211  QCString diskName() const;
212  void writeXML(FTextStream &t);
213  void writeDocbook(FTextStream &t);
214  private:
215  void buildGraph(DotNode *n,FileDef *fd,int distance);
216  void determineVisibleNodes(QList<DotNode> &queue,int &maxNodes);
217  void determineTruncatedNodes(QList<DotNode> &queue);
218 
220  QDict<DotNode> *m_usedNodes;
221  static int m_curNodeNumber;
223  bool m_inverse;
224 };
225 
226 /** Representation of an call graph */
228 {
229  public:
230  DotCallGraph(MemberDef *md,bool inverse);
231  ~DotCallGraph();
233  const char *path,const char *fileName,
234  const char *relPath,bool writeImageMap=TRUE,
235  int graphId=-1) const;
236  void buildGraph(DotNode *n,MemberDef *md,int distance);
237  bool isTrivial() const;
238  bool isTooBig() const;
239  void determineVisibleNodes(QList<DotNode> &queue, int &maxNodes);
240  void determineTruncatedNodes(QList<DotNode> &queue);
241 
242  private:
244  static int m_curNodeNumber;
245  QDict<DotNode> *m_usedNodes;
246  bool m_inverse;
249 };
250 
251 /** Representation of an directory dependency graph */
253 {
254  public:
256  ~DotDirDeps();
257  bool isTrivial() const;
258  QCString writeGraph(FTextStream &out,
261  const char *path,
262  const char *fileName,
263  const char *relPath,
264  bool writeImageMap=TRUE,
265  int graphId=-1,
266  bool linkRelations=TRUE) const;
267  private:
269 };
270 
271 /** Representation of a group collaboration graph */
273 {
274  public :
275  enum EdgeType
276  { tmember = 0,
282  thierarchy
283  };
284 
285  class Link
286  {
287  public:
288  Link(const QCString lab,const QCString &u) : label(lab), url(u) {}
291  };
292 
293  class Edge
294  {
295  public :
297  : pNStart(start), pNEnd(end), eType(type)
298  { links.setAutoDelete(TRUE); }
299 
303 
305  void write( FTextStream &t ) const;
306  };
307 
311  const char *path,const char *fileName,const char *relPath,
312  bool writeImageMap=TRUE,int graphId=-1) const;
313  void buildGraph(GroupDef* gd);
314  bool isTrivial() const;
315  private :
316  void addCollaborationMember( Definition* def, QCString& url, EdgeType eType );
317  void addMemberList( class MemberList* ml );
318  void writeGraphHeader(FTextStream &t,const QCString &title) const;
319  Edge* addEdge( DotNode* _pNStart, DotNode* _pNEnd, EdgeType _eType,
320  const QCString& _label, const QCString& _url );
321 
324  QDict<DotNode> *m_usedNodes;
327 };
328 
329 /** Minimal constant string class that is thread safe, once initialized. */
331 {
332  public:
333  DotConstString() { m_str=0; }
334  ~DotConstString() { delete[] m_str; }
335  DotConstString(const QCString &s) : m_str(0) { set(s); }
336  DotConstString(const DotConstString &s) : m_str(0) { set(s.data()); }
337  const char *data() const { return m_str; }
338  bool isEmpty() const { return m_str==0 || m_str[0]=='\0'; }
339  void set(const QCString &s)
340  {
341  delete[] m_str;
342  m_str=0;
343  if (!s.isEmpty())
344  {
345  m_str=new char[s.length()+1];
346  qstrcpy(m_str,s.data());
347  }
348  }
349  private:
350  DotConstString &operator=(const DotConstString &);
351  char *m_str;
352 };
353 
354 /** Helper class to run dot from doxygen.
355  */
357 {
358  public:
359  struct CleanupItem
360  {
363  };
364 
365  /** Creates a runner for a dot \a file. */
366  DotRunner(const QCString &file,const QCString &fontPath,bool checkResult,
367  const QCString &imageName = QCString());
368 
369  /** Adds an additional job to the run.
370  * Performing multiple jobs one file can be faster.
371  */
372  void addJob(const char *format,const char *output);
373 
374  void addPostProcessing(const char *cmd,const char *args);
375 
376  void preventCleanUp() { m_cleanUp = FALSE; }
377 
378  /** Runs dot for all jobs added. */
379  bool run();
380  const CleanupItem &cleanup() const { return m_cleanupItem; }
381 
382  private:
393  bool m_cleanUp;
395 };
396 
397 /** Helper class to insert a set of map file into an output file */
399 {
400  public:
401  struct Map
402  {
405  bool urlOnly;
408  bool zoomable;
409  int graphId;
410  };
411  DotFilePatcher(const char *patchFile);
412  int addMap(const QCString &mapFile,const QCString &relPath,
413  bool urlOnly,const QCString &context,const QCString &label);
414  int addFigure(const QCString &baseName,
415  const QCString &figureName,bool heightCheck);
416  int addSVGConversion(const QCString &relPath,bool urlOnly,
417  const QCString &context,bool zoomable,int graphId);
418  int addSVGObject(const QCString &baseName, const QCString &figureName,
419  const QCString &relPath);
420  bool run();
421  QCString file() const;
422 
423  private:
426 };
427 
428 /** Queue of dot jobs to run. */
430 {
431  public:
432  void enqueue(DotRunner *runner);
433  DotRunner *dequeue();
434  uint count() const;
435  private:
438  mutable QMutex m_mutex;
439 };
440 
441 /** Worker thread to execute a dot run */
442 class DotWorkerThread : public QThread
443 {
444  public:
446  void run();
447  void cleanup();
448  private:
451 };
452 
453 /** Singleton that manages dot relation actions */
455 {
456  public:
457  static DotManager *instance();
458  void addRun(DotRunner *run);
459  int addMap(const QCString &file,const QCString &mapFile,
460  const QCString &relPath,bool urlOnly,
461  const QCString &context,const QCString &label);
462  int addFigure(const QCString &file,const QCString &baseName,
463  const QCString &figureName,bool heightCheck);
464  int addSVGConversion(const QCString &file,const QCString &relPath,
465  bool urlOnly,const QCString &context,bool zoomable,int graphId);
466  int addSVGObject(const QCString &file,const QCString &baseName,
467  const QCString &figureNAme,const QCString &relPath);
468  bool run();
469 
470  private:
471  DotManager();
472  virtual ~DotManager();
478 };
479 
480 
481 /** Generated a graphs legend page */
482 void generateGraphLegend(const char *path);
483 
484 void writeDotGraphFromFile(const char *inFile,const char *outDir,
485  const char *outFile,GraphOutputFormat format);
487  const QCString& inFile, const QCString& outDir,
488  const QCString& relPath,const QCString& baseName,
489  const QCString& context,int graphId=-1);
490 
491 #endif
TruncState m_truncated
does the node have non-visible children/parents
Definition: dot.h:116
QCString m_patchFile
Definition: dot.h:425
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
QList< EdgeInfo > * m_edgeInfo
edge info for each child
Definition: dot.h:109
QCString m_tooltip
node&#39;s tooltip
Definition: dot.h:105
bool m_lrRank
Definition: dot.h:197
DotNode * m_rootNode
Definition: dot.h:322
void writeDotGraphFromFile(const char *inFile, const char *outDir, const char *outFile, GraphOutputFormat format)
Definition: dot.cpp:4203
Definition: qmutex.h:49
EmbeddedOutputFormat
Definition: dot.h:43
const CleanupItem & cleanup() const
Definition: dot.h:380
QCString mapFile
Definition: dot.h:403
bool isEmpty() const
Definition: qcstring.h:189
DotConstString m_postArgs
Definition: dot.h:386
Definition: dot.h:356
bool isEmpty() const
Definition: dot.h:338
uint length() const
Definition: qcstring.h:195
DotNodeList * m_rootSubgraphs
Definition: dot.h:164
QCString computeMd5Signature(DotNode *root, DotNode::GraphType gt, GraphOutputFormat format, bool lrRank, bool renderParents, bool backArrows, const QCString &title, QCString &graphStr)
Definition: dot.cpp:3018
QCString m_diskName
Definition: dot.h:222
QCString m_diskName
Definition: dot.h:247
QDict< DotNode > * m_usedNodes
Definition: dot.h:245
bool m_checkResult
Definition: dot.h:390
bool m_isRoot
indicates if this is a root node
Definition: dot.h:113
DotConstString file
Definition: dot.h:362
DotNode * m_startNode
Definition: dot.h:219
Definition: dot.h:60
DirDef * m_dir
Definition: dot.h:268
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
Definition: qstring.cpp:11496
TruncState isTruncated() const
Definition: dot.h:90
const bool FALSE
Definition: qglobal.h:370
QCString m_label
Definition: dot.h:54
const std::string instance
DotConstString m_postCmd
Definition: dot.h:387
size_t write(int, const char *, size_t)
Writes count bytes from buf to the filedescriptor fd.
QDict< DotNode > * m_usedNodes
Definition: dot.h:162
QList< Map > m_maps
Definition: dot.h:424
void preventCleanUp()
Definition: dot.h:376
TFile * outFile
Definition: makeDST.cxx:36
QCString label() const
Definition: dot.h:87
Simplified and optimized version of QTextStream.
Definition: ftextstream.h:11
void generateGraphLegend(const char *path)
Definition: dot.cpp:4127
string dir
DotConstString m_file
Definition: dot.h:388
GraphType
Definition: dot.h:63
QDict< DotNode > * m_usedNodes
Definition: dot.h:220
static QCString args
Definition: declinfo.cpp:674
Styles
Definition: dot.h:49
QAsciiDict< Entry > cl
static int m_curNodeNumber
Definition: dot.h:163
QList< Link > links
Definition: dot.h:304
QQueue< DotRunner > m_queue
Definition: dot.h:437
int distance() const
Definition: dot.h:91
QDict< DotNode > * m_usedNodes
Definition: dot.h:324
int m_style
Definition: dot.h:53
DotNodeList()
Definition: dot.h:141
DotConstString m_path
Definition: dot.h:389
static void writeGraphHeader(FTextStream &t, const QCString &title=QCString())
Definition: dot.cpp:251
QCString m_url
Definition: dot.h:55
Definition: sortdict.h:73
DotConstString path
Definition: dot.h:361
QCString m_url
url of the node (format: remote$local)
Definition: dot.h:106
QList< DotRunner > m_dotRuns
Definition: dot.h:473
QCString m_diskName
Definition: dot.h:325
Definition: dot.h:43
QList< Edge > m_edges
Definition: dot.h:326
QList< DotNode > * m_rootNodes
Definition: dot.h:161
fileName
Definition: dumpTree.py:9
int m_labColor
Definition: dot.h:56
bool m_cleanUp
Definition: dot.h:393
DotConstString m_imageName
Definition: dot.h:391
std::void_t< T > n
Definition * m_scope
Definition: dot.h:248
QList< DotNode > * m_children
list of child nodes (outgoing arrows)
Definition: dot.h:108
void markAsTruncated(bool b=TRUE)
Definition: dot.h:102
bool m_written
used to mark a node as written
Definition: dot.h:111
QCString context
Definition: dot.h:406
~DotNodeList()
Definition: dot.h:142
~EdgeInfo()
Definition: dot.h:51
SDict< DotFilePatcher > m_dotMaps
Definition: dot.h:474
int m_color
Definition: dot.h:52
int m_number
Definition: dot.h:103
const char * data() const
Definition: qcstring.h:207
Definition: dirdef.h:44
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
QList< DotNode > * m_parents
list of parent nodes (incoming arrows)
Definition: dot.h:107
DotConstString(const DotConstString &s)
Definition: dot.h:336
bool m_inverse
Definition: dot.h:246
Definition: dot.h:46
Definition: dot.h:42
const DotNodeList * subGraphs() const
Definition: dot.h:155
QCString m_diskName
Definition: dot.h:196
QCString relPath
Definition: dot.h:404
DotRunnerQueue * m_queue
Definition: dot.h:449
static DotManager * m_theInstance
Definition: dot.h:475
int number() const
Definition: dot.h:88
DotNode * m_startNode
Definition: dot.h:192
bool m_inverse
Definition: dot.h:223
TFile * inFile
Definition: makeDST.cxx:36
DotConstString m_dotExe
Definition: dot.h:383
TruncState
Definition: dot.h:64
QList< DotConstString > m_jobs
Definition: dot.h:385
char * m_str
Definition: dot.h:351
Definition: dot.h:43
ClassDef * m_classDef
class representing this node (can be 0)
Definition: dot.h:114
CleanupItem m_cleanupItem
Definition: dot.h:394
genFinder * gf
static int m_curNodeNumber
Definition: dot.h:244
static int m_curNodeNumber
Definition: dot.h:221
QMutex m_mutex
Definition: dot.h:438
~DotConstString()
Definition: dot.h:334
DotConstString()
Definition: dot.h:333
static int m_curNodeNumber
Definition: dot.h:194
int m_subgraphId
Definition: dot.h:82
Q_EXPORT char * qstrcpy(char *dst, const char *src)
Definition: qcstring.h:87
bool m_hasDoc
used to mark a node as documented
Definition: dot.h:112
static bool * b
Definition: config.cpp:1043
bool m_deleted
used to mark a node as deleted
Definition: dot.h:110
QCString m_label
label text
Definition: dot.h:104
bool m_multiTargets
Definition: dot.h:384
Edge(DotNode *start, DotNode *end, EdgeType type)
Definition: dot.h:296
bool m_visible
is the node visible in the output
Definition: dot.h:115
GraphOutputFormat
Definition: dot.h:42
list cmd
Definition: getreco.py:22
int m_distance
shortest path to the root node
Definition: dot.h:117
static QCString baseName
Definition: scanner.cpp:10890
void markAsVisible(bool b=TRUE)
Definition: dot.h:101
QList< DotWorkerThread > m_workers
Definition: dot.h:477
EdgeInfo()
Definition: dot.h:50
DotConstString m_imgExt
Definition: dot.h:392
DotRunnerQueue * m_queue
Definition: dot.h:476
QWaitCondition m_bufferNotEmpty
Definition: dot.h:436
DotNode * m_startNode
Definition: dot.h:243
Definition: dot.h:42
QCString label
Definition: dot.h:407
DotConstString(const QCString &s)
Definition: dot.h:335
unsigned uint
Definition: qglobal.h:351
Colors
Definition: dot.h:48
QDict< DotNode > * m_usedNodes
Definition: dot.h:193
Definition: dot.h:43
static QCString * s
Definition: config.cpp:1042
bool isVisible() const
Definition: dot.h:89
const bool TRUE
Definition: qglobal.h:371
const char * data() const
Definition: dot.h:337
DotNode::GraphType m_graphType
Definition: dot.h:195
QList< DotRunner::CleanupItem > m_cleanupItems
Definition: dot.h:450
TFile * ef
Definition: doAna.cpp:25
void writeDotImageMapFromFile(FTextStream &t, const QCString &inFile, const QCString &outDir, const QCString &relPath, const QCString &baseName, const QCString &context, int graphId=-1)
Definition: dot.cpp:4255