From 08eac0c3675ff4baff4ad3d0aae4d5ab10a8a133 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 9 Jul 2014 10:27:31 +0200 Subject: Add bone_groups.new() and bone_groups.remove() methods to RNA. To do so, matching BKE 'API' was also refactored a bit: * Get Pose data instead of Object, as parameter; * Removed some sanity checks not needed at such a low level (callers are supposed to do that); * You can now remove an arbitrary bone group, not only the active one. Based on patch by pkrime (Paolo Acampora), with own edits. Reviewers: #python, pkrime, aligorith Reviewed By: aligorith Differential Revision: https://developer.blender.org/D522 --- source/blender/blenkernel/intern/action.c | 76 ++++++++++++++++++------------- 1 file changed, 44 insertions(+), 32 deletions(-) (limited to 'source/blender/blenkernel/intern/action.c') diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 3219219bee5..8f1382dacc3 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -952,52 +952,52 @@ void framechange_poses_clear_unkeyed(void) /* ************************** Bone Groups ************************** */ -/* Adds a new bone-group */ -void BKE_pose_add_group(Object *ob) +/* Adds a new bone-group (name may be NULL) */ +bActionGroup *BKE_pose_add_group(bPose *pose, const char *name) { - bPose *pose = (ob) ? ob->pose : NULL; bActionGroup *grp; - if (ELEM(NULL, ob, ob->pose)) - return; + if (!name) { + name = DATA_("Group"); + } grp = MEM_callocN(sizeof(bActionGroup), "PoseGroup"); - BLI_strncpy(grp->name, DATA_("Group"), sizeof(grp->name)); + BLI_strncpy(grp->name, name, sizeof(grp->name)); BLI_addtail(&pose->agroups, grp); - BLI_uniquename(&pose->agroups, grp, DATA_("Group"), '.', offsetof(bActionGroup, name), sizeof(grp->name)); + BLI_uniquename(&pose->agroups, grp, name, '.', offsetof(bActionGroup, name), sizeof(grp->name)); pose->active_group = BLI_countlist(&pose->agroups); + + return grp; } -/* Remove the active bone-group */ -void BKE_pose_remove_group(Object *ob) +/* Remove the given bone-group (expects 'virtual' index (+1 one, used by active_group etc.)) + * index might be invalid ( < 1), in which case it will be find from grp. */ +void BKE_pose_remove_group(bPose *pose, bActionGroup *grp, const int index) { - bPose *pose = (ob) ? ob->pose : NULL; - bActionGroup *grp = NULL; bPoseChannel *pchan; + int idx = index; - /* sanity checks */ - if (ELEM(NULL, ob, pose)) - return; - if (pose->active_group <= 0) - return; + if (idx < 1) { + idx = BLI_findindex(&pose->agroups, grp) + 1; + } - /* get group to remove */ - grp = BLI_findlink(&pose->agroups, pose->active_group - 1); - if (grp) { - /* adjust group references (the trouble of using indices!): - * - firstly, make sure nothing references it - * - also, make sure that those after this item get corrected - */ - for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { - if (pchan->agrp_index == pose->active_group) - pchan->agrp_index = 0; - else if (pchan->agrp_index > pose->active_group) - pchan->agrp_index--; - } - - /* now, remove it from the pose */ - BLI_freelinkN(&pose->agroups, grp); + BLI_assert(idx > 0); + + /* adjust group references (the trouble of using indices!): + * - firstly, make sure nothing references it + * - also, make sure that those after this item get corrected + */ + for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { + if (pchan->agrp_index == idx) + pchan->agrp_index = 0; + else if (pchan->agrp_index > idx) + pchan->agrp_index--; + } + + /* now, remove it from the pose */ + BLI_freelinkN(&pose->agroups, grp); + if (pose->active_group >= idx) { pose->active_group--; if (pose->active_group < 0 || BLI_listbase_is_empty(&pose->agroups)) { pose->active_group = 0; @@ -1005,6 +1005,18 @@ void BKE_pose_remove_group(Object *ob) } } +/* Remove the indexed bone-group (expects 'virtual' index (+1 one, used by active_group etc.)) */ +void BKE_pose_remove_group_index(bPose *pose, const int index) +{ + bActionGroup *grp = NULL; + + /* get group to remove */ + grp = BLI_findlink(&pose->agroups, index - 1); + if (grp) { + BKE_pose_remove_group(pose, grp, index); + } +} + /* ************** F-Curve Utilities for Actions ****************** */ /* Check if the given action has any keyframes */ -- cgit v1.2.3