[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20142] branches/blender2.5/blender/source /blender/makesrna/intern/rna_access.c: 2.5 - RNA Bugfix 2 (for Keyframing):

Joshua Leung aligorith at gmail.com
Mon May 11 07:18:51 CEST 2009


Revision: 20142
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20142
Author:   aligorith
Date:     2009-05-11 07:18:49 +0200 (Mon, 11 May 2009)

Log Message:
-----------
2.5 - RNA Bugfix 2 (for Keyframing):

Now properties in nested structs should be able to be keyframed (i.e. AO in World, and SSS in Materials). Added an extra method to RNA for this to work.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c	2009-05-11 05:10:09 UTC (rev 20141)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c	2009-05-11 05:18:49 UTC (rev 20142)
@@ -382,6 +382,30 @@
 	return prop;
 }
 
+/* Find the property which uses the given nested struct */
+PropertyRNA *RNA_struct_find_nested(PointerRNA *ptr, StructRNA *srna)
+{
+	CollectionPropertyIterator iter;
+	PropertyRNA *iterprop, *prop;
+	int i = 0;
+
+	iterprop= RNA_struct_iterator_property(ptr->type);
+	RNA_property_collection_begin(ptr, iterprop, &iter);
+	prop= NULL;
+
+	for(; iter.valid; RNA_property_collection_next(&iter), i++) {
+		/* This assumes that there can only be one user of this nested struct */
+		if (RNA_property_pointer_type(iter.ptr.data) == srna) {
+			prop= iter.ptr.data;
+			break;
+		}
+	}
+
+	RNA_property_collection_end(&iter);
+
+	return prop;
+}
+
 const struct ListBase *RNA_struct_defined_properties(StructRNA *srna)
 {
 	return &srna->cont.properties;
@@ -1718,18 +1742,27 @@
 		return NULL;
 	
 	if(!RNA_struct_is_ID(ptr->type)) {
-		if(ptr->type && ptr->type->nested) {
-			//StructRNA *nestedType= ptr->type->nested;
+		if(ptr->type->path) {
+			/* if type has a path to some ID, use it */
+			ptrpath= ptr->type->path(ptr);
+		}
+		else if(ptr->type->nested) {
+			PointerRNA parentptr;
+			PropertyRNA *userprop;
 			
-			printf("RNA - struct is nested \n");
-			// TODO: how do we get the identifier of the way this is nested into the main?
-		}
-		else {
-			if(ptr->type->path)
-				ptrpath= ptr->type->path(ptr);
+			/* find the property in the struct we're nested in that references this struct, and 
+			 * use its identifier as the first part of the path used...
+			 */
+			RNA_pointer_create(ptr->id.data, ptr->type->nested, ptr->data, &parentptr);
+			userprop= RNA_struct_find_nested(&parentptr, ptr->type); 
+			
+			if(userprop)
+				ptrpath= BLI_strdup(RNA_property_identifier(userprop));
 			else
-				return NULL;
+				return NULL; // can't do anything about this case yet...
 		}
+		else
+			return NULL;
 	}
 
 	propname= RNA_property_identifier(prop);





More information about the Bf-blender-cvs mailing list