Blender V4.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
9#include "BKE_armature.hh"
10
11#include "BLI_listbase.h"
12
13#include "DNA_action_types.h"
14#include "DNA_armature_types.h"
15
17
18namespace blender::bke {
19
20namespace {
21
22void find_selected_bones__visit_bone(const bArmature *armature,
24 SelectedBonesResult &result,
25 Bone *bone)
26{
27 const bool is_selected = PBONE_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} // namespace
40
43{
45 LISTBASE_FOREACH (Bone *, root_bone, &armature->bonebase) {
46 find_selected_bones__visit_bone(armature, callback, result, root_bone);
47 }
48
49 return result;
50}
51
53{
54 BoneNameSet selected_bone_names;
55
56 /* Iterate over the selected bones to fill the set of bone names. */
57 auto callback = [&](Bone *bone) { selected_bone_names.add(bone->name); };
59
60 /* If no bones are selected, act as if all are. */
61 if (result.all_bones_selected || result.no_bones_selected) {
62 return BoneNameSet();
63 }
64
65 return selected_bone_names;
66}
67
68} // namespace blender::bke
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
#define PBONE_SELECTED(arm, bone)
#define LISTBASE_FOREACH(type, var, list)
bool add(const Key &key)
Definition BLI_set.hh:248
DEGForeachIDComponentCallback callback
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