/* note, must be freed */ int *defgroup_flip_map_single(Object *ob, int *flip_map_len, const bool use_default, int defgroup) { int defbase_tot = *flip_map_len = BLI_countlist(&ob->defbase); if (defbase_tot == 0) { return NULL; } else { bDeformGroup *dg; char name[sizeof(dg->name)]; int i, flip_num, *map = MEM_mallocN(defbase_tot * sizeof(int), __func__); for (i = 0; i < defbase_tot; i++) { map[i] = use_default ? i : -1; } dg = BLI_findlink(&ob->defbase, defgroup); flip_side_name(name, dg->name, FALSE); if (strcmp(name, dg->name)) { flip_num = defgroup_name_index(ob, name); if (flip_num != -1) { map[defgroup] = flip_num; map[flip_num] = defgroup; } } return map; } }
/* note, must be freed */ int *defgroup_flip_map(Object *ob, int use_default) { bDeformGroup *dg; int totdg= BLI_countlist(&ob->defbase); if(totdg==0) { return NULL; } else { char name[sizeof(dg->name)]; int i, flip_num, *map= MEM_mallocN(totdg * sizeof(int), "get_defgroup_flip_map"); memset(map, -1, totdg * sizeof(int)); for (dg=ob->defbase.first, i=0; dg; dg=dg->next, i++) { if(map[i] == -1) { /* may be calculated previously */ /* incase no valid value is found, use this */ if(use_default) map[i]= i; flip_side_name(name, dg->name, 0); if(strcmp(name, dg->name)) { flip_num= defgroup_name_index(ob, name); if(flip_num >= 0) { map[i]= flip_num; map[flip_num]= i; /* save an extra lookup */ } } } } return map; } }
int defgroup_flip_index(Object *ob, int index, const bool use_default) { bDeformGroup *dg = BLI_findlink(&ob->defbase, index); int flip_index = -1; if (dg) { char name[sizeof(dg->name)]; flip_side_name(name, dg->name, 0); if (strcmp(name, dg->name)) flip_index = defgroup_name_index(ob, name); } return (flip_index == -1 && use_default) ? index : flip_index; }
static int armature_flip_names_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_edit_object(C); bArmature *arm; char newname[MAXBONENAME]; /* paranoia checks */ if (ELEM(NULL, ob, ob->pose)) return OPERATOR_CANCELLED; arm = ob->data; /* loop through selected bones, auto-naming them */ CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) { flip_side_name(newname, ebone->name, TRUE); // 1 = do strip off number extensions ED_armature_bone_rename(arm, ebone->name, newname); }
/* note, must be freed */ int *defgroup_flip_map(Object *ob, int *flip_map_len, const bool use_default) { int defbase_tot = *flip_map_len = BLI_countlist(&ob->defbase); if (defbase_tot == 0) { return NULL; } else { bDeformGroup *dg; char name[sizeof(dg->name)]; int i, flip_num, *map = MEM_mallocN(defbase_tot * sizeof(int), __func__); for (i = 0; i < defbase_tot; i++) { map[i] = -1; } for (dg = ob->defbase.first, i = 0; dg; dg = dg->next, i++) { if (map[i] == -1) { /* may be calculated previously */ /* in case no valid value is found, use this */ if (use_default) map[i] = i; flip_side_name(name, dg->name, FALSE); if (strcmp(name, dg->name)) { flip_num = defgroup_name_index(ob, name); if (flip_num >= 0) { map[i] = flip_num; map[flip_num] = i; /* save an extra lookup */ } } } } return map; } }