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