Doxygen
dotgroupcollaboration.cpp
浏览该文件的文档.
1 /******************************************************************************
2 *
3 * Copyright (C) 1997-2019 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15 
16 #include "dotgroupcollaboration.h"
17 #include "classlist.h"
18 #include "doxygen.h"
19 #include "namespacedef.h"
20 #include "pagedef.h"
21 #include "util.h"
22 #include "config.h"
23 #include "textstream.h"
24 
26 {
27  QCString tmp_url = gd->getReference()+"$"+gd->getOutputFileBase();
28  QCString tooltip = gd->briefDescriptionAsTooltip();
29  m_rootNode = new DotNode(getNextNodeNumber(), gd->groupTitle(), tooltip, tmp_url, TRUE );
31  m_usedNodes.insert(std::make_pair(gd->name().str(), m_rootNode));
32 
34 
35  buildGraph( gd );
36 }
37 
39 {
40  // delete all created Nodes saved in m_usedNodes map
41  for (const auto &kv : m_usedNodes)
42  {
43  delete kv.second;
44  }
45 }
46 
48 {
49  QCString tmp_url;
50  //===========================
51  // hierarchy.
52 
53  // Write parents
54  for (const auto &d : gd->partOfGroups())
55  {
56  DotNode *nnode = 0;
57  auto it = m_usedNodes.find(d->name().str());
58  if ( it==m_usedNodes.end())
59  { // add node
60  tmp_url = d->getReference()+"$"+d->getOutputFileBase();
61  QCString tooltip = d->briefDescriptionAsTooltip();
62  nnode = new DotNode(getNextNodeNumber(), d->groupTitle(), tooltip, tmp_url );
63  nnode->markAsVisible();
64  m_usedNodes.insert(std::make_pair(d->name().str(), nnode));
65  }
66  else
67  {
68  nnode = it->second;
69  }
70  tmp_url = "";
71  addEdge( nnode, m_rootNode, DotGroupCollaboration::thierarchy, tmp_url, tmp_url );
72  }
73 
74  // Add subgroups
75  for (const auto &def : gd->getSubGroups())
76  {
77  DotNode *nnode = 0;
78  auto it = m_usedNodes.find(def->name().str());
79  if ( it==m_usedNodes.end())
80  { // add node
81  tmp_url = def->getReference()+"$"+def->getOutputFileBase();
82  QCString tooltip = def->briefDescriptionAsTooltip();
83  nnode = new DotNode(getNextNodeNumber(), def->groupTitle(), tooltip, tmp_url );
84  nnode->markAsVisible();
85  m_usedNodes.insert(std::make_pair(def->name().str(), nnode));
86  }
87  else
88  {
89  nnode = it->second;
90  }
91  tmp_url = "";
92  addEdge( m_rootNode, nnode, DotGroupCollaboration::thierarchy, tmp_url, tmp_url );
93  }
94 
95  //=======================
96  // Write collaboration
97 
98  // Add members
100 
101  // Add classes
102  for (const auto &def : gd->getClasses())
103  {
104  tmp_url = def->getReference()+"$"+addHtmlExtensionIfMissing(def->getOutputFileBase());
105  if (!def->anchor().isEmpty())
106  {
107  tmp_url+="#"+def->anchor();
108  }
110  }
111 
112  // Add namespaces
113  for (const auto &def : gd->getNamespaces())
114  {
115  tmp_url = def->getReference()+"$"+addHtmlExtensionIfMissing(def->getOutputFileBase());
117  }
118 
119  // Add files
120  for (const auto &def : gd->getFiles())
121  {
122  tmp_url = def->getReference()+"$"+addHtmlExtensionIfMissing(def->getOutputFileBase());
124  }
125 
126  // Add pages
127  for (const auto &def : gd->getPages())
128  {
129  tmp_url = def->getReference()+"$"+addHtmlExtensionIfMissing(def->getOutputFileBase());
131  }
132 
133  // Add directories
134  if ( !gd->getDirs().empty() )
135  {
136  for(const auto def : gd->getDirs())
137  {
138  tmp_url = def->getReference()+"$"+addHtmlExtensionIfMissing(def->getOutputFileBase());
140  }
141  }
142 }
143 
145 {
146  if ( ml==0 || ml->empty() ) return;
147  for (const auto &def : *ml)
148  {
149  QCString tmp_url = def->getReference()+"$"+addHtmlExtensionIfMissing(def->getOutputFileBase());
150  +"#"+def->anchor();
152  }
153 }
154 
156  DotNode* _pNStart, DotNode* _pNEnd, EdgeType _eType,
157  const QCString& _label, const QCString& _url )
158 {
159  // search a existing link.
160  auto it = std::find_if(m_edges.begin(),m_edges.end(),
161  [&_pNStart,&_pNEnd,&_eType](const auto &edge)
162  { return edge->pNStart==_pNStart && edge->pNEnd==_pNEnd && edge->eType==_eType; });
163 
164  if (it==m_edges.end()) // new link
165  {
166  m_edges.emplace_back(std::make_unique<Edge>(_pNStart,_pNEnd,_eType));
167  it = m_edges.end()-1;
168  }
169 
170  if (!_label.isEmpty()) // add label
171  {
172  (*it)->links.emplace_back(_label,_url);
173  }
174 
175  // return found or added edge
176  return (*it).get();
177 }
178 
180  const Definition* def, QCString& url, EdgeType eType )
181 {
182  // Create group nodes
183  QCString tmp_str;
184  for (const auto &d : def->partOfGroups())
185  {
186  auto it = m_usedNodes.find(d->name().str());
187  DotNode* nnode = it!=m_usedNodes.end() ? it->second : 0;
188  if ( nnode != m_rootNode )
189  {
190  if ( nnode==0 )
191  { // add node
192  tmp_str = d->getReference()+"$"+d->getOutputFileBase();
193  QCString tooltip = d->briefDescriptionAsTooltip();
194  nnode = new DotNode(getNextNodeNumber(), d->groupTitle(), tooltip, tmp_str );
195  nnode->markAsVisible();
196  m_usedNodes.insert(std::make_pair(d->name().str(), nnode));
197  }
198  tmp_str = def->qualifiedName();
199  addEdge( m_rootNode, nnode, eType, tmp_str, url );
200  }
201  }
202 }
203 
205 {
206  return m_diskName;
207 }
208 
210 {
211  TextStream md5stream;
212  writeGraphHeader(md5stream,m_rootNode->label());
213 
214  // clean write flags
215  for (const auto &kv : m_usedNodes)
216  {
217  kv.second->clearWriteFlag();
218  }
219 
220  // write other nodes.
221  for (const auto &kv : m_usedNodes)
222  {
223  kv.second->write(md5stream,Inheritance,m_graphFormat,TRUE,FALSE,FALSE);
224  }
225 
226  // write edges
227  for (const auto &edge : m_edges)
228  {
229  edge->write( md5stream );
230  }
231 
232  writeGraphFooter(md5stream);
233 
234  m_theGraph = md5stream.str();
235 }
236 
238 {
240 }
241 
243  GraphOutputFormat graphFormat, EmbeddedOutputFormat textFormat,
244  const QCString &path, const QCString &fileName, const QCString &relPath,
245  bool generateImageMap,int graphId)
246 {
248 
249  return DotGraph::writeGraph(t, graphFormat, textFormat, path, fileName, relPath, generateImageMap, graphId);
250 }
251 
253 {
254  const char* linkTypeColor[] = {
255  "darkorchid3"
256  ,"orange"
257  ,"blueviolet"
258  ,"darkgreen"
259  ,"firebrick4"
260  ,"grey75"
261  ,"midnightblue"
262  };
263  QCString arrowStyle = "dir=\"none\", style=\"dashed\"";
264  t << " Node" << pNStart->number();
265  t << "->";
266  t << "Node" << pNEnd->number();
267 
268  t << " [shape=plaintext";
269  if (!links.empty()) // there are links
270  {
271  t << ", ";
272  // HTML-like edge labels crash on my Mac with Graphviz 2.0! and
273  // are not supported by older version of dot.
274  //
275  //t << label=<<TABLE BORDER=\"0\" CELLBORDER=\"0\">";
276  //for (const auto &link : links)
277  //{
278  // t << "<TR><TD";
279  // if ( !link.url.isEmpty() )
280  // t << " HREF=\"" << link.url << "\"";
281  // t << ">" << DotNode::convertLabel(link->label) << "</TD></TR>";
282  //}
283  //t << "</TABLE>>";
284 
285  t << "label=\"";
286  bool first=TRUE;
287  int count=0;
288  const int maxLabels = 10;
289  for (const auto &link : links)
290  {
291  if (first) first=FALSE; else t << "\\n";
292  t << DotNode::convertLabel(link.label);
293  count++;
294  }
295  if (count==maxLabels) t << "\\n...";
296  t << "\"";
297 
298  }
299  switch( eType )
300  {
301  case thierarchy:
302  arrowStyle = "dir=\"back\", style=\"solid\"";
303  break;
304  default:
305  t << ", color=\"" << linkTypeColor[(int)eType] << "\"";
306  break;
307  }
308  t << ", " << arrowStyle;
309  t << "];\n";
310 }
311 
313 {
314  return m_usedNodes.size() <= 1;
315 }
316 
318 {
319  int fontSize = Config_getInt(DOT_FONTSIZE);
320  QCString fontName = Config_getString(DOT_FONTNAME);
321  t << "digraph ";
322  if (title.isEmpty())
323  {
324  t << "\"Dot Graph\"";
325  }
326  else
327  {
328  t << "\"" << convertToXML(title) << "\"";
329  }
330  t << "\n";
331  t << "{\n";
332  if (Config_getBool(DOT_TRANSPARENT))
333  {
334  t << " bgcolor=\"transparent\";\n";
335  }
336  t << " edge [fontname=\"" << fontName << "\",fontsize=\"" << fontSize << "\","
337  "labelfontname=\"" << fontName << "\",labelfontsize=\"" << fontSize << "\"];\n";
338  t << " node [fontname=\"" << fontName << "\",fontsize=\"" << fontSize << "\",shape=box];\n";
339  t << " rankdir=LR;\n";
340 }
DotGroupCollaboration::Edge::write
void write(TextStream &t) const
Definition: dotgroupcollaboration.cpp:252
DotGroupCollaboration::Edge::links
std::vector< Link > links
Definition: dotgroupcollaboration.h:71
DotGroupCollaboration::computeTheGraph
virtual void computeTheGraph()
Definition: dotgroupcollaboration.cpp:209
DotGroupCollaboration::addCollaborationMember
void addCollaborationMember(const Definition *def, QCString &url, EdgeType eType)
Definition: dotgroupcollaboration.cpp:179
Definition
The common base class of all entity definitions found in the sources.
Definition: definition.h:76
DotGroupCollaboration::m_usedNodes
DotNodeMap m_usedNodes
Definition: dotgroupcollaboration.h:83
DotGraph::m_theGraph
QCString m_theGraph
Definition: dotgraph.h:89
DotGraph::m_doNotAddImageToIndex
bool m_doNotAddImageToIndex
Definition: dotgraph.h:91
DotGroupCollaboration::~DotGroupCollaboration
~DotGroupCollaboration()
Definition: dotgroupcollaboration.cpp:38
DotGroupCollaboration::getMapLabel
virtual QCString getMapLabel() const
Definition: dotgroupcollaboration.cpp:237
GroupDef::getClasses
virtual const ClassLinkedRefMap & getClasses() const =0
DotGroupCollaboration::tnamespace
@ tnamespace
Definition: dotgroupcollaboration.h:48
pagedef.h
DotGroupCollaboration::m_rootNode
DotNode * m_rootNode
Definition: dotgroupcollaboration.h:82
QCString::isEmpty
bool isEmpty() const
Returns TRUE iff the string is empty
Definition: qcstring.h:144
MemberListType_allMembersList
@ MemberListType_allMembersList
Definition: types.h:147
DotGroupCollaboration::thierarchy
@ thierarchy
Definition: dotgroupcollaboration.h:52
namespacedef.h
GroupDef::groupTitle
virtual QCString groupTitle() const =0
DotGroupCollaboration::Edge::pNStart
DotNode * pNStart
Definition: dotgroupcollaboration.h:67
DotGroupCollaboration::isTrivial
bool isTrivial() const
Definition: dotgroupcollaboration.cpp:312
GroupDef::getFiles
virtual const FileList & getFiles() const =0
GroupDef::getMemberList
virtual MemberList * getMemberList(MemberListType lt) const =0
DotGroupCollaboration::writeGraph
QCString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const QCString &path, const QCString &fileName, const QCString &relPath, bool writeImageMap=TRUE, int graphId=-1)
Definition: dotgroupcollaboration.cpp:242
DotGraph::writeGraphFooter
static void writeGraphFooter(TextStream &t)
Definition: dotgraph.cpp:300
QCString::str
std::string str() const
Definition: qcstring.h:442
DotGroupCollaboration::addMemberList
void addMemberList(class MemberList *ml)
Definition: dotgroupcollaboration.cpp:144
DotGraph::getNextNodeNumber
int getNextNodeNumber()
returns node numbers.
Definition: dotgraph.h:41
textstream.h
GroupDef::getSubGroups
virtual const GroupList & getSubGroups() const =0
TextStream
Text streaming class that buffers data.
Definition: textstream.h:33
DotGroupCollaboration::Edge::pNEnd
DotNode * pNEnd
Definition: dotgroupcollaboration.h:68
DotNode::markAsVisible
void markAsVisible(bool b=TRUE)
Definition: dotnode.h:107
GroupDef
A model of a group of symbols.
Definition: groupdef.h:49
Definition::qualifiedName
virtual QCString qualifiedName() const =0
addHtmlExtensionIfMissing
QCString addHtmlExtensionIfMissing(const QCString &fName)
Definition: util.cpp:5275
DotNode
A node in a dot graph
Definition: dotnode.h:56
GroupDef::getDirs
virtual const DirList & getDirs() const =0
classlist.h
Config_getInt
#define Config_getInt(name)
Definition: config.h:34
MemberVector::empty
bool empty() const
Definition: memberlist.h:47
DotNode::number
int number() const
Definition: dotnode.h:90
dotgroupcollaboration.h
DotGroupCollaboration::tclass
@ tclass
Definition: dotgroupcollaboration.h:47
DotGroupCollaboration::tdir
@ tdir
Definition: dotgroupcollaboration.h:51
DotGroupCollaboration::Edge::eType
EdgeType eType
Definition: dotgroupcollaboration.h:69
Definition::name
virtual QCString name() const =0
DotNode::label
QCString label() const
Definition: dotnode.h:89
doxygen.h
DotGroupCollaboration::m_diskName
QCString m_diskName
Definition: dotgroupcollaboration.h:84
DotGroupCollaboration::Edge
Definition: dotgroupcollaboration.h:62
DotGraph::m_graphFormat
GraphOutputFormat m_graphFormat
Definition: dotgraph.h:79
TRUE
#define TRUE
Definition: qcstring.h:36
GroupDef::getNamespaces
virtual const NamespaceLinkedRefMap & getNamespaces() const =0
DotGroupCollaboration::writeGraphHeader
void writeGraphHeader(TextStream &t, const QCString &title) const
Definition: dotgroupcollaboration.cpp:317
TextStream::str
std::string str() const
Return the contents of the buffer as a std::string object
Definition: textstream.h:208
Definition::partOfGroups
virtual const GroupList & partOfGroups() const =0
DotGraph::writeGraph
QCString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const QCString &path, const QCString &fileName, const QCString &relPath, bool writeImageMap=TRUE, int graphId=-1)
Definition: dotgraph.cpp:111
DotGroupCollaboration::EdgeType
EdgeType
Definition: dotgroupcollaboration.h:44
DotGroupCollaboration::addEdge
Edge * addEdge(DotNode *_pNStart, DotNode *_pNEnd, EdgeType _eType, const QCString &_label, const QCString &_url)
Definition: dotgroupcollaboration.cpp:155
GroupDef::getPages
virtual const PageLinkedRefMap & getPages() const =0
Definition::getReference
virtual QCString getReference() const =0
DotGroupCollaboration::buildGraph
void buildGraph(const GroupDef *gd)
Definition: dotgroupcollaboration.cpp:47
Config_getBool
#define Config_getBool(name)
Definition: config.h:33
GroupDef::getOutputFileBase
virtual QCString getOutputFileBase() const =0
escapeCharsInString
QCString escapeCharsInString(const QCString &name, bool allowDots, bool allowUnderscore)
Definition: util.cpp:3442
Config_getString
#define Config_getString(name)
Definition: config.h:32
Inheritance
@ Inheritance
Definition: dotgraph.h:29
DotGroupCollaboration::getBaseName
virtual QCString getBaseName() const
Definition: dotgroupcollaboration.cpp:204
config.h
DotGroupCollaboration::tmember
@ tmember
Definition: dotgroupcollaboration.h:46
convertToXML
QCString convertToXML(const QCString &s, bool keepEntities)
Definition: util.cpp:3948
EmbeddedOutputFormat
EmbeddedOutputFormat
Definition: dotgraph.h:28
GraphOutputFormat
GraphOutputFormat
Definition: dotgraph.h:27
DotGroupCollaboration::tfile
@ tfile
Definition: dotgroupcollaboration.h:49
DotNode::convertLabel
static QCString convertLabel(const QCString &l)
Definition: dotnode.cpp:184
Definition::briefDescriptionAsTooltip
virtual QCString briefDescriptionAsTooltip() const =0
DotGroupCollaboration::m_edges
std::vector< std::unique_ptr< Edge > > m_edges
Definition: dotgroupcollaboration.h:85
DotGroupCollaboration::tpages
@ tpages
Definition: dotgroupcollaboration.h:50
util.h
A bunch of utility functions.
MemberList
A list of MemberDef objects as shown in documentation sections.
Definition: memberlist.h:81
DotGroupCollaboration::DotGroupCollaboration
DotGroupCollaboration(const GroupDef *gd)
Definition: dotgroupcollaboration.cpp:25
DotGraph::m_baseName
QCString m_baseName
Definition: dotgraph.h:88
FALSE
#define FALSE
Definition: qcstring.h:33
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108