[Bf-blender-cvs] [c98a534] soc-2016-layer_manager: Custom layer property support

Julian Eisel noreply at git.blender.org
Sun Jun 19 01:02:41 CEST 2016


Commit: c98a534a97d3b59f713b28a7f2a9fd2755dedc7d
Author: Julian Eisel
Date:   Sun Jun 19 00:58:25 2016 +0200
Branches: soc-2016-layer_manager
https://developer.blender.org/rBc98a534a97d3b59f713b28a7f2a9fd2755dedc7d

Custom layer property support

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

M	source/blender/blenkernel/intern/layer.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index def50eb..ed76f58 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -34,14 +34,12 @@
 #include <stdlib.h>
 
 #include "BKE_context.h"
+#include "BKE_idprop.h"
 #include "BKE_layer.h" /* own include */
 
 #include "BLI_listbase.h"
 #include "BLI_string.h"
 
-#include "DNA_defs.h"
-#include "DNA_space_types.h"
-
 #include "MEM_guardedalloc.h"
 
 static void layeritem_free(LayerTreeItem *litem);
@@ -185,6 +183,12 @@ static void layeritem_free(LayerTreeItem *litem)
 	if (litem->free) {
 		litem->free(litem);
 	}
+
+	if (litem->prop) {
+		IDP_FreeProperty(litem->prop);
+		MEM_freeN(litem->prop);
+	}
+
 	MEM_freeN(litem);
 }
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 4e0810f..ce4347f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5831,6 +5831,8 @@ static void direct_link_layeritems(FileData *fd, ListBase *layeritems, LayerTree
 
 		litem->tree = ltree;
 		litem->parent = newdataadr(fd, litem->parent);
+		litem->prop = newdataadr(fd, litem->prop);
+		IDP_DirectLinkGroup_OrFree(&litem->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
 
 		if (litem->type == LAYER_ITEMTYPE_LAYER) {
 			LayerTypeObject *oblayer = (LayerTypeObject *)litem;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 49fc183..d537ad1 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2407,6 +2407,9 @@ static void write_layeritems(WriteData *wd, Scene *scene, ListBase *layeritems)
 		else {
 			writestruct(wd, DATA, "LayerTreeItem", 1, litem);
 		}
+		if (litem->prop) {
+			IDP_WriteProperty(litem->prop, wd);
+		}
 		litem->tree = scene->object_layers;
 		write_layeritems(wd, scene, &litem->childs);
 	}
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 63fc6aa..e21df3b 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -108,6 +108,9 @@ typedef struct LayerTreeItem {
 	struct LayerTreeItem *parent; /* the group this item belongs to */
 	ListBase childs; /* LayerTreeItem */
 
+	/* custom props */
+	IDProperty *prop;
+
 	/* item is grayed out if this check fails */
 	short (*poll)(const struct bContext *, struct LayerTreeItem *); /* LayerItemPollFunc */
 	/* drawing of the item in the list */
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index bb6564d..f67383f 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -421,6 +421,7 @@ EnumPropertyItem rna_enum_bake_pass_filter_type_items[] = {
 #include "BKE_brush.h"
 #include "BKE_context.h"
 #include "BKE_global.h"
+#include "BKE_idprop.h"
 #include "BKE_image.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
@@ -789,6 +790,18 @@ static void rna_Scene_all_keyingsets_next(CollectionPropertyIterator *iter)
 	iter->valid = (internal->link != NULL);
 }
 
+static IDProperty *rna_LayerTreeItem_idprops(PointerRNA *ptr, bool create)
+{
+	LayerTreeItem *litem = ptr->data;
+
+	if (create && !litem->prop) {
+		IDPropertyTemplate val = {0};
+		litem->prop = IDP_New(IDP_GROUP, &val, "RNA_LayerTreeItem ID properties");
+	}
+
+	return litem->prop;
+}
+
 static void rna_layer_tree_items_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
 	LayerTree *ltree = ptr->data;
@@ -6431,6 +6444,8 @@ static void rna_def_display_safe_areas(BlenderRNA *brna)
 static void rna_def_layer_tree_item(BlenderRNA *brna)
 {
 	StructRNA *srna = RNA_def_struct(brna, "LayerTreeItem", NULL);
+	RNA_def_struct_idprops_func(srna, "rna_LayerTreeItem_idprops");
+
 	PropertyRNA *prop;
 
 	prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
@@ -6444,11 +6459,11 @@ static void rna_def_layer_tree(BlenderRNA *brna)
 
 	prop = RNA_def_property(srna, "tree_items", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_collection_sdna(prop, NULL, "items_all", NULL);
-	RNA_def_property_struct_type(prop, "LayerTreeItem");
 	RNA_def_property_ui_text(prop, "Layer Items", "The items of the layer tree that represent the "
 	                         "layer types (object layer, layer group, compositing layer, ...)");
 	RNA_def_property_collection_funcs(prop, "rna_layer_tree_items_begin", "rna_iterator_array_next",
-	                                  "rna_iterator_array_end", "rna_iterator_array_get", NULL, NULL, NULL, NULL);
+	                                  "rna_iterator_array_end", "rna_iterator_array_dereference_get",
+	                                  NULL, NULL, NULL, NULL);
 
 	rna_def_layer_tree_item(brna);
 }




More information about the Bf-blender-cvs mailing list