Doxygen
Loading...
Searching...
No Matches
dotgroupcollaboration.cpp
Go to the documentation of this file.
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
17
18#include "classlist.h"
19#include "config.h"
20#include "doxygen.h"
21#include "groupdef.h"
22#include "namespacedef.h"
23#include "pagedef.h"
24#include "textstream.h"
25#include "util.h"
26#include "filedef.h"
27
29{
30 DString tmp_url = gd->getReference()+"$"+gd->getOutputFileBase();
31 DString tooltip = gd->briefDescriptionAsTooltip();
32 m_rootNode = new DotNode(this, gd->groupTitle(), tooltip, tmp_url, true );
34 m_usedNodes.emplace(gd->name().str(), m_rootNode);
35
37
38 buildGraph( gd );
39}
40
42{
43 // delete all created Nodes saved in m_usedNodes map
44 for (const auto &[name,node] : m_usedNodes)
45 {
46 delete node;
47 }
48}
49
50static void makeURL(const Definition *def,DString &url)
51{
52 DString fn = def->getOutputFileBase();
54 url = def->getReference()+"$"+fn;
55 if (!def->anchor().empty())
56 {
57 url+="#"+def->anchor();
58 }
59}
60
62{
63 DString url;
64 //===========================
65 // hierarchy.
66
67 // Write parents
68 for (const auto &d : gd->partOfGroups())
69 {
70 DotNode *nnode = nullptr;
71 auto it = m_usedNodes.find(d->name().str());
72 if ( it==m_usedNodes.end())
73 { // add node
74 makeURL(d,url);
75 DString tooltip = d->briefDescriptionAsTooltip();
76 nnode = new DotNode(this, d->groupTitle(), tooltip, url );
77 nnode->markAsVisible();
78 m_usedNodes.emplace(d->name().str(), nnode);
79 }
80 else
81 {
82 nnode = it->second;
83 }
84 url = "";
86 }
87
88 // Add subgroups
89 for (const auto &def : gd->getSubGroups())
90 {
91 DotNode *nnode = nullptr;
92 auto it = m_usedNodes.find(def->name().str());
93 if ( it==m_usedNodes.end())
94 { // add node
95 makeURL(def,url);
96 DString tooltip = def->briefDescriptionAsTooltip();
97 nnode = new DotNode(this, def->groupTitle(), tooltip, url );
98 nnode->markAsVisible();
99 m_usedNodes.emplace(def->name().str(), nnode);
100 }
101 else
102 {
103 nnode = it->second;
104 }
105 url = "";
107 }
108
109 //=======================
110 // Write collaboration
111
112 // Add members
113 addMemberList( gd->getMemberList(MemberListType::AllMembersList()) );
114
115 // Add classes
116 for (const auto &def : gd->getClasses())
117 {
118 makeURL(def,url);
120 }
121
122 // Add namespaces
123 for (const auto &def : gd->getNamespaces())
124 {
125 makeURL(def,url);
127 }
128
129 // Add files
130 for (const auto &def : gd->getFiles())
131 {
132 makeURL(def,url);
134 }
135
136 // Add pages
137 for (const auto &def : gd->getPages())
138 {
139 makeURL(def,url);
141 }
142
143 // Add directories
144 if ( !gd->getDirs().empty() )
145 {
146 for(const auto &def : gd->getDirs())
147 {
148 makeURL(def,url);
150 }
151 }
152}
153
155{
156 DString url;
157 if ( ml==nullptr || ml->empty() ) return;
158 for (const auto &def : *ml)
159 {
160 makeURL(def,url);
162 }
163}
164
166 DotNode* _pNStart, DotNode* _pNEnd, EdgeType _eType,
167 const DString& _label, const DString& _url )
168{
169 // search a existing link.
170 auto it = std::find_if(m_edges.begin(),m_edges.end(),
171 [&_pNStart,&_pNEnd,&_eType](const auto &edge)
172 { return edge->pNStart==_pNStart && edge->pNEnd==_pNEnd && edge->eType==_eType; });
173
174 if (it==m_edges.end()) // new link
175 {
176 m_edges.emplace_back(std::make_unique<Edge>(_pNStart,_pNEnd,_eType));
177 it = m_edges.end()-1;
178 }
179
180 if (!_label.empty()) // add label
181 {
182 (*it)->links.emplace_back(_label,_url);
183 }
184
185 // return found or added edge
186 return (*it).get();
187}
188
190 const Definition* def, DString& url, EdgeType eType )
191{
192 // Create group nodes
193 DString tmp_str;
194 for (const auto &d : def->partOfGroups())
195 {
196 auto it = m_usedNodes.find(d->name().str());
197 DotNode* nnode = it!=m_usedNodes.end() ? it->second : nullptr;
198 if ( nnode != m_rootNode )
199 {
200 if ( nnode==nullptr )
201 { // add node
202 tmp_str = d->getReference()+"$"+d->getOutputFileBase();
203 DString tooltip = d->briefDescriptionAsTooltip();
204 nnode = new DotNode(this, d->groupTitle(), tooltip, tmp_str );
205 nnode->markAsVisible();
206 m_usedNodes.emplace(d->name().str(), nnode);
207 }
208 tmp_str = def->qualifiedName();
209 addEdge( m_rootNode, nnode, eType, tmp_str, url );
210 }
211 }
212}
213
218
220{
221 TextStream md5stream;
222 writeGraphHeader(md5stream,m_rootNode->label());
223
224 // clean write flags
225 for (const auto &[name,node] : m_usedNodes)
226 {
227 node->clearWriteFlag();
228 }
229
230 // write other nodes.
231 for (const auto &[name,node] : m_usedNodes)
232 {
233 node->write(md5stream,GraphType::Inheritance,m_graphFormat,true,false,false);
234 }
235
236 // write edges
237 for (const auto &edge : m_edges)
238 {
239 edge->write( md5stream );
240 }
241
242 writeGraphFooter(md5stream);
243
244 m_theGraph = md5stream.str();
245}
246
251
253 GraphOutputFormat graphFormat, EmbeddedOutputFormat textFormat,
254 const DString &path, const DString &fileName, const DString &relPath,
255 bool generateImageMap,int graphId)
256{
258
259 return DotGraph::writeGraph(t, graphFormat, textFormat, path, fileName, relPath, generateImageMap, graphId);
260}
261
263{
264 const char* linkTypeColor[] = {
265 "darkorchid3"
266 ,"orange"
267 ,"blueviolet"
268 ,"darkgreen"
269 ,"firebrick4"
270 ,"grey75"
271 ,"midnightblue"
272 };
273 DString arrowStyle = "dir=\"none\", style=\"dashed\"";
274 t << " Node" << pNStart->number();
275 t << "->";
276 t << "Node" << pNEnd->number();
277
278 t << " [shape=plaintext";
279 if (!links.empty()) // there are links
280 {
281 t << ", ";
282 // HTML-like edge labels crash on my Mac with Graphviz 2.0! and
283 // are not supported by older version of dot.
284 //
285 //t << label=<<TABLE BORDER=\"0\" CELLBORDER=\"0\">";
286 //for (const auto &link : links)
287 //{
288 // t << "<TR><TD";
289 // if ( !link.url.empty() )
290 // t << " HREF=\"" << link.url << "\"";
291 // t << ">" << DotNode::convertLabel(link->label) << "</TD></TR>";
292 //}
293 //t << "</TABLE>>";
294
295 t << "label=\"";
296 bool first=true;
297 int count=0;
298 const int maxLabels = 10;
299 for (const auto &link : links)
300 {
301 if (first) first=false; else t << "\\n";
302 t << DotNode::convertLabel(link.label);
303 count++;
304 }
305 if (count==maxLabels) t << "\\n...";
306 t << "\"";
307
308 }
309 switch( eType )
310 {
311 case thierarchy:
312 arrowStyle = "dir=\"back\", style=\"solid\"";
313 break;
314 default:
315 t << ", color=\"" << linkTypeColor[static_cast<int>(eType)] << "\"";
316 break;
317 }
318 t << ", " << arrowStyle;
319 t << "];\n";
320}
321
323{
324 return m_usedNodes.size() <= 1;
325}
326
328{
329 return numNodes()>=Config_getInt(DOT_GRAPH_MAX_NODES);
330}
331
333{
334 return static_cast<int>(m_usedNodes.size());
335}
336
338{
340 t << " rankdir=LR;\n";
341}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:88
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:152
const std::string & str() const
Definition dstring.h:649
The common base class of all entity definitions found in the sources.
Definition definition.h:77
virtual const DString & name() const =0
virtual DString briefDescriptionAsTooltip() const =0
virtual DString qualifiedName() const =0
virtual DString anchor() const =0
virtual DString getReference() const =0
virtual const GroupList & partOfGroups() const =0
virtual DString getOutputFileBase() const =0
DString m_baseName
Definition dotgraph.h:94
DString m_theGraph
Definition dotgraph.h:95
static void writeGraphFooter(TextStream &t)
Definition dotgraph.cpp:294
GraphOutputFormat m_graphFormat
Definition dotgraph.h:85
bool m_doNotAddImageToIndex
Definition dotgraph.h:97
DString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const DString &path, const DString &fileName, const DString &relPath, bool writeImageMap=true, int graphId=-1)
Definition dotgraph.cpp:114
static void writeGraphHeader(TextStream &t, const DString &title=DString())
Definition dotgraph.cpp:269
friend class DotNode
Definition dotgraph.h:36
std::vector< std::unique_ptr< Edge > > m_edges
DotGroupCollaboration(const GroupDef *gd)
DString getMapLabel() const override
void addMemberList(class MemberList *ml)
DString getBaseName() const override
void writeGraphHeader(TextStream &t, const DString &title) const
void addCollaborationMember(const Definition *def, DString &url, EdgeType eType)
DString writeGraph(TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const DString &path, const DString &fileName, const DString &relPath, bool writeImageMap=true, int graphId=-1)
void buildGraph(const GroupDef *gd)
Edge * addEdge(DotNode *_pNStart, DotNode *_pNEnd, EdgeType _eType, const DString &_label, const DString &_url)
static DString convertLabel(const DString &, LabelStyle=LabelStyle::Plain)
Definition dotnode.cpp:196
void markAsVisible(bool b=true)
Definition dotnode.h:120
int number() const
Definition dotnode.h:103
DotNode(DotGraph *graph, const DString &lab, const DString &tip, const DString &url, bool rootNode=false, const ClassDef *cd=nullptr)
Definition dotnode.cpp:326
DString label() const
Definition dotnode.h:102
A model of a group of symbols.
Definition groupdef.h:48
virtual DString groupTitle() const =0
virtual const DirList & getDirs() const =0
virtual const GroupList & getSubGroups() const =0
virtual const FileList & getFiles() const =0
virtual const PageLinkedRefMap & getPages() const =0
virtual const NamespaceLinkedRefMap & getNamespaces() const =0
virtual const ClassLinkedRefMap & getClasses() const =0
virtual MemberList * getMemberList(MemberListType lt) const =0
A list of MemberDef objects as shown in documentation sections.
Definition memberlist.h:125
bool empty() const noexcept
Definition memberlist.h:60
Text streaming class that buffers data.
Definition textstream.h:36
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:232
#define Config_getInt(name)
Definition config.h:34
@ Inheritance
Definition dotgraph.h:31
EmbeddedOutputFormat
Definition dotgraph.h:30
GraphOutputFormat
Definition dotgraph.h:29
static void makeURL(const Definition *def, DString &url)
void write(TextStream &t) const
void addHtmlExtensionIfMissing(DString &fName)
Definition util.cpp:3933
DString escapeCharsInString(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2690
A bunch of utility functions.