Blender V5.3
armature_selection.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "ANIM_armature.hh"
10
11#include "BKE_armature.hh"
12
13#include "BLI_listbase.hh"
14
15#include "DNA_armature_types.h"
16#include "DNA_object_types.h"
17
18namespace blender::bke {
19
20namespace {
21
22void find_selected_bones__visit_bone(const bArmature *armature,
23 SelectedBoneCallback callback,
25 Bone *bone)
26{
27 const bool is_selected = animrig::bone_is_selected(armature, bone);
28 result.all_bones_selected &= is_selected;
29 result.no_bones_selected &= !is_selected;
30
31 if (is_selected) {
32 callback(bone);
33 }
34
35 for (Bone &child_bone : bone->childbase) {
36 find_selected_bones__visit_bone(armature, callback, result, &child_bone);
37 }
38}
39
40} // namespace
41
43 SelectedBoneCallback callback)
44{
46 for (Bone &root_bone : armature->bonebase) {
47 find_selected_bones__visit_bone(armature, callback, result, &root_bone);
48 }
49
50 return result;
51}
52
54{
55 BoneNameSet selected_bone_names;
56
57 /* Iterate over the selected bones to fill the set of bone names. */
58 auto callback = [&](Bone *bone) { selected_bone_names.add(bone->name); };
59 BKE_armature_find_selected_bones(armature, callback);
60 return selected_bone_names;
61}
62
64{
65 if (!object->pose) {
66 return {};
67 }
68
69 BoneNameSet selected_bone_names;
70 const bArmature *armature = BKE_armature_from_object(const_cast<Object *>(object));
71 /* Since there is a pose, there should be an armature. */
72 BLI_assert(armature);
73 for (bPoseChannel &pose_bone : object->pose->chanbase) {
74 if (animrig::bone_is_selected(armature, {&pose_bone, pose_bone.bone_get(*object)})) {
75 selected_bone_names.add(pose_bone.name);
76 }
77 }
78 return selected_bone_names;
79}
80
81} // namespace blender::bke
Functions to deal with Armatures.
Object is a sort of wrapper for general info.
bool add(const Key &key)
Definition BLI_set.hh:248
bool bone_is_selected(const bArmature *armature, const Bone *bone)
FunctionRef< void(Bone *bone)> SelectedBoneCallback
SelectedBonesResult BKE_armature_find_selected_bones(const bArmature *armature, SelectedBoneCallback callback)
Set< std::string > BoneNameSet
BoneNameSet BKE_armature_find_selected_bone_names(const bArmature *armature)
BoneNameSet BKE_pose_channel_find_selected_names(const Object *object)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bArmature * BKE_armature_from_object(Object *ob)
ListBaseT< Bone > bonebase