diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-07-13 23:33:59 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-07-13 23:33:59 +0400 |
commit | 2ba8b72157d22ee92359e87e88860443a1f5cef2 (patch) | |
tree | b2347faeae5aed1c99681fe1803969ff8af57e8b /source/blender | |
parent | 1334ed303816531240294d17457575736bdd212b (diff) |
RNA & PyAPI
* support for dynamic enums to be inspected enumProp.items() from python.
* fix, enums check for a separator was flipped, meant no enums were in docs.
* dynamic enum functions now check for a NULL context and return all possible options for the "items" attribute used for docs.
* added an arg for rna arrays to free the array there looping over (needed to free dynamically allocated enum items)
* python api checks for NULL items since this can happen in some cases.
* python api, When getting an enum ID from an int in an array - If it failed it would get the first enum identifier and return that. Brecht? dont understand, making it return an empty string in these cases.
Diffstat (limited to 'source/blender')
21 files changed, 197 insertions, 73 deletions
diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c index 2995e2d895b..5fc2ce46792 100644 --- a/source/blender/editors/mesh/editmesh_mods.c +++ b/source/blender/editors/mesh/editmesh_mods.c @@ -1229,12 +1229,25 @@ static int select_similar_exec(bContext *C, wmOperator *op) static EnumPropertyItem *select_similar_type_itemf(bContext *C, PointerRNA *ptr, int *free) { - Object *obedit= CTX_data_edit_object(C); - + Object *obedit; + EnumPropertyItem *item= NULL; + int totitem= 0; + + if(C==NULL) { + /* needed for doc generation */ + RNA_enum_items_add(&item, &totitem, prop_simvertex_types); + RNA_enum_items_add(&item, &totitem, prop_simedge_types); + RNA_enum_items_add(&item, &totitem, prop_simface_types); + RNA_enum_item_end(&item, &totitem); + *free= 1; + + return item; + } + + obedit= CTX_data_edit_object(C); + if(obedit && obedit->type == OB_MESH) { EditMesh *em= BKE_mesh_get_editmesh(obedit->data); - EnumPropertyItem *item= NULL; - int totitem= 0; if(em->selectmode & SCE_SELECT_VERTEX) RNA_enum_items_add(&item, &totitem, prop_simvertex_types); @@ -1248,7 +1261,7 @@ static EnumPropertyItem *select_similar_type_itemf(bContext *C, PointerRNA *ptr, return item; } - + return NULL; } diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index eab06444a79..efb68f69dac 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -5795,13 +5795,24 @@ static EnumPropertyItem merge_type_items[]= { {0, NULL, 0, NULL, NULL}}; static EnumPropertyItem *merge_type_itemf(bContext *C, PointerRNA *ptr, int *free) -{ - Object *obedit= CTX_data_edit_object(C); - +{ + EnumPropertyItem *item= NULL; + int totitem= 0; + + Object *obedit; + + if(C==NULL) { + /* needed for doc generation */ + RNA_enum_items_add(&item, &totitem, merge_type_items); + RNA_enum_item_end(&item, &totitem); + + *free= 1; + return item; + } + + obedit= CTX_data_edit_object(C); if(obedit && obedit->type == OB_MESH) { EditMesh *em= BKE_mesh_get_editmesh(obedit->data); - EnumPropertyItem *item= NULL; - int totitem= 0; if(em->selectmode & SCE_SELECT_VERTEX) { if(em->selected.first && em->selected.last && @@ -5824,7 +5835,7 @@ static EnumPropertyItem *merge_type_itemf(bContext *C, PointerRNA *ptr, int *fre return item; } - + return NULL; } diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index f3b373f0e48..6d60c7602f4 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -358,8 +358,10 @@ void BIF_selectTransformOrientationValue(bContext *C, int orientation) { EnumPropertyItem *BIF_enumTransformOrientation(bContext *C) { - ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; - TransformOrientation *ts = transform_spaces->first; + Scene *scene; + ListBase *transform_spaces; + TransformOrientation *ts= NULL; + EnumPropertyItem global = {V3D_MANIP_GLOBAL, "GLOBAL", 0, "Global", ""}; EnumPropertyItem normal = {V3D_MANIP_NORMAL, "NORMAL", 0, "Normal", ""}; EnumPropertyItem local = {V3D_MANIP_LOCAL, "LOCAL", 0, "Local", ""}; @@ -374,6 +376,15 @@ EnumPropertyItem *BIF_enumTransformOrientation(bContext *C) RNA_enum_item_add(&item, &totitem, &local); RNA_enum_item_add(&item, &totitem, &view); + if(C) { + scene= CTX_data_scene(C); + + if(scene) { + transform_spaces = &scene->transform_spaces; + ts = transform_spaces->first; + } + } + if(ts) RNA_enum_item_add(&item, &totitem, &sepr); diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 61a8f8a29e9..85c266e3f27 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -699,9 +699,9 @@ static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA * } else { if(dp->dnalengthname) - fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), data->%s, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthname); + fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), data->%s, 0, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthname); else - fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), %d, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthfixed); + fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), %d, 0, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthfixed); } } else { diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index d6ca03c85a2..e504d1d030b 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -643,15 +643,18 @@ StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop) void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item, int *totitem, int *free) { EnumPropertyRNA *eprop= (EnumPropertyRNA*)rna_ensure_property(prop); - int tot; *free= 0; - if(C && eprop->itemf) { + if(eprop->itemf) { + int tot= 0; *item= eprop->itemf(C, ptr, free); if(totitem) { - for(tot=0; (*item)[tot].identifier; tot++); + if(*item) { + for( ; (*item)[tot].identifier; tot++); + } + *totitem= tot; } } @@ -710,11 +713,14 @@ int RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop int result, free; RNA_property_enum_items(C, ptr, prop, &item, NULL, &free); - result= RNA_enum_identifier(item, value, identifier); - if(free) - MEM_freeN(item); + if(item) { + result= RNA_enum_identifier(item, value, identifier); + if(free) + MEM_freeN(item); - return result; + return result; + } + return 0; } const char *RNA_property_ui_name(PropertyRNA *prop) @@ -1303,9 +1309,9 @@ void RNA_property_collection_begin(PointerRNA *ptr, PropertyRNA *prop, Collectio iter->prop= prop; if(idprop) - rna_iterator_array_begin(iter, IDP_IDPArray(idprop), sizeof(IDProperty), idprop->len, NULL); + rna_iterator_array_begin(iter, IDP_IDPArray(idprop), sizeof(IDProperty), idprop->len, 0, NULL); else - rna_iterator_array_begin(iter, NULL, sizeof(IDProperty), 0, NULL); + rna_iterator_array_begin(iter, NULL, sizeof(IDProperty), 0, 0, NULL); if(iter->valid) rna_property_collection_get_idp(iter); @@ -1902,7 +1908,7 @@ void rna_iterator_listbase_end(CollectionPropertyIterator *iter) iter->internal= NULL; } -void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, IteratorSkipFunc skip) +void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, int free_ptr, IteratorSkipFunc skip) { ArrayIterator *internal; @@ -1911,6 +1917,7 @@ void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int i internal= MEM_callocN(sizeof(ArrayIterator), "ArrayIterator"); internal->ptr= ptr; + internal->free_ptr= free_ptr ? ptr:NULL; internal->endptr= ((char*)ptr)+length*itemsize; internal->itemsize= itemsize; internal->skip= skip; @@ -1955,6 +1962,11 @@ void *rna_iterator_array_dereference_get(CollectionPropertyIterator *iter) void rna_iterator_array_end(CollectionPropertyIterator *iter) { + ArrayIterator *internal= iter->internal; + + if(internal->free_ptr) + MEM_freeN(internal->free_ptr); + MEM_freeN(iter->internal); iter->internal= NULL; } diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index 7355261c5aa..3b7df3aa948 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -37,7 +37,7 @@ static void rna_Brush_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Brush *brush= (Brush*)ptr->data; - rna_iterator_array_begin(iter, (void*)brush->mtex, sizeof(MTex*), MAX_MTEX, NULL); + rna_iterator_array_begin(iter, (void*)brush->mtex, sizeof(MTex*), MAX_MTEX, 0, NULL); } static PointerRNA rna_Brush_active_texture_get(PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c index 179808ab66d..f4248d18db3 100644 --- a/source/blender/makesrna/intern/rna_color.c +++ b/source/blender/makesrna/intern/rna_color.c @@ -50,7 +50,7 @@ static void rna_CurveMapping_curves_begin(CollectionPropertyIterator *iter, Poin { CurveMapping *cumap= (CurveMapping*)ptr->data; - rna_iterator_array_begin(iter, cumap->cm, sizeof(CurveMap), rna_CurveMapping_curves_length(ptr), NULL); + rna_iterator_array_begin(iter, cumap->cm, sizeof(CurveMap), rna_CurveMapping_curves_length(ptr), 0, NULL); } static void rna_CurveMapping_clip_set(PointerRNA *ptr, int value) diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c index 56c0ca1b491..0e3dd799612 100644 --- a/source/blender/makesrna/intern/rna_constraint.c +++ b/source/blender/makesrna/intern/rna_constraint.c @@ -181,6 +181,20 @@ static EnumPropertyItem *rna_Constraint_owner_space_itemf(bContext *C, PointerRN { Object *ob= (Object*)ptr->id.data; bConstraint *con= (bConstraint*)ptr->data; + + if(C==NULL) { + EnumPropertyItem *item= NULL; + int totitem= 0; + + /* needed for doc generation */ + RNA_enum_items_add(&item, &totitem, space_object_items); + RNA_enum_items_add(&item, &totitem, space_pchan_items); + RNA_enum_item_end(&item, &totitem); + + *free= 1; + + return item; + } if(BLI_findindex(&ob->constraints, con) == -1) return space_pchan_items; @@ -195,6 +209,20 @@ static EnumPropertyItem *rna_Constraint_target_space_itemf(bContext *C, PointerR ListBase targets = {NULL, NULL}; bConstraintTarget *ct; + if(C==NULL) { + EnumPropertyItem *item= NULL; + int totitem= 0; + + /* needed for doc generation */ + RNA_enum_items_add(&item, &totitem, space_object_items); + RNA_enum_items_add(&item, &totitem, space_pchan_items); + RNA_enum_item_end(&item, &totitem); + + *free= 1; + + return item; + } + if(cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c index 5c9da19f9b2..faf6c3a1f75 100644 --- a/source/blender/makesrna/intern/rna_curve.c +++ b/source/blender/makesrna/intern/rna_curve.c @@ -139,7 +139,7 @@ static int rna_Nurb_length(PointerRNA *ptr) static void rna_BPoint_array_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Nurb *nu= (Nurb*)ptr->data; - rna_iterator_array_begin(iter, (void*)nu->bp, sizeof(BPoint*), nu->pntsv>0 ? nu->pntsu*nu->pntsv : nu->pntsu, NULL); + rna_iterator_array_begin(iter, (void*)nu->bp, sizeof(BPoint*), nu->pntsv>0 ? nu->pntsu*nu->pntsv : nu->pntsu, 0, NULL); } #else diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 6a5d5ccfdc3..ad0e05b91a6 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -240,11 +240,12 @@ void rna_iterator_listbase_end(struct CollectionPropertyIterator *iter); typedef struct ArrayIterator { char *ptr; char *endptr; + void *free_ptr; /* will be free'd if set */ int itemsize; IteratorSkipFunc skip; } ArrayIterator; -void rna_iterator_array_begin(struct CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, IteratorSkipFunc skip); +void rna_iterator_array_begin(struct CollectionPropertyIterator *iter, void *ptr, int itemsize, int length, int free_ptr, IteratorSkipFunc skip); void rna_iterator_array_next(struct CollectionPropertyIterator *iter); void *rna_iterator_array_get(struct CollectionPropertyIterator *iter); void *rna_iterator_array_dereference_get(struct CollectionPropertyIterator *iter); diff --git a/source/blender/makesrna/intern/rna_key.c b/source/blender/makesrna/intern/rna_key.c index 0a7e989a93a..7297ee8cb97 100644 --- a/source/blender/makesrna/intern/rna_key.c +++ b/source/blender/makesrna/intern/rna_key.c @@ -198,7 +198,7 @@ static void rna_ShapeKey_data_begin(CollectionPropertyIterator *iter, PointerRNA } } - rna_iterator_array_begin(iter, (void*)kb->data, size, tot, NULL); + rna_iterator_array_begin(iter, (void*)kb->data, size, tot, 0, NULL); } static int rna_ShapeKey_data_length(PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_lamp.c b/source/blender/makesrna/intern/rna_lamp.c index a49b4377d9d..e592cb38693 100644 --- a/source/blender/makesrna/intern/rna_lamp.c +++ b/source/blender/makesrna/intern/rna_lamp.c @@ -54,7 +54,7 @@ static PointerRNA rna_Lamp_sky_settings_get(PointerRNA *ptr) static void rna_Lamp_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Lamp *la= (Lamp*)ptr->data; - rna_iterator_array_begin(iter, (void*)la->mtex, sizeof(MTex*), MAX_MTEX, NULL); + rna_iterator_array_begin(iter, (void*)la->mtex, sizeof(MTex*), MAX_MTEX, 0, NULL); } static PointerRNA rna_Lamp_active_texture_get(PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_lattice.c b/source/blender/makesrna/intern/rna_lattice.c index c685e5b6912..03a1dc9ec8f 100644 --- a/source/blender/makesrna/intern/rna_lattice.c +++ b/source/blender/makesrna/intern/rna_lattice.c @@ -68,10 +68,10 @@ static void rna_LatticePoint_groups_begin(CollectionPropertyIterator *iter, Poin BPoint *bp= (BPoint*)ptr->data; MDeformVert *dvert= lt->dvert + (bp-lt->def); - rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, NULL); + rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, 0, NULL); } else - rna_iterator_array_begin(iter, NULL, 0, 0, NULL); + rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL); } static void rna_Lattice_points_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) @@ -80,11 +80,11 @@ static void rna_Lattice_points_begin(CollectionPropertyIterator *iter, PointerRN int tot= lt->pntsu*lt->pntsv*lt->pntsw; if(lt->editlatt && lt->editlatt->def) - rna_iterator_array_begin(iter, (void*)lt->editlatt->def, sizeof(BPoint), tot, NULL); + rna_iterator_array_begin(iter, (void*)lt->editlatt->def, sizeof(BPoint), tot, 0, NULL); else if(lt->def) - rna_iterator_array_begin(iter, (void*)lt->def, sizeof(BPoint), tot, NULL); + rna_iterator_array_begin(iter, (void*)lt->def, sizeof(BPoint), tot, 0, NULL); else - rna_iterator_array_begin(iter, NULL, 0, 0, NULL); + rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL); } static void rna_Lattice_update_data(bContext *C, PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c index 41f31594f6e..17c91088761 100644 --- a/source/blender/makesrna/intern/rna_material.c +++ b/source/blender/makesrna/intern/rna_material.c @@ -75,7 +75,7 @@ static void rna_Material_type_set(PointerRNA *ptr, int value) static void rna_Material_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Material *ma= (Material*)ptr->data; - rna_iterator_array_begin(iter, (void*)ma->mtex, sizeof(MTex*), MAX_MTEX, NULL); + rna_iterator_array_begin(iter, (void*)ma->mtex, sizeof(MTex*), MAX_MTEX, 0, NULL); } static PointerRNA rna_Material_active_texture_get(PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index b69a804cf6a..3a7015b65be 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -197,10 +197,10 @@ static void rna_MeshVertex_groups_begin(CollectionPropertyIterator *iter, Pointe MVert *mvert= (MVert*)ptr->data; MDeformVert *dvert= me->dvert + (mvert-me->mvert); - rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, NULL); + rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, 0, NULL); } else - rna_iterator_array_begin(iter, NULL, 0, 0, NULL); + rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL); } static void rna_MeshFace_material_index_range(PointerRNA *ptr, int *min, int *max) @@ -262,7 +262,7 @@ static void rna_Mesh_uv_textures_begin(CollectionPropertyIterator *iter, Pointer { Mesh *me= (Mesh*)ptr->data; CustomData *fdata= rna_mesh_fdata(me); - rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, rna_uv_texture_check); + rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_uv_texture_check); } static int rna_Mesh_uv_textures_length(PointerRNA *ptr) @@ -390,7 +390,7 @@ static void rna_MeshTextureFaceLayer_data_begin(CollectionPropertyIterator *iter { Mesh *me= (Mesh*)ptr->id.data; CustomDataLayer *layer= (CustomDataLayer*)ptr->data; - rna_iterator_array_begin(iter, layer->data, sizeof(MTFace), me->totface, NULL); + rna_iterator_array_begin(iter, layer->data, sizeof(MTFace), me->totface, 0, NULL); } static int rna_MeshTextureFaceLayer_data_length(PointerRNA *ptr) @@ -437,7 +437,7 @@ static void rna_Mesh_vertex_colors_begin(CollectionPropertyIterator *iter, Point { Mesh *me= (Mesh*)ptr->data; CustomData *fdata= rna_mesh_fdata(me); - rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, rna_vertex_color_check); + rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_vertex_color_check); } static int rna_Mesh_vertex_colors_length(PointerRNA *ptr) @@ -501,7 +501,7 @@ static void rna_MeshColorLayer_data_begin(CollectionPropertyIterator *iter, Poin { Mesh *me= (Mesh*)ptr->id.data; CustomDataLayer *layer= (CustomDataLayer*)ptr->data; - rna_iterator_array_begin(iter, layer->data, sizeof(MCol)*4, me->totface, NULL); + rna_iterator_array_begin(iter, layer->data, sizeof(MCol)*4, me->totface, 0, NULL); } static int rna_MeshColorLayer_data_length(PointerRNA *ptr) @@ -542,7 +542,7 @@ static void rna_MeshFloatPropertyLayer_data_begin(CollectionPropertyIterator *it { Mesh *me= (Mesh*)ptr->id.data; CustomDataLayer *layer= (CustomDataLayer*)ptr->data; - rna_iterator_array_begin(iter, layer->data, sizeof(MFloatProperty), me->totface, NULL); + rna_iterator_array_begin(iter, layer->data, sizeof(MFloatProperty), me->totface, 0, NULL); } static int rna_MeshFloatPropertyLayer_data_length(PointerRNA *ptr) @@ -561,7 +561,7 @@ static void rna_Mesh_float_layers_begin(CollectionPropertyIterator *iter, Pointe { Mesh *me= (Mesh*)ptr->data; CustomData *fdata= rna_mesh_fdata(me); - rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, rna_float_layer_check); + rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_float_layer_check); } static int rna_Mesh_float_layers_length(PointerRNA *ptr) @@ -579,7 +579,7 @@ static void rna_MeshIntPropertyLayer_data_begin(CollectionPropertyIterator *iter { Mesh *me= (Mesh*)ptr->id.data; CustomDataLayer *layer= (CustomDataLayer*)ptr->data; - rna_iterator_array_begin(iter, layer->data, sizeof(MIntProperty), me->totface, NULL); + rna_iterator_array_begin(iter, layer->data, sizeof(MIntProperty), me->totface, 0, NULL); } static int rna_MeshIntPropertyLayer_data_length(PointerRNA *ptr) @@ -592,7 +592,7 @@ static void rna_Mesh_int_layers_begin(CollectionPropertyIterator *iter, PointerR { Mesh *me= (Mesh*)ptr->data; CustomData *fdata= rna_mesh_fdata(me); - rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, rna_int_layer_check); + rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_int_layer_check); } static int rna_Mesh_int_layers_length(PointerRNA *ptr) @@ -610,7 +610,7 @@ static void rna_MeshStringPropertyLayer_data_begin(CollectionPropertyIterator *i { Mesh *me= (Mesh*)ptr->id.data; CustomDataLayer *layer= (CustomDataLayer*)ptr->data; - rna_iterator_array_begin(iter, layer->data, sizeof(MStringProperty), me->totface, NULL); + rna_iterator_array_begin(iter, layer->data, sizeof(MStringProperty), me->totface, 0, NULL); } static int rna_MeshStringPropertyLayer_data_length(PointerRNA *ptr) @@ -623,7 +623,7 @@ static void rna_Mesh_string_layers_begin(CollectionPropertyIterator *iter, Point { Mesh *me= (Mesh*)ptr->data; CustomData *fdata= rna_mesh_fdata(me); - rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, rna_string_layer_check); + rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_string_layer_check); } static int rna_Mesh_string_layers_length(PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index a789f9065e3..f207f4f605d 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -83,7 +83,7 @@ EnumPropertyItem modifier_type_items[] ={ static void rna_UVProject_projectors_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { UVProjectModifierData *uvp= (UVProjectModifierData*)ptr->data; - rna_iterator_array_begin(iter, (void*)uvp->projectors, sizeof(Object*), 10, NULL); + rna_iterator_array_begin(iter, (void*)uvp->projectors, sizeof(Object*), 10, 0, NULL); } static StructRNA* rna_Modifier_refine(struct PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c index 39411752792..ef68e0ba019 100644 --- a/source/blender/makesrna/intern/rna_particle.c +++ b/source/blender/makesrna/intern/rna_particle.c @@ -430,6 +430,20 @@ static EnumPropertyItem *rna_Particle_from_itemf(bContext *C, PointerRNA *ptr, i { ParticleSettings *part = ptr->id.data; + if(C==NULL) { + EnumPropertyItem *item= NULL; + int totitem= 0; + + /* needed for doc generation */ + RNA_enum_items_add(&item, &totitem, part_reactor_from_items); + RNA_enum_items_add(&item, &totitem, part_from_items); + RNA_enum_item_end(&item, &totitem); + + *free= 1; + + return item; + } + if(part->type==PART_REACTOR) return part_reactor_from_items; else @@ -440,6 +454,20 @@ static EnumPropertyItem *rna_Particle_draw_as_itemf(bContext *C, PointerRNA *ptr { ParticleSettings *part = ptr->id.data; + if(C==NULL) { + EnumPropertyItem *item= NULL; + int totitem= 0; + + /* needed for doc generation */ + RNA_enum_items_add(&item, &totitem, part_hair_draw_as_items); + RNA_enum_items_add(&item, &totitem, part_draw_as_items); + RNA_enum_item_end(&item, &totitem); + + *free= 1; + + return item; + } + if(part->type==PART_HAIR) return part_hair_draw_as_items; else @@ -450,6 +478,20 @@ static EnumPropertyItem *rna_Particle_ren_as_itemf(bContext *C, PointerRNA *ptr, { ParticleSettings *part = ptr->id.data; + if(C==NULL) { + EnumPropertyItem *item= NULL; + int totitem= 0; + + /* needed for doc generation */ + RNA_enum_items_add(&item, &totitem, part_hair_ren_as_items); + RNA_enum_items_add(&item, &totitem, part_ren_as_items); + RNA_enum_item_end(&item, &totitem); + + *free= 1; + + return item; + } + if(part->type==PART_HAIR) return part_hair_ren_as_items; else diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index 0b605db20cf..aeaedd6f81d 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -520,18 +520,21 @@ static int rna_enum_check_separator(CollectionPropertyIterator *iter, void *data { EnumPropertyItem *item= (EnumPropertyItem*)data; - return (item->identifier[0] != 0); + return (item->identifier[0] == 0); } static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; EnumPropertyRNA *eprop; - + EnumPropertyItem *item= NULL; + int totitem, free= 0; + rna_idproperty_check(&prop, ptr); eprop= (EnumPropertyRNA*)prop; - - rna_iterator_array_begin(iter, (void*)eprop->item, sizeof(eprop->item[0]), eprop->totitem, rna_enum_check_separator); + + RNA_property_enum_items(NULL, ptr, prop, &item, &totitem, &free); + rna_iterator_array_begin(iter, (void*)item, sizeof(EnumPropertyItem), totitem, free, rna_enum_check_separator); } static void rna_EnumPropertyItem_identifier_get(PointerRNA *ptr, char *value) diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index fa81af8f140..3f9b87a7f37 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -179,6 +179,11 @@ static EnumPropertyItem *rna_SpaceImageEditor_draw_channels_itemf(bContext *C, P ImBuf *ibuf= ED_space_image_buffer(sima); int zbuf, alpha; + if(C==NULL) { + /* needed for doc generation */ + return dc_all_items; + } + alpha= ibuf && (ibuf->channels == 4); zbuf= ibuf && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels==1)); diff --git a/source/blender/makesrna/intern/rna_world.c b/source/blender/makesrna/intern/rna_world.c index 67328455a77..9ff474b82b0 100644 --- a/source/blender/makesrna/intern/rna_world.c +++ b/source/blender/makesrna/intern/rna_world.c @@ -56,7 +56,7 @@ static PointerRNA rna_World_mist_get(PointerRNA *ptr) static void rna_World_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { World *wo= (World*)ptr->data; - rna_iterator_array_begin(iter, (void*)wo->mtex, sizeof(MTex*), MAX_MTEX, NULL); + rna_iterator_array_begin(iter, (void*)wo->mtex, sizeof(MTex*), MAX_MTEX, 0, NULL); } static PointerRNA rna_World_active_texture_get(PointerRNA *ptr) diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 49bca247431..9ce9ec8e838 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -225,10 +225,16 @@ static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop) { EnumPropertyItem *item; char *result; - int free; + int free= 0; RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free); - result= (char*)BPy_enum_as_string(item); + if(item) { + result= (char*)BPy_enum_as_string(item); + } + else { + result= ""; + } + if(free) MEM_freeN(item); @@ -319,12 +325,12 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) ret = PyUnicode_FromString( identifier ); } else { EnumPropertyItem *item; - int free; + int free= 0; /* don't throw error here, can't trust blender 100% to give the * right values, python code should not generate error for that */ RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free); - if(item->identifier) { + if(item && item->identifier) { ret = PyUnicode_FromString( item->identifier ); } else { @@ -1831,20 +1837,12 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data) if (RNA_property_enum_identifier(BPy_GetContext(), ptr, prop, val, &identifier)) { ret = PyUnicode_FromString( identifier ); } else { - EnumPropertyItem *item; - int free; - - /* don't throw error here, can't trust blender 100% to give the - * right values, python code should not generate error for that */ - RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free); - if(item[0].identifier) - ret = PyUnicode_FromString( item[0].identifier ); - else - ret = PyUnicode_FromString( "" ); - - if(free) - MEM_freeN(item); - + /* prefer not fail silently incase of api errors, maybe disable it later */ + char error_str[128]; + sprintf(error_str, "RNA Warning: Current value \"%d\" matches no enum", val); + PyErr_Warn(PyExc_RuntimeWarning, error_str); + + ret = PyUnicode_FromString( "" ); /*PyErr_Format(PyExc_AttributeError, "RNA Error: Current value \"%d\" matches no enum", val); ret = NULL;*/ } |