Blender V4.5
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
17namespace blender::bke {
18
19namespace {
20
21void find_selected_bones__visit_bone(const bArmature *armature,
22 SelectedBoneCallback callback,
24 Bone *bone)
25{
26 const bool is_selected = PBONE_SELECTED(armature, bone);
27 result.all_bones_selected &= is_selected;
28 result.no_bones_selected &= !is_selected;
29
30 if (is_selected) {
31 callback(bone);
32 }
33
34 LISTBASE_FOREACH (Bone *, child_bone, &bone->childbase) {
35 find_selected_bones__visit_bone(armature, callback, result, child_bone);
36 }
37}
38} // namespace
39
41 SelectedBoneCallback callback)
42{
44 LISTBASE_FOREACH (Bone *, root_bone, &armature->bonebase) {
45 find_selected_bones__visit_bone(armature, callback, result, root_bone);
46 }
47
48 return result;
49}
50
52{
53 BoneNameSet selected_bone_names;
54
55 /* Iterate over the selected bones to fill the set of bone names. */
56 auto callback = [&](Bone *bone) { selected_bone_names.add(bone->name); };
57 BKE_armature_find_selected_bones(armature, callback);
58 return selected_bone_names;
59}
60
61} // namespace blender::bke
Functions to deal with Armatures.
#define PBONE_SELECTED(arm, bone)
#define LISTBASE_FOREACH(type, var, list)
struct Bone Bone
struct bArmature bArmature
bool add(const Key &key)
Definition BLI_set.hh:248
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
ListBase childbase