RNA: add new property falg for pointers (and collection), 'NO_OWNERSHIP'.

This flag means that the pointer does not 'own' the data it references.
This is the case of nearly all ID RNA pointers (NodeTrees will probably
again be some nasty exception here :( ), but also several other cases.

That kind of information is mandatory for complex processing over whole
data-blocks done in RNA, like some static override tasks (advanced
comparison...).
This commit is contained in:
Bastien Montagne 2017-12-18 10:08:22 +01:00
parent c2ad5e805a
commit 994648a674
4 changed files with 35 additions and 1 deletions

View File

@ -158,7 +158,7 @@ typedef enum PropertySubType {
/* Make sure enums are updated with these */
/* HIGHEST FLAG IN USE: 1 << 31
* FREE FLAGS: 3, 7, 9, 11, 13, 14, 15, 30 */
* FREE FLAGS: 3, 9, 11, 13, 14, 15, 30 */
typedef enum PropertyFlag {
/* editable means the property is editable in the user
* interface, properties are editable by default except
@ -213,6 +213,13 @@ typedef enum PropertyFlag {
* but setting NULL on a mesh object is not possible. So, if its not NULL, setting NULL cant be done! */
PROP_NEVER_UNLINK = (1 << 25),
/* Pointers to data that is not owned by the struct.
* Typical example: Bone.parent, Bone.child, etc., and nearly all ID pointers.
* This is crucial information for processes that walk the whole data of an ID e.g. (like static override).
* Note that all ID pointers are enforced to this by default, this probably will need to be rechecked
* (see ugly infamous NodeTrees of mat/tex/scene/etc.). */
PROP_PTR_NO_OWNERSHIP = (1 << 7),
/* flag contains multiple enums.
* note: not to be confused with prop->enumbitflags
* this exposes the flag as multiple options in python and the UI.

View File

@ -2995,6 +2995,28 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
}
break;
}
case PROP_POINTER:
{
PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
/* XXX This systematically enforces that flag on ID pointers... we'll probably have to revisit. :/ */
StructRNA *type = rna_find_struct((const char *)pprop->type);
if (type && (type->flag & STRUCT_ID)) {
prop->flag |= PROP_PTR_NO_OWNERSHIP;
}
break;
}
case PROP_COLLECTION:
{
CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
/* XXX This systematically enforces that flag on ID pointers... we'll probably have to revisit. :/ */
StructRNA *type = rna_find_struct((const char *)cprop->item_type);
if (type && (type->flag & STRUCT_ID)) {
prop->flag |= PROP_PTR_NO_OWNERSHIP;
}
break;
}
default:
break;
}

View File

@ -726,6 +726,7 @@ static void rna_def_bone(BlenderRNA *brna)
prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Bone");
RNA_def_property_pointer_sdna(prop, NULL, "parent");
RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_ui_text(prop, "Parent", "Parent bone (in same Armature)");
RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
@ -733,6 +734,7 @@ static void rna_def_bone(BlenderRNA *brna)
prop = RNA_def_property(srna, "children", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "childbase", NULL);
RNA_def_property_struct_type(prop, "Bone");
RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_ui_text(prop, "Children", "Bones which are children of this bone");
rna_def_bone_common(srna, 0);

View File

@ -823,16 +823,19 @@ static void rna_def_pose_channel(BlenderRNA *brna)
prop = RNA_def_property(srna, "bone", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_struct_type(prop, "Bone");
RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Bone", "Bone associated with this PoseBone");
prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "PoseBone");
RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Parent", "Parent of this pose bone");
prop = RNA_def_property(srna, "child", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "PoseBone");
RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Child", "Child of this pose bone");