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
path: root/source
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2013-01-09 20:07:42 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2013-01-09 20:07:42 +0400
commitb29f7038814341639d91b815db3871801e9649ca (patch)
treeb36d7beb9be13fb5f72fdcbf560000e6a4f94ae2 /source
parent9a4a5fa2b441ce0265202f5ae663b2254317d4cc (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 456a6ff83c2..276eba2033e 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -288,6 +288,43 @@ static const char *rna_Node_get_node_type(StructRNA *type)
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 @@ static void rna_def_node(BlenderRNA *brna)
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);