Blender  V3.3
armature_selection.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BKE_armature.hh"
8 
9 #include "BLI_listbase.h"
10 
11 #include "DNA_action_types.h"
12 #include "DNA_armature_types.h"
13 
14 namespace blender::bke {
15 
16 namespace {
17 
18 void find_selected_bones__visit_bone(const bArmature *armature,
20  SelectedBonesResult &result,
21  Bone *bone)
22 {
23  const bool is_selected = PBONE_SELECTED(armature, bone);
24  result.all_bones_selected &= is_selected;
25  result.no_bones_selected &= !is_selected;
26 
27  if (is_selected) {
28  callback(bone);
29  }
30 
31  LISTBASE_FOREACH (Bone *, child_bone, &bone->childbase) {
32  find_selected_bones__visit_bone(armature, callback, result, child_bone);
33  }
34 }
35 } // namespace
36 
39 {
41  LISTBASE_FOREACH (Bone *, root_bone, &armature->bonebase) {
42  find_selected_bones__visit_bone(armature, callback, result, root_bone);
43  }
44 
45  return result;
46 }
47 
49 {
50  BoneNameSet selected_bone_names;
51 
52  /* Iterate over the selected bones to fill the set of bone names. */
53  auto callback = [&](Bone *bone) { selected_bone_names.add(bone->name); };
55 
56  /* If no bones are selected, act as if all are. */
57  if (result.all_bones_selected || result.no_bones_selected) {
58  return BoneNameSet();
59  }
60 
61  return selected_bone_names;
62 }
63 
64 } // namespace blender::bke
#define PBONE_SELECTED(arm, bone)
Definition: BKE_armature.h:557
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
bool add(const Key &key)
Definition: BLI_set.hh:253
DEGForeachIDComponentCallback callback
SelectedBonesResult BKE_armature_find_selected_bones(const bArmature *armature, SelectedBoneCallback callback)
blender::Set< std::string > BoneNameSet
Definition: BKE_armature.hh:27
BoneNameSet BKE_armature_find_selected_bone_names(const bArmature *armature)
blender::FunctionRef< void(Bone *bone)> SelectedBoneCallback
Definition: BKE_armature.hh:23
ListBase childbase
ListBase bonebase