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(), and NON_COPYABLE.

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:106

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 299 of file dotgraph.cpp.

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

205{
206 DString imgExt = getDotImageExtension();
208 {
209 t << "<para>\n";
210 t << " <informalfigure>\n";
211 t << " <mediaobject>\n";
212 t << " <imageobject>\n";
213 t << " <imagedata";
214 t << " width=\"50%\" align=\"center\" valign=\"middle\" scalefit=\"0\" fileref=\"" << m_relPath << m_baseName << "." << imgExt << "\">";
215 t << "</imagedata>\n";
216 t << " </imageobject>\n";
217 t << " </mediaobject>\n";
218 t << " </informalfigure>\n";
219 t << "</para>\n";
220 }
221 else if (m_graphFormat==GraphOutputFormat::BITMAP && m_generateImageMap) // produce HTML to include the image
222 {
223 if (imgExt=="svg") // add link to SVG file without map file
224 {
225 if (!m_noDivTag) t << "<div class=\"center\">";
226 if (m_regenerate || !DotFilePatcher::writeSVGFigureLink(t,m_relPath,m_baseName,absImgName())) // need to patch the links in the generated SVG file
227 {
228 if (m_regenerate)
229 {
231 createFilePatcher(absImgName())->
232 addSVGConversion(m_relPath,false,DString(),m_zoomable,m_graphId);
233 }
234 int mapId = DotManager::instance()->
235 createFilePatcher(m_fileName)->
236 addSVGObject(m_baseName,absImgName(),m_relPath);
237 t << "<!-- " << "SVG " << mapId << " -->";
238 }
239 if (!m_noDivTag) t << "</div>\n";
240 }
241 else // add link to bitmap file with image map
242 {
243 if (!m_noDivTag) t << "<div class=\"center\">";
244 t << "<img src=\"" << relImgName() << "\" border=\"0\" usemap=\"#"
245 << DotFilePatcher::mapLabelToId(getMapLabel()) << "\" loading=\"lazy\" alt=\"" << getImgAltText() << "\"/>";
246 if (!m_noDivTag) t << "</div>";
247 t << "\n";
249 {
250 int mapId = DotManager::instance()->
251 createFilePatcher(m_fileName)->
253 t << "<!-- MAP " << mapId << " -->\n";
254 }
255 }
256 }
257 else if (m_graphFormat==GraphOutputFormat::EPS) // produce tex to include the .eps image
258 {
260 {
261 int figId = DotManager::instance()->
262 createFilePatcher(m_fileName)->
263 addFigure(m_baseName,absBaseName(),false /*true*/);
264 t << "\n% FIG " << figId << "\n";
265 }
266 }
267}
DString()=default
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:79
static bool insertMapFile(TextStream &out, const DString &mapFile, const DString &relPath, const DString &mapLabel)
Definition dotgraph.cpp:85
DString getDotImageExtension()
Definition util.cpp:4966

References absBaseName(), absImgName(), absMapName(), BITMAP, DocBook, DString::DString(), 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 106 of file dotgraph.cpp.

107{
109 ("." + getDotImageExtension()) : (Config_getBool(USE_PDFLATEX) ? ".pdf" : ".eps"));
110}
#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 150 of file dotgraph.cpp.

151{
152 if (!m_dir.exists())
153 {
154 term("Output dir {} does not exist!\n", m_dir.path());
155 }
156
157 // calculate md5
158 DString sigStr = md5str(m_theGraph.view());
159
160 // already queued files are processed again in case the output format has changed
161
162 if (sameMd5Signature(absBaseName(), sigStr) &&
165 )
166 )
167 {
168 // all needed files are there
169 return false;
170 }
171
172 // need to rebuild the image
173
174 // write .dot file because image was new or has changed
175 std::ofstream f = Portable::openOutputStream(absDotName());
176 if (!f.is_open())
177 {
178 err("Could not open file {} for writing\n",absDotName());
179 return true;
180 }
181 f << m_theGraph;
182 f.close();
183
185 {
186 // run dot to create a bitmap image
188 }
190 {
191 // run dot to create a .eps image
192 if (Config_getBool(USE_PDFLATEX))
193 {
195 }
196 else
197 {
199 }
200 }
201 return true;
202}
std::string_view view() const
Definition dstring.h:166
size_t size() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:158
std::string path() const
Definition dir.cpp:235
bool exists() const
Definition dir.cpp:258
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:93
#define Config_getEnumAsString(name)
Definition config.h:36
static bool sameMd5Signature(const DString &baseName, const DString &md5)
Definition dotgraph.cpp:42
static bool deliverablesPresent(const DString &file1, const DString &file2)
Definition dotgraph.cpp:68
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:665
DotJob(const DString &ap, const DString &rdn, const DString &f, const DString &m, const DString &s, size_t sz, bool genMap=false)
Definition dotjob.h:25

References absBaseName(), absDotName(), absImgName(), absMapName(), DotManager::addJob(), BITMAP, Config_getBool, Config_getEnumAsString, deliverablesPresent(), DotJob::DotJob(), DString::DString(), 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 114 of file dotgraph.cpp.

123{
124 m_graphFormat = gf;
125 m_textFormat = ef;
126 m_dir = Dir(path.str());
127 m_fileName = fileName;
128 m_relPath = relPath;
129 m_generateImageMap = generateImageMap;
130 m_graphId = graphId;
131
132 m_absPath = m_dir.absPath() + "/";
134
136
138
140 {
141 std::lock_guard<std::mutex> lock(g_dotIndexListMutex);
143 }
144
145 generateCode(t);
146
147 return m_baseName;
148}
const std::string & str() const
Definition dstring.h:649
Dir()
Definition dir.cpp:190
std::string absPath() const
Definition dir.cpp:365
void generateCode(TextStream &t)
Definition dotgraph.cpp:204
bool prepareDotFile()
Definition dotgraph.cpp:150
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:112

References Dir::absPath(), IndexList::addImageFile(), computeTheGraph(), Dir::Dir(), 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 269 of file dotgraph.cpp.

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

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: