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
|
/******************************************************************************
*
* Copyright (C) 1997-2019 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.
*
*/
#include "dotgroupcollaboration.h"
#include "dotnode.h"
#include "classlist.h"
#include "doxygen.h"
#include "namespacedef.h"
#include "pagedef.h"
#include "util.h"
#include "config.h"
#define DOT_TRANSPARENT Config_getBool(DOT_TRANSPARENT)
DotGroupCollaboration::DotGroupCollaboration(const GroupDef* gd)
{
QCString tmp_url = gd->getReference()+"$"+gd->getOutputFileBase();
m_usedNodes = new QDict<DotNode>(1009);
QCString tooltip = gd->briefDescriptionAsTooltip();
m_rootNode = new DotNode(getNextNodeNumber(), gd->groupTitle(), tooltip, tmp_url, TRUE );
m_rootNode->markAsVisible();
m_usedNodes->insert(gd->name(), m_rootNode );
m_edges.setAutoDelete(TRUE);
m_diskName = gd->getOutputFileBase();
buildGraph( gd );
}
DotGroupCollaboration::~DotGroupCollaboration()
{
// delete all created Nodes saved in m_usedNodes:QDict
if(m_usedNodes != NULL)
{
QDictIterator<DotNode> it(*m_usedNodes);
for(;it.current(); ++it)
{
delete it.current();
}
}
delete m_usedNodes;
}
void DotGroupCollaboration::buildGraph(const GroupDef* gd)
{
QCString tmp_url;
//===========================
// hierarchy.
// Write parents
const GroupList *groups = gd->partOfGroups();
if ( groups )
{
GroupListIterator gli(*groups);
const GroupDef *d;
for (gli.toFirst();(d=gli.current());++gli)
{
DotNode* nnode = m_usedNodes->find(d->name());
if ( !nnode )
{ // add node
tmp_url = d->getReference()+"$"+d->getOutputFileBase();
QCString tooltip = d->briefDescriptionAsTooltip();
nnode = new DotNode(getNextNodeNumber(), d->groupTitle(), tooltip, tmp_url );
nnode->markAsVisible();
m_usedNodes->insert(d->name(), nnode );
}
tmp_url = "";
addEdge( nnode, m_rootNode, DotGroupCollaboration::thierarchy, tmp_url, tmp_url );
}
}
// Add subgroups
if ( gd->getSubGroups() && gd->getSubGroups()->count() )
{
QListIterator<GroupDef> defli(*gd->getSubGroups());
const GroupDef *def;
for (;(def=defli.current());++defli)
{
DotNode* nnode = m_usedNodes->find(def->name());
if ( !nnode )
{ // add node
tmp_url = def->getReference()+"$"+def->getOutputFileBase();
QCString tooltip = def->briefDescriptionAsTooltip();
nnode = new DotNode(getNextNodeNumber(), def->groupTitle(), tooltip, tmp_url );
nnode->markAsVisible();
m_usedNodes->insert(def->name(), nnode );
}
tmp_url = "";
addEdge( m_rootNode, nnode, DotGroupCollaboration::thierarchy, tmp_url, tmp_url );
}
}
//=======================
// Write collaboration
// Add members
addMemberList( gd->getMemberList(MemberListType_allMembersList) );
// Add classes
if ( gd->getClasses() && gd->getClasses()->count() )
{
ClassSDict::Iterator defli(*gd->getClasses());
ClassDef *def;
for (;(def=defli.current());++defli)
{
tmp_url = def->getReference()+"$"+def->getOutputFileBase()+Doxygen::htmlFileExtension;
if (!def->anchor().isEmpty())
{
tmp_url+="#"+def->anchor();
}
addCollaborationMember( def, tmp_url, DotGroupCollaboration::tclass );
}
}
// Add namespaces
if ( gd->getNamespaces() && gd->getNamespaces()->count() )
{
NamespaceSDict::Iterator defli(*gd->getNamespaces());
NamespaceDef *def;
for (;(def=defli.current());++defli)
{
tmp_url = def->getReference()+"$"+def->getOutputFileBase()+Doxygen::htmlFileExtension;
addCollaborationMember( def, tmp_url, DotGroupCollaboration::tnamespace );
}
}
// Add files
if ( gd->getFiles() && gd->getFiles()->count() )
{
QListIterator<FileDef> defli(*gd->getFiles());
const FileDef *def;
for (;(def=defli.current());++defli)
{
tmp_url = def->getReference()+"$"+def->getOutputFileBase()+Doxygen::htmlFileExtension;
addCollaborationMember( def, tmp_url, DotGroupCollaboration::tfile );
}
}
// Add pages
if ( gd->getPages() && gd->getPages()->count() )
{
PageSDict::Iterator defli(*gd->getPages());
PageDef *def;
for (;(def=defli.current());++defli)
{
tmp_url = def->getReference()+"$"+def->getOutputFileBase()+Doxygen::htmlFileExtension;
addCollaborationMember( def, tmp_url, DotGroupCollaboration::tpages );
}
}
// Add directories
if ( !gd->getDirs().empty() )
{
for(const auto def : gd->getDirs())
{
tmp_url = def->getReference()+"$"+def->getOutputFileBase()+Doxygen::htmlFileExtension;
addCollaborationMember( def, tmp_url, DotGroupCollaboration::tdir );
}
}
}
void DotGroupCollaboration::addMemberList( MemberList* ml )
{
if ( !( ml && ml->count()) ) return;
MemberListIterator defli(*ml);
MemberDef *def;
for (;(def=defli.current());++defli)
{
QCString tmp_url = def->getReference()+"$"+def->getOutputFileBase()+Doxygen::htmlFileExtension
+"#"+def->anchor();
addCollaborationMember( def, tmp_url, DotGroupCollaboration::tmember );
}
}
DotGroupCollaboration::Edge* DotGroupCollaboration::addEdge(
DotNode* _pNStart, DotNode* _pNEnd, EdgeType _eType,
const QCString& _label, const QCString& _url )
{
// search a existing link.
QListIterator<Edge> lli(m_edges);
Edge* newEdge = 0;
for ( lli.toFirst(); (newEdge=lli.current()); ++lli)
{
if ( newEdge->pNStart==_pNStart &&
newEdge->pNEnd==_pNEnd &&
newEdge->eType==_eType
)
{ // edge already found
break;
}
}
if ( newEdge==0 ) // new link
{
newEdge = new Edge(_pNStart,_pNEnd,_eType);
m_edges.append( newEdge );
}
if (!_label.isEmpty())
{
newEdge->links.append(new Link(_label,_url));
}
return newEdge;
}
void DotGroupCollaboration::addCollaborationMember(
const Definition* def, QCString& url, EdgeType eType )
{
// Create group nodes
if ( !def->partOfGroups() )
return;
GroupListIterator gli(*def->partOfGroups());
GroupDef *d;
QCString tmp_str;
for (;(d=gli.current());++gli)
{
DotNode* nnode = m_usedNodes->find(d->name());
if ( nnode != m_rootNode )
{
if ( nnode==0 )
{ // add node
tmp_str = d->getReference()+"$"+d->getOutputFileBase();
QCString tooltip = d->briefDescriptionAsTooltip();
nnode = new DotNode(getNextNodeNumber(), d->groupTitle(), tooltip, tmp_str );
nnode->markAsVisible();
m_usedNodes->insert(d->name(), nnode );
}
tmp_str = def->qualifiedName();
addEdge( m_rootNode, nnode, eType, tmp_str, url );
}
}
}
QCString DotGroupCollaboration::getBaseName() const
{
return m_diskName;
}
void DotGroupCollaboration::computeTheGraph()
{
FTextStream md5stream(&m_theGraph);
writeGraphHeader(md5stream,m_rootNode->label());
// clean write flags
QDictIterator<DotNode> dni(*m_usedNodes);
DotNode *pn;
for (dni.toFirst();(pn=dni.current());++dni)
{
pn->clearWriteFlag();
}
// write other nodes.
for (dni.toFirst();(pn=dni.current());++dni)
{
pn->write(md5stream,Inheritance,m_graphFormat,TRUE,FALSE,FALSE);
}
// write edges
QListIterator<Edge> eli(m_edges);
Edge* edge;
for (eli.toFirst();(edge=eli.current());++eli)
{
edge->write( md5stream );
}
writeGraphFooter(md5stream);
}
QCString DotGroupCollaboration::getMapLabel() const
{
return escapeCharsInString(m_baseName, FALSE);
}
QCString DotGroupCollaboration::writeGraph( FTextStream &t,
GraphOutputFormat graphFormat, EmbeddedOutputFormat textFormat,
const char *path, const char *fileName, const char *relPath,
bool generateImageMap,int graphId)
{
m_doNotAddImageToIndex = TRUE;
return DotGraph::writeGraph(t, graphFormat, textFormat, path, fileName, relPath, generateImageMap, graphId);
}
void DotGroupCollaboration::Edge::write( FTextStream &t ) const
{
const char* linkTypeColor[] = {
"darkorchid3"
,"orange"
,"blueviolet"
,"darkgreen"
,"firebrick4"
,"grey75"
,"midnightblue"
};
QCString arrowStyle = "dir=\"none\", style=\"dashed\"";
t << " Node" << pNStart->number();
t << "->";
t << "Node" << pNEnd->number();
t << " [shape=plaintext";
if (links.count()>0) // there are links
{
t << ", ";
// HTML-like edge labels crash on my Mac with Graphviz 2.0! and
// are not supported by older version of dot.
//
//t << label=<<TABLE BORDER=\"0\" CELLBORDER=\"0\">";
//QListIterator<Link> lli(links);
//Link *link;
//for( lli.toFirst(); (link=lli.current()); ++lli)
//{
// t << "<TR><TD";
// if ( !link->url.isEmpty() )
// t << " HREF=\"" << link->url << "\"";
// t << ">" << link->label << "</TD></TR>";
//}
//t << "</TABLE>>";
t << "label=\"";
QListIterator<Link> lli(links);
Link *link;
bool first=TRUE;
int count=0;
const int maxLabels = 10;
for( lli.toFirst(); (link=lli.current()) && count<maxLabels; ++lli,++count)
{
if (first) first=FALSE; else t << "\\n";
t << DotNode::convertLabel(link->label);
}
if (count==maxLabels) t << "\\n...";
t << "\"";
}
switch( eType )
{
case thierarchy:
arrowStyle = "dir=\"back\", style=\"solid\"";
break;
default:
t << ", color=\"" << linkTypeColor[(int)eType] << "\"";
break;
}
t << ", " << arrowStyle;
t << "];" << endl;
}
bool DotGroupCollaboration::isTrivial() const
{
return m_usedNodes->count() <= 1;
}
void DotGroupCollaboration::writeGraphHeader(FTextStream &t,const QCString &title) const
{
int fontSize = Config_getInt(DOT_FONTSIZE);
QCString fontName = Config_getString(DOT_FONTNAME);
t << "digraph ";
if (title.isEmpty())
{
t << "\"Dot Graph\"";
}
else
{
t << "\"" << convertToXML(title) << "\"";
}
t << endl;
t << "{" << endl;
if (DOT_TRANSPARENT)
{
t << " bgcolor=\"transparent\";" << endl;
}
t << " edge [fontname=\"" << fontName << "\",fontsize=\"" << fontSize << "\","
"labelfontname=\"" << fontName << "\",labelfontsize=\"" << fontSize << "\"];\n";
t << " node [fontname=\"" << fontName << "\",fontsize=\"" << fontSize << "\",shape=box];\n";
t << " rankdir=LR;\n";
}
|