Doxygen
Loading...
Searching...
No Matches
DotGraph Class Referenceabstract

A dot graph. More...

#include <src/dotgraph.h>

Inheritance diagram for DotGraph:
Collaboration diagram for DotGraph:

Public Member Functions

 DotGraph ()
virtual ~DotGraph ()=default

Protected Member Functions

int getNextNodeNumber ()
 returns the node number.
int getNextEdgeNumber ()
 returns the edge number.
DString writeGraph (TextStream &t, GraphOutputFormat gf, EmbeddedOutputFormat ef, const DString &path, const DString &fileName, const DString &relPath, bool writeImageMap=true, int graphId=-1)
virtual DString getBaseName () const =0
virtual DString absMapName () const
virtual DString getMapLabel () const =0
virtual DString getImgAltText () const
virtual void computeTheGraph ()=0
DString absBaseName () const
DString absDotName () const
DString imgName () const
DString absImgName () const
DString relImgName () const

Static Protected Member Functions

static void writeGraphHeader (TextStream &t, const DString &title=DString())
static void writeGraphFooter (TextStream &t)
static void computeGraph (DotNode *root, GraphType gt, GraphOutputFormat format, const DString &rank, bool renderParents, bool backArrows, const DString &title, DString &graphStr)

Protected Attributes

GraphOutputFormat m_graphFormat = GraphOutputFormat::BITMAP
EmbeddedOutputFormat m_textFormat = EmbeddedOutputFormat::Html
Dir m_dir
DString m_fileName
DString m_relPath
bool m_generateImageMap = false
int m_graphId = 0
DString m_absPath
DString m_baseName
DString m_theGraph
bool m_regenerate = false
bool m_doNotAddImageToIndex = false
bool m_noDivTag = false
bool m_zoomable = true
bool m_urlOnly = false

Private Member Functions

bool prepareDotFile ()
void generateCode (TextStream &t)

Private Attributes

int m_curNodeNumber = 0
int m_curEdgeNumber = 0

Friends

class DotNode

Detailed Description

A dot graph.

Definition at line 34 of file dotgraph.h.

Constructor & Destructor Documentation

◆ DotGraph()

DotGraph::DotGraph ( )
inline

Definition at line 38 of file dotgraph.h.

38 : m_doNotAddImageToIndex(false), m_noDivTag(false),
39 m_zoomable(true), m_urlOnly(false) {}
bool m_noDivTag
Definition dotgraph.h:98
bool m_urlOnly
Definition dotgraph.h:100
bool m_doNotAddImageToIndex
Definition dotgraph.h:97
bool m_zoomable
Definition dotgraph.h:99

References m_doNotAddImageToIndex, m_noDivTag, m_urlOnly, and m_zoomable.

Referenced by ~DotGraph().

◆ ~DotGraph()

virtual DotGraph::~DotGraph ( )
virtualdefault

References DotGraph().

Member Function Documentation

◆ absBaseName()

DString DotGraph::absBaseName ( ) const
inlineprotected

Definition at line 78 of file dotgraph.h.

78{ return m_absPath + m_baseName; }
DString m_baseName
Definition dotgraph.h:94
DString m_absPath
Definition dotgraph.h:93

References m_absPath, and m_baseName.

Referenced by generateCode(), prepareDotFile(), and DotLegendGraph::writeGraph().

◆ absDotName()

DString DotGraph::absDotName ( ) const
inlineprotected

Definition at line 79 of file dotgraph.h.

79{ return m_absPath + m_baseName + ".dot"; }

References m_absPath, and m_baseName.

Referenced by prepareDotFile().

◆ absImgName()

DString DotGraph::absImgName ( ) const
inlineprotected

Definition at line 81 of file dotgraph.h.

81{ return m_absPath + imgName(); }
DString imgName() const
Definition dotgraph.cpp:107

References imgName(), and m_absPath.

Referenced by generateCode(), prepareDotFile(), and DotLegendGraph::writeGraph().

◆ absMapName()

virtual DString DotGraph::absMapName ( ) const
inlineprotectedvirtual

Definition at line 72 of file dotgraph.h.

72{ return m_absPath + m_baseName + ".map"; }

References m_absPath, and m_baseName.

Referenced by generateCode(), and prepareDotFile().

◆ computeGraph()

void DotGraph::computeGraph ( DotNode * root,
GraphType gt,
GraphOutputFormat format,
const DString & rank,
bool renderParents,
bool backArrows,
const DString & title,
DString & graphStr )
staticprotected

Definition at line 300 of file dotgraph.cpp.

308{
309 //printf("computeMd5Signature\n");
310 TextStream md5stream;
311 writeGraphHeader(md5stream,title);
312 if (!rank.empty())
313 {
314 md5stream << " rankdir=\"" << rank << "\";\n";
315 }
316 root->clearWriteFlag();
317 root->write(md5stream, gt, format, gt!=GraphType::CallGraph && gt!=GraphType::Dependency, true, backArrows);
318 if (renderParents)
319 {
320 for (const auto &pn : root->parents())
321 {
322 if (pn->isVisible())
323 {
324 const auto &children = pn->children();
325 auto child_it = std::find(children.begin(),children.end(),root);
326 size_t index = child_it - children.begin();
327 root->writeArrow(md5stream, // stream
328 gt, // graph type
329 format, // output format
330 pn, // child node
331 &pn->edgeInfo()[index], // edge info
332 false, // topDown?
333 backArrows // point back?
334 );
335 }
336 pn->write(md5stream, // stream
337 gt, // graph type
338 format, // output format
339 true, // topDown?
340 false, // toChildren?
341 backArrows // backward pointing arrows?
342 );
343 }
344 }
345 writeGraphFooter(md5stream);
346
347 graphStr=md5stream.str();
348}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
static void writeGraphFooter(TextStream &t)
Definition dotgraph.cpp:295
static void writeGraphHeader(TextStream &t, const DString &title=DString())
Definition dotgraph.cpp:270
void writeArrow(TextStream &t, GraphType gt, GraphOutputFormat f, const DotNode *cn, const EdgeInfo *ei, bool topDown, bool pointBack=true) const
Definition dotnode.cpp:605
void write(TextStream &t, GraphType gt, GraphOutputFormat f, bool topDown, bool toChildren, bool backArrows)
Definition dotnode.cpp:656
void clearWriteFlag()
Definition dotnode.cpp:887
const DotNodeRefVector & parents() const
Definition dotnode.h:123
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:232
@ Dependency
Definition dotgraph.h:31
@ CallGraph
Definition dotgraph.h:31

References CallGraph, DotNode::clearWriteFlag(), Dependency, DotNode, DString::empty(), DotNode::parents(), TextStream::str(), DotNode::write(), DotNode::writeArrow(), writeGraphFooter(), and writeGraphHeader().

Referenced by DotCallGraph::computeTheGraph(), DotClassGraph::computeTheGraph(), and DotInclDepGraph::computeTheGraph().

◆ computeTheGraph()

virtual void DotGraph::computeTheGraph ( )
protectedpure virtual

◆ generateCode()

void DotGraph::generateCode ( TextStream & t)
private

Definition at line 205 of file dotgraph.cpp.

206{
207 DString imgExt = getDotImageExtension();
209 {
210 t << "<para>\n";
211 t << " <informalfigure>\n";
212 t << " <mediaobject>\n";
213 t << " <imageobject>\n";
214 t << " <imagedata";
215 t << " width=\"50%\" align=\"center\" valign=\"middle\" scalefit=\"0\" fileref=\"" << m_relPath << m_baseName << "." << imgExt << "\">";
216 t << "</imagedata>\n";
217 t << " </imageobject>\n";
218 t << " </mediaobject>\n";
219 t << " </informalfigure>\n";
220 t << "</para>\n";
221 }
222 else if (m_graphFormat==GraphOutputFormat::BITMAP && m_generateImageMap) // produce HTML to include the image
223 {
224 if (imgExt=="svg") // add link to SVG file without map file
225 {
226 if (!m_noDivTag) t << "<div class=\"center\">";
227 if (m_regenerate || !DotFilePatcher::writeSVGFigureLink(t,m_relPath,m_baseName,absImgName())) // need to patch the links in the generated SVG file
228 {
229 if (m_regenerate)
230 {
232 createFilePatcher(absImgName())->
233 addSVGConversion(m_relPath,false,DString(),m_zoomable,m_graphId);
234 }
235 int mapId = DotManager::instance()->
236 createFilePatcher(m_fileName)->
237 addSVGObject(m_baseName,absImgName(),m_relPath);
238 t << "<!-- " << "SVG " << mapId << " -->";
239 }
240 if (!m_noDivTag) t << "</div>\n";
241 }
242 else // add link to bitmap file with image map
243 {
244 if (!m_noDivTag) t << "<div class=\"center\">";
245 t << "<img src=\"" << relImgName() << "\" border=\"0\" usemap=\"#"
246 << DotFilePatcher::mapLabelToId(getMapLabel()) << "\" loading=\"lazy\" alt=\"" << getImgAltText() << "\"/>";
247 if (!m_noDivTag) t << "</div>";
248 t << "\n";
250 {
251 int mapId = DotManager::instance()->
252 createFilePatcher(m_fileName)->
253 addMap(absMapName(), m_relPath, m_urlOnly, DString(), getMapLabel());
254 t << "<!-- MAP " << mapId << " -->\n";
255 }
256 }
257 }
258 else if (m_graphFormat==GraphOutputFormat::EPS) // produce tex to include the .eps image
259 {
261 {
262 int figId = DotManager::instance()->
263 createFilePatcher(m_fileName)->
264 addFigure(m_baseName,absBaseName(),false /*true*/);
265 t << "\n% FIG " << figId << "\n";
266 }
267 }
268}
static DString mapLabelToId(const DString &mapLabel)
static bool writeVecGfxFigure(TextStream &out, const DString &baseName, const DString &figureName)
static bool writeSVGFigureLink(TextStream &out, const DString &relPath, const DString &baseName, const DString &absImgName)
Check if a reference to a SVG figure can be written and do so if possible.
int m_graphId
Definition dotgraph.h:91
EmbeddedOutputFormat m_textFormat
Definition dotgraph.h:86
GraphOutputFormat m_graphFormat
Definition dotgraph.h:85
DString m_fileName
Definition dotgraph.h:88
DString absImgName() const
Definition dotgraph.h:81
virtual DString getImgAltText() const
Definition dotgraph.h:74
DString m_relPath
Definition dotgraph.h:89
DString relImgName() const
Definition dotgraph.h:82
virtual DString getMapLabel() const =0
bool m_regenerate
Definition dotgraph.h:96
virtual DString absMapName() const
Definition dotgraph.h:72
DString absBaseName() const
Definition dotgraph.h:78
bool m_generateImageMap
Definition dotgraph.h:90
static DotManager * instance()
Definition dot.cpp:78
static bool insertMapFile(TextStream &out, const DString &mapFile, const DString &relPath, const DString &mapLabel)
Definition dotgraph.cpp:86
DString getDotImageExtension()
Definition util.cpp:4964

References absBaseName(), absImgName(), absMapName(), BITMAP, DocBook, EPS, getDotImageExtension(), getImgAltText(), getMapLabel(), insertMapFile(), DotManager::instance(), m_baseName, m_fileName, m_generateImageMap, m_graphFormat, m_graphId, m_noDivTag, m_regenerate, m_relPath, m_textFormat, m_urlOnly, m_zoomable, DotFilePatcher::mapLabelToId(), relImgName(), DotFilePatcher::writeSVGFigureLink(), and DotFilePatcher::writeVecGfxFigure().

Referenced by writeGraph().

◆ getBaseName()

virtual DString DotGraph::getBaseName ( ) const
protectedpure virtual

◆ getImgAltText()

virtual DString DotGraph::getImgAltText ( ) const
inlineprotectedvirtual

Reimplemented in DotClassGraph, and DotDirDeps.

Definition at line 74 of file dotgraph.h.

74{ return ""; }

Referenced by generateCode().

◆ getMapLabel()

virtual DString DotGraph::getMapLabel ( ) const
protectedpure virtual

◆ getNextEdgeNumber()

int DotGraph::getNextEdgeNumber ( )
inlineprotected

returns the edge number.

Definition at line 47 of file dotgraph.h.

47{ return ++m_curEdgeNumber; }
int m_curEdgeNumber
Definition dotgraph.h:108

References m_curEdgeNumber.

Referenced by DotNode::writeArrow().

◆ getNextNodeNumber()

int DotGraph::getNextNodeNumber ( )
inlineprotected

returns the node number.

Definition at line 45 of file dotgraph.h.

45{ return ++m_curNodeNumber; }
int m_curNodeNumber
Definition dotgraph.h:107

References m_curNodeNumber.

◆ imgName()

DString DotGraph::imgName ( ) const
protected

Definition at line 107 of file dotgraph.cpp.

108{
110 ("." + getDotImageExtension()) : (Config_getBool(USE_PDFLATEX) ? ".pdf" : ".eps"));
111}
#define Config_getBool(name)
Definition config.h:33

References BITMAP, Config_getBool, getDotImageExtension(), m_baseName, and m_graphFormat.

Referenced by absImgName(), relImgName(), and writeGraph().

◆ prepareDotFile()

bool DotGraph::prepareDotFile ( )
private

Definition at line 151 of file dotgraph.cpp.

152{
153 if (!m_dir.exists())
154 {
155 term("Output dir {} does not exist!\n", m_dir.path());
156 }
157
158 // calculate md5
159 DString sigStr = md5str(m_theGraph.view());
160
161 // already queued files are processed again in case the output format has changed
162
163 if (sameMd5Signature(absBaseName(), sigStr) &&
166 )
167 )
168 {
169 // all needed files are there
170 return false;
171 }
172
173 // need to rebuild the image
174
175 // write .dot file because image was new or has changed
176 std::ofstream f = Portable::openOutputStream(absDotName());
177 if (!f.is_open())
178 {
179 err("Could not open file {} for writing\n",absDotName());
180 return true;
181 }
182 f << m_theGraph;
183 f.close();
184
186 {
187 // run dot to create a bitmap image
189 }
191 {
192 // run dot to create a .eps image
193 if (Config_getBool(USE_PDFLATEX))
194 {
195 DotManager::instance()->addJob(DotJob(m_absPath, m_baseName + ".dot", "pdf", sigStr, absDotName(), m_theGraph.size()));
196 }
197 else
198 {
199 DotManager::instance()->addJob(DotJob(m_absPath, m_baseName + ".dot", "eps", sigStr, absDotName(), m_theGraph.size()));
200 }
201 }
202 return true;
203}
std::string_view view() const
Definition dstring.h:162
size_t size() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:154
std::string path() const
Definition dir.cpp:240
bool exists() const
Definition dir.cpp:263
Dir m_dir
Definition dotgraph.h:87
DString m_theGraph
Definition dotgraph.h:95
DString absDotName() const
Definition dotgraph.h:79
void addJob(const DotJob &newJob)
Definition dot.cpp:92
#define Config_getEnumAsString(name)
Definition config.h:36
static bool sameMd5Signature(const DString &baseName, const DString &md5)
Definition dotgraph.cpp:43
static bool deliverablesPresent(const DString &file1, const DString &file2)
Definition dotgraph.cpp:69
DString md5str(const std::string_view &str)
Definition md5hash.h:33
#define err(fmt,...)
Definition message.h:127
#define term(fmt,...)
Definition message.h:137
std::ofstream openOutputStream(const DString &name, bool append=false)
Definition portable.cpp:681

References absBaseName(), absDotName(), absImgName(), absMapName(), DotManager::addJob(), BITMAP, Config_getBool, Config_getEnumAsString, deliverablesPresent(), EPS, err, Dir::exists(), DotManager::instance(), m_absPath, m_baseName, m_dir, m_generateImageMap, m_graphFormat, m_theGraph, md5str(), Portable::openOutputStream(), Dir::path(), sameMd5Signature(), DString::size(), term, and DString::view().

Referenced by writeGraph().

◆ relImgName()

DString DotGraph::relImgName ( ) const
inlineprotected

Definition at line 82 of file dotgraph.h.

82{ return m_relPath + imgName(); }

References imgName(), and m_relPath.

Referenced by generateCode().

◆ writeGraph()

DString DotGraph::writeGraph ( TextStream & t,
GraphOutputFormat gf,
EmbeddedOutputFormat ef,
const DString & path,
const DString & fileName,
const DString & relPath,
bool writeImageMap = true,
int graphId = -1 )
protected

Definition at line 115 of file dotgraph.cpp.

124{
125 m_graphFormat = gf;
126 m_textFormat = ef;
127 m_dir = Dir(path.str());
128 m_fileName = fileName;
129 m_relPath = relPath;
130 m_generateImageMap = generateImageMap;
131 m_graphId = graphId;
132
133 m_absPath = m_dir.absPath() + "/";
135
137
139
141 {
142 std::lock_guard<std::mutex> lock(g_dotIndexListMutex);
144 }
145
146 generateCode(t);
147
148 return m_baseName;
149}
const std::string & str() const
Definition dstring.h:645
std::string absPath() const
Definition dir.cpp:370
void generateCode(TextStream &t)
Definition dotgraph.cpp:205
bool prepareDotFile()
Definition dotgraph.cpp:151
virtual DString getBaseName() const =0
virtual void computeTheGraph()=0
static IndexList * indexList
Definition doxygen.h:125
void addImageFile(const DString &name)
Definition indexlist.h:124
std::mutex g_dotIndexListMutex
Definition dotgraph.cpp:113

References Dir::absPath(), IndexList::addImageFile(), computeTheGraph(), g_dotIndexListMutex, generateCode(), getBaseName(), imgName(), Doxygen::indexList, m_absPath, m_baseName, m_dir, m_doNotAddImageToIndex, m_fileName, m_generateImageMap, m_graphFormat, m_graphId, m_regenerate, m_relPath, m_textFormat, prepareDotFile(), and DString::str().

Referenced by DotGfxHierarchyTable::createGraph(), DotCallGraph::writeGraph(), DotClassGraph::writeGraph(), DotDirDeps::writeGraph(), DotGroupCollaboration::writeGraph(), DotInclDepGraph::writeGraph(), and DotLegendGraph::writeGraph().

◆ writeGraphFooter()

void DotGraph::writeGraphFooter ( TextStream & t)
staticprotected

◆ writeGraphHeader()

void DotGraph::writeGraphHeader ( TextStream & t,
const DString & title = DString() )
staticprotected

Definition at line 270 of file dotgraph.cpp.

271{
272 t << "digraph ";
273 if (title.empty())
274 {
275 t << "\"Dot Graph\"";
276 }
277 else
278 {
279 t << "\"" << convertToXML(title) << "\"";
280 }
281 t << "\n{\n";
282 if (Config_getBool(INTERACTIVE_SVG)) // insert a comment to force regeneration when this
283 // option is toggled
284 {
285 t << " // INTERACTIVE_SVG=YES\n";
286 }
287 t << " // LATEX_PDF_SIZE\n"; // write placeholder for LaTeX PDF bounding box size replacement
288 t << " bgcolor=\"transparent\";\n";
289 DString c = Config_getString(DOT_COMMON_ATTR);
290 if (!c.empty()) c += ",";
291 t << " edge [" << c << Config_getString(DOT_EDGE_ATTR) << "];\n";
292 t << " node [" << c << Config_getString(DOT_NODE_ATTR) << "];\n";
293}
#define Config_getString(name)
Definition config.h:32
DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
Definition util.cpp:3232

References Config_getBool, Config_getString, convertToXML(), and DString::empty().

Referenced by computeGraph(), DotDirDeps::computeTheGraph(), DotGfxHierarchyTable::computeTheGraph(), DotLegendGraph::computeTheGraph(), and DotGroupCollaboration::writeGraphHeader().

◆ DotNode

Member Data Documentation

◆ m_absPath

DString DotGraph::m_absPath
protected

Definition at line 93 of file dotgraph.h.

Referenced by absBaseName(), absDotName(), absImgName(), absMapName(), prepareDotFile(), and writeGraph().

◆ m_baseName

◆ m_curEdgeNumber

int DotGraph::m_curEdgeNumber = 0
private

Definition at line 108 of file dotgraph.h.

Referenced by getNextEdgeNumber().

◆ m_curNodeNumber

int DotGraph::m_curNodeNumber = 0
private

Definition at line 107 of file dotgraph.h.

Referenced by getNextNodeNumber().

◆ m_dir

Dir DotGraph::m_dir
protected

Definition at line 87 of file dotgraph.h.

Referenced by prepareDotFile(), and writeGraph().

◆ m_doNotAddImageToIndex

bool DotGraph::m_doNotAddImageToIndex = false
protected

◆ m_fileName

DString DotGraph::m_fileName
protected

Definition at line 88 of file dotgraph.h.

Referenced by generateCode(), and writeGraph().

◆ m_generateImageMap

bool DotGraph::m_generateImageMap = false
protected

Definition at line 90 of file dotgraph.h.

Referenced by generateCode(), prepareDotFile(), and writeGraph().

◆ m_graphFormat

◆ m_graphId

int DotGraph::m_graphId = 0
protected

Definition at line 91 of file dotgraph.h.

Referenced by generateCode(), and writeGraph().

◆ m_noDivTag

bool DotGraph::m_noDivTag = false
protected

Definition at line 98 of file dotgraph.h.

Referenced by DotGfxHierarchyTable::createGraph(), DotGraph(), and generateCode().

◆ m_regenerate

bool DotGraph::m_regenerate = false
protected

Definition at line 96 of file dotgraph.h.

Referenced by generateCode(), and writeGraph().

◆ m_relPath

DString DotGraph::m_relPath
protected

Definition at line 89 of file dotgraph.h.

Referenced by generateCode(), relImgName(), and writeGraph().

◆ m_textFormat

EmbeddedOutputFormat DotGraph::m_textFormat = EmbeddedOutputFormat::Html
protected

Definition at line 86 of file dotgraph.h.

Referenced by generateCode(), and writeGraph().

◆ m_theGraph

◆ m_urlOnly

bool DotGraph::m_urlOnly = false
protected

Definition at line 100 of file dotgraph.h.

Referenced by DotGraph(), generateCode(), and DotDirDeps::writeGraph().

◆ m_zoomable

bool DotGraph::m_zoomable = true
protected

Definition at line 99 of file dotgraph.h.

Referenced by DotGfxHierarchyTable::createGraph(), DotGraph(), and generateCode().


The documentation for this class was generated from the following files: