/* Dynamically populate an enum of Keying Sets */ EnumPropertyItem *ANIM_keying_sets_enum_itemf (bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { Scene *scene = CTX_data_scene(C); KeyingSet *ks; EnumPropertyItem *item= NULL, item_tmp= {0}; int totitem= 0; int i= 0; if (C == NULL) { return DummyRNA_DEFAULT_items; } /* active Keying Set * - only include entry if it exists */ if (scene->active_keyingset) { /* active Keying Set */ item_tmp.identifier= item_tmp.name= "Active Keying Set"; item_tmp.value= i++; RNA_enum_item_add(&item, &totitem, &item_tmp); /* separator */ RNA_enum_item_add_separator(&item, &totitem); } else i++; /* user-defined Keying Sets * - these are listed in the order in which they were defined for the active scene */ if (scene->keyingsets.first) { for (ks= scene->keyingsets.first; ks; ks= ks->next) { if (ANIM_keyingset_context_ok_poll(C, ks)) { item_tmp.identifier= item_tmp.name= ks->name; item_tmp.value= i++; RNA_enum_item_add(&item, &totitem, &item_tmp); } } /* separator */ RNA_enum_item_add_separator(&item, &totitem); } /* builtin Keying Sets */ i= -1; for (ks= builtin_keyingsets.first; ks; ks= ks->next) { /* only show KeyingSet if context is suitable */ if (ANIM_keyingset_context_ok_poll(C, ks)) { item_tmp.identifier= item_tmp.name= ks->name; item_tmp.value= i--; RNA_enum_item_add(&item, &totitem, &item_tmp); } } RNA_enum_item_end(&item, &totitem); *free= 1; return item; }
static EnumPropertyItem *rna_DynamicPaint_surface_type_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free) { DynamicPaintSurface *surface = (DynamicPaintSurface *)ptr->data; EnumPropertyItem *item = NULL; EnumPropertyItem tmp = {0, "", 0, "", ""}; int totitem = 0; /* Paint type - available for all formats */ tmp.value = MOD_DPAINT_SURFACE_T_PAINT; tmp.identifier = "PAINT"; tmp.name = "Paint"; tmp.icon = ICON_TPAINT_HLT; RNA_enum_item_add(&item, &totitem, &tmp); /* Displace */ if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX || surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { tmp.value = MOD_DPAINT_SURFACE_T_DISPLACE; tmp.identifier = "DISPLACE"; tmp.name = "Displace"; tmp.icon = ICON_MOD_DISPLACE; RNA_enum_item_add(&item, &totitem, &tmp); } /* Weight */ if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { tmp.value = MOD_DPAINT_SURFACE_T_WEIGHT; tmp.identifier = "WEIGHT"; tmp.name = "Weight"; tmp.icon = ICON_MOD_VERTEX_WEIGHT; RNA_enum_item_add(&item, &totitem, &tmp); } /* Height waves */ { tmp.value = MOD_DPAINT_SURFACE_T_WAVE; tmp.identifier = "WAVE"; tmp.name = "Waves"; tmp.icon = ICON_MOD_WAVE; RNA_enum_item_add(&item, &totitem, &tmp); } RNA_enum_item_end(&item, &totitem); *free = 1; return item; }
/* can be called with C == NULL */ static EnumPropertyItem *group_object_active_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { Object *ob; EnumPropertyItem *item = NULL, item_tmp = {0}; int totitem = 0; if (C == NULL) { return DummyRNA_NULL_items; } ob = ED_object_context(C); /* check that the action exists */ if (ob) { Group *group = NULL; int i = 0; while ((group = BKE_group_object_find(group, ob))) { item_tmp.identifier = item_tmp.name = group->id.name + 2; /* item_tmp.icon = ICON_ARMATURE_DATA; */ item_tmp.value = i; RNA_enum_item_add(&item, &totitem, &item_tmp); i++; } } RNA_enum_item_end(&item, &totitem); *free = 1; return item; }
/* can be called with C == NULL */ static EnumPropertyItem *poselib_stored_pose_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { Object *ob = get_poselib_object(C); bAction *act = (ob) ? ob->poselib : NULL; TimeMarker *marker; EnumPropertyItem *item= NULL, item_tmp= {0}; int totitem= 0; int i= 0; if (C == NULL) { return DummyRNA_DEFAULT_items; } /* check that the action exists */ if (act) { /* add each marker to the list */ for (marker=act->markers.first, i=0; marker; marker= marker->next, i++) { item_tmp.identifier= item_tmp.name= marker->name; item_tmp.icon= ICON_ARMATURE_DATA; item_tmp.value= i; RNA_enum_item_add(&item, &totitem, &item_tmp); } } RNA_enum_item_end(&item, &totitem); *free= 1; return item; }
/* Dynamic Enums of GP Palettes */ const EnumPropertyItem *ED_gpencil_palettes_enum_itemf( bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) { bGPdata *gpd = CTX_data_gpencil_data(C); bGPDpalette *palette; EnumPropertyItem *item = NULL, item_tmp = { 0 }; int totitem = 0; int i = 0; if (ELEM(NULL, C, gpd)) { return DummyRNA_DEFAULT_items; } /* Existing palettes */ for (palette = gpd->palettes.first; palette; palette = palette->next, i++) { item_tmp.identifier = palette->info; item_tmp.name = palette->info; item_tmp.value = i; if (palette->flag & PL_PALETTE_ACTIVE) item_tmp.icon = ICON_COLOR; else item_tmp.icon = ICON_NONE; RNA_enum_item_add(&item, &totitem, &item_tmp); } RNA_enum_item_end(&item, &totitem); *r_free = true; return item; }
/* Dynamic Enums of GP Brushes */ const EnumPropertyItem *ED_gpencil_brushes_enum_itemf( bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) { ToolSettings *ts = CTX_data_tool_settings(C); bGPDbrush *brush; EnumPropertyItem *item = NULL, item_tmp = { 0 }; int totitem = 0; int i = 0; if (ELEM(NULL, C, ts)) { return DummyRNA_DEFAULT_items; } /* Existing brushes */ for (brush = ts->gp_brushes.first; brush; brush = brush->next, i++) { item_tmp.identifier = brush->info; item_tmp.name = brush->info; item_tmp.value = i; if (brush->flag & GP_BRUSH_ACTIVE) item_tmp.icon = ICON_BRUSH_DATA; else item_tmp.icon = ICON_NONE; RNA_enum_item_add(&item, &totitem, &item_tmp); } RNA_enum_item_end(&item, &totitem); *r_free = true; return item; }
static EnumPropertyItem *modifier_add_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { Object *ob= ED_object_active_context(C); EnumPropertyItem *item= NULL, *md_item; ModifierTypeInfo *mti; int totitem= 0, a; if(!ob) return modifier_type_items; for(a=0; modifier_type_items[a].identifier; a++) { md_item= &modifier_type_items[a]; if(md_item->identifier[0]) { mti= modifierType_getInfo(md_item->value); if(mti->flags & eModifierTypeFlag_NoUserAdd) continue; if(!((mti->flags & eModifierTypeFlag_AcceptsCVs) || (ob->type==OB_MESH && (mti->flags & eModifierTypeFlag_AcceptsMesh)))) continue; } RNA_enum_item_add(&item, &totitem, md_item); } RNA_enum_item_end(&item, &totitem); *free= 1; return item; }
static EnumPropertyItem *hook_mod_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) { Object *ob = CTX_data_edit_object(C); EnumPropertyItem tmp = {0, "", 0, "", ""}; EnumPropertyItem *item= NULL; ModifierData *md = NULL; int a, totitem= 0; if(!ob) return DummyRNA_NULL_items; for(a=0, md=ob->modifiers.first; md; md= md->next, a++) { if (md->type==eModifierType_Hook) { tmp.value= a; tmp.icon = ICON_HOOK; tmp.identifier= md->name; tmp.name= md->name; RNA_enum_item_add(&item, &totitem, &tmp); } } RNA_enum_item_end(&item, &totitem); *free= 1; return item; }
/* Just existing layers */ EnumPropertyItem *ED_gpencil_layers_enum_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) { bGPdata *gpd = CTX_data_gpencil_data(C); bGPDlayer *gpl; EnumPropertyItem *item = NULL, item_tmp = {0}; int totitem = 0; int i = 0; if (ELEM(NULL, C, gpd)) { return DummyRNA_DEFAULT_items; } /* Existing layers */ for (gpl = gpd->layers.first; gpl; gpl = gpl->next, i++) { item_tmp.identifier = gpl->info; item_tmp.name = gpl->info; item_tmp.value = i; if (gpl->flag & GP_LAYER_ACTIVE) item_tmp.icon = ICON_GREASEPENCIL; else item_tmp.icon = ICON_NONE; RNA_enum_item_add(&item, &totitem, &item_tmp); } RNA_enum_item_end(&item, &totitem); *r_free = true; return item; }
/* Existing + Option to add/use new layer */ const EnumPropertyItem *ED_gpencil_layers_with_new_enum_itemf( bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) { bGPdata *gpd = CTX_data_gpencil_data(C); bGPDlayer *gpl; EnumPropertyItem *item = NULL, item_tmp = {0}; int totitem = 0; int i = 0; if (ELEM(NULL, C, gpd)) { return DummyRNA_DEFAULT_items; } /* Create new layer */ /* TODO: have some way of specifying that we don't want this? */ { /* active Keying Set */ item_tmp.identifier = "__CREATE__"; item_tmp.name = "New Layer"; item_tmp.value = -1; item_tmp.icon = ICON_ZOOMIN; RNA_enum_item_add(&item, &totitem, &item_tmp); /* separator */ RNA_enum_item_add_separator(&item, &totitem); } /* Existing layers */ for (gpl = gpd->layers.first, i = 0; gpl; gpl = gpl->next, i++) { item_tmp.identifier = gpl->info; item_tmp.name = gpl->info; item_tmp.value = i; if (gpl->flag & GP_LAYER_ACTIVE) item_tmp.icon = ICON_GREASEPENCIL; else item_tmp.icon = ICON_NONE; RNA_enum_item_add(&item, &totitem, &item_tmp); } RNA_enum_item_end(&item, &totitem); *r_free = true; return item; }
/* can be called with C == NULL */ static EnumPropertyItem *group_object_active_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) { Object *ob; EnumPropertyItem *item = NULL, item_tmp = {0}; int totitem = 0; if (C == NULL) { return DummyRNA_NULL_items; } ob = ED_object_context(C); /* check that the object exists */ if (ob) { Group *group; int i = 0, count = 0; /* if 2 or more groups, add option to add to all groups */ group = NULL; while ((group = BKE_group_object_find(group, ob))) count++; if (count >= 2) { item_tmp.identifier = item_tmp.name = "All Groups"; item_tmp.value = INT_MAX; /* this will give NULL on lookup */ RNA_enum_item_add(&item, &totitem, &item_tmp); RNA_enum_item_add_separator(&item, &totitem); } /* add groups */ group = NULL; while ((group = BKE_group_object_find(group, ob))) { item_tmp.identifier = item_tmp.name = group->id.name + 2; /* item_tmp.icon = ICON_ARMATURE_DATA; */ item_tmp.value = i; RNA_enum_item_add(&item, &totitem, &item_tmp); i++; } } RNA_enum_item_end(&item, &totitem); *r_free = true; return item; }
static const EnumPropertyItem *gpencil_modifier_add_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) { Object *ob = ED_object_active_context(C); EnumPropertyItem *item = NULL; const EnumPropertyItem *md_item, *group_item = NULL; const GpencilModifierTypeInfo *mti; int totitem = 0, a; if (!ob) { return rna_enum_object_greasepencil_modifier_type_items; } for (a = 0; rna_enum_object_greasepencil_modifier_type_items[a].identifier; a++) { md_item = &rna_enum_object_greasepencil_modifier_type_items[a]; if (md_item->identifier[0]) { mti = BKE_gpencil_modifierType_getInfo(md_item->value); if (mti->flags & eGpencilModifierTypeFlag_NoUserAdd) { continue; } } else { group_item = md_item; md_item = NULL; continue; } if (group_item) { RNA_enum_item_add(&item, &totitem, group_item); group_item = NULL; } RNA_enum_item_add(&item, &totitem, md_item); } RNA_enum_item_end(&item, &totitem); *r_free = true; return item; }
/* create enum based on undo items */ static const EnumPropertyItem *rna_undo_itemf(bContext *C, int undosys, int *totitem) { EnumPropertyItem item_tmp = {0}, *item = NULL; int i = 0; bool active; while (true) { const char *name = NULL; if (undosys == UNDOSYSTEM_PARTICLE) { name = PE_undo_get_name(CTX_data_scene(C), i, &active); } else if (undosys == UNDOSYSTEM_EDITMODE) { name = undo_editmode_get_name(C, i, &active); } else if (undosys == UNDOSYSTEM_IMAPAINT) { name = ED_undo_paint_get_name(C, UNDO_PAINT_IMAGE, i, &active); } else if (undosys == UNDOSYSTEM_SCULPT) { name = ED_undo_paint_get_name(C, UNDO_PAINT_MESH, i, &active); } else { name = BKE_undo_get_name(i, &active); } if (name) { item_tmp.identifier = name; /* XXX This won't work with non-default contexts (e.g. operators) :/ */ item_tmp.name = IFACE_(name); if (active) item_tmp.icon = ICON_RESTRICT_VIEW_OFF; else item_tmp.icon = ICON_NONE; item_tmp.value = i++; RNA_enum_item_add(&item, totitem, &item_tmp); } else break; } RNA_enum_item_end(&item, totitem); return item; }
/* add dupligroup */ static EnumPropertyItem *add_dupligroup_itemf(bContext *C, PointerRNA *ptr, int *free) { EnumPropertyItem *item= NULL, item_tmp; int totitem= 0; int i= 0; Group *group; memset(&item_tmp, 0, sizeof(item_tmp)); for(group= CTX_data_main(C)->group.first; group; group= group->id.next) { item_tmp.identifier= item_tmp.name= group->id.name+2; item_tmp.value= i++; RNA_enum_item_add(&item, &totitem, &item_tmp); } RNA_enum_item_end(&item, &totitem); *free= 1; return item; }
/* Filtering callback for driver mapping types enum */ static const EnumPropertyItem *driver_mapping_type_itemsf(bContext *C, PointerRNA *UNUSED(owner_ptr), PropertyRNA *UNUSED(owner_prop), bool *r_free) { EnumPropertyItem *input = prop_driver_create_mapping_types; EnumPropertyItem *item = NULL; PointerRNA ptr = {{NULL}}; PropertyRNA *prop = NULL; int index; int totitem = 0; if (!C) { /* needed for docs */ return prop_driver_create_mapping_types; } UI_context_active_but_prop_get(C, &ptr, &prop, &index); if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) { const bool is_array = RNA_property_array_check(prop); while (input->identifier) { if (ELEM(input->value, CREATEDRIVER_MAPPING_1_1, CREATEDRIVER_MAPPING_NONE) || (is_array)) { RNA_enum_item_add(&item, &totitem, input); } input++; } } else { /* We need at least this one! */ RNA_enum_items_add_value(&item, &totitem, input, CREATEDRIVER_MAPPING_NONE); } RNA_enum_item_end(&item, &totitem); *r_free = true; return item; }
static EnumPropertyItem *rna_ComponentSetProperty_itemf(bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free) { PythonComponentProperty *cprop = (PythonComponentProperty *)(ptr->data); EnumPropertyItem *items = NULL; int totitem = 0; int j = 0; for (LinkData *link = cprop->enumval.first; link; link = link->next, ++j) { EnumPropertyItem item = {0, "", 0, "", ""}; item.value = j; item.identifier = link->data; item.icon = 0; item.name = link->data; item.description = ""; RNA_enum_item_add(&items, &totitem, &item); } RNA_enum_item_end(&items, &totitem); *r_free = true; return items; }
static EnumPropertyItem *vgroup_itemf(bContext *C, PointerRNA *ptr, int *free) { Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; EnumPropertyItem tmp = {0, "", 0, "", ""}; EnumPropertyItem *item= NULL; bDeformGroup *def; int a, totitem= 0; if(!ob) return vgroup_items; for(a=0, def=ob->defbase.first; def; def=def->next, a++) { tmp.value= a; tmp.identifier= def->name; tmp.name= def->name; RNA_enum_item_add(&item, &totitem, &tmp); } RNA_enum_item_end(&item, &totitem); *free= 1; return item; }
static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, int *defvalue, const short is_enum_flag) { EnumPropertyItem *items= NULL; PyObject *item; int seq_len, i, totitem= 0; short def_used= 0; const char *def_cmp= NULL; seq_len= PySequence_Fast_GET_SIZE(seq_fast); if(is_enum_flag) { if(seq_len > RNA_ENUM_BITFLAG_SIZE) { PyErr_SetString(PyExc_TypeError, "EnumProperty(...): maximum " STRINGIFY(RNA_ENUM_BITFLAG_SIZE) " members for a ENUM_FLAG type property"); return NULL; } if(def && !PySet_Check(def)) { PyErr_Format(PyExc_TypeError, "EnumProperty(...): default option must be a 'set' type when ENUM_FLAG is enabled, not a '%.200s'", Py_TYPE(def)->tp_name); return NULL; } } else { if(def) { def_cmp= _PyUnicode_AsString(def); if(def_cmp==NULL) { PyErr_Format(PyExc_TypeError, "EnumProperty(...): default option must be a 'str' type when ENUM_FLAG is disabled, not a '%.200s'", Py_TYPE(def)->tp_name); return NULL; } } } /* blank value */ *defvalue= 0; for(i=0; i<seq_len; i++) { EnumPropertyItem tmp= {0, "", 0, "", ""}; item= PySequence_Fast_GET_ITEM(seq_fast, i); if(PyTuple_Check(item)==0) { PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected a sequence of tuples for the enum items"); if(items) MEM_freeN(items); return NULL; } if(!PyArg_ParseTuple(item, "sss", &tmp.identifier, &tmp.name, &tmp.description)) { PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected an identifier, name and description in the tuple"); return NULL; } if(is_enum_flag) { tmp.value= 1<<i; if(def && PySet_Contains(def, PyTuple_GET_ITEM(item, 0))) { *defvalue |= tmp.value; def_used++; } } else { tmp.value= i; if(def && def_used == 0 && strcmp(def_cmp, tmp.identifier)==0) { *defvalue= tmp.value; def_used++; /* only ever 1 */ } } RNA_enum_item_add(&items, &totitem, &tmp); } RNA_enum_item_end(&items, &totitem); if(is_enum_flag) { /* strict check that all set members were used */ if(def && def_used != PySet_GET_SIZE(def)) { MEM_freeN(items); PyErr_Format(PyExc_TypeError, "EnumProperty(..., default={...}): set has %d unused member(s)", PySet_GET_SIZE(def) - def_used); return NULL; } } else { if(def && def_used == 0) { MEM_freeN(items); PyErr_Format(PyExc_TypeError, "EnumProperty(..., default=\'%s\'): not found in enum members", def); return NULL; } } return items; }
/* Note: rna_enum_dt_layers_select_src_items enum is from rna_modifier.c */ static EnumPropertyItem *dt_layers_select_src_itemf( bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free) { EnumPropertyItem *item = NULL, tmp_item = {0}; int totitem = 0; const int data_type = RNA_enum_get(ptr, "data_type"); if (!C) { /* needed for docs and i18n tools */ return rna_enum_dt_layers_select_src_items; } RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ACTIVE_SRC); RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ALL_SRC); if (data_type == DT_TYPE_MDEFORMVERT) { Object *ob_src = CTX_data_active_object(C); if (BKE_object_pose_armature_get(ob_src)) { RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_VGROUP_SRC_BONE_SELECT); RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_VGROUP_SRC_BONE_DEFORM); } if (ob_src) { bDeformGroup *dg; int i; RNA_enum_item_add_separator(&item, &totitem); for (i = 0, dg = ob_src->defbase.first; dg; i++, dg = dg->next) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = dg->name; RNA_enum_item_add(&item, &totitem, &tmp_item); } } } else if (data_type == DT_TYPE_SHAPEKEY) { /* TODO */ } else if (data_type == DT_TYPE_UV) { Object *ob_src = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); if (ob_src) { DerivedMesh *dm_src; CustomData *pdata; int num_data, i; /* XXX Is this OK? */ dm_src = mesh_get_derived_final(scene, ob_src, CD_MASK_BAREMESH | CD_MTEXPOLY); pdata = dm_src->getPolyDataLayout(dm_src); num_data = CustomData_number_of_layers(pdata, CD_MTEXPOLY); RNA_enum_item_add_separator(&item, &totitem); for (i = 0; i < num_data; i++) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(pdata, CD_MTEXPOLY, i); RNA_enum_item_add(&item, &totitem, &tmp_item); } } } else if (data_type == DT_TYPE_VCOL) { Object *ob_src = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); if (ob_src) { DerivedMesh *dm_src; CustomData *ldata; int num_data, i; /* XXX Is this OK? */ dm_src = mesh_get_derived_final(scene, ob_src, CD_MASK_BAREMESH | CD_MLOOPCOL); ldata = dm_src->getLoopDataLayout(dm_src); num_data = CustomData_number_of_layers(ldata, CD_MLOOPCOL); RNA_enum_item_add_separator(&item, &totitem); for (i = 0; i < num_data; i++) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(ldata, CD_MLOOPCOL, i); RNA_enum_item_add(&item, &totitem, &tmp_item); } } } RNA_enum_item_end(&item, &totitem); *r_free = true; return item; }