From dc2524eaaeb121aa48c5b81de67d3ede8a319123 Mon Sep 17 00:00:00 2001 From: Erik Abrahamsson Date: Sun, 24 Oct 2021 11:19:10 +0200 Subject: Geometry Nodes: Rename node "String Substring" This patch renames the node "String Substring" to "Slice String" to conform to the "verb first" naming convention. Default length is also changed to 10 to make it easier for users to understand what the node does. Reviewed By: HooglyBoogly Differential Revision: https://developer.blender.org/D12931 --- release/scripts/startup/nodeitems_builtins.py | 2 +- source/blender/blenkernel/BKE_node.h | 2 +- source/blender/blenkernel/intern/node.cc | 2 +- source/blender/blenloader/intern/versioning_300.c | 8 ++++ source/blender/nodes/CMakeLists.txt | 2 +- source/blender/nodes/NOD_function.h | 2 +- source/blender/nodes/NOD_static_types.h | 2 +- .../nodes/function/nodes/node_fn_slice_string.cc | 53 ++++++++++++++++++++++ .../function/nodes/node_fn_string_substring.cc | 53 ---------------------- 9 files changed, 67 insertions(+), 59 deletions(-) create mode 100644 source/blender/nodes/function/nodes/node_fn_slice_string.cc delete mode 100644 source/blender/nodes/function/nodes/node_fn_string_substring.cc diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py index 4d227be50ad..0a34f541e5c 100644 --- a/release/scripts/startup/nodeitems_builtins.py +++ b/release/scripts/startup/nodeitems_builtins.py @@ -719,7 +719,7 @@ geometry_node_categories = [ GeometryNodeCategory("GEO_POINT", "Point", items=point_node_items), GeometryNodeCategory("GEO_TEXT", "Text", items=[ NodeItem("FunctionNodeStringLength"), - NodeItem("FunctionNodeStringSubstring"), + NodeItem("FunctionNodeSliceString"), NodeItem("FunctionNodeValueToString"), NodeItem("GeometryNodeStringJoin"), NodeItem("FunctionNodeInputSpecialCharacters"), diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 1280b83b765..ef1e7249658 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1562,7 +1562,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree, #define FN_NODE_FLOAT_TO_INT 1209 #define FN_NODE_VALUE_TO_STRING 1210 #define FN_NODE_STRING_LENGTH 1211 -#define FN_NODE_STRING_SUBSTRING 1212 +#define FN_NODE_SLICE_STRING 1212 #define FN_NODE_INPUT_SPECIAL_CHARACTERS 1213 #define FN_NODE_RANDOM_VALUE 1214 #define FN_NODE_ROTATE_EULER 1215 diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index bd0f0df6e02..eda57d9e984 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -5886,8 +5886,8 @@ static void registerFunctionNodes() register_node_type_fn_random_value(); register_node_type_fn_replace_string(); register_node_type_fn_rotate_euler(); + register_node_type_fn_slice_string(); register_node_type_fn_string_length(); - register_node_type_fn_string_substring(); register_node_type_fn_value_to_string(); } diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c index c68bae1d4af..8168b917b5e 100644 --- a/source/blender/blenloader/intern/versioning_300.c +++ b/source/blender/blenloader/intern/versioning_300.c @@ -2030,7 +2030,15 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) * * \note Keep this message at the bottom of the function. */ + { + /* Update the `idnames` for renamed geometry and function nodes. */ + LISTBASE_FOREACH (bNodeTree *, ntree, &bmain->nodetrees) { + if (ntree->type != NTREE_GEOMETRY) { + continue; + } + version_node_id(ntree, FN_NODE_SLICE_STRING, "FunctionNodeSliceString"); + } /* Keep this block, even when empty. */ } } diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index 6c6ce821d0e..7a728b9041b 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -149,8 +149,8 @@ set(SRC function/nodes/node_fn_random_value.cc function/nodes/node_fn_replace_string.cc function/nodes/node_fn_rotate_euler.cc + function/nodes/node_fn_slice_string.cc function/nodes/node_fn_string_length.cc - function/nodes/node_fn_string_substring.cc function/nodes/node_fn_value_to_string.cc function/node_function_util.cc diff --git a/source/blender/nodes/NOD_function.h b/source/blender/nodes/NOD_function.h index 78069a2fade..81f0667fe1c 100644 --- a/source/blender/nodes/NOD_function.h +++ b/source/blender/nodes/NOD_function.h @@ -35,8 +35,8 @@ void register_node_type_fn_input_vector(void); void register_node_type_fn_random_value(void); void register_node_type_fn_replace_string(void); void register_node_type_fn_rotate_euler(void); +void register_node_type_fn_slice_string(void); void register_node_type_fn_string_length(void); -void register_node_type_fn_string_substring(void); void register_node_type_fn_value_to_string(void); #ifdef __cplusplus diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index e966839ab27..af14538e6cc 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -278,8 +278,8 @@ DefNode(FunctionNode, FN_NODE_INPUT_VECTOR, def_fn_input_vector, "INPUT_VECTOR", DefNode(FunctionNode, FN_NODE_RANDOM_VALUE, def_fn_random_value, "RANDOM_VALUE", RandomValue, "Random Value", "") DefNode(FunctionNode, FN_NODE_REPLACE_STRING, 0, "REPLACE_STRING", ReplaceString, "Replace String", "") DefNode(FunctionNode, FN_NODE_ROTATE_EULER, def_fn_rotate_euler, "ROTATE_EULER", RotateEuler, "Rotate Euler", "") +DefNode(FunctionNode, FN_NODE_SLICE_STRING, 0, "SLICE_STRING", SliceString, "Slice String", "") DefNode(FunctionNode, FN_NODE_STRING_LENGTH, 0, "STRING_LENGTH", StringLength, "String Length", "") -DefNode(FunctionNode, FN_NODE_STRING_SUBSTRING, 0, "STRING_SUBSTRING", StringSubstring, "String Substring", "") DefNode(FunctionNode, FN_NODE_VALUE_TO_STRING, 0, "VALUE_TO_STRING", ValueToString, "Value to String", "") DefNode(GeometryNode, GEO_NODE_LEGACY_ALIGN_ROTATION_TO_VECTOR, def_geo_align_rotation_to_vector, "LEGACY_ALIGN_ROTATION_TO_VECTOR", LegacyAlignRotationToVector, "Align Rotation to Vector", "") diff --git a/source/blender/nodes/function/nodes/node_fn_slice_string.cc b/source/blender/nodes/function/nodes/node_fn_slice_string.cc new file mode 100644 index 00000000000..08e17da0d92 --- /dev/null +++ b/source/blender/nodes/function/nodes/node_fn_slice_string.cc @@ -0,0 +1,53 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "BLI_string_utf8.h" + +#include "node_function_util.hh" + +namespace blender::nodes { + +static void fn_node_slice_string_declare(NodeDeclarationBuilder &b) +{ + b.add_input("String"); + b.add_input("Position"); + b.add_input("Length").min(0).default_value(10); + b.add_output("String"); +}; + +static void fn_node_slice_string_build_multi_function(NodeMultiFunctionBuilder &builder) +{ + static blender::fn::CustomMF_SI_SI_SI_SO slice_fn{ + "Slice", [](const std::string &str, int a, int b) { + const int len = BLI_strlen_utf8(str.c_str()); + const int start = BLI_str_utf8_offset_from_index(str.c_str(), std::clamp(a, 0, len)); + const int end = BLI_str_utf8_offset_from_index(str.c_str(), std::clamp(a + b, 0, len)); + return str.substr(start, std::max(end - start, 0)); + }}; + builder.set_matching_fn(&slice_fn); +} + +} // namespace blender::nodes + +void register_node_type_fn_slice_string() +{ + static bNodeType ntype; + + fn_node_type_base(&ntype, FN_NODE_SLICE_STRING, "Slice String", NODE_CLASS_CONVERTER, 0); + ntype.declare = blender::nodes::fn_node_slice_string_declare; + ntype.build_multi_function = blender::nodes::fn_node_slice_string_build_multi_function; + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/function/nodes/node_fn_string_substring.cc b/source/blender/nodes/function/nodes/node_fn_string_substring.cc deleted file mode 100644 index 0f91b1af813..00000000000 --- a/source/blender/nodes/function/nodes/node_fn_string_substring.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "BLI_string_utf8.h" - -#include "node_function_util.hh" - -namespace blender::nodes { - -static void fn_node_string_substring_declare(NodeDeclarationBuilder &b) -{ - b.add_input("String"); - b.add_input("Position"); - b.add_input("Length").min(0); - b.add_output("String"); -}; - -static void fn_node_string_substring_build_multi_function(NodeMultiFunctionBuilder &builder) -{ - static fn::CustomMF_SI_SI_SI_SO substring_fn{ - "Substring", [](const std::string &str, int a, int b) { - const int len = BLI_strlen_utf8(str.c_str()); - const int start = BLI_str_utf8_offset_from_index(str.c_str(), std::clamp(a, 0, len)); - const int end = BLI_str_utf8_offset_from_index(str.c_str(), std::clamp(a + b, 0, len)); - return str.substr(start, std::max(end - start, 0)); - }}; - builder.set_matching_fn(&substring_fn); -} - -} // namespace blender::nodes - -void register_node_type_fn_string_substring() -{ - static bNodeType ntype; - - fn_node_type_base(&ntype, FN_NODE_STRING_SUBSTRING, "String Substring", NODE_CLASS_CONVERTER, 0); - ntype.declare = blender::nodes::fn_node_string_substring_declare; - ntype.build_multi_function = blender::nodes::fn_node_string_substring_build_multi_function; - nodeRegisterType(&ntype); -} -- cgit v1.2.3