Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/armature/armature_naming.c
| Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_constraint.h" | #include "BKE_constraint.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_deform.h" | #include "BKE_deform.h" | ||||
| #include "BKE_depsgraph.h" | #include "BKE_depsgraph.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "MEM_guardedalloc.h" | |||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "ED_armature.h" | #include "ED_armature.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| ▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | /* correct view locking */ | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * 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. | |||||
| * | |||||
| * arm - Armature the bones belong to | |||||
| * bones - ListBase of LinkData elems, where LinkData->data points to the bone name | |||||
| */ | |||||
mont29: //sigh// I did not say 'no doxygen', I said 'use the `\<doxycommand>` syntax, not the… | |||||
| typedef struct BoneConflict { | |||||
| struct BoneConflict *next, *prev; | |||||
| char *name; | |||||
| char new_name[MAXBONENAME]; | |||||
| } BoneConflict; | |||||
| void ED_armature_bones_flip_names(bArmature *arm, ListBase *bones_names) | |||||
Not Done Inline Actions\<doxycommand>, not @<doxycommand> please ;) mont29: `\<doxycommand>`, not `@<doxycommand>` please ;) | |||||
| { | |||||
| ListBase bones = {NULL}; | |||||
| for (LinkData *link = bones_names->first; link; link = link->next) { | |||||
| BoneConflict *bc = MEM_callocN(sizeof(BoneConflict), "BoneConflict"); | |||||
| bc->name = link->data; | |||||
| BKE_deform_flip_side_name(bc->new_name, bc->name, true); | |||||
| BLI_addtail(&bones, bc); | |||||
Not Done Inline Actionssame, no @ for doxygen commands mont29: same, no `@` for doxygen commands | |||||
| } | |||||
| /* first pass, just rename all bones */ | |||||
| for (BoneConflict *bc = bones.first; bc; bc = bc->next) { | |||||
| ED_armature_bone_rename(arm, bc->name, bc->new_name); | |||||
| } | |||||
| /* second pass to handle the bones that have naming conflicts with other selected bones */ | |||||
| for (BoneConflict *bc = bones.first; bc; bc = bc->next) { | |||||
| if (!STREQ(bc->name, bc->new_name)) { | |||||
| ED_armature_bone_rename(arm, bc->name, bc->new_name); | |||||
| } | |||||
| } | |||||
| BLI_freelistN(&bones); | |||||
| } | |||||
mont29Unsubmitted 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… | |||||
| /* ************************************************** */ | /* ************************************************** */ | ||||
| /* 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).