Nodes: add utility to find NodeRef for node

In the future `NodeTreeRef` could have a lazy initialized map,
but for now this is good enough.
This commit is contained in:
Jacques Lucke 2021-10-21 15:38:41 +02:00
parent df00463764
commit 6600ae3aa7
2 changed files with 12 additions and 0 deletions

View File

@ -275,6 +275,8 @@ class NodeTreeRef : NonCopyable, NonMovable {
Span<const LinkRef *> links() const;
const NodeRef *find_node(const bNode &bnode) const;
bool has_link_cycles() const;
bool has_undefined_nodes_or_sockets() const;

View File

@ -576,6 +576,16 @@ Vector<const NodeRef *> NodeTreeRef::toposort(const ToposortDirection direction)
return toposort;
}
const NodeRef *NodeTreeRef::find_node(const bNode &bnode) const
{
for (const NodeRef *node : this->nodes_by_type(bnode.typeinfo)) {
if (node->bnode_ == &bnode) {
return node;
}
}
return nullptr;
}
std::string NodeTreeRef::to_dot() const
{
dot::DirectedGraph digraph;