[Bf-blender-cvs] [4ea39f1e033] temp-geometry-nodes-attribute-search: It stopped working

Hans Goudey noreply at git.blender.org
Mon Feb 22 21:39:44 CET 2021


Commit: 4ea39f1e033f47f4bca30673f3e56c614cf158a8
Author: Hans Goudey
Date:   Thu Feb 18 17:27:24 2021 -0600
Branches: temp-geometry-nodes-attribute-search
https://developer.blender.org/rB4ea39f1e033f47f4bca30673f3e56c614cf158a8

It stopped working

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

M	source/blender/blenkernel/BKE_node_ui_storage.hh
M	source/blender/editors/interface/interface_region_search.c
M	source/blender/editors/space_node/CMakeLists.txt
M	source/blender/editors/space_node/drawnode.c
M	source/blender/editors/space_node/node_geometry_attribute_search.cc
M	source/blender/editors/space_node/node_intern.h

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

diff --git a/source/blender/blenkernel/BKE_node_ui_storage.hh b/source/blender/blenkernel/BKE_node_ui_storage.hh
index 22866fe09fc..4d88bfc7bd2 100644
--- a/source/blender/blenkernel/BKE_node_ui_storage.hh
+++ b/source/blender/blenkernel/BKE_node_ui_storage.hh
@@ -19,6 +19,7 @@
 #include "BLI_hash.hh"
 #include "BLI_map.hh"
 #include "BLI_session_uuid.h"
+#include "BLI_set.hh"
 
 #include "DNA_ID.h"
 #include "DNA_modifier_types.h"
diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c
index 464793968d3..2c07f5c3c03 100644
--- a/source/blender/editors/interface/interface_region_search.c
+++ b/source/blender/editors/interface/interface_region_search.c
@@ -719,7 +719,7 @@ static void ui_searchbox_region_free_cb(ARegion *region)
   region->regiondata = NULL;
 }
 
-ARegion *UI_searchbox_create_generic(bContext *C, ARegion *butregion, uiButSearch *search_but)
+ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiButSearch *search_but)
 {
   wmWindow *win = CTX_wm_window(C);
   const uiStyle *style = UI_style_get();
diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt
index c640b076ba4..bc043a4e665 100644
--- a/source/blender/editors/space_node/CMakeLists.txt
+++ b/source/blender/editors/space_node/CMakeLists.txt
@@ -42,6 +42,7 @@ set(SRC
   node_buttons.c
   node_draw.cc
   node_edit.c
+  node_geometry_attribute_search.cc
   node_gizmo.c
   node_group.c
   node_ops.c
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 4716f1c29ea..07070cb2840 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3387,7 +3387,15 @@ static void std_node_socket_draw(
     case SOCK_STRING: {
       uiLayout *row = uiLayoutSplit(layout, 0.5f, false);
       uiItemL(row, text, 0);
-      uiItemR(row, ptr, "default_value", DEFAULT_FLAGS, "", 0);
+
+      uiBlock *block = uiLayoutGetBlock(row);
+
+      static char search[256] = "";
+      uiBut *but = uiDefSearchBut(
+          block, search, 0, ICON_NONE, sizeof(search), 10, 10, 200, UI_UNIT_Y, 0, 0, "");
+      button_add_attribute_search(C, node, sock, but);
+
+      // uiItemR(row, ptr, "default_value", DEFAULT_FLAGS, "", 0);
       break;
     }
     case SOCK_OBJECT: {
diff --git a/source/blender/editors/space_node/node_geometry_attribute_search.cc b/source/blender/editors/space_node/node_geometry_attribute_search.cc
index 7fa86d13ef1..234eacd502d 100644
--- a/source/blender/editors/space_node/node_geometry_attribute_search.cc
+++ b/source/blender/editors/space_node/node_geometry_attribute_search.cc
@@ -24,6 +24,7 @@
 #include "DNA_modifier_types.h"
 #include "DNA_node_types.h"
 #include "DNA_object_types.h"
+#include "DNA_space_types.h"
 
 #include "BKE_context.h"
 #include "BKE_node_ui_storage.hh"
@@ -32,6 +33,8 @@
 #include "UI_interface.h"
 #include "UI_resources.h"
 
+#include "node_intern.h"
+
 using blender::IndexRange;
 using blender::Map;
 using blender::Set;
@@ -62,21 +65,28 @@ static const NodeUIStorage *node_ui_storage_get_from_context(const bContext *C,
 }
 
 struct AttributeSearchData {
-  Set<std::string> attributes;
+  const bNodeTree &node_tree;
+  const bNode &node;
   bNodeSocket &socket;
 };
 
-static void attribute_search_update_fn(const bContext *UNUSED(C),
+static void attribute_search_update_fn(const bContext *C,
                                        void *arg,
                                        const char *str,
                                        uiSearchItems *items)
 {
-  const NodeUIStorage &storage = *static_cast<const NodeUIStorage *>(arg);
-  Set<std::string> attribute_name_hints = {"HELLO!", "DOES", "THIS", "WORK???"};
+  AttributeSearchData *data = static_cast<AttributeSearchData *>(arg);
+  const NodeUIStorage *ui_storage = node_ui_storage_get_from_context(
+      C, data->node_tree, data->node);
+  if (ui_storage == nullptr) {
+    // return;
+  }
 
-  StringSearch *search = BLI_string_search_new();
+  // const Set<std::string> &attribute_name_hints = ui_storage->attribute_name_hints;
+  const Set<std::string> attribute_name_hints = {"HELLO!", "DOES", "THIS", "WORK???"};
 
-  for (const std::string attribute_name : attribute_name_hints) {
+  StringSearch *search = BLI_string_search_new();
+  for (const std::string &attribute_name : attribute_name_hints) {
     BLI_string_search_add(search, attribute_name.c_str(), (void *)&attribute_name);
   }
 
@@ -94,7 +104,7 @@ static void attribute_search_update_fn(const bContext *UNUSED(C),
   BLI_string_search_free(search);
 }
 
-static void attribute_search_exec_fn(struct bContext *C, void *arg1, void *arg2)
+static void attribute_search_exec_fn(struct bContext *UNUSED(C), void *arg1, void *arg2)
 {
   AttributeSearchData *data = static_cast<AttributeSearchData *>(arg1);
   const std::string *attribute_name = static_cast<std::string *>(arg2);
@@ -105,14 +115,29 @@ static void attribute_search_exec_fn(struct bContext *C, void *arg1, void *arg2)
   BLI_strncpy(string_value->value, attribute_name->c_str(), 1024);
 }
 
-void button_add_attribute_search(uiBut *but, const NodeUIStorage &ui_storage, bNodeSocket *socket)
+static void attribute_search_free_fn(void *arg)
+{
+  AttributeSearchData *data = static_cast<AttributeSearchData *>(arg);
+  delete data;
+}
+
+void button_add_attribute_search(const bContext *C, bNode *node, bNodeSocket *socket, uiBut *but)
 {
-  AttributeSearchData data = {ui_storage.attribute_name_hints, *socket};
+  /* TODO: This could just get a node tree argument. */
+  SpaceNode *space_node = CTX_wm_space_node(C);
+  if (space_node == nullptr) {
+    return;
+  }
+  if (space_node->edittree == nullptr) {
+    return;
+  }
+
+  AttributeSearchData *data = new AttributeSearchData{*space_node->edittree, *node, *socket};
   UI_but_func_search_set(but,
                          nullptr,
                          attribute_search_update_fn,
-                         (void *)&data,
-                         nullptr,
+                         static_cast<void *>(data),
+                         attribute_search_free_fn,
                          attribute_search_exec_fn,
                          nullptr);
 }
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index 1566c1e8571..42ade9ffb44 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -38,6 +38,7 @@ struct bContext;
 struct bNode;
 struct bNodeLink;
 struct bNodeSocket;
+struct uiBut;
 struct wmGizmoGroupType;
 struct wmKeyConfig;
 struct wmWindow;
@@ -327,6 +328,11 @@ enum eNodeSpace_ButEvents {
   B_NODE_SETIMAGE,
 };
 
+void button_add_attribute_search(const struct bContext *C,
+                                 struct bNode *node,
+                                 struct bNodeSocket *socket,
+                                 struct uiBut *but);
+
 #ifdef __cplusplus
 }
 #endif



More information about the Bf-blender-cvs mailing list