[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53685] trunk/blender/source/blender/ makesrna/intern/rna_nodetree.c: Make the node. parent property editable in RNA, so frame hierarchy can be changed by scripts without resorting to operator hacks .

Lukas Toenne lukas.toenne at googlemail.com
Wed Jan 9 17:07:44 CET 2013


Revision: 53685
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53685
Author:   lukastoenne
Date:     2013-01-09 16:07:42 +0000 (Wed, 09 Jan 2013)
Log Message:
-----------
Make the node.parent property editable in RNA, so frame hierarchy can be changed by scripts without resorting to operator hacks.

Performs sanity checks internally to make sure that
a) Only frames are used as parents. In future other nodes may be used for parenting, that will require more sophisticated poll functions.
b) Avoid infinite recursion. If the supposed parent is already attached to a frame node the parent assignment will be ignored.

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-01-09 15:58:34 UTC (rev 53684)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-01-09 16:07:42 UTC (rev 53685)
@@ -288,6 +288,43 @@
 	return "";
 }
 
+static void rna_Node_parent_set(PointerRNA *ptr, PointerRNA value)
+{
+	bNode *node = ptr->data;
+	bNode *parent = value.data;
+	
+	/* XXX only Frame node allowed for now,
+	 * in the future should have a poll function or so to test possible attachment.
+	 */
+	if (parent->type != NODE_FRAME)
+		return;
+	
+	/* make sure parent is not attached to the node */
+	if (nodeAttachNodeCheck(parent, node))
+		return;
+	
+	nodeDetachNode(node);
+	nodeAttachNode(node, parent);
+}
+
+static int rna_Node_parent_poll(PointerRNA *ptr, PointerRNA value)
+{
+	bNode *node = ptr->data;
+	bNode *parent = value.data;
+	
+	/* XXX only Frame node allowed for now,
+	 * in the future should have a poll function or so to test possible attachment.
+	 */
+	if (parent->type != NODE_FRAME)
+		return FALSE;
+	
+	/* make sure parent is not attached to the node */
+	if (nodeAttachNodeCheck(parent, node))
+		return FALSE;
+	
+	return TRUE;
+}
+
 static StructRNA *rna_NodeSocket_refine(PointerRNA *ptr)
 {
 	bNodeSocket *sock = (bNodeSocket *)ptr->data;
@@ -4689,8 +4726,9 @@
 
 	prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
 	RNA_def_property_pointer_sdna(prop, NULL, "parent");
+	RNA_def_property_pointer_funcs(prop, NULL, "rna_Node_parent_set", NULL, "rna_Node_parent_poll");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
 	RNA_def_property_struct_type(prop, "Node");
-	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Parent", "Parent this node is attached to");
 	
 	prop = RNA_def_property(srna, "use_custom_color", PROP_BOOLEAN, PROP_NONE);




More information about the Bf-blender-cvs mailing list