rna read/write access to ...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 11 Jun 2012 18:43:48 +0000 (18:43 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 11 Jun 2012 18:43:48 +0000 (18:43 +0000)
  node_tree.nodes.active

source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/editors/space_node/space_node.c
source/blender/makesrna/intern/rna_nodetree.c

index b1e5fabc456e9edf632a71e5e7e53cc6bac9db94..e4d96c2219c88f24f4f88ed686198322ee8b659d 100644 (file)
@@ -372,6 +372,7 @@ void                        nodeSetActive(struct bNodeTree *ntree, struct bNode *node);
 struct bNode   *nodeGetActive(struct bNodeTree *ntree);
 struct bNode   *nodeGetActiveID(struct bNodeTree *ntree, short idtype);
 int                            nodeSetActiveID(struct bNodeTree *ntree, short idtype, struct ID *id);
+void                   nodeClearActive(struct bNodeTree *ntree);
 void                   nodeClearActiveID(struct bNodeTree *ntree, short idtype);
 struct bNode   *nodeGetActiveTexture(struct bNodeTree *ntree);
 
index d62e91dbde5042b27fd763041769b813fcecf29a..924e6a354ef7a080a7440b35da6d90352f1b192f 100644 (file)
@@ -1313,6 +1313,17 @@ void nodeClearActiveID(bNodeTree *ntree, short idtype)
                        node->flag &= ~NODE_ACTIVE_ID;
 }
 
+void nodeClearActive(bNodeTree *ntree)
+{
+       bNode *node;
+
+       if (ntree==NULL) return;
+
+       for (node= ntree->nodes.first; node; node= node->next)
+               node->flag &= ~(NODE_ACTIVE | NODE_ACTIVE_ID);
+}
+
+
 /* two active flags, ID nodes have special flag for buttons display */
 void nodeSetActive(bNodeTree *ntree, bNode *node)
 {
index c477e2bcdda84ec296a4bb3cf2169e49ffc67406..e069ba2a5fc3e4653d34ec985d7b5f4f202c3ea7 100644 (file)
@@ -492,16 +492,11 @@ static int node_context(const bContext *C, const char *member, bContextDataResul
                return 1;
        }
        else if (CTX_data_equals(member, "active_node")) {
-               bNode *node;
-               
                if (snode->edittree) {
-                       for (node=snode->edittree->nodes.last; node; node=node->prev) {
-                               if (node->flag & NODE_ACTIVE) {
-                                       CTX_data_pointer_set(result, &snode->edittree->id, &RNA_Node, node);
-                                       break;
-                               }
-                       }
+                       bNode *node = nodeGetActive(snode->edittree);
+                       CTX_data_pointer_set(result, &snode->edittree->id, &RNA_Node, node);
                }
+
                CTX_data_type_set(result, CTX_DATA_TYPE_POINTER);
                return 1;
        }
index 01bf39714393bd2659e0a1056a051bfe8790ab1e..5ffdfe6d71dc588ca73698674abf17a070999c8e 100644 (file)
@@ -634,6 +634,22 @@ static EnumPropertyItem *rna_Node_channel_itemf(bContext *UNUSED(C), PointerRNA
        return item;
 }
 
+static PointerRNA rna_NodeTree_active_node_get(PointerRNA *ptr)
+{
+       bNodeTree *ntree = (bNodeTree *)ptr->data;
+       bNode *node = nodeGetActive(ntree);
+       return rna_pointer_inherit_refine(ptr, &RNA_Node, node);
+}
+
+static void rna_NodeTree_active_node_set(PointerRNA *ptr, PointerRNA value)
+{
+       bNodeTree *ntree = (bNodeTree *)ptr->data;
+       if (value.data)
+               nodeSetActive(ntree, (bNode *)value.data);
+       else
+               nodeClearActive(ntree);
+}
+
 static bNode *rna_NodeTree_node_new(bNodeTree *ntree, bContext *C, ReportList *reports,
                                     int type, bNodeTree *group)
 {
@@ -3632,6 +3648,19 @@ static void rna_def_nodetree_link_api(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_function_ui_description(func, "remove all node links from the node tree");
 }
 
+/* shared between all note tree types*/
+static void rna_def_nodetree_active_api(StructRNA *srna, PropertyRNA *cprop)
+{
+       PropertyRNA *prop;
+
+       prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
+       RNA_def_property_struct_type(prop, "Node");
+       RNA_def_property_pointer_funcs(prop, "rna_NodeTree_active_node_get", "rna_NodeTree_active_node_set", NULL, NULL);
+       RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
+       RNA_def_property_ui_text(prop, "Active Node", "Active node in this tree");
+       RNA_def_property_update(prop, NC_SCENE | ND_OB_ACTIVE, NULL);
+}
+
 static void rna_def_composite_nodetree_api(BlenderRNA *brna, PropertyRNA *cprop)
 {
        StructRNA *srna;
@@ -3661,6 +3690,8 @@ static void rna_def_composite_nodetree_api(BlenderRNA *brna, PropertyRNA *cprop)
 
        func = RNA_def_function(srna, "clear", "rna_NodeTree_node_clear");
        RNA_def_function_ui_description(func, "Remove all nodes from this node tree");
+
+       rna_def_nodetree_active_api(srna, cprop);
 }
 
 static void rna_def_shader_nodetree_api(BlenderRNA *brna, PropertyRNA *cprop)
@@ -3692,6 +3723,8 @@ static void rna_def_shader_nodetree_api(BlenderRNA *brna, PropertyRNA *cprop)
 
        func = RNA_def_function(srna, "clear", "rna_NodeTree_node_clear");
        RNA_def_function_ui_description(func, "Remove all nodes from this node tree");
+
+       rna_def_nodetree_active_api(srna, cprop);
 }
 
 static void rna_def_texture_nodetree_api(BlenderRNA *brna, PropertyRNA *cprop)
@@ -3723,6 +3756,8 @@ static void rna_def_texture_nodetree_api(BlenderRNA *brna, PropertyRNA *cprop)
 
        func = RNA_def_function(srna, "clear", "rna_NodeTree_node_clear");
        RNA_def_function_ui_description(func, "Remove all nodes from this node tree");
+
+       rna_def_nodetree_active_api(srna, cprop);
 }
 
 static void rna_def_node_socket(BlenderRNA *brna)