Anim: Add bone.collections.clear() RNA function

Add the RNA function `bone.collections.clear()` to remove a bone from all
its collections.
This commit is contained in:
Sybren A. Stüvel
2023-09-08 15:16:05 +02:00
parent 9d65214d5b
commit 0ea79698ac
3 changed files with 33 additions and 6 deletions

View File

@@ -124,6 +124,7 @@ bool ANIM_armature_bonecoll_assign(struct BoneCollection *bcoll, struct Bone *bo
bool ANIM_armature_bonecoll_assign_editbone(struct BoneCollection *bcoll, struct EditBone *ebone);
bool ANIM_armature_bonecoll_assign_and_move(struct BoneCollection *bcoll, struct Bone *bone);
bool ANIM_armature_bonecoll_unassign(struct BoneCollection *bcoll, struct Bone *bone);
void ANIM_armature_bonecoll_unassign_all(struct Bone *bone);
bool ANIM_armature_bonecoll_unassign_editbone(struct BoneCollection *bcoll,
struct EditBone *ebone);

View File

@@ -265,11 +265,7 @@ bool ANIM_armature_bonecoll_assign_editbone(BoneCollection *bcoll, EditBone *ebo
bool ANIM_armature_bonecoll_assign_and_move(BoneCollection *bcoll, Bone *bone)
{
/* Remove the bone from all its current collections. */
LISTBASE_FOREACH_MUTABLE (BoneCollectionReference *, ref, &bone->runtime.collections) {
ANIM_armature_bonecoll_unassign(ref->bcoll, bone);
}
/* Assign the new collection. */
ANIM_armature_bonecoll_unassign_all(bone);
return ANIM_armature_bonecoll_assign(bcoll, bone);
}
@@ -299,6 +295,13 @@ bool ANIM_armature_bonecoll_unassign(BoneCollection *bcoll, Bone *bone)
return was_found;
}
void ANIM_armature_bonecoll_unassign_all(Bone *bone)
{
LISTBASE_FOREACH_MUTABLE (BoneCollectionReference *, ref, &bone->runtime.collections) {
ANIM_armature_bonecoll_unassign(ref->bcoll, bone);
}
}
bool ANIM_armature_bonecoll_unassign_editbone(BoneCollection *bcoll, EditBone *ebone)
{
bool was_found = false;

View File

@@ -246,6 +246,12 @@ static IDProperty **rna_BoneCollection_idprops(PointerRNA *ptr)
return &bcoll->prop;
}
static void rna_BoneCollectionMemberships_clear(Bone *bone)
{
ANIM_armature_bonecoll_unassign_all(bone);
WM_main_add_notifier(NC_OBJECT | ND_BONE_COLLECTION, nullptr);
}
/* BoneCollection.bones iterator functions. */
static void rna_BoneCollection_bones_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
@@ -1396,6 +1402,23 @@ static void rna_def_bone_common(StructRNA *srna, int editbone)
RNA_define_lib_overridable(false);
}
/** Bone.collections collection-of-bone-collections interface. */
static void rna_def_bone_collection_memberships(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
FunctionRNA *func;
RNA_def_property_srna(cprop, "BoneCollectionMemberships");
srna = RNA_def_struct(brna, "BoneCollectionMemberships", nullptr);
RNA_def_struct_sdna(srna, "Bone");
RNA_def_struct_ui_text(
srna, "Bone Collection Memberships", "The Bone Collections that contain this Bone");
/* Bone.collections.clear(...) */
func = RNA_def_function(srna, "clear", "rna_BoneCollectionMemberships_clear");
RNA_def_function_ui_description(func, "Remove this bone from all bone collections");
}
/* Err... bones should not be directly edited (only edit-bones should be...). */
static void rna_def_bone(BlenderRNA *brna)
{
@@ -1436,8 +1459,8 @@ static void rna_def_bone(BlenderRNA *brna)
nullptr,
nullptr);
RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Collections", "Bone Collections that contain this bone");
rna_def_bone_collection_memberships(brna, prop);
rna_def_bone_common(srna, 0);
rna_def_bone_curved_common(srna, false, false);