Skip to content

Commit

Permalink
Added support for directory dependency graphs to template engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri van Heesch committed Aug 28, 2015
1 parent 43a0883 commit abe254f
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 23 deletions.
96 changes: 91 additions & 5 deletions src/context.cpp
Expand Up @@ -456,6 +456,18 @@ class TranslateContext::Private : public PropertyMapper
}
return TemplateVariant();
}
TemplateVariant handleDirDependencyGraphFor(const QValueList<TemplateVariant> &args) const
{
if (args.count()==1)
{
return theTranslator->trDirDepGraph(args[0].toString());
}
else
{
err("tr.dirDependencyGraphFor should take one argument, got %d!\n",args.count());
}
return TemplateVariant();
}
TemplateVariant handleInheritsList(const QValueList<TemplateVariant> &args) const
{
if (args.count()==1)
Expand Down Expand Up @@ -571,6 +583,10 @@ class TranslateContext::Private : public PropertyMapper
{
return TemplateVariant::Delegate::fromMethod<Private,&Private::handleCollaborationDiagramFor>(this);
}
TemplateVariant dirDependencyGraphFor() const
{
return TemplateVariant::Delegate::fromMethod<Private,&Private::handleDirDependencyGraphFor>(this);
}
TemplateVariant search() const
{
return theTranslator->trSearch();
Expand Down Expand Up @@ -1138,6 +1154,8 @@ class TranslateContext::Private : public PropertyMapper
addProperty("panelSyncOn", this,&Private::panelSyncOn);
//%% string panelSyncOff
addProperty("panelSyncOff", this,&Private::panelSyncOff);
//%% string dirDependencyGraph
addProperty("dirDependencyGraphFor", this,&Private::dirDependencyGraphFor);

m_javaOpt = Config_getBool("OPTIMIZE_OUTPUT_JAVA");
m_fortranOpt = Config_getBool("OPTIMIZE_FOR_FORTRAN");
Expand Down Expand Up @@ -1819,6 +1837,7 @@ class ClassContext::Private : public DefinitionContext<ClassContext::Private>
err("context.cpp: output format not yet supported");
break;
}
g_globals.dynSectionId++;
}
else if (classDiagrams)
{
Expand Down Expand Up @@ -1850,8 +1869,8 @@ class ClassContext::Private : public DefinitionContext<ClassContext::Private>
err("context.cpp: output format not yet supported");
break;
}
g_globals.dynSectionId++;
}
g_globals.dynSectionId++;
return TemplateVariant(result.data(),TRUE);
}
DotClassGraph *getCollaborationGraph() const
Expand Down Expand Up @@ -1900,8 +1919,8 @@ class ClassContext::Private : public DefinitionContext<ClassContext::Private>
err("context.cpp: output format not yet supported");
break;
}
g_globals.dynSectionId++;
}
g_globals.dynSectionId++;
return TemplateVariant(result.data(),TRUE);
}

Expand Down Expand Up @@ -2794,8 +2813,8 @@ class FileContext::Private : public DefinitionContext<FileContext::Private>
err("context.cpp: output format not yet supported");
break;
}
g_globals.dynSectionId++;
}
g_globals.dynSectionId++;
return TemplateVariant(result.data(),TRUE);
}
DotInclDepGraph *getIncludedByGraph() const
Expand Down Expand Up @@ -2845,8 +2864,8 @@ class FileContext::Private : public DefinitionContext<FileContext::Private>
err("context.cpp: output format not yet supported");
break;
}
g_globals.dynSectionId++;
}
g_globals.dynSectionId++;
return TemplateVariant(result.data(),TRUE);
}
TemplateVariant hasDetails() const
Expand Down Expand Up @@ -3109,6 +3128,8 @@ class DirContext::Private : public DefinitionContext<DirContext::Private>
addProperty("dirs", this,&Private::dirs);
addProperty("files", this,&Private::files);
addProperty("hasDetails", this,&Private::hasDetails);
addProperty("hasDirGraph", this,&Private::hasDirGraph);
addProperty("dirGraph", this,&Private::dirGraph);
addProperty("compoundType", this,&Private::compoundType);
}
virtual ~Private() {}
Expand Down Expand Up @@ -3176,6 +3197,70 @@ class DirContext::Private : public DefinitionContext<DirContext::Private>
{
return "";
}
DotDirDeps *getDirDepsGraph() const
{
if (!m_cache.dirDepsGraph)
{
m_cache.dirDepsGraph.reset(new DotDirDeps(m_dirDef));
}
return m_cache.dirDepsGraph.get();
}
TemplateVariant hasDirGraph() const
{
bool result=FALSE;
static bool haveDot = Config_getBool("HAVE_DOT");
static bool dirGraph = Config_getBool("DIRECTORY_GRAPH");
if (haveDot && dirGraph)
{
DotDirDeps *graph = getDirDepsGraph();
result = !graph->isTrivial();
}
return result;
}
TemplateVariant dirGraph() const
{
QGString result;
static bool haveDot = Config_getBool("HAVE_DOT");
static bool dirGraph = Config_getBool("DIRECTORY_GRAPH");
if (haveDot && dirGraph)
{
DotDirDeps *graph = getDirDepsGraph();
FTextStream t(&result);
switch (g_globals.outputFormat)
{
case ContextOutputFormat_Html:
{
graph->writeGraph(t,GOF_BITMAP,
EOF_Html,
g_globals.outputDir,
g_globals.outputDir+portable_pathSeparator()+m_dirDef->getOutputFileBase()+Doxygen::htmlFileExtension,
relPathAsString(),
TRUE,
g_globals.dynSectionId,
FALSE);
}
break;
case ContextOutputFormat_Latex:
{
graph->writeGraph(t,GOF_EPS,
EOF_LaTeX,
g_globals.outputDir,
g_globals.outputDir+portable_pathSeparator()+m_dirDef->getOutputFileBase()+".tex",
relPathAsString(),
TRUE,
g_globals.dynSectionId,
FALSE);
}
break;
// TODO: support other generators
default:
err("context.cpp: output format not yet supported");
break;
}
g_globals.dynSectionId++;
}
return TemplateVariant(result.data(),TRUE);
}

private:
DirDef *m_dirDef;
Expand All @@ -3184,6 +3269,7 @@ class DirContext::Private : public DefinitionContext<DirContext::Private>
Cachable() {}
SharedPtr<TemplateList> dirs;
SharedPtr<TemplateList> files;
ScopedPtr<DotDirDeps> dirDepsGraph;
};
mutable Cachable m_cache;
};
Expand Down Expand Up @@ -4687,8 +4773,8 @@ class ModuleContext::Private : public DefinitionContext<ModuleContext::Private>
err("context.cpp: output format not yet supported");
break;
}
g_globals.dynSectionId++;
}
g_globals.dynSectionId++;
return TemplateVariant(result.data(),TRUE);
}
TemplateVariant hasDetails() const
Expand Down
9 changes: 2 additions & 7 deletions src/dirdef.cpp
Expand Up @@ -385,7 +385,7 @@ void DirDef::writeDocumentation(OutputList &ol)
ol.pushGeneratorState();

QCString title=theTranslator->trDirReference(m_dispName);
startFile(ol,getOutputFileBase(),name(),title,HLI_None,!generateTreeView);
startFile(ol,getOutputFileBase(),name(),title,HLI_Files,!generateTreeView);

if (!generateTreeView)
{
Expand Down Expand Up @@ -610,7 +610,7 @@ bool DirDef::isParentOf(DirDef *dir) const

bool DirDef::depGraphIsTrivial() const
{
return FALSE;
return m_usedDirs->count()==0;
}

//----------------------------------------------------------------------
Expand Down Expand Up @@ -696,11 +696,6 @@ DirDef *DirDef::mergeDirectoryInTree(const QCString &path)
return dir;
}

void DirDef::writeDepGraph(FTextStream &t)
{
writeDotDirDepGraph(t,this);
}

//----------------------------------------------------------------------

static void writePartialDirPath(OutputList &ol,const DirDef *root,const DirDef *target)
Expand Down
1 change: 0 additions & 1 deletion src/dirdef.h
Expand Up @@ -71,7 +71,6 @@ class DirDef : public Definition

// generate output
void writeDocumentation(OutputList &ol);
void writeDepGraph(FTextStream &t);
void writeTagFile(FTextStream &t);

static DirDef *mergeDirectoryInTree(const QCString &path);
Expand Down
18 changes: 12 additions & 6 deletions src/dot.cpp
Expand Up @@ -3965,6 +3965,7 @@ bool DotCallGraph::isTooBig() const
}

//-------------------------------------------------------------
static void writeDotDirDepGraph(FTextStream &t,DirDef *dd,bool linkRelations);

DotDirDeps::DotDirDeps(DirDef *dir) : m_dir(dir)
{
Expand All @@ -3981,7 +3982,8 @@ QCString DotDirDeps::writeGraph(FTextStream &out,
const char *fileName,
const char *relPath,
bool generateImageMap,
int graphId) const
int graphId,
bool linkRelations) const
{
QDir d(path);
// store the original directory
Expand All @@ -4006,7 +4008,8 @@ QCString DotDirDeps::writeGraph(FTextStream &out,
// compute md5 checksum of the graph were are about to generate
QGString theGraph;
FTextStream md5stream(&theGraph);
m_dir->writeDepGraph(md5stream);
//m_dir->writeDepGraph(md5stream);
writeDotDirDepGraph(md5stream,m_dir,linkRelations);
uchar md5_sig[16];
QCString sigStr(33);
MD5Buffer((const unsigned char *)theGraph.data(),theGraph.length(),md5_sig);
Expand Down Expand Up @@ -4764,7 +4767,7 @@ void DotGroupCollaboration::writeGraphHeader(FTextStream &t,
t << " rankdir=LR;\n";
}

void writeDotDirDepGraph(FTextStream &t,DirDef *dd)
void writeDotDirDepGraph(FTextStream &t,DirDef *dd,bool linkRelations)
{
t << "digraph \"" << dd->displayName() << "\" {\n";
if (Config_getBool("DOT_TRANSPARENT"))
Expand Down Expand Up @@ -4896,11 +4899,14 @@ void writeDotDirDepGraph(FTextStream &t,DirDef *dd)
new DirRelation(relationName,dir,udir));
}
int nrefs = udir->filePairs().count();
t << " " << dir->getOutputFileBase() << "->"
t << " " << dir->getOutputFileBase() << "->"
<< usedDir->getOutputFileBase();
t << " [headlabel=\"" << nrefs << "\", labeldistance=1.5";
t << " headhref=\"" << relationName << Doxygen::htmlFileExtension
<< "\"];\n";
if (linkRelations)
{
t << " headhref=\"" << relationName << Doxygen::htmlFileExtension << "\"";
}
t << "];\n";
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/dot.h
Expand Up @@ -262,7 +262,8 @@ class DotDirDeps
const char *fileName,
const char *relPath,
bool writeImageMap=TRUE,
int graphId=-1) const;
int graphId=-1,
bool linkRelations=TRUE) const;
private:
DirDef *m_dir;
};
Expand Down Expand Up @@ -459,6 +460,4 @@ void writeDotImageMapFromFile(FTextStream &t,
const QCString& relPath,const QCString& baseName,
const QCString& context,int graphId=-1);

void writeDotDirDepGraph(FTextStream &t,DirDef *dd);

#endif
13 changes: 12 additions & 1 deletion templates/html/htmldir.tpl
Expand Up @@ -45,7 +45,18 @@
{% endif %}
{% endif %}
{# dir graph #}
{# TODO #}
{% if compound.hasDirGraph %}
{% with obj=compound %}
{% include 'htmldynheader.tpl' %}
{% endwith %}
{{ tr.dirDependencyGraphFor:compound.dirName }}
</div>
{% with obj=compound %}
{% include 'htmldyncontents.tpl' %}
{% endwith %}
{{ compound.dirGraph }}
</div>
{% endif %}
{# member declarations #}
{# directories #}
{% with list=compound.dirs label='subdirs' title=tr.directories local=False %}
Expand Down

0 comments on commit abe254f

Please sign in to comment.