Blender V5.0
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.h"
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 = blender::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 LISTBASE_FOREACH (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 LISTBASE_FOREACH (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 LISTBASE_FOREACH (bPoseChannel *, pose_bone, &object->pose->chanbase) {
71 if (pose_bone->flag & POSE_SELECTED) {
72 selected_bone_names.add(pose_bone->name);
73 }
74 }
75 return selected_bone_names;
76}
77
78} // namespace blender::bke
Functions to deal with Armatures.
#define LISTBASE_FOREACH(type, var, list)
@ POSE_SELECTED
struct Bone Bone
struct bArmature bArmature
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)
SelectedBonesResult BKE_armature_find_selected_bones(const bArmature *armature, SelectedBoneCallback callback)
blender::FunctionRef< void(Bone *bone)> SelectedBoneCallback
BoneNameSet BKE_armature_find_selected_bone_names(const bArmature *armature)
blender::Set< std::string > BoneNameSet
BoneNameSet BKE_pose_channel_find_selected_names(const Object *object)
ListBase childbase