[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33622] trunk/blender/source/blender/ makesrna/intern/rna_access.c: multi-dimensional array resolving for rna paths.
Campbell Barton
ideasman42 at gmail.com
Mon Dec 13 03:33:19 CET 2010
Revision: 33622
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33622
Author: campbellbarton
Date: 2010-12-13 03:33:14 +0100 (Mon, 13 Dec 2010)
Log Message:
-----------
multi-dimensional array resolving for rna paths.
eg, "matrix[3][2]" could be used as a driver.
Test from python
bpy.context.object.path_resolve("matrix_world[2][3]")
Before this was always treated as a 1 dimensional array.
Modified Paths:
--------------
trunk/blender/source/blender/makesrna/intern/rna_access.c
Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c 2010-12-12 23:02:19 UTC (rev 33621)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c 2010-12-13 02:33:14 UTC (rev 33622)
@@ -3085,36 +3085,76 @@
*index= -1;
if (*path) {
- if (*path=='[') {
- token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
+ int index_arr[RNA_MAX_ARRAY_DIMENSION]= {0};
+ int len[RNA_MAX_ARRAY_DIMENSION];
+ const int dim= RNA_property_array_dimension(&curptr, prop, len);
+ int i, temp_index;
- if(token==NULL) {
- /* invalid syntax blah[] */
- return 0;
+ for(i=0; i<dim; i++) {
+ temp_index= -1;
+
+ /* multi index resolve */
+ if (*path=='[') {
+ token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1);
+
+ if(token==NULL) {
+ /* invalid syntax blah[] */
+ return 0;
+ }
+ /* check for "" to see if it is a string */
+ else if(rna_token_strip_quotes(token)) {
+ temp_index= RNA_property_array_item_index(prop, *(token+1));
+ }
+ else {
+ /* otherwise do int lookup */
+ temp_index= atoi(token);
+
+ if(temp_index==0 && (token[0] != '0' || token[1] != '\0')) {
+ if(token != fixedbuf) {
+ MEM_freeN(token);
+ }
+
+ return 0;
+ }
+ }
}
- /* check for "" to see if it is a string */
- else if(rna_token_strip_quotes(token)) {
- *index= RNA_property_array_item_index(prop, *(token+1));
- }
- else {
- /* otherwise do int lookup */
- *index= atoi(token);
- if(intkey==0 && (token[0] != '0' || token[1] != '\0')) {
- return 0; /* we can be sure the fixedbuf was used in this case */
+ else if(dim==1) {
+ /* location.x || scale.X, single dimension arrays only */
+ token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 0);
+ if(token==NULL) {
+ /* invalid syntax blah.. */
+ return 0;
}
+ temp_index= RNA_property_array_item_index(prop, *token);
}
+
+ if(token != fixedbuf) {
+ MEM_freeN(token);
+ }
+
+ /* out of range */
+ if(temp_index < 0 || temp_index >= len[i])
+ return 0;
+
+ index_arr[i]= temp_index;
+ /* end multi index resolve */
}
+
+ /* arrays always contain numbers so further values are not valid */
+ if(*path) {
+ return 0;
+ }
else {
- token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 0);
- if(token==NULL) {
- /* invalid syntax blah.. */
- return 0;
+ int totdim= 1;
+ int flat_index= 0;
+
+ for(i=dim-1; i>=0; i--) {
+ flat_index += index_arr[i] * totdim;
+ totdim *= len[i];
}
- *index= RNA_property_array_item_index(prop, *token);
+
+ *index= flat_index;
}
-
- if(token != fixedbuf)
- MEM_freeN(token);
}
}
}
More information about the Bf-blender-cvs
mailing list