From 6e52be862cdbd5989c31402a3ef1dad5d9a98062 Mon Sep 17 00:00:00 2001 From: David Hebbeker Date: Tue, 29 Dec 2020 21:17:42 +0100 Subject: Outsource common code to draw directories. --- src/dotdirdeps.cpp | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/dotdirdeps.cpp b/src/dotdirdeps.cpp index a670d68..bd154f6 100644 --- a/src/dotdirdeps.cpp +++ b/src/dotdirdeps.cpp @@ -20,6 +20,30 @@ #include "doxygen.h" #include "config.h" +/** + * Puts DOT code for drawing directory to stream and adds it to the list. + * @param outStream[in,out] stream to which the DOT code is written to + * @param directory + * @param fillBackground + * @param directoriesInGraph[in,out] + */ +static void drawDirectory(FTextStream &outStream, const DirDef *const directory, const bool fillBackground, + QDict &directoriesInGraph) +{ + outStream << " " << directory->getOutputFileBase() << " [shape=box " + "label=\"" << directory->shortName() << "\" "; + if (fillBackground) + { + outStream << "fillcolor=\"white\" style=\"filled\" "; + } + if (directory->isCluster()) + { + outStream << "color=\"red\" "; + } + outStream << "URL=\"" << directory->getOutputFileBase() << Doxygen::htmlFileExtension << "\"];\n"; + directoriesInGraph.insert(directory->getOutputFileBase(), directory); +} + void writeDotDirDepGraph(FTextStream &t,const DirDef *dd,bool linkRelations) { int fontSize = Config_getInt(DOT_FONTSIZE); @@ -57,21 +81,7 @@ void writeDotDirDepGraph(FTextStream &t,const DirDef *dd,bool linkRelations) // add nodes for sub directories for(const auto sdir : dd->subDirs()) { - t << " " << sdir->getOutputFileBase() << " [shape=box label=\"" - << sdir->shortName() << "\""; - if (sdir->isCluster()) - { - t << " color=\"red\""; - } - else - { - t << " color=\"black\""; - } - t << " fillcolor=\"white\" style=\"filled\""; - t << " URL=\"" << sdir->getOutputFileBase() - << Doxygen::htmlFileExtension << "\""; - t << "];\n"; - dirsInGraph.insert(sdir->getOutputFileBase(),sdir); + drawDirectory(t, sdir, true, dirsInGraph); } t << " }\n"; } @@ -108,19 +118,7 @@ void writeDotDirDepGraph(FTextStream &t,const DirDef *dd,bool linkRelations) !usedDir->isParentOf(dd)) // include if both have the same parent (or no parent) { - t << " " << usedDir->getOutputFileBase() << " [shape=box label=\"" - << usedDir->shortName() << "\""; - if (usedDir->isCluster()) - { - if (!Config_getBool(DOT_TRANSPARENT)) - { - t << " fillcolor=\"white\" style=\"filled\""; - } - t << " color=\"red\""; - } - t << " URL=\"" << usedDir->getOutputFileBase() - << Doxygen::htmlFileExtension << "\"];\n"; - dirsInGraph.insert(usedDir->getOutputFileBase(),usedDir); + drawDirectory(t, usedDir, usedDir->isCluster() && !Config_getBool(DOT_TRANSPARENT), dirsInGraph); break; } dir=dir->parent(); -- cgit v0.12 From 95ba6002eb7d5e8c43a64a239d39ca99015caa09 Mon Sep 17 00:00:00 2001 From: David Hebbeker Date: Tue, 29 Dec 2020 23:44:22 +0100 Subject: Draw sibling directories in parent directory. --- src/dotdirdeps.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/dotdirdeps.cpp b/src/dotdirdeps.cpp index bd154f6..af5e8e9 100644 --- a/src/dotdirdeps.cpp +++ b/src/dotdirdeps.cpp @@ -60,7 +60,15 @@ void writeDotDirDepGraph(FTextStream &t,const DirDef *dd,bool linkRelations) QDict dirsInGraph(257); dirsInGraph.insert(dd->getOutputFileBase(),dd); - if (dd->parent()) + + std::vector usedDirsToBeDrawn; + for(const auto& usedDir : dd->usedDirs()) + { + usedDirsToBeDrawn.push_back(usedDir->dir()); + } + + const auto parent = dd->parent(); + if (parent) { t << " subgraph cluster" << dd->parent()->getOutputFileBase() << " {\n"; t << " graph [ bgcolor=\"#ddddee\", pencolor=\"black\", label=\"" @@ -68,6 +76,21 @@ void writeDotDirDepGraph(FTextStream &t,const DirDef *dd,bool linkRelations) << "\" fontname=\"" << fontName << "\", fontsize=\"" << fontSize << "\", URL=\""; t << dd->parent()->getOutputFileBase() << Doxygen::htmlFileExtension; t << "\"]\n"; + + { + // draw all directories which have `dd->parent()` as parent and `dd` as dependent + const auto newEnd = std::remove_if(usedDirsToBeDrawn.begin(), usedDirsToBeDrawn.end(), [&](const DirDef *const usedDir) + { + if (usedDir->parent() == parent) + { + drawDirectory(t, usedDir, usedDir->isCluster() && !Config_getBool(DOT_TRANSPARENT), dirsInGraph); + return true; + } + return false; + } + ); + usedDirsToBeDrawn.erase(newEnd, usedDirsToBeDrawn.end()); + } } if (dd->isCluster()) { @@ -100,10 +123,9 @@ void writeDotDirDepGraph(FTextStream &t,const DirDef *dd,bool linkRelations) // add nodes for other used directories { //printf("*** For dir %s\n",shortName().data()); - for (const auto &udir : dd->usedDirs()) + for (const auto &usedDir : usedDirsToBeDrawn) // for each used dir (=directly used or a parent of a directly used dir) { - const DirDef *usedDir = udir->dir(); const DirDef *dir=dd; while (dir) { -- cgit v0.12 From a61f19c0bc756482d7e7b4314d84f44d387eeea1 Mon Sep 17 00:00:00 2001 From: David Hebbeker Date: Wed, 30 Dec 2020 19:17:11 +0100 Subject: Rename variable. --- src/dotdirdeps.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dotdirdeps.cpp b/src/dotdirdeps.cpp index af5e8e9..2722e29 100644 --- a/src/dotdirdeps.cpp +++ b/src/dotdirdeps.cpp @@ -61,10 +61,10 @@ void writeDotDirDepGraph(FTextStream &t,const DirDef *dd,bool linkRelations) dirsInGraph.insert(dd->getOutputFileBase(),dd); - std::vector usedDirsToBeDrawn; + std::vector usedDirsNotDrawn; for(const auto& usedDir : dd->usedDirs()) { - usedDirsToBeDrawn.push_back(usedDir->dir()); + usedDirsNotDrawn.push_back(usedDir->dir()); } const auto parent = dd->parent(); @@ -79,9 +79,9 @@ void writeDotDirDepGraph(FTextStream &t,const DirDef *dd,bool linkRelations) { // draw all directories which have `dd->parent()` as parent and `dd` as dependent - const auto newEnd = std::remove_if(usedDirsToBeDrawn.begin(), usedDirsToBeDrawn.end(), [&](const DirDef *const usedDir) + const auto newEnd = std::remove_if(usedDirsNotDrawn.begin(), usedDirsNotDrawn.end(), [&](const DirDef *const usedDir) { - if (usedDir->parent() == parent) + if (dd!=usedDir && dd->parent()==usedDir->parent() && !usedDir->isParentOf(dd)) { drawDirectory(t, usedDir, usedDir->isCluster() && !Config_getBool(DOT_TRANSPARENT), dirsInGraph); return true; @@ -89,7 +89,7 @@ void writeDotDirDepGraph(FTextStream &t,const DirDef *dd,bool linkRelations) return false; } ); - usedDirsToBeDrawn.erase(newEnd, usedDirsToBeDrawn.end()); + usedDirsNotDrawn.erase(newEnd, usedDirsNotDrawn.end()); } } if (dd->isCluster()) @@ -123,7 +123,7 @@ void writeDotDirDepGraph(FTextStream &t,const DirDef *dd,bool linkRelations) // add nodes for other used directories { //printf("*** For dir %s\n",shortName().data()); - for (const auto &usedDir : usedDirsToBeDrawn) + for (const auto &usedDir : usedDirsNotDrawn) // for each used dir (=directly used or a parent of a directly used dir) { const DirDef *dir=dd; -- cgit v0.12 From f80b03899246f9b2e0d52bafafffaca01ad08f0f Mon Sep 17 00:00:00 2001 From: David Hebbeker Date: Fri, 1 Jan 2021 18:52:37 +0100 Subject: Add documentation of parameters of new function. --- src/dotdirdeps.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dotdirdeps.cpp b/src/dotdirdeps.cpp index 2722e29..f049527 100644 --- a/src/dotdirdeps.cpp +++ b/src/dotdirdeps.cpp @@ -23,9 +23,9 @@ /** * Puts DOT code for drawing directory to stream and adds it to the list. * @param outStream[in,out] stream to which the DOT code is written to - * @param directory - * @param fillBackground - * @param directoriesInGraph[in,out] + * @param directory[in] will be mapped to a node in DOT code + * @param fillBackground[in] if the node shall be explicitly filled + * @param directoriesInGraph[in,out] lists the directories which have been written to the output stream */ static void drawDirectory(FTextStream &outStream, const DirDef *const directory, const bool fillBackground, QDict &directoriesInGraph) -- cgit v0.12