[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55986] trunk/blender/source/blender/ makesrna/intern/rna_nodetree.c: Added 'move' functions to the inputs and outputs node socket collections ( similar to move function in CollectionProperty).

Lukas Toenne lukas.toenne at googlemail.com
Fri Apr 12 14:19:23 CEST 2013


Revision: 55986
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55986
Author:   lukastoenne
Date:     2013-04-12 12:19:22 +0000 (Fri, 12 Apr 2013)
Log Message:
-----------
Added 'move' functions to the inputs and outputs node socket collections (similar to move function in CollectionProperty). This is useful to change the socket order in pynodes. Otherwise one would have to remember socket values and links, remove a socket, insert a new one and copy back these values, which is tedious and error prone.

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

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-04-12 12:03:56 UTC (rev 55985)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-04-12 12:19:22 UTC (rev 55986)
@@ -1593,7 +1593,7 @@
 	}
 }
 
-static void rna_Node_inputs_clear(ID *id, bNode *node, ReportList *reports)
+static void rna_Node_inputs_clear(ID *id, bNode *node)
 {
 	bNodeTree *ntree = (bNodeTree *)id;
 	bNodeSocket *sock, *nextsock;
@@ -1607,7 +1607,7 @@
 	WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
 }
 
-static void rna_Node_outputs_clear(ID *id, bNode *node, ReportList *reports)
+static void rna_Node_outputs_clear(ID *id, bNode *node)
 {
 	bNodeTree *ntree = (bNodeTree *)id;
 	bNodeSocket *sock, *nextsock;
@@ -1621,6 +1621,66 @@
 	WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
 }
 
+static void rna_Node_inputs_move(ID *id, bNode *node, int from_index, int to_index)
+{
+	bNodeTree *ntree = (bNodeTree *)id;
+	bNodeSocket *sock;
+	
+	if (from_index == to_index)
+		return;
+	if (from_index < 0 || to_index < 0)
+		return;
+	
+	sock = BLI_findlink(&node->inputs, from_index);
+	if (to_index < from_index) {
+		bNodeSocket *nextsock = BLI_findlink(&node->inputs, to_index);
+		if (nextsock) {
+			BLI_remlink(&node->inputs, sock);
+			BLI_insertlinkbefore(&node->inputs, nextsock, sock);
+		}
+	}
+	else {
+		bNodeSocket *prevsock = BLI_findlink(&node->inputs, to_index);
+		if (prevsock) {
+			BLI_remlink(&node->inputs, sock);
+			BLI_insertlinkafter(&node->inputs, prevsock, sock);
+		}
+	}
+	
+	ntreeUpdateTree(ntree);
+	WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
+}
+
+static void rna_Node_outputs_move(ID *id, bNode *node, int from_index, int to_index)
+{
+	bNodeTree *ntree = (bNodeTree *)id;
+	bNodeSocket *sock;
+	
+	if (from_index == to_index)
+		return;
+	if (from_index < 0 || to_index < 0)
+		return;
+	
+	sock = BLI_findlink(&node->outputs, from_index);
+	if (to_index < from_index) {
+		bNodeSocket *nextsock = BLI_findlink(&node->outputs, to_index);
+		if (nextsock) {
+			BLI_remlink(&node->outputs, sock);
+			BLI_insertlinkbefore(&node->outputs, nextsock, sock);
+		}
+	}
+	else {
+		bNodeSocket *prevsock = BLI_findlink(&node->outputs, to_index);
+		if (prevsock) {
+			BLI_remlink(&node->outputs, sock);
+			BLI_insertlinkafter(&node->outputs, prevsock, sock);
+		}
+	}
+	
+	ntreeUpdateTree(ntree);
+	WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
+}
+
 static void rna_Node_width_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
 {
 	bNode *node = ptr->data;
@@ -6236,6 +6296,7 @@
 	const char *uiname =  (in_out == SOCK_IN ? "Node Inputs" : "Node Outputs");
 	const char *newfunc = (in_out == SOCK_IN ? "rna_Node_inputs_new" : "rna_Node_outputs_new");
 	const char *clearfunc = (in_out == SOCK_IN ? "rna_Node_inputs_clear" : "rna_Node_outputs_clear");
+	const char *movefunc = (in_out == SOCK_IN ? "rna_Node_inputs_move" : "rna_Node_outputs_move");
 
 	RNA_def_property_srna(cprop, structtype);
 	srna = RNA_def_struct(brna, structtype, NULL);
@@ -6262,7 +6323,15 @@
 
 	func = RNA_def_function(srna, "clear", clearfunc);
 	RNA_def_function_ui_description(func, "Remove all sockets from this node");
-	RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS);
+	RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+
+	func = RNA_def_function(srna, "move", movefunc);
+	RNA_def_function_ui_description(func, "Move a socket 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 rna_def_node(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list