[Bf-blender-cvs] [7ac2cf40a75] temp-geometry-nodes-attribute-search: Attribute Search: Deduplicate function

Hans Goudey noreply at git.blender.org
Tue Feb 23 23:48:45 CET 2021


Commit: 7ac2cf40a75dc5cfd66fd4d35c2180db1777cdc6
Author: Hans Goudey
Date:   Tue Feb 23 16:48:36 2021 -0600
Branches: temp-geometry-nodes-attribute-search
https://developer.blender.org/rB7ac2cf40a75dc5cfd66fd4d35c2180db1777cdc6

Attribute Search: Deduplicate function

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

M	source/blender/blenkernel/BKE_node_ui_storage.hh
M	source/blender/blenkernel/intern/node_ui_storage.cc
M	source/blender/editors/space_node/node_draw.cc
M	source/blender/editors/space_node/node_geometry_attribute_search.cc

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

diff --git a/source/blender/blenkernel/BKE_node_ui_storage.hh b/source/blender/blenkernel/BKE_node_ui_storage.hh
index 4b9886f6293..4e9f9c1ce8c 100644
--- a/source/blender/blenkernel/BKE_node_ui_storage.hh
+++ b/source/blender/blenkernel/BKE_node_ui_storage.hh
@@ -29,6 +29,7 @@ struct ModifierData;
 struct Object;
 struct bNode;
 struct bNodeTree;
+struct bContext;
 
 /**
  * Contains the context necessary to determine when to display settings for a certain node tree
@@ -83,6 +84,10 @@ struct NodeTreeUIStorage {
   blender::Map<NodeTreeEvaluationContext, blender::Map<std::string, NodeUIStorage>> context_map;
 };
 
+const NodeUIStorage *BKE_node_tree_ui_storage_get_from_context(const bContext *C,
+                                                               const bNodeTree &ntree,
+                                                               const bNode &node);
+
 void BKE_nodetree_ui_storage_free_for_context(bNodeTree &ntree,
                                               const NodeTreeEvaluationContext &context);
 
diff --git a/source/blender/blenkernel/intern/node_ui_storage.cc b/source/blender/blenkernel/intern/node_ui_storage.cc
index 7bf8895262d..e03617a6505 100644
--- a/source/blender/blenkernel/intern/node_ui_storage.cc
+++ b/source/blender/blenkernel/intern/node_ui_storage.cc
@@ -23,7 +23,9 @@
 #include "DNA_node_types.h"
 #include "DNA_object_types.h"
 
+#include "BKE_context.h"
 #include "BKE_node_ui_storage.hh"
+#include "BKE_object.h"
 
 static CLG_LogRef LOG = {"bke.node_ui_storage"};
 
@@ -38,6 +40,30 @@ static void ui_storage_ensure(bNodeTree &ntree)
   }
 }
 
+const NodeUIStorage *BKE_node_tree_ui_storage_get_from_context(const bContext *C,
+                                                               const bNodeTree &ntree,
+                                                               const bNode &node)
+{
+  const NodeTreeUIStorage *ui_storage = ntree.ui_storage;
+  if (ui_storage == nullptr) {
+    return nullptr;
+  }
+
+  const Object *active_object = CTX_data_active_object(C);
+  const ModifierData *active_modifier = BKE_object_active_modifier(active_object);
+  if (active_object == nullptr || active_modifier == nullptr) {
+    return nullptr;
+  }
+
+  const NodeTreeEvaluationContext context(*active_object, *active_modifier);
+  const Map<std::string, NodeUIStorage> *storage = ui_storage->context_map.lookup_ptr(context);
+  if (storage == nullptr) {
+    return nullptr;
+  }
+
+  return storage->lookup_ptr_as(StringRef(node.name));
+}
+
 /**
  * Removes only the UI data associated with a particular evaluation context. The same node tree
  * can be used for execution in multiple places, but the entire UI storage can't be removed when
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index d0b62463ad9..c610a0c7bd2 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -1254,34 +1254,10 @@ static char *node_errors_tooltip_fn(bContext *UNUSED(C), void *argN, const char
 
 #define NODE_HEADER_ICON_SIZE (0.8f * U.widget_unit)
 
-static const NodeUIStorage *node_ui_storage_get_from_context(const bContext *C,
-                                                             const bNodeTree &ntree,
-                                                             const bNode &node)
-{
-  const NodeTreeUIStorage *ui_storage = ntree.ui_storage;
-  if (ui_storage == nullptr) {
-    return nullptr;
-  }
-
-  const Object *active_object = CTX_data_active_object(C);
-  const ModifierData *active_modifier = BKE_object_active_modifier(active_object);
-  if (active_object == nullptr || active_modifier == nullptr) {
-    return nullptr;
-  }
-
-  const NodeTreeEvaluationContext context(*active_object, *active_modifier);
-  const Map<std::string, NodeUIStorage> *storage = ui_storage->context_map.lookup_ptr(context);
-  if (storage == nullptr) {
-    return nullptr;
-  }
-
-  return storage->lookup_ptr_as(StringRef(node.name));
-}
-
 static void node_add_error_message_button(
     const bContext *C, bNodeTree &ntree, bNode &node, const rctf &rect, float &icon_offset)
 {
-  const NodeUIStorage *node_ui_storage = node_ui_storage_get_from_context(C, ntree, node);
+  const NodeUIStorage *node_ui_storage = BKE_node_tree_ui_storage_get_from_context(C, ntree, node);
   if (node_ui_storage == nullptr || node_ui_storage->warnings.is_empty()) {
     return;
   }
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 1eba849c59b..cf03533767d 100644
--- a/source/blender/editors/space_node/node_geometry_attribute_search.cc
+++ b/source/blender/editors/space_node/node_geometry_attribute_search.cc
@@ -40,30 +40,6 @@ using blender::Map;
 using blender::Set;
 using blender::StringRef;
 
-static const NodeUIStorage *node_ui_storage_get_from_context(const bContext *C,
-                                                             const bNodeTree &ntree,
-                                                             const bNode &node)
-{
-  const NodeTreeUIStorage *ui_storage = ntree.ui_storage;
-  if (ui_storage == nullptr) {
-    return nullptr;
-  }
-
-  const Object *active_object = CTX_data_active_object(C);
-  const ModifierData *active_modifier = BKE_object_active_modifier(active_object);
-  if (active_object == nullptr || active_modifier == nullptr) {
-    return nullptr;
-  }
-
-  const NodeTreeEvaluationContext context(*active_object, *active_modifier);
-  const Map<std::string, NodeUIStorage> *storage = ui_storage->context_map.lookup_ptr(context);
-  if (storage == nullptr) {
-    return nullptr;
-  }
-
-  return storage->lookup_ptr_as(StringRef(node.name));
-}
-
 struct AttributeSearchData {
   const bNodeTree &node_tree;
   const bNode &node;
@@ -83,7 +59,7 @@ static void attribute_search_update_fn(const bContext *C,
                                        uiSearchItems *items)
 {
   AttributeSearchData *data = static_cast<AttributeSearchData *>(arg);
-  const NodeUIStorage *ui_storage = node_ui_storage_get_from_context(
+  const NodeUIStorage *ui_storage = BKE_node_tree_ui_storage_get_from_context(
       C, data->node_tree, data->node);
   if (ui_storage == nullptr) {
     return;
@@ -123,12 +99,6 @@ void button_add_attribute_search(
 {
   BLI_assert(socket->type == SOCK_STRING);
 
-  /* Always adding the button default value is valid because this search menu
-   * shouldn't display when the socket is connected with an input link anyway. */
-  const bNodeSocketValueString *socket_value = static_cast<bNodeSocketValueString *>(
-      socket->default_value);
-  const char *current_value = socket_value->value;
-
   /* TODO: This could just get a node tree argument. */
   SpaceNode *space_node = CTX_wm_space_node(C);
   if (space_node == nullptr) {



More information about the Bf-blender-cvs mailing list