Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/armature/armature_naming.c
| Show First 20 Lines • Show All 291 Lines • ▼ Show 20 Lines | /* correct view locking */ | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #define BONE_TEMP_SUFFIX "_BR" | |||||
| static void temp_suffix_add(char name[MAXBONENAME]) | |||||
| { | |||||
| BLI_strncpy(name + BLI_strnlen(name, MAXBONENAME), BONE_TEMP_SUFFIX, MAXBONENAME); | |||||
| } | |||||
| static void temp_suffix_del(char name[MAXBONENAME]) | |||||
| { | |||||
mont29: //sigh// I did not say 'no doxygen', I said 'use the `\<doxycommand>` syntax, not the… | |||||
| int len = BLI_strnlen(name, MAXBONENAME); | |||||
| name[len - strlen(BONE_TEMP_SUFFIX)] = '\0'; | |||||
| } | |||||
| #undef BONE_TEMP_SUFFIX | |||||
| /** | |||||
| * @brief ED_armature_bones_flip_names | |||||
mont29Unsubmitted Not Done Inline Actions\<doxycommand>, not @<doxycommand> please ;) mont29: `\<doxycommand>`, not `@<doxycommand>` please ;) | |||||
| * | |||||
| * Renames (by flipping) all selected bones at once. | |||||
| * | |||||
| * This way if we are flipping related bones (e.g., Bone.L, Bone.R) at the same time | |||||
| * all the bones are safely renamed, without conflicting with each other. | |||||
| * | |||||
| * @param arm Armature the bones belong to | |||||
| * @param bones ListBase of LinkData elems, where LinkData->data points to the bone name | |||||
mont29Unsubmitted Not Done Inline Actionssame, no @ for doxygen commands mont29: same, no `@` for doxygen commands | |||||
| */ | |||||
| void ED_armature_bones_flip_names(bArmature *arm, ListBase *bones_names) | |||||
| { | |||||
| ListBase lb_conflict = {NULL}; | |||||
| /* loop through selected bones, auto-naming them */ | |||||
| for (LinkData *link = bones_names->first; link; link = link->next) { | |||||
| char name_flip[MAXBONENAME]; | |||||
| char *name = link->data; | |||||
| BKE_deform_flip_side_name(name_flip, name, true); | |||||
| /* In case Bone.L is being flipped at the same time as Bone.R | |||||
| * one of them will have to be solved later */ | |||||
| if (BLI_findstring_ptr(bones_names, name_flip, offsetof(LinkData, data))) { | |||||
| BLI_addtail(&lb_conflict, BLI_genericNodeN(name)); | |||||
Not Done Inline ActionsThis can be done much more efficiently I think, no need for three loops, in first one you can:
Then second loop only runs over actual conflicts to perfom second rename. mont29: This can be done much more efficiently I think, no need for three loops, in first one you can… | |||||
| temp_suffix_add(name_flip); | |||||
| } | |||||
| ED_armature_bone_rename(arm, name, name_flip); | |||||
| } | |||||
| /* Loop over "conflict bones" renaming them accordingly */ | |||||
| for (LinkData *link = lb_conflict.first; link; link = link->next) { | |||||
| char name_flip[MAXBONENAME]; | |||||
| char *name = link->data; | |||||
| BLI_strncpy(name_flip, name, MAXBONENAME); | |||||
| temp_suffix_del(name_flip); | |||||
| ED_armature_bone_rename(arm, name, name_flip); | |||||
| } | |||||
| BLI_freelistN(&lb_conflict); | |||||
| } | |||||
| /* ************************************************** */ | /* ************************************************** */ | ||||
| /* Bone Renaming - EditMode */ | /* Bone Renaming - EditMode */ | ||||
| static int armature_flip_names_exec(bContext *C, wmOperator *UNUSED(op)) | static int armature_flip_names_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Object *ob = CTX_data_edit_object(C); | Object *ob = CTX_data_edit_object(C); | ||||
| bArmature *arm; | bArmature *arm; | ||||
| /* paranoia checks */ | /* paranoia checks */ | ||||
| if (ELEM(NULL, ob, ob->pose)) | if (ELEM(NULL, ob, ob->pose)) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| arm = ob->data; | arm = ob->data; | ||||
| /* loop through selected bones, auto-naming them */ | ListBase bones_names = {NULL}; | ||||
| CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) | CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) | ||||
| { | { | ||||
| char name_flip[MAXBONENAME]; | BLI_addtail(&bones_names, BLI_genericNodeN(ebone->name)); | ||||
| BKE_deform_flip_side_name(name_flip, ebone->name, true); | |||||
| ED_armature_bone_rename(arm, ebone->name, name_flip); | |||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| ED_armature_bones_flip_names(arm, &bones_names); | |||||
| BLI_freelistN(&bones_names); | |||||
| /* since we renamed stuff... */ | /* since we renamed stuff... */ | ||||
| DAG_id_tag_update(&ob->id, OB_RECALC_DATA); | DAG_id_tag_update(&ob->id, OB_RECALC_DATA); | ||||
| /* copied from #rna_Bone_update_renamed */ | /* copied from #rna_Bone_update_renamed */ | ||||
| /* redraw view */ | /* redraw view */ | ||||
| WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); | WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); | ||||
| /* update animation channels */ | /* update animation channels */ | ||||
| ▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines | |||||
sigh I did not say 'no doxygen', I said 'use the \<doxycommand> syntax, not the @<doxycommand> syntax'!
So \param, not @param, etc. (though the \brief one was indeed useless).