Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2013-04-12 16:19:22 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2013-04-12 16:19:22 +0400
commitc83925599abbf4e88e4703ee906dc5775467da3c (patch)
treeadd36b3f6803527c5fb0c90d24222c37d386fa47 /source/blender/makesrna/intern/rna_nodetree.c
parente8474d64f8b1cf24045a3707395a862f9a543eaa (diff)
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.
Diffstat (limited to 'source/blender/makesrna/intern/rna_nodetree.c')
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c75
1 files changed, 72 insertions, 3 deletions
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index b10a3da4cd1..dce4bcc2171 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -1593,7 +1593,7 @@ static void rna_Node_socket_remove(ID *id, bNode *node, ReportList *reports, bNo
}
}
-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 @@ static void rna_Node_inputs_clear(ID *id, bNode *node, ReportList *reports)
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 @@ static void rna_Node_outputs_clear(ID *id, bNode *node, ReportList *reports)
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 @@ static void rna_def_node_sockets_api(BlenderRNA *brna, PropertyRNA *cprop, int i
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 @@ static void rna_def_node_sockets_api(BlenderRNA *brna, PropertyRNA *cprop, int i
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)