Commit: 28fc08bff95e00297ccddb6f08f5ea19542a3b88
Author: Jacques Lucke
Date:   Wed Mar 20 18:06:27 2019 +0100
Branches: functions
https://developer.blender.org/rB28fc08bff95e00297ccddb6f08f5ea19542a3b88

replace Append to List and Combine Lists nodes with Pack List

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

D       release/scripts/startup/function_nodes/nodes/append_to_list.py
D       release/scripts/startup/function_nodes/nodes/combine_lists.py
R078    release/scripts/startup/function_nodes/nodes/create_list.py     
release/scripts/startup/function_nodes/nodes/pack_list.py
M       release/scripts/startup/function_nodes/socket_decl.py
M       source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
M       source/blender/functions/functions/lists.cpp
M       source/blender/functions/functions/lists.hpp

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

diff --git a/release/scripts/startup/function_nodes/nodes/append_to_list.py 
b/release/scripts/startup/function_nodes/nodes/append_to_list.py
deleted file mode 100644
index b321bd5d3f5..00000000000
--- a/release/scripts/startup/function_nodes/nodes/append_to_list.py
+++ /dev/null
@@ -1,17 +0,0 @@
-import bpy
-from .. base import FunctionNode
-from .. socket_decl import ListSocketDecl
-
-class AppendToListNode(bpy.types.Node, FunctionNode):
-    bl_idname = "fn_AppendToListNode"
-    bl_label = "Append to List"
-
-    active_type: ListSocketDecl.Property()
-
-    def get_sockets(self):
-        return [
-            ListSocketDecl("list", "List", "active_type", "LIST"),
-            ListSocketDecl("value", "Value", "active_type", "BASE"),
-        ], [
-            ListSocketDecl("list", "List", "active_type", "LIST"),
-        ]
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/nodes/combine_lists.py 
b/release/scripts/startup/function_nodes/nodes/combine_lists.py
deleted file mode 100644
index 1aa3519440c..00000000000
--- a/release/scripts/startup/function_nodes/nodes/combine_lists.py
+++ /dev/null
@@ -1,17 +0,0 @@
-import bpy
-from .. base import FunctionNode
-from .. socket_decl import ListSocketDecl
-
-class CombineListsNode(bpy.types.Node, FunctionNode):
-    bl_idname = "fn_CombineListsNode"
-    bl_label = "Combine Lists"
-
-    active_type: ListSocketDecl.Property()
-
-    def get_sockets(self):
-        return [
-            ListSocketDecl("list1", "List 1", "active_type", "LIST"),
-            ListSocketDecl("list2", "List 2", "active_type", "LIST"),
-        ], [
-            ListSocketDecl("list", "List", "active_type", "LIST"),
-        ]
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/nodes/create_list.py 
b/release/scripts/startup/function_nodes/nodes/pack_list.py
similarity index 78%
rename from release/scripts/startup/function_nodes/nodes/create_list.py
rename to release/scripts/startup/function_nodes/nodes/pack_list.py
index fb3b7289fb2..3c657d10a07 100644
--- a/release/scripts/startup/function_nodes/nodes/create_list.py
+++ b/release/scripts/startup/function_nodes/nodes/pack_list.py
@@ -4,9 +4,9 @@ from .. base import FunctionNode
 from .. socket_decl import PackListDecl, FixedSocketDecl
 from .. sockets import type_infos
 
-class CreateListNode(bpy.types.Node, FunctionNode):
-    bl_idname = "fn_CreateListNode"
-    bl_label = "Create List"
+class PackListNode(bpy.types.Node, FunctionNode):
+    bl_idname = "fn_PackListNode"
+    bl_label = "Pack List"
 
     active_type: StringProperty(default="Float")
     variadic: PackListDecl.Property()
diff --git a/release/scripts/startup/function_nodes/socket_decl.py 
b/release/scripts/startup/function_nodes/socket_decl.py
index 0e7f61bdd72..f20afea1556 100644
--- a/release/scripts/startup/function_nodes/socket_decl.py
+++ b/release/scripts/startup/function_nodes/socket_decl.py
@@ -133,7 +133,11 @@ class PackListDecl(SocketDeclBase):
 class PackListPropertyGroup(bpy.types.PropertyGroup):
     bl_idname = "fn_PackListPropertyGroup"
 
-    state: StringProperty(default="BASE")
+    state: EnumProperty(
+        default="BASE",
+        items=[
+            ("BASE", "Base", "", "NONE", 0),
+            ("LIST", "Base", "", "NONE", 1)])
     identifier_prefix: StringProperty()
 
 class AnyVariadicDecl(SocketDeclBase):
diff --git a/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp 
b/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
index a355f3d75ca..ac5b80a333c 100644
--- a/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
@@ -104,6 +104,51 @@ namespace FN { namespace DataFlowNodes {
                builder.map_sockets(node, bnode);
        }
 
+       static void insert_pack_list_node(
+               Builder &builder,
+               const BuilderContext ctx,
+               bNode *bnode)
+       {
+               SharedType &base_type = ctx.type_from_rna(bnode, "active_type");
+
+               PointerRNA ptr;
+               ctx.get_rna(bnode, &ptr);
+               int input_amount = RNA_collection_length(&ptr, "variadic");
+
+               auto &empty_fn = Functions::empty_list(base_type);
+               Node *node = builder.insert_function(empty_fn);
+
+               int index = 0;
+               RNA_BEGIN(&ptr, itemptr, "variadic")
+               {
+                       Node *new_node;
+                       int state = RNA_enum_get(&itemptr, "state");
+                       if (state == 0) {
+                               /* single value case */
+                               auto &append_fn = 
Functions::append_to_list(base_type);
+                               new_node = builder.insert_function(append_fn);
+                               builder.insert_link(node->output(0), 
new_node->input(0));
+                               builder.map_input(new_node->input(1), bnode, 
index);
+                       }
+                       else if (state == 1) {
+                               /* list case */
+                               auto &combine_fn = 
Functions::combine_lists(base_type);
+                               new_node = builder.insert_function(combine_fn);
+                               builder.insert_link(node->output(0), 
new_node->input(0));
+                               builder.map_input(new_node->input(1), bnode, 
index);
+                       }
+                       else {
+                               BLI_assert(false);
+                               new_node = nullptr;
+                       }
+                       node = new_node;
+                       index++;
+               }
+               RNA_END;
+
+               builder.map_output(node->output(0), bnode, 0);
+       }
+
        void register_node_inserters(GraphInserters &inserters)
        {
                inserters.reg_node_function("fn_CombineVectorNode", 
Functions::combine_vector);
@@ -118,6 +163,7 @@ namespace FN { namespace DataFlowNodes {
                inserters.reg_node_inserter("fn_AppendToListNode", 
insert_append_list_node);
                inserters.reg_node_inserter("fn_GetListElementNode", 
insert_get_list_element_node);
                inserters.reg_node_inserter("fn_CombineListsNode", 
insert_combine_lists_node);
+               inserters.reg_node_inserter("fn_PackListNode", 
insert_pack_list_node);
        }
 
 } }
\ No newline at end of file
diff --git a/source/blender/functions/functions/lists.cpp 
b/source/blender/functions/functions/lists.cpp
index e41358e3885..6d539012758 100644
--- a/source/blender/functions/functions/lists.cpp
+++ b/source/blender/functions/functions/lists.cpp
@@ -8,6 +8,29 @@ namespace FN { namespace Functions {
 
        using namespace Types;
 
+       template<typename T>
+       class CreateEmptyList : public TupleCallBody {
+               void call(Tuple &UNUSED(fn_in), Tuple &fn_out) const override
+               {
+                       auto list = SharedList<T>::New();
+                       fn_out.move_in(0, list);
+               }
+       };
+
+       template<typename T>
+       SharedFunction build_create_empty_list_function(
+               SharedType &base_type,
+               SharedType &list_type)
+       {
+               std::string name = "Create Empty " + base_type->name() + " 
List";
+               auto fn = SharedFunction::New(name, Signature({}, {
+                       OutputParameter("List", list_type),
+               }));
+               fn->add_body(new CreateEmptyList<T>());
+               return fn;
+       }
+
+
        template<typename T>
        class AppendToList : public TupleCallBody {
                void call(Tuple &fn_in, Tuple &fn_out) const override
@@ -113,6 +136,7 @@ namespace FN { namespace Functions {
        using FunctionPerType = SmallMap<SharedType, SharedFunction>;
 
        struct ListFunctions {
+               FunctionPerType m_create_empty;
                FunctionPerType m_append;
                FunctionPerType m_get_element;
                FunctionPerType m_combine;
@@ -124,6 +148,9 @@ namespace FN { namespace Functions {
                SharedType &base_type,
                SharedType &list_type)
        {
+               functions.m_create_empty.add(
+                       base_type,
+                       build_create_empty_list_function<T>(base_type, 
list_type));
                functions.m_append.add(
                        base_type,
                        build_append_function<T>(base_type, list_type));
@@ -151,6 +178,13 @@ namespace FN { namespace Functions {
        /* Access List Functions
         *************************************/
 
+       SharedFunction &empty_list(SharedType &base_type)
+       {
+               FunctionPerType &functions = 
get_list_functions().m_create_empty;
+               BLI_assert(functions.contains(base_type));
+               return functions.lookup_ref(base_type);
+       }
+
        SharedFunction &append_to_list(SharedType &base_type)
        {
                FunctionPerType &functions = get_list_functions().m_append;
diff --git a/source/blender/functions/functions/lists.hpp 
b/source/blender/functions/functions/lists.hpp
index 922f53b2af2..09a211f7e18 100644
--- a/source/blender/functions/functions/lists.hpp
+++ b/source/blender/functions/functions/lists.hpp
@@ -4,6 +4,7 @@
 
 namespace FN { namespace Functions {
 
+       SharedFunction &empty_list(SharedType &base_type);
        SharedFunction &append_to_list(SharedType &base_type);
        SharedFunction &get_list_element(SharedType &base_type);
        SharedFunction &combine_lists(SharedType &base_type);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to