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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-12-13 05:33:14 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-12-13 05:33:14 +0300
commit2ca6e5dd019b30519926b1d743df10aa72c5519b (patch)
tree74c91fb97265ed0f6d5f564488a005173b9f5e58 /source/blender/makesrna/intern/rna_access.c
parent19d0736862e69a5642f4086c1b7ce0dbeffedebc (diff)
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.
Diffstat (limited to 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r--source/blender/makesrna/intern/rna_access.c84
1 files changed, 62 insertions, 22 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 44155a8c528..4dc696e32dc 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -3085,36 +3085,76 @@ int RNA_path_resolve_full(PointerRNA *ptr, const char *path, PointerRNA *r_ptr,
*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;
- }
- /* 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));
+ 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;
+ }
+ }
}
- 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);
- }
- if(token != fixedbuf)
- MEM_freeN(token);
+ *index= flat_index;
+ }
}
}
}