Commit: acbfda0c6bc686dd736ba16cb598f3aa1f61c724
Author: Jacques Lucke
Date:   Sat Apr 6 15:23:17 2019 +0200
Branches: functions
https://developer.blender.org/rBacbfda0c6bc686dd736ba16cb598f3aa1f61c724

Implicit conversion from individual elements to lists

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

M       release/scripts/startup/function_nodes/types_base.py
M       
source/blender/functions/frontends/data_flow_nodes/inserters/conversions.cpp
M       source/blender/functions/functions/lists.cpp
M       source/blender/functions/functions/lists.hpp

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

diff --git a/release/scripts/startup/function_nodes/types_base.py 
b/release/scripts/startup/function_nodes/types_base.py
index b5e990593e0..6f1bd2c9c4e 100644
--- a/release/scripts/startup/function_nodes/types_base.py
+++ b/release/scripts/startup/function_nodes/types_base.py
@@ -35,6 +35,8 @@ class DataTypesInfo:
         self.list_by_base[base_type] = list_type
         self.base_by_list[list_type] = base_type
 
+        self.insert_implicit_conversion(base_type, list_type)
+
     def insert_implicitly_convertable_types(self, types):
         for type_1, type_2 in itertools.combinations(types, 2):
             self.insert_implicit_conversion(type_1, type_2)
diff --git 
a/source/blender/functions/frontends/data_flow_nodes/inserters/conversions.cpp 
b/source/blender/functions/frontends/data_flow_nodes/inserters/conversions.cpp
index ef8443447bb..e897abd017b 100644
--- 
a/source/blender/functions/frontends/data_flow_nodes/inserters/conversions.cpp
+++ 
b/source/blender/functions/frontends/data_flow_nodes/inserters/conversions.cpp
@@ -4,10 +4,29 @@
 
 namespace FN { namespace DataFlowNodes {
 
+       static void insert_base_to_list_conversion(
+               Builder &builder,
+               const BuilderContext &UNUSED(ctx),
+               Socket from,
+               Socket to,
+               struct bNodeLink *UNUSED(source_link))
+       {
+               SharedType &base_type = from.type();
+               auto fn = Functions::list_from_element(base_type);
+               Node *node = builder.insert_function(fn);
+               builder.insert_link(from, node->input(0));
+               builder.insert_link(node->output(0), to);
+       }
+
+
        void register_conversion_inserters(GraphInserters &inserters)
        {
                inserters.reg_conversion_function("Integer", "Float", 
Functions::int32_to_float);
                inserters.reg_conversion_function("Float", "Integer", 
Functions::float_to_int32);
+
+               inserters.reg_conversion_inserter("Float", "Float List", 
insert_base_to_list_conversion);
+               inserters.reg_conversion_inserter("Vector", "Vector List", 
insert_base_to_list_conversion);
+               inserters.reg_conversion_inserter("Integer", "Integer List", 
insert_base_to_list_conversion);
        }
 
 } } /* namespace FN::DataFlowNodes */
\ No newline at end of file
diff --git a/source/blender/functions/functions/lists.cpp 
b/source/blender/functions/functions/lists.cpp
index 05bf31eb6e2..44f72ee8fdf 100644
--- a/source/blender/functions/functions/lists.cpp
+++ b/source/blender/functions/functions/lists.cpp
@@ -31,6 +31,33 @@ namespace FN { namespace Functions {
        }
 
 
+       template<typename T>
+       class CreateSingleElementList : public TupleCallBody {
+               void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext 
&UNUSED(ctx)) const override
+               {
+                       auto list = SharedList<T>::New();
+                       T value = fn_in.relocate_out<T>(0);
+                       list->append(value);
+                       fn_out.move_in(0, list);
+               }
+       };
+
+       template<typename T>
+       SharedFunction build_create_single_element_list_function(
+               SharedType &base_type,
+               SharedType &list_type)
+       {
+               std::string name = "Create " + base_type->name() + " List from 
Value";
+               auto fn = SharedFunction::New(name, Signature({
+                       InputParameter("Value", base_type),
+               }, {
+                       OutputParameter("List", list_type),
+               }));
+               fn->add_body(new CreateSingleElementList<T>());
+               return fn;
+       }
+
+
        template<typename T>
        class AppendToList : public TupleCallBody {
                void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext 
&UNUSED(ctx)) const override
@@ -161,6 +188,7 @@ namespace FN { namespace Functions {
 
        struct ListFunctions {
                FunctionPerType m_create_empty;
+               FunctionPerType m_from_element;
                FunctionPerType m_append;
                FunctionPerType m_get_element;
                FunctionPerType m_combine;
@@ -176,6 +204,9 @@ namespace FN { namespace Functions {
                functions.m_create_empty.add(
                        base_type,
                        build_create_empty_list_function<T>(base_type, 
list_type));
+               functions.m_from_element.add(
+                       base_type,
+                       build_create_single_element_list_function<T>(base_type, 
list_type));
                functions.m_append.add(
                        base_type,
                        build_append_function<T>(base_type, list_type));
@@ -213,6 +244,13 @@ namespace FN { namespace Functions {
                return functions.lookup_ref(base_type);
        }
 
+       SharedFunction &list_from_element(SharedType &base_type)
+       {
+               FunctionPerType &functions = 
get_list_functions().m_from_element;
+               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;
@@ -241,4 +279,10 @@ namespace FN { namespace Functions {
                return functions.lookup_ref(base_type);
        }
 
+       SharedType &get_list_type(SharedType &base_type)
+       {
+               SharedFunction &fn = append_to_list(base_type);
+               return fn->signature().inputs()[0].type();
+       }
+
 } } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/functions/lists.hpp 
b/source/blender/functions/functions/lists.hpp
index 1035d963356..2da8e3c61e7 100644
--- a/source/blender/functions/functions/lists.hpp
+++ b/source/blender/functions/functions/lists.hpp
@@ -4,7 +4,10 @@
 
 namespace FN { namespace Functions {
 
+       SharedType &get_list_type(SharedType &base_type);
+
        SharedFunction &empty_list(SharedType &base_type);
+       SharedFunction &list_from_element(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