57 if (armature ==
nullptr) {
63 "Cannot add bone collections to a linked Armature without an "
64 "override on the Armature Data");
70 "Cannot add bone collections to a linked Armature with a system "
71 "override; explicitly create an override on the Armature Data");
82 if (armature ==
nullptr) {
88 "Cannot update a linked Armature with a system override; "
89 "explicitly create an override on the Armature Data");
94 if (bcoll ==
nullptr) {
101 C,
"Cannot edit bone collections that are linked from another blend file");
135 ot->
name =
"Add Bone Collection";
136 ot->
idname =
"ARMATURE_OT_collection_add";
163 ot->
name =
"Remove Bone Collection";
164 ot->
idname =
"ARMATURE_OT_collection_remove";
165 ot->
description =
"Remove the active bone collection";
197 {-1,
"UP", 0,
"Up",
""},
198 {1,
"DOWN", 0,
"Down",
""},
199 {0,
nullptr, 0,
nullptr,
nullptr},
203 ot->
name =
"Move Bone Collection";
204 ot->
idname =
"ARMATURE_OT_collection_move";
205 ot->
description =
"Change position of active Bone Collection in list of Bone collections";
219 "Direction to move the active Bone Collection towards");
229 if (bcoll_name[0] ==
'\0') {
252 bool *made_any_changes,
253 bool *had_bones_to_assign)
257 *made_any_changes |= assign_func(bcoll, pchan->bone_get(*ob));
258 *had_bones_to_assign =
true;
272 bool *made_any_changes,
273 bool *had_bones_to_assign)
282 *made_any_changes |= assign_func(bcoll, &ebone);
283 *had_bones_to_assign =
true;
301 bool *made_any_changes,
302 bool *had_bones_to_assign)
332 const char *bone_name,
335 bool *made_any_changes,
336 bool *had_bones_to_assign)
347 *had_bones_to_assign =
true;
361 *had_bones_to_assign =
true;
395 C,
"Cannot edit bone collections on linked Armatures without override");
400 "Cannot edit bone collections on a linked Armature with a system "
401 "override; explicitly create an override on the Armature Data");
421 if (bcoll ==
nullptr) {
431 bool made_any_changes =
false;
432 bool had_bones_to_assign =
false;
440 &had_bones_to_assign);
442 if (!mode_is_supported) {
444 op->
reports,
RPT_ERROR,
"This operator only works in pose mode and armature edit mode");
447 if (!had_bones_to_assign) {
452 if (!made_any_changes) {
465 ot->
name =
"Add Selected Bones to Collection";
466 ot->
idname =
"ARMATURE_OT_collection_assign";
467 ot->
description =
"Add selected bones to the chosen bone collection";
482 "Name of the bone collection to assign this bone to; empty to assign to the "
483 "active bone collection");
501 C,
"Cannot edit bone collections on linked Armatures without override");
506 "Cannot edit bone collections on a linked Armature with a system "
507 "override; explicitly create an override on the Armature Data");
531 bool made_any_changes =
false;
532 bool had_bones_to_assign =
false;
540 &had_bones_to_assign);
542 if (!mode_is_supported) {
544 op->
reports,
RPT_ERROR,
"This operator only works in pose mode and armature edit mode");
548 if (!had_bones_to_assign) {
564 ot->
name =
"Add Selected Bones to New Collection";
565 ot->
idname =
"ARMATURE_OT_collection_create_and_assign";
566 ot->
description =
"Create a new bone collection and assign all selected bones";
581 "Name of the bone collection to create");
592 if (bcoll ==
nullptr) {
596 bool made_any_changes =
false;
597 bool had_bones_to_unassign =
false;
605 &had_bones_to_unassign);
607 if (!mode_is_supported) {
609 op->
reports,
RPT_ERROR,
"This operator only works in pose mode and armature edit mode");
612 if (!had_bones_to_unassign) {
614 op->
reports,
RPT_WARNING,
"No bones selected, nothing to unassign from bone collection");
617 if (!made_any_changes) {
619 op->
reports,
RPT_WARNING,
"None of the selected bones were assigned to this collection");
628 ot->
name =
"Remove Selected from Bone collections";
629 ot->
idname =
"ARMATURE_OT_collection_unassign";
630 ot->
description =
"Remove selected bones from the active bone collection";
644 "Name of the bone collection to unassign this bone from; empty to unassign from "
645 "the active bone collection");
656 if (bcoll ==
nullptr) {
667 bool made_any_changes =
false;
668 bool had_bones_to_unassign =
false;
677 &had_bones_to_unassign);
679 if (!mode_is_supported) {
681 op->
reports,
RPT_ERROR,
"This operator only works in pose mode and armature edit mode");
684 if (!had_bones_to_unassign) {
688 if (!made_any_changes) {
691 "Bone '%s' was not assigned to collection '%s'",
702 ot->
name =
"Remove Bone from Bone Collection";
703 ot->
idname =
"ARMATURE_OT_collection_unassign_named";
704 ot->
description =
"Unassign the named bone from this bone collection";
718 "Name of the bone collection to unassign this bone from; empty to unassign from "
719 "the active bone collection");
725 "Name of the bone to unassign from the collection; empty to use the active bone");
731 if (ref.
bcoll == bcoll) {
747 C,
"Cannot (de)select bones on linked object, that would need an override");
753 if (armature ==
nullptr) {
757 const bool is_editmode = armature->
edbo !=
nullptr;
761 active_object->
data != id_cast<const ID *>(armature))
782 const bool is_editmode = armature->
edbo !=
nullptr;
798 active_object->
data != id_cast<const ID *>(armature))
807 BLI_assert_msg(pose_bone !=
nullptr,
"The pose bones and armature bones are out of sync");
839 if (armature ==
nullptr) {
844 if (bcoll ==
nullptr) {
855 ot->
name =
"Select Bones of Bone Collection";
856 ot->
idname =
"ARMATURE_OT_collection_select";
857 ot->
description =
"Select bones in active Bone Collection";
870 if (armature ==
nullptr) {
875 if (bcoll ==
nullptr) {
886 ot->
name =
"Deselect Bone Collection";
887 ot->
idname =
"ARMATURE_OT_collection_deselect";
888 ot->
description =
"Deselect bones of active Bone Collection";
902 const int collection_index =
RNA_int_get(op->
ptr,
"collection_index");
910 (collection_index < 0))
917 "It should always be possible to create a new bone collection on an armature");
921 if (index_exceeds_range) {
924 "Bone collection with index %d not found on Armature %s",
935 "Bone collection %s is not editable, maybe add an override on the armature Data?",
964 bool made_any_changes =
false;
965 bool had_bones_to_assign =
false;
972 &had_bones_to_assign);
974 if (!mode_is_supported) {
976 op->
reports,
RPT_ERROR,
"This operator only works in pose mode and armature edit mode");
979 if (!had_bones_to_assign) {
984 if (!made_any_changes) {
1014 if (ob ==
nullptr) {
1031 "Cannot update a linked Armature with a system override; "
1032 "explicitly create an override on the Armature Data");
1056 const uintptr_t index_and_move_bit = ((bcoll_index + 1) << 1) | (is_move_operation << 0);
1057 return reinterpret_cast<void *
>(index_and_move_bit);
1067 const uintptr_t index_and_move_bit =
reinterpret_cast<intptr_t>(menu_custom_data);
1068 const bool is_move_operation = (index_and_move_bit & 1) == 1;
1069 const int bcoll_index = int(index_and_move_bit >> 1) - 1;
1070 return std::make_pair(bcoll_index, is_move_operation);
1075 return collection_contains_active_bone ? ICON_REMOVE : ICON_ADD;
1081 const int bcoll_index,
1082 const bool is_move_operation)
1084 if (is_move_operation) {
1085 PointerRNA op_ptr = layout.
op(
"ARMATURE_OT_move_to_collection", bcoll->
name, ICON_NONE);
1086 RNA_int_set(&op_ptr,
"collection_index", bcoll_index);
1093 if (contains_active_bone) {
1094 PointerRNA op_ptr = layout.
op(
"ARMATURE_OT_collection_unassign", bcoll->
name, icon);
1098 PointerRNA op_ptr = layout.
op(
"ARMATURE_OT_collection_assign", bcoll->
name, icon);
1116 int parent_bcoll_index;
1117 bool is_move_operation;
1127 is_move_operation ?
"ARMATURE_OT_move_to_collection" :
"ARMATURE_OT_assign_to_collection",
1130 RNA_int_set(&op_ptr,
"collection_index", parent_bcoll_index);
1138 int child_index, child_count;
1139 if (parent_bcoll_index == -1) {
1149 *layout, arm, parent, parent_bcoll_index, is_move_operation);
1158 for (
int index = child_index;
index < child_index + child_count;
index++) {
1188 const bool is_move_operation =
STREQ(op->
type->
idname,
"ARMATURE_OT_move_to_collection");
1191 popup_menu_end(
C, pup);
1200 C, op, 200,
IFACE_(
"Move to New Bone Collection"),
IFACE_(
"Create"));
1222 ot->
name =
"Move to Collection";
1224 ot->
idname =
"ARMATURE_OT_move_to_collection";
1244 "Index of the collection to move selected bones to. When the operator should create a new "
1245 "bone collection, do not include this parameter and pass new_collection_name",
1252 "new_collection_name",
1256 "Name of a to-be-added bone collection. Only pass this if you want to create a new bone "
1257 "collection and move the selected bones to it. To move to an existing collection, do not "
1258 "include this parameter and use collection_index");
1268 ot->
name =
"Assign to Collection";
1270 "Assign all selected bones to a collection, or unassign them, depending on whether the "
1271 "active bone is already assigned or not";
1272 ot->
idname =
"ARMATURE_OT_assign_to_collection";
1292 "Index of the collection to assign selected bones to. When the operator should create a new "
1293 "bone collection, use new_collection_name to define the collection name, and set this "
1294 "parameter to the parent index of the new bone collection",
1301 "new_collection_name",
1305 "Name of a to-be-added bone collection. Only pass this if you want to create a new bone "
1306 "collection and assign the selected bones to it. To assign to an existing collection, do "
1307 "not include this parameter and use collection_index");
Functions to deal with Armatures.
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
Blender kernel action and pose functionality.
#define FOREACH_PCHAN_SELECTED_IN_OBJECT_END
#define FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN(_ob, _pchan)
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
ID and Library types, which are fundamental for SDNA.
#define ID_IS_EDITABLE(_id)
#define ID_IS_OVERRIDE_LIBRARY(_id)
Object is a sort of wrapper for general info.
#define EBONE_SELECTABLE(arm, ebone)
#define EBONE_EDITABLE(ebone)
#define ND_BONE_COLLECTION
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
void bone_deselect(bPoseChannel *pchan)
bool bone_is_visible(const bArmature *armature, const Bone *bone)
bool bonecoll_has_children(const BoneCollection *bcoll)
int armature_bonecoll_child_number_set(bArmature *armature, BoneCollection *bcoll, int new_child_number)
int armature_bonecoll_find_parent_index(const bArmature *armature, int bcoll_index)
int armature_bonecoll_child_number_find(const bArmature *armature, const BoneCollection *bcoll)
void bone_select(bPoseChannel *pchan)
Object * context_object(const bContext *C)
Object * context_active_object(const bContext *C)
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
void WM_main_add_notifier(uint type, void *reference)
static void bone_collection_assign_pchans(bContext *C, Object *ob, BoneCollection *bcoll, assign_bone_func assign_func, bool *made_any_changes, bool *had_bones_to_assign)
static wmOperatorStatus bone_collection_add_exec(bContext *C, wmOperator *)
void ARMATURE_OT_collection_move(wmOperatorType *ot)
static wmOperatorStatus bone_collection_assign_exec(bContext *C, wmOperator *op)
static bool bone_collection_add_poll(bContext *C)
static void move_to_collection_menu_create(bContext *C, ui::Layout *layout, void *menu_custom_data)
bool ANIM_armature_bonecoll_assign(BoneCollection *bcoll, Bone *bone)
static wmOperatorStatus bone_collection_create_and_assign_exec(bContext *C, wmOperator *op)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static bool bone_collection_create_and_assign_poll(bContext *C)
bool ANIM_armature_bonecoll_assign_editbone(BoneCollection *bcoll, EditBone *ebone)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void ED_outliner_select_sync_from_pose_bone_tag(bContext *C)
static bool bone_collection_assign_named_mode_specific(bContext *C, Object *ob, BoneCollection *bcoll, const char *bone_name, assign_bone_func assign_bone_func, assign_ebone_func assign_ebone_func, bool *made_any_changes, bool *had_bones_to_assign)
static bool active_bone_collection_poll(bContext *C)
static wmOperatorStatus bone_collection_select_exec(bContext *C, wmOperator *)
void ARMATURE_OT_collection_select(wmOperatorType *ot)
bool(*)(BoneCollection *bcoll, EditBone *ebone) assign_ebone_func
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
BoneCollection * ANIM_armature_bonecoll_new(bArmature *armature, const char *name, int parent_index=-1)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static void * menu_custom_data_encode(const int bcoll_index, const bool is_move_operation)
void ANIM_armature_bonecoll_remove(bArmature *armature, BoneCollection *bcoll)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static wmOperatorStatus move_to_collection_invoke(bContext *C, wmOperator *op, const wmEvent *)
int RNA_int_get(PointerRNA *ptr, const char *name)
bool ANIM_armature_bonecoll_assign_and_move(BoneCollection *bcoll, Bone *bone)
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
void ARMATURE_OT_collection_add(wmOperatorType *ot)
void ANIM_armature_bonecoll_active_runtime_refresh(bArmature *armature)
bool BKE_lib_override_library_is_system_defined(const Main *bmain, const ID *id)
Object * ED_pose_object_from_context(bContext *C)
void ARMATURE_OT_assign_to_collection(wmOperatorType *ot)
static int icon_for_bone_collection(const bool collection_contains_active_bone)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
void ARMATURE_OT_collection_assign(wmOperatorType *ot)
static bool bone_collection_assign_poll(bContext *C)
static bool armature_bone_select_poll(bContext *C)
static void bone_collection_assign_editbones(bContext *C, Object *ob, BoneCollection *bcoll, assign_ebone_func assign_func, bool *made_any_changes, bool *had_bones_to_assign)
static BoneCollection * add_or_move_to_collection_bcoll(wmOperator *op, bArmature *arm)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
void ED_armature_edit_sync_selection(ListBaseT< EditBone > *edbo)
static void menu_add_item_for_move_assign_unassign(ui::Layout &layout, const bArmature *arm, const BoneCollection *bcoll, const int bcoll_index, const bool is_move_operation)
static wmOperatorStatus assign_to_collection_exec(bContext *C, wmOperator *op)
bool ANIM_armature_bonecoll_unassign_editbone(BoneCollection *bcoll, EditBone *ebone)
static wmOperatorStatus bone_collection_unassign_exec(bContext *C, wmOperator *op)
bArmature * ED_armature_context(const bContext *C)
BoneCollection * ANIM_armature_bonecoll_get_by_name(bArmature *armature, const char *name) ATTR_WARN_UNUSED_RESULT
static bool move_to_collection_poll(bContext *C)
void ARMATURE_OT_move_to_collection(wmOperatorType *ot)
bool ANIM_armature_bonecoll_contains_active_bone(const bArmature *armature, const BoneCollection *bcoll)
wmOperatorStatus WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message, const bool show_icon)
static wmOperatorStatus bone_collection_move_exec(bContext *C, wmOperator *op)
bool(*)(BoneCollection *bcoll, Bone *bone) assign_bone_func
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static wmOperatorStatus add_or_move_to_collection_exec(bContext *C, wmOperator *op, const assign_bone_func assign_func_bone, const assign_ebone_func assign_func_ebone)
_W64 unsigned int uintptr_t
bool ANIM_armature_bonecoll_assign_and_move_editbone(BoneCollection *bcoll, EditBone *ebone)
static wmOperatorStatus bone_collection_unassign_named_exec(bContext *C, wmOperator *op)
static BoneCollection * get_bonecoll_named_or_active(bContext *, wmOperator *op, Object *ob)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
static wmOperatorStatus move_to_new_collection_invoke(bContext *C, wmOperator *op)
static bool editbone_is_member(const EditBone *ebone, const BoneCollection *bcoll)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void ANIM_armature_bonecoll_active_set(bArmature *armature, BoneCollection *bcoll)
void ARMATURE_OT_collection_deselect(wmOperatorType *ot)
static wmOperatorStatus bone_collection_deselect_exec(bContext *C, wmOperator *)
void ED_outliner_select_sync_from_edit_bone_tag(bContext *C)
static wmOperatorStatus bone_collection_remove_exec(bContext *C, wmOperator *)
void ARMATURE_OT_collection_create_and_assign(wmOperatorType *ot)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
bool ANIM_armature_bonecoll_unassign(BoneCollection *bcoll, Bone *bone)
static bool bone_collection_assign_mode_specific(bContext *C, Object *ob, BoneCollection *bcoll, assign_bone_func assign_bone_func, assign_ebone_func assign_ebone_func, bool *made_any_changes, bool *had_bones_to_assign)
static wmOperatorStatus move_to_collection_regular_invoke(bContext *C, wmOperator *op)
static wmOperatorStatus move_to_collection_exec(bContext *C, wmOperator *op)
void ARMATURE_OT_collection_remove(wmOperatorType *ot)
static std::pair< int, bool > menu_custom_data_decode(void *menu_custom_data)
static void bone_collection_select(bContext *C, bArmature *armature, BoneCollection *bcoll, const bool select)
void ED_armature_ebone_select_set(EditBone *ebone, bool select)
bool ANIM_armature_bonecoll_move(bArmature *armature, BoneCollection *bcoll, int step)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void ARMATURE_OT_collection_unassign_named(wmOperatorType *ot)
EditBone * ED_armature_ebone_find_name(const ListBaseT< EditBone > *edbo, const char *name)
bool ANIM_armature_bonecoll_is_editable(const bArmature *armature, const BoneCollection *bcoll)
void ARMATURE_OT_collection_unassign(wmOperatorType *ot)
struct BoneCollection * bcoll
ListBaseT< BoneCollectionMember > bones
ListBaseT< BoneCollectionReference > bone_collections
ListBaseT< EditBone > * edbo
bke::bArmature_Runtime * runtime
struct BoneCollection ** collection_array
int collection_root_count
int active_collection_index
BoneCollection * active_collection
void enabled_set(bool enabled)
void operator_context_set(wm::OpCallContext opcontext)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
void menu_fn(StringRefNull name, int icon, MenuCreateFunc func, void *arg)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
const char * translation_context
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
struct wmOperatorType * type