[Bf-blender-cvs] [994648a6741] blender2.8: RNA: add new property falg for pointers (and collection), 'NO_OWNERSHIP'.

Bastien Montagne noreply at git.blender.org
Mon Dec 18 10:21:06 CET 2017


Commit: 994648a6741087ae40227037ee87395aa18f5b18
Author: Bastien Montagne
Date:   Mon Dec 18 10:08:22 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB994648a6741087ae40227037ee87395aa18f5b18

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...).

===================================================================

M	source/blender/makesrna/RNA_types.h
M	source/blender/makesrna/intern/makesrna.c
M	source/blender/makesrna/intern/rna_armature.c
M	source/blender/makesrna/intern/rna_pose.c

===================================================================

diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index 47aebbc13e7..e0824281656 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -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.
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 19f66109665..9745ca39872 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -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;
 	}
diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c
index 1ec0fd92a67..bbcb583ab39 100644
--- a/source/blender/makesrna/intern/rna_armature.c
+++ b/source/blender/makesrna/intern/rna_armature.c
@@ -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);
diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c
index baf7f5e6aa3..f50be85c446 100644
--- a/source/blender/makesrna/intern/rna_pose.c
+++ b/source/blender/makesrna/intern/rna_pose.c
@@ -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");



More information about the Bf-blender-cvs mailing list