diff --git a/include/aidge/graph/GraphView.hpp b/include/aidge/graph/GraphView.hpp index 73dc7950daec42b803a3e14f596725a6ede34658..17bd3b1e9aeece2c80dab8c1aa1cba6498cc730f 100644 --- a/include/aidge/graph/GraphView.hpp +++ b/include/aidge/graph/GraphView.hpp @@ -96,6 +96,12 @@ public: */ inline void setName(const std::string &name) { mName = name; } + /** + * @brief Set the name of every Node based on the current GraphView name in + * following form: "name_type#type-id" + */ + void setNodesName()const; + /** * @brief Save the GraphView as a Mermaid graph in a .md file at the * specified location. diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp index 4ec3334454034f20badb246b7030594bee0c0e48..8a0c3b275c09ac4c685078201a8d3f1e7d833db7 100644 --- a/src/graph/GraphView.cpp +++ b/src/graph/GraphView.cpp @@ -225,6 +225,18 @@ void Aidge::GraphView::save(const std::string& path, bool verbose, bool showProd fmt::print(fp.get(), "\n"); } +void Aidge::GraphView::setNodesName() const { + std::map<std::string, std::int32_t> typeIds; + for (const auto& nodePtr: getNodes()) { + const std::string& t = nodePtr->getOperator()->type(); + if (typeIds.find(t) == typeIds.cend()) { + typeIds.emplace(t, 0); + } + const std::string nodeName = name() + std::string("_") + t + std::string("#") + std::to_string(typeIds[t]++); + nodePtr->setName(nodeName); + } +} + void Aidge::GraphView::logOutputs(const std::string& dirName) const { if (!Aidge::createDirectories(dirName)){ AIDGE_THROW_OR_ABORT(std::runtime_error, "Failed to create directory: {}.", dirName);