diff options
-rw-r--r-- | source/blender/blenlib/BLI_string.h | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 19 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_define.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 31 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 10 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal_types.h | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_key.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_lattice.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_mesh.c | 121 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_packedfile.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_world.c | 1 |
13 files changed, 195 insertions, 7 deletions
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index d9d030432d3..22b41d0055b 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -73,6 +73,12 @@ char *BLI_strncpy(char *dst, const char *src, int maxncpy); */ int BLI_snprintf(char *buffer, size_t count, const char *format, ...); + /* + * Print formatted string into a newly mallocN'd string + * and return it. + */ +char *BLI_sprintfN(const char *format, ...); + /** * Compare two strings * diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index e0522e60dd0..8485a0c975b 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -40,6 +40,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_dynstr.h" #include "BLI_string.h" char *BLI_strdupn(const char *str, int len) { @@ -81,6 +82,24 @@ int BLI_snprintf(char *buffer, size_t count, const char *format, ...) return n; } +char *BLI_sprintfN(const char *format, ...) +{ + DynStr *ds; + va_list arg; + char *n; + + va_start(arg, format); + + ds= BLI_dynstr_new(); + BLI_dynstr_vappendf(ds, format, arg); + n= BLI_dynstr_get_cstring(ds); + BLI_dynstr_free(ds); + + va_end(arg); + + return n; +} + int BLI_streq(char *a, char *b) { return (strcmp(a, b)==0); } diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 0317e855b6e..e2d3f85f550 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -411,6 +411,8 @@ char *RNA_path_back(const char *path); int RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop); +char *RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop); + #if 0 /* Dependency * diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index c8a189367b5..94a2c51c660 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -53,6 +53,7 @@ void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop); void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname); void RNA_def_struct_flag(StructRNA *srna, int flag); void RNA_def_struct_refine_func(StructRNA *srna, const char *refine); +void RNA_def_struct_path_func(StructRNA *srna, const char *path); void RNA_def_struct_identifier(StructRNA *srna, const char *identifier); void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description); void RNA_struct_free(BlenderRNA *brna, StructRNA *srna); diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index fc76223d8bf..0d124a121d5 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -1385,6 +1385,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f) else fprintf(f, "\tNULL,\n"); fprintf(f, "\t%s,\n", rna_function_string(srna->refine)); + fprintf(f, "\t%s,\n", rna_function_string(srna->path)); prop= srna->properties.first; if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 35eb0cef667..3fcc2d18487 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -318,7 +318,7 @@ PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier) prop= NULL; for(; iter.valid; RNA_property_collection_next(&iter), i++) { - if(strcmp(identifier, RNA_property_identifier(&iter.ptr, iter.ptr.data)) == 0) { + if(strcmp(identifier, RNA_property_identifier(ptr, iter.ptr.data)) == 0) { prop= iter.ptr.data; break; } @@ -1462,7 +1462,7 @@ int RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, Prope prop= NULL; for(; iter.valid; RNA_property_collection_next(&iter)) { - if(strcmp(token, RNA_property_identifier(&iter.ptr, iter.ptr.data)) == 0) { + if(strcmp(token, RNA_property_identifier(&curptr, iter.ptr.data)) == 0) { prop= iter.ptr.data; break; } @@ -1622,6 +1622,33 @@ char *RNA_path_back(const char *path) return result; } +char *RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop) +{ + char *ptrpath=NULL, *path; + const char *propname; + + if(!ptr->id.data || !ptr->data || !prop) + return NULL; + + if(!RNA_struct_is_ID(ptr)) { + if(ptr->type->path) + ptrpath= ptr->type->path(ptr); + else + return NULL; + } + + propname= RNA_property_identifier(ptr, prop); + + if(ptrpath) { + path= BLI_sprintfN("%s.%s", ptrpath, propname); + MEM_freeN(ptrpath); + } + else + path= BLI_strdup(propname); + + return path; +} + /* Quick name based property access */ int RNA_boolean_get(PointerRNA *ptr, const char *name) diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index b08c4aeaed4..e05a5f6a20e 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -514,6 +514,16 @@ void RNA_def_struct_refine_func(StructRNA *srna, const char *refine) if(refine) srna->refine= (StructRefineFunc)refine; } +void RNA_def_struct_path_func(StructRNA *srna, const char *path) +{ + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_struct_path_func: only during preprocessing.\n"); + return; + } + + if(path) srna->path= (StructPathFunc)path; +} + void RNA_def_struct_identifier(StructRNA *srna, const char *identifier) { if(DefRNA.preprocess) { diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index f8dd33c9df4..bc0c2a07b35 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -41,6 +41,7 @@ struct bContext; typedef void (*UpdateFunc)(struct bContext *C, struct PointerRNA *ptr); typedef int (*EditableFunc)(struct PointerRNA *ptr); typedef struct StructRNA *(*StructRefineFunc)(struct PointerRNA *ptr); +typedef char *(*StructPathFunc)(struct PointerRNA *ptr); typedef int (*PropBooleanGetFunc)(struct PointerRNA *ptr); typedef void (*PropBooleanSetFunc)(struct PointerRNA *ptr, int value); @@ -240,6 +241,9 @@ struct StructRNA { /* function to give the more specific type */ StructRefineFunc refine; + /* function to find path to this struct in an ID */ + StructPathFunc path; + /* properties of this struct */ ListBase properties; }; diff --git a/source/blender/makesrna/intern/rna_key.c b/source/blender/makesrna/intern/rna_key.c index feda1448c8b..0a21ad1d940 100644 --- a/source/blender/makesrna/intern/rna_key.c +++ b/source/blender/makesrna/intern/rna_key.c @@ -1,5 +1,5 @@ /** - * $Id$ + * $Id: rna_key.c 19382 2009-03-23 13:24:48Z blendix $ * * ***** BEGIN GPL LICENSE BLOCK ***** * diff --git a/source/blender/makesrna/intern/rna_lattice.c b/source/blender/makesrna/intern/rna_lattice.c index c479e66c08b..ca77d3b519f 100644 --- a/source/blender/makesrna/intern/rna_lattice.c +++ b/source/blender/makesrna/intern/rna_lattice.c @@ -1,5 +1,5 @@ /** - * $Id$ + * $Id: rna_lattice.c 19382 2009-03-23 13:24:48Z blendix $ * * ***** BEGIN GPL LICENSE BLOCK ***** * diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index d5caf57165f..3f862199ea0 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -467,6 +467,111 @@ static int rna_Mesh_string_layers_length(PointerRNA *ptr) return rna_CustomDataLayer_length(ptr, CD_PROP_STR); } +/* path construction */ + +static char *rna_VertexGroupElement_path(PointerRNA *ptr) +{ + Mesh *me= (Mesh*)ptr->id.data; /* XXX not always! */ + MDeformWeight *dw= (MDeformWeight*)ptr->data; + MDeformVert *dvert; + int a, b; + + for(a=0, dvert=me->dvert; a<me->totvert; a++, dvert++) + for(b=0; b<dvert->totweight; b++) + if(dw == &dvert->dw[b]) + return BLI_sprintfN("verts[%d].groups[%d]", a, b); + + return NULL; +} + +static char *rna_MeshFace_path(PointerRNA *ptr) +{ + return BLI_sprintfN("faces[%d]", (MFace*)ptr->data - ((Mesh*)ptr->id.data)->mface); +} + +static char *rna_MeshEdge_path(PointerRNA *ptr) +{ + return BLI_sprintfN("edges[%d]", (MEdge*)ptr->data - ((Mesh*)ptr->id.data)->medge); +} + +static char *rna_MeshVertex_path(PointerRNA *ptr) +{ + return BLI_sprintfN("verts[%d]", (MVert*)ptr->data - ((Mesh*)ptr->id.data)->mvert); +} + +static char *rna_MeshTextureFaceLayer_path(PointerRNA *ptr) +{ + return BLI_sprintfN("uv_layers[%s]", ((CustomDataLayer*)ptr->data)->name); +} + +static char *rna_CustomDataData_path(PointerRNA *ptr, char *collection, int type) +{ + Mesh *me= (Mesh*)ptr->id.data; + CustomDataLayer *cdl; + int a; + size_t b; + + for(cdl=me->fdata.layers, a=0; a<me->fdata.totlayer; cdl++, a++) { + if(cdl->type == type) { + b= ((char*)ptr->data - ((char*)cdl->data))/CustomData_sizeof(type); + if(b >= 0 && b < me->totface) + return BLI_sprintfN("%s[%s].data[%d]", collection, cdl->name, b); + } + } + + return NULL; +} + +static char *rna_MeshTextureFace_path(PointerRNA *ptr) +{ + return rna_CustomDataData_path(ptr, "uv_layers", CD_MTFACE); +} + +static char *rna_MeshColorLayer_path(PointerRNA *ptr) +{ + return BLI_sprintfN("vcol_layers[%s]", ((CustomDataLayer*)ptr->data)->name); +} + +static char *rna_MeshColor_path(PointerRNA *ptr) +{ + return rna_CustomDataData_path(ptr, "vcol_layers", CD_MCOL); +} + +static char *rna_MeshSticky_path(PointerRNA *ptr) +{ + return BLI_sprintfN("sticky[%d]", (MSticky*)ptr->data - ((Mesh*)ptr->id.data)->msticky); +} + +static char *rna_MeshIntPropertyLayer_path(PointerRNA *ptr) +{ + return BLI_sprintfN("int_layers[%s]", ((CustomDataLayer*)ptr->data)->name); +} + +static char *rna_MeshIntProperty_path(PointerRNA *ptr) +{ + return rna_CustomDataData_path(ptr, "int_layers", CD_MCOL); +} + +static char *rna_MeshFloatPropertyLayer_path(PointerRNA *ptr) +{ + return BLI_sprintfN("float_layers[%s]", ((CustomDataLayer*)ptr->data)->name); +} + +static char *rna_MeshFloatProperty_path(PointerRNA *ptr) +{ + return rna_CustomDataData_path(ptr, "float_layers", CD_MCOL); +} + +static char *rna_MeshStringPropertyLayer_path(PointerRNA *ptr) +{ + return BLI_sprintfN("string_layers[%s]", ((CustomDataLayer*)ptr->data)->name); +} + +static char *rna_MeshStringProperty_path(PointerRNA *ptr) +{ + return rna_CustomDataData_path(ptr, "string_layers", CD_MCOL); +} + #else static void rna_def_mvert_group(BlenderRNA *brna) @@ -477,6 +582,7 @@ static void rna_def_mvert_group(BlenderRNA *brna) srna= RNA_def_struct(brna, "VertexGroupElement", NULL); RNA_def_struct_ui_text(srna, "Vertex Group Element", "Weight value of a vertex in a vertex group."); RNA_def_struct_sdna(srna, "MDeformWeight"); + RNA_def_struct_path_func(srna, "rna_VertexGroupElement_path"); /* we can't point to actual group, it is in the object and so * there is no unique group to point to, hence the index */ @@ -498,6 +604,7 @@ static void rna_def_mvert(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshVertex", NULL); RNA_def_struct_sdna(srna, "MVert"); RNA_def_struct_ui_text(srna, "Mesh Vertex", "Vertex in a Mesh datablock."); + RNA_def_struct_path_func(srna, "rna_MeshVertex_path"); prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_VECTOR); RNA_def_property_ui_text(prop, "Location", ""); @@ -533,6 +640,7 @@ static void rna_def_medge(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshEdge", NULL); RNA_def_struct_sdna(srna, "MEdge"); RNA_def_struct_ui_text(srna, "Mesh Edge", "Edge in a Mesh datablock."); + RNA_def_struct_path_func(srna, "rna_MeshEdge_path"); prop= RNA_def_property(srna, "verts", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "v1"); @@ -573,6 +681,7 @@ static void rna_def_mface(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshFace", NULL); RNA_def_struct_sdna(srna, "MFace"); RNA_def_struct_ui_text(srna, "Mesh Face", "Face in a Mesh datablock."); + RNA_def_struct_path_func(srna, "rna_MeshFace_path"); prop= RNA_def_property(srna, "verts", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "v1"); @@ -613,6 +722,7 @@ static void rna_def_mtface(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshTextureFaceLayer", NULL); RNA_def_struct_ui_text(srna, "Mesh Texture Face Layer", "Layer of texture faces in a Mesh datablock."); RNA_def_struct_sdna(srna, "CustomDataLayer"); + RNA_def_struct_path_func(srna, "rna_MeshTextureFaceLayer_path"); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_struct_name_property(srna, prop); @@ -635,6 +745,7 @@ static void rna_def_mtface(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshTextureFace", NULL); RNA_def_struct_sdna(srna, "MTFace"); RNA_def_struct_ui_text(srna, "Mesh Texture Face", "UV mapping, texturing and game engine data for a face."); + RNA_def_struct_path_func(srna, "rna_MeshTextureFace_path"); /* prop= RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "tpage"); @@ -735,6 +846,7 @@ static void rna_def_msticky(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshSticky", NULL); RNA_def_struct_sdna(srna, "MSticky"); RNA_def_struct_ui_text(srna, "Mesh Vertex Sticky Texture Coordinate", "Stricky texture coordinate."); + RNA_def_struct_path_func(srna, "rna_MeshSticky_path"); prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_VECTOR); RNA_def_property_ui_text(prop, "Location", "Sticky texture coordinate location."); @@ -748,6 +860,7 @@ static void rna_def_mcol(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshColorLayer", NULL); RNA_def_struct_ui_text(srna, "Mesh Vertex Color Layer", "Layer of vertex colors in a Mesh datablock."); RNA_def_struct_sdna(srna, "CustomDataLayer"); + RNA_def_struct_path_func(srna, "rna_MeshColorLayer_path"); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_struct_name_property(srna, prop); @@ -770,6 +883,7 @@ static void rna_def_mcol(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshColor", NULL); RNA_def_struct_sdna(srna, "MCol"); RNA_def_struct_ui_text(srna, "Mesh Vertex Color", "Vertex colors for a face in a Mesh."); + RNA_def_struct_path_func(srna, "rna_MeshColor_path"); prop= RNA_def_property(srna, "color1", PROP_FLOAT, PROP_COLOR); RNA_def_property_array(prop, 3); @@ -801,6 +915,7 @@ static void rna_def_mproperties(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshFloatPropertyLayer", NULL); RNA_def_struct_sdna(srna, "CustomDataLayer"); RNA_def_struct_ui_text(srna, "Mesh Float Property Layer", "User defined layer of floating pointer number values."); + RNA_def_struct_path_func(srna, "rna_MeshFloatPropertyLayer_path"); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_struct_name_property(srna, prop); @@ -814,6 +929,7 @@ static void rna_def_mproperties(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshFloatProperty", NULL); RNA_def_struct_sdna(srna, "MFloatProperty"); RNA_def_struct_ui_text(srna, "Mesh Float Property", "User defined floating point number value in a float properties layer."); + RNA_def_struct_path_func(srna, "rna_MeshFloatProperty_path"); prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "f"); @@ -823,6 +939,7 @@ static void rna_def_mproperties(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshIntPropertyLayer", NULL); RNA_def_struct_sdna(srna, "CustomDataLayer"); RNA_def_struct_ui_text(srna, "Mesh Int Property Layer", "User defined layer of integer number values."); + RNA_def_struct_path_func(srna, "rna_MeshIntPropertyLayer_path"); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_struct_name_property(srna, prop); @@ -836,6 +953,7 @@ static void rna_def_mproperties(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshIntProperty", NULL); RNA_def_struct_sdna(srna, "MIntProperty"); RNA_def_struct_ui_text(srna, "Mesh Int Property", "User defined integer number value in an integer properties layer."); + RNA_def_struct_path_func(srna, "rna_MeshIntProperty_path"); prop= RNA_def_property(srna, "value", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "i"); @@ -845,6 +963,7 @@ static void rna_def_mproperties(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshStringPropertyLayer", NULL); RNA_def_struct_sdna(srna, "CustomDataLayer"); RNA_def_struct_ui_text(srna, "Mesh String Property Layer", "User defined layer of string text values."); + RNA_def_struct_path_func(srna, "rna_MeshStringPropertyLayer_path"); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_struct_name_property(srna, prop); @@ -858,6 +977,7 @@ static void rna_def_mproperties(BlenderRNA *brna) srna= RNA_def_struct(brna, "MeshStringProperty", NULL); RNA_def_struct_sdna(srna, "MStringProperty"); RNA_def_struct_ui_text(srna, "Mesh String Property", "User defined string text value in a string properties layer."); + RNA_def_struct_path_func(srna, "rna_MeshStringProperty_path"); prop= RNA_def_property(srna, "value", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "s"); @@ -896,7 +1016,6 @@ void rna_def_texmat_common(StructRNA *srna, const char *texspace_editable) RNA_def_property_ui_text(prop, "Materials", ""); } - static void rna_def_mesh(BlenderRNA *brna) { StructRNA *srna; diff --git a/source/blender/makesrna/intern/rna_packedfile.c b/source/blender/makesrna/intern/rna_packedfile.c index 6b9a708f555..6b6db71ef87 100644 --- a/source/blender/makesrna/intern/rna_packedfile.c +++ b/source/blender/makesrna/intern/rna_packedfile.c @@ -1,5 +1,5 @@ /** - * $Id$ + * $Id: rna_packedfile.c 19382 2009-03-23 13:24:48Z blendix $ * * ***** BEGIN GPL LICENSE BLOCK ***** * diff --git a/source/blender/makesrna/intern/rna_world.c b/source/blender/makesrna/intern/rna_world.c index dedc9492d1f..d2e93fb787d 100644 --- a/source/blender/makesrna/intern/rna_world.c +++ b/source/blender/makesrna/intern/rna_world.c @@ -411,7 +411,6 @@ void RNA_def_world(BlenderRNA *brna) prop= RNA_def_property(srna, "script_link", PROP_POINTER, PROP_NEVER_NULL); RNA_def_property_pointer_sdna(prop, NULL, "scriptlink"); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Script Link", "Scripts linked to this object."); rna_def_ambient_occlusion(brna); |