Revision: 60065
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60065
Author:   lukastoenne
Date:     2013-09-12 08:43:25 +0000 (Thu, 12 Sep 2013)
Log Message:
-----------
Fix #36706: Added complementary API functions for the FileOutput node so 
file/layer slots (input sockets) can be added without using the operator. 
Instead of adding sockets to these node using the
node.inputs collection, the node.file_slots or node.layer_slots collections 
should be used. Both of them work, they just provide slightly different 
properties for use with simple files or multi-layer
EXR.

The FileOutput node design is cumbersome and should be considered broken. It 
should eventually be replaced, the problem with that is backward/forward 
compatibility.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/nodes/NOD_static_types.h

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c 2013-09-12 
08:43:24 UTC (rev 60064)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c 2013-09-12 
08:43:25 UTC (rev 60065)
@@ -2726,6 +2726,23 @@
        }
 }
 
+static bNodeSocket *rna_NodeOutputFile_slots_new(ID *id, bNode *node, bContext 
*C, ReportList *UNUSED(reports), const char *name)
+{
+       bNodeTree *ntree = (bNodeTree *)id;
+       Scene *scene = CTX_data_scene(C);
+       ImageFormatData *im_format = NULL;
+       bNodeSocket *sock;
+       if (scene)
+               im_format = &scene->r.im_format;
+       
+       sock = ntreeCompositOutputFileAddSocket(ntree, node, name, im_format);
+       
+       ntreeUpdateTree(CTX_data_main(C), ntree);
+       WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
+       
+       return sock;
+}
+
 static void rna_ShaderNodeScript_mode_set(PointerRNA *ptr, int value)
 {
        bNode *node = (bNode *)ptr->data;
@@ -4111,8 +4128,50 @@
        RNA_def_property_ui_text(prop, "Name", "OpenEXR layer name used for 
this slot");
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, NULL);
 }
-static void def_cmp_output_file(StructRNA *srna)
+static void rna_def_cmp_output_file_slots_api(BlenderRNA *brna, PropertyRNA 
*cprop, const char *struct_name)
 {
+       StructRNA *srna;
+       PropertyRNA *parm;
+       FunctionRNA *func;
+
+       RNA_def_property_srna(cprop, struct_name);
+       srna = RNA_def_struct(brna, struct_name, NULL);
+       RNA_def_struct_sdna(srna, "bNode");
+       RNA_def_struct_ui_text(srna, "File Output Slots", "Collection of File 
Output node slots");
+
+       func = RNA_def_function(srna, "new", "rna_NodeOutputFile_slots_new");
+       RNA_def_function_ui_description(func, "Add a file slot to this node");
+       RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS | 
FUNC_USE_CONTEXT);
+       parm = RNA_def_string(func, "name", "", MAX_NAME, "Name", "");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       /* return value */
+       parm = RNA_def_pointer(func, "socket", "NodeSocket", "", "New socket");
+       RNA_def_function_return(func, parm);
+
+       /* NB: methods below can use the standard node socket API functions,
+        * included here for completeness.
+        */
+
+       func = RNA_def_function(srna, "remove", "rna_Node_socket_remove");
+       RNA_def_function_ui_description(func, "Remove a file slot from this 
node");
+       RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS);
+       parm = RNA_def_pointer(func, "socket", "NodeSocket", "", "The socket to 
remove");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+
+       func = RNA_def_function(srna, "clear", "rna_Node_inputs_clear");
+       RNA_def_function_ui_description(func, "Remove all file slots from this 
node");
+       RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+
+       func = RNA_def_function(srna, "move", "rna_Node_inputs_move");
+       RNA_def_function_ui_description(func, "Move a file slot to another 
position");
+       RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+       parm = RNA_def_int(func, "from_index", -1, 0, INT_MAX, "From Index", 
"Index of the socket to move", 0, 10000);
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       parm = RNA_def_int(func, "to_index", -1, 0, INT_MAX, "To Index", 
"Target index for the socket", 0, 10000);
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+}
+static void def_cmp_output_file(BlenderRNA *brna, StructRNA *srna)
+{
        PropertyRNA *prop;
        
        RNA_def_struct_sdna_from(srna, "NodeImageMultiFile", "storage");
@@ -4139,12 +4198,14 @@
                                          "rna_NodeOutputFile_slot_file_get", 
NULL, NULL, NULL, NULL);
        RNA_def_property_struct_type(prop, "NodeOutputFileSlotFile");
        RNA_def_property_ui_text(prop, "File Slots", "");
+       rna_def_cmp_output_file_slots_api(brna, prop, 
"CompositorNodeOutputFileFileSlots");
        
        prop = RNA_def_property(srna, "layer_slots", PROP_COLLECTION, 
PROP_NONE);
        RNA_def_property_collection_funcs(prop, 
"rna_NodeOutputFile_slots_begin", "rna_iterator_listbase_next", 
"rna_iterator_listbase_end",
                                          "rna_NodeOutputFile_slot_layer_get", 
NULL, NULL, NULL, NULL);
        RNA_def_property_struct_type(prop, "NodeOutputFileSlotLayer");
        RNA_def_property_ui_text(prop, "EXR Layer Slots", "");
+       rna_def_cmp_output_file_slots_api(brna, prop, 
"CompositorNodeOutputFileLayerSlots");
 }
 
 static void def_cmp_dilate_erode(StructRNA *srna)
@@ -7386,8 +7447,8 @@
        RNA_def_struct_ui_icon(srna, ICON_TEXTURE);
 }
 
-static void define_specific_node(BlenderRNA *brna, const char *struct_name, 
const char *base_name,
-                                 const char *ui_name, const char *ui_desc, 
void (*def_func)(StructRNA *))
+static StructRNA *define_specific_node(BlenderRNA *brna, const char 
*struct_name, const char *base_name,
+                                       const char *ui_name, const char 
*ui_desc, void (*def_func)(StructRNA *))
 {
        StructRNA *srna;
        FunctionRNA *func;
@@ -7434,6 +7495,8 @@
 
        if (def_func)
                def_func(srna);
+
+       return srna;
 }
 
 static void rna_def_node_instance_hash(BlenderRNA *brna)
@@ -7451,6 +7514,8 @@
 
 void RNA_def_nodetree(BlenderRNA *brna)
 {
+       StructRNA *srna;
+       
        rna_def_node_socket(brna);
        rna_def_node_socket_interface(brna);
        
@@ -7471,7 +7536,13 @@
        rna_def_texture_nodetree(brna);
        
        #define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, 
UIDesc) \
-               define_specific_node(brna, #Category #StructName, #Category, 
UIName, UIDesc, DefFunc);
+       { \
+               srna = define_specific_node(brna, #Category #StructName, 
#Category, UIName, UIDesc, DefFunc); \
+               if (ID == CMP_NODE_OUTPUT_FILE) { \
+                       /* needs brna argument, can't use NOD_static_types.h */ 
\
+                       def_cmp_output_file(brna, srna); \
+               } \
+       }
        
        /* hack, don't want to add include path to RNA just for this, since in 
the future RNA types
         * for nodes should be defined locally at runtime anyway ...

Modified: trunk/blender/source/blender/nodes/NOD_static_types.h
===================================================================
--- trunk/blender/source/blender/nodes/NOD_static_types.h       2013-09-12 
08:43:24 UTC (rev 60064)
+++ trunk/blender/source/blender/nodes/NOD_static_types.h       2013-09-12 
08:43:25 UTC (rev 60065)
@@ -142,7 +142,8 @@
 DefNode( CompositorNode, CMP_NODE_IMAGE,          def_cmp_image,          
"IMAGE",          Image,            "Image",             ""              )
 DefNode( CompositorNode, CMP_NODE_R_LAYERS,       def_cmp_render_layers,  
"R_LAYERS",       RLayers,          "Render Layers",     ""              )
 DefNode( CompositorNode, CMP_NODE_COMPOSITE,      def_cmp_composite,      
"COMPOSITE",      Composite,        "Composite",         ""              )
-DefNode( CompositorNode, CMP_NODE_OUTPUT_FILE,    def_cmp_output_file,    
"OUTPUT_FILE",    OutputFile,       "File Output",       ""              )
+/* NB: OutputFile node has special rna setup function called in rna_nodetree.c 
*/
+DefNode( CompositorNode, CMP_NODE_OUTPUT_FILE,    0,                      
"OUTPUT_FILE",    OutputFile,       "File Output",       ""              )
 DefNode( CompositorNode, CMP_NODE_TEXTURE,        def_texture,            
"TEXTURE",        Texture,          "Texture",           ""              )
 DefNode( CompositorNode, CMP_NODE_TRANSLATE,      def_cmp_translate,      
"TRANSLATE",      Translate,        "Translate",         ""              )
 DefNode( CompositorNode, CMP_NODE_ZCOMBINE,       def_cmp_zcombine,       
"ZCOMBINE",       Zcombine,         "Z Combine",         ""              )

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to