[Bf-blender-cvs] [6600ae3aa70] master: Nodes: add utility to find NodeRef for node

Jacques Lucke noreply at git.blender.org
Thu Oct 21 15:50:22 CEST 2021


Commit: 6600ae3aa707d7e1c2728b9af50dc15e81fd7f2b
Author: Jacques Lucke
Date:   Thu Oct 21 15:38:41 2021 +0200
Branches: master
https://developer.blender.org/rB6600ae3aa707d7e1c2728b9af50dc15e81fd7f2b

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.

===================================================================

M	source/blender/nodes/NOD_node_tree_ref.hh
M	source/blender/nodes/intern/node_tree_ref.cc

===================================================================

diff --git a/source/blender/nodes/NOD_node_tree_ref.hh b/source/blender/nodes/NOD_node_tree_ref.hh
index 5337f79536b..b6e372470c8 100644
--- a/source/blender/nodes/NOD_node_tree_ref.hh
+++ b/source/blender/nodes/NOD_node_tree_ref.hh
@@ -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;
 
diff --git a/source/blender/nodes/intern/node_tree_ref.cc b/source/blender/nodes/intern/node_tree_ref.cc
index 43c7fbd2599..2ca797009da 100644
--- a/source/blender/nodes/intern/node_tree_ref.cc
+++ b/source/blender/nodes/intern/node_tree_ref.cc
@@ -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;



More information about the Bf-blender-cvs mailing list