[Bf-blender-cvs] [7b4dcec3ec7] temp-nodes-group-declarations: Various fixes

Hans Goudey noreply at git.blender.org
Tue Dec 20 00:00:04 CET 2022


Commit: 7b4dcec3ec7c8e22fc7e5315afec737797e79894
Author: Hans Goudey
Date:   Mon Dec 19 16:59:55 2022 -0600
Branches: temp-nodes-group-declarations
https://developer.blender.org/rB7b4dcec3ec7c8e22fc7e5315afec737797e79894

Various fixes

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

M	source/blender/blenkernel/intern/node_tree_update.cc
M	source/blender/editors/space_node/link_drag_search.cc
M	source/blender/editors/space_node/node_group.cc
M	source/blender/nodes/NOD_socket.h
M	source/blender/nodes/intern/node_common.cc
M	source/blender/nodes/intern/node_socket.cc

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

diff --git a/source/blender/blenkernel/intern/node_tree_update.cc b/source/blender/blenkernel/intern/node_tree_update.cc
index f43d3f0d1d2..d51aa3f2bef 100644
--- a/source/blender/blenkernel/intern/node_tree_update.cc
+++ b/source/blender/blenkernel/intern/node_tree_update.cc
@@ -550,10 +550,7 @@ class NodeTreeMainUpdater {
           if (!node->runtime->declaration) {
             node->runtime->declaration = new blender::nodes::NodeDeclaration();
           }
-          build_node_declaration_dynamic(ntree, *node, *node->runtime->declaration);
-          /* TODO: Move this to blenkernel or something. */
-          nodes::refresh_node_sockets_from_declaration(
-              ntree, *node, *node->runtime->declaration, true);
+          nodes::update_node_declaration_and_sockets(ntree, *node);
         }
       }
     }
diff --git a/source/blender/editors/space_node/link_drag_search.cc b/source/blender/editors/space_node/link_drag_search.cc
index e4197c98ea1..11226c99804 100644
--- a/source/blender/editors/space_node/link_drag_search.cc
+++ b/source/blender/editors/space_node/link_drag_search.cc
@@ -13,6 +13,7 @@
 #include "BKE_node_tree_update.h"
 #include "BKE_screen.h"
 
+#include "NOD_socket.h"
 #include "NOD_socket_search_link.hh"
 
 #include "BLT_translation.h"
@@ -198,7 +199,7 @@ static void search_link_ops_for_asset_metadata(const bNodeTree &node_tree,
            DEG_relations_tag_update(&bmain);
 
            /* Create the inputs and outputs on the new node. */
-           node.typeinfo->updatefunc(&params.node_tree, &node);
+           nodes::update_node_declaration_and_sockets(params.node_tree, node);
 
            bNodeSocket *new_node_socket = bke::node_find_enabled_socket(
                node, in_out, socket_property->name);
diff --git a/source/blender/editors/space_node/node_group.cc b/source/blender/editors/space_node/node_group.cc
index 32946888635..5b9ab65be06 100644
--- a/source/blender/editors/space_node/node_group.cc
+++ b/source/blender/editors/space_node/node_group.cc
@@ -780,8 +780,8 @@ static void node_group_make_redirect_incoming_link(
                                                                     socket_for_naming->name);
 
     /* Update the group node and interface sockets so the new interface socket can be linked. */
-    /* TODO: Update sockets based on declaration here. */
-
+    nodes::update_node_declaration_and_sockets(ntree, *gnode);
+    nodes::update_node_declaration_and_sockets(ntree, *input_node);
     /* Create new internal link. */
     bNodeSocket *input_sock = node_group_input_find_socket(input_node, iosock->identifier);
     nodeAddLink(ngroup, input_node, input_sock, link->tonode, link->tosock);
@@ -941,7 +941,11 @@ static void node_group_make_insert_selected(const bContext &C,
             &ntree.links, link->fromnode, link->fromsock, &link_node, &link_sock);
         bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link_node, link_sock);
 
-        /* TODO: Update sockets based on declaration here. */
+        /* update the group node and interface node sockets,
+         * so the new interface socket can be linked.
+         */
+        nodes::update_node_declaration_and_sockets(ntree, *gnode);
+        nodes::update_node_declaration_and_sockets(ntree, *output_node);
 
         /* create new internal link */
         bNodeSocket *output_sock = node_group_output_find_socket(output_node, iosock->identifier);
@@ -993,7 +997,7 @@ static void node_group_make_insert_selected(const bContext &C,
 
         bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock);
 
-        /* TODO: Update sockets based on declaration here. */
+        nodes::update_node_declaration_and_sockets(ntree, *input_node);
 
         /* create new internal link */
         bNodeSocket *input_sock = node_group_input_find_socket(input_node, iosock->identifier);
@@ -1016,7 +1020,7 @@ static void node_group_make_insert_selected(const bContext &C,
 
         bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock);
 
-        /* TODO: Update sockets based on declaration here. */
+        nodes::update_node_declaration_and_sockets(ntree, *output_node);
 
         /* create new internal link */
         bNodeSocket *output_sock = node_group_output_find_socket(output_node, iosock->identifier);
diff --git a/source/blender/nodes/NOD_socket.h b/source/blender/nodes/NOD_socket.h
index 1eeda4a7edf..87693ea296c 100644
--- a/source/blender/nodes/NOD_socket.h
+++ b/source/blender/nodes/NOD_socket.h
@@ -49,7 +49,8 @@ void refresh_node_sockets_from_declaration(bNodeTree &ntree,
                                            bNode &node,
                                            const NodeDeclaration &node_decl,
                                            bool do_id_user);
+void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node);
 
-}
+}  // namespace blender::nodes
 
 #endif
diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc
index 7900db475f7..1947aea5a48 100644
--- a/source/blender/nodes/intern/node_common.cc
+++ b/source/blender/nodes/intern/node_common.cc
@@ -32,6 +32,7 @@
 #include "NOD_common.h"
 #include "NOD_node_declaration.hh"
 #include "NOD_register.hh"
+#include "NOD_socket.h"
 #include "NOD_socket_declarations.hh"
 #include "NOD_socket_declarations_geometry.hh"
 #include "node_common.h"
@@ -452,7 +453,7 @@ static void group_output_declare_dynamic(const bNodeTree &node_tree,
                                          const bNode & /*node*/,
                                          NodeDeclaration &r_declaration)
 {
-  LISTBASE_FOREACH (const bNodeSocket *, input, &node_tree.inputs) {
+  LISTBASE_FOREACH (const bNodeSocket *, input, &node_tree.outputs) {
     r_declaration.inputs_.append(declataion_for_interface_socket(*input));
     r_declaration.inputs_.last()->in_out_ = SOCK_IN;
   }
@@ -465,18 +466,32 @@ static void group_input_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *li
 {
   BLI_assert(link->tonode != node);
   BLI_assert(link->tosock->in_out == SOCK_IN);
-  if (link->fromsock->identifier == StringRef("__extend__")) {
-    ntreeAddSocketInterfaceFromSocket(ntree, link->tonode, link->tosock);
+  if (link->fromsock->identifier != StringRef("__extend__")) {
+    return;
+  }
+  const bNodeSocket *io_socket = ntreeAddSocketInterfaceFromSocket(
+      ntree, link->tonode, link->tosock);
+  if (!io_socket) {
+    return;
   }
+  update_node_declaration_and_sockets(*ntree, *node);
+  link->fromsock = node_group_input_find_socket(node, io_socket->identifier);
 }
 
 static void group_output_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
 {
   BLI_assert(link->fromnode != node);
   BLI_assert(link->fromsock->in_out == SOCK_OUT);
-  if (link->tosock->identifier == StringRef("__extend__")) {
-    ntreeAddSocketInterfaceFromSocket(ntree, link->fromnode, link->fromsock);
+  if (link->tosock->identifier != StringRef("__extend__")) {
+    return;
+  }
+  const bNodeSocket *io_socket = ntreeAddSocketInterfaceFromSocket(
+      ntree, link->fromnode, link->fromsock);
+  if (!io_socket) {
+    return;
   }
+  update_node_declaration_and_sockets(*ntree, *node);
+  link->tosock = node_group_output_find_socket(node, io_socket->identifier);
 }
 
 }  // namespace blender::nodes
diff --git a/source/blender/nodes/intern/node_socket.cc b/source/blender/nodes/intern/node_socket.cc
index fa2a55d3d1c..749cf529b46 100644
--- a/source/blender/nodes/intern/node_socket.cc
+++ b/source/blender/nodes/intern/node_socket.cc
@@ -258,6 +258,15 @@ void refresh_node_sockets_from_declaration(bNodeTree &ntree,
   nodeSocketDeclarationsUpdate(&node);
 }
 
+void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node)
+{
+  if (!node.runtime->declaration) {
+    node.runtime->declaration = new NodeDeclaration();
+  }
+  build_node_declaration_dynamic(ntree, node, *node.runtime->declaration);
+  refresh_node_sockets_from_declaration(ntree, node, *node.runtime->declaration, true);
+}
+
 }  // namespace blender::nodes
 
 void node_verify_sockets(bNodeTree *ntree, bNode *node, bool do_id_user)



More information about the Bf-blender-cvs mailing list