[Bf-blender-cvs] [ad9082c] soc-2016-layer_manager: Support Layer Properties per layer type

Julian Eisel noreply at git.blender.org
Tue Jun 21 20:47:28 CEST 2016


Commit: ad9082c1ebb9b7f414c5354a74d1b9cf936aad56
Author: Julian Eisel
Date:   Tue Jun 21 20:44:36 2016 +0200
Branches: soc-2016-layer_manager
https://developer.blender.org/rBad9082c1ebb9b7f414c5354a74d1b9cf936aad56

Support Layer Properties per layer type

It's now supported to create custom properties for layer types, just like with operator types. Doesn't work from .py yet, it only allows adding custom properties for all layers.
And some minor cleanup.

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

M	source/blender/blenkernel/BKE_layer.h
M	source/blender/blenkernel/intern/layer.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
index fb16e78..06cad9b 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -70,17 +70,6 @@ int  BKE_layertree_get_totitems(const LayerTree *ltree);
 /* -------------------------------------------------------------------- */
 /* Layer Types */
 
-void BKE_layertypes_init(void);
-void BKE_layertypes_free(void);
-
-void BKE_layertype_append(void (*ltfunc)(struct LayerType *));
-
-/* -------------------------------------------------------------------- */
-/* Layer Tree Item */
-
-typedef void  (*LayerItemDrawFunc)(const struct bContext *, struct LayerTreeItem *, struct uiLayout *layout);
-typedef void  (*LayerItemDrawSettingsFunc)(const struct bContext *, struct LayerTreeItem *, struct uiLayout *layout);
-
 typedef enum eLayerTreeItem_Type {
 	LAYER_ITEMTYPE_LAYER = 0,
 	LAYER_ITEMTYPE_GROUP, /* layer group */
@@ -90,7 +79,7 @@ typedef enum eLayerTreeItem_Type {
 } eLayerTreeItem_Type;
 
 typedef struct LayerType {
-	eLayerTreeItem_Type type; /* eLayerTreeItem_Type */
+	eLayerTreeItem_Type type;
 
 	/* drawing of the item in the list */
 	void (*draw)(const struct bContext *, struct LayerTreeItem *, struct uiLayout *); /* LayerItemDrawFunc */
@@ -99,8 +88,22 @@ typedef struct LayerType {
 
 	/* Optional free callback. Don't free item itself! */
 	void (*free)(struct LayerTreeItem *);
+
+	/* rna for properties */
+	struct StructRNA *srna;
 } LayerType;
 
+void BKE_layertypes_init(void);
+void BKE_layertypes_free(void);
+
+void BKE_layertype_append(void (*ltfunc)(LayerType *));
+
+/* -------------------------------------------------------------------- */
+/* Layer Tree Item */
+
+typedef void  (*LayerItemDrawFunc)(const struct bContext *, struct LayerTreeItem *, struct uiLayout *layout);
+typedef void  (*LayerItemDrawSettingsFunc)(const struct bContext *, struct LayerTreeItem *, struct uiLayout *layout);
+
 LayerTreeItem *BKE_layeritem_add(
         LayerTree *tree, LayerTreeItem *parent,
         const eLayerTreeItem_Type type, const char *name,
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index 372ef1f..905a705 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -43,6 +43,9 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "RNA_access.h"
+#include "RNA_define.h"
+
 static void layeritem_free(LayerTreeItem *litem);
 
 
@@ -148,6 +151,7 @@ static void LAYERTYPE_group(LayerType *lt)
 void BKE_layertype_append(void (*ltfunc)(LayerType *))
 {
 	LayerType *lt = MEM_callocN(sizeof(LayerType), __func__);
+	lt->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_LayerProperties);
 	ltfunc(lt);
 
 	BLI_assert(lt->type >= 0 && lt->type < LAYER_ITEMTYPE_TOT);
@@ -194,6 +198,13 @@ void BKE_layeritem_register(
         LayerItemDrawFunc draw, LayerItemDrawSettingsFunc draw_settings)
 {
 	litem->type = layertypes[type];
+
+	/* initialize properties */
+	IDPropertyTemplate val = {0};
+	litem->ptr = MEM_callocN(sizeof(PointerRNA), "LayerTreeItem PointerRNA");
+	litem->prop = IDP_New(IDP_GROUP, &val, "LayerTreeItem Properties");
+	RNA_pointer_create(NULL, litem->type->srna, litem->prop, litem->ptr);
+
 	litem->index = tree->tot_items;
 	litem->tree = tree;
 	BLI_strncpy(litem->name, name, sizeof(litem->name));
@@ -241,6 +252,8 @@ static void layeritem_free(LayerTreeItem *litem)
 		litem->type->free(litem);
 	}
 
+	if (litem->ptr)
+		MEM_freeN(litem->ptr);
 	if (litem->prop) {
 		IDP_FreeProperty(litem->prop);
 		MEM_freeN(litem->prop);
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 8cd7006..6248baf 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -110,7 +110,8 @@ typedef struct LayerTreeItem {
 	ListBase childs; /* LayerTreeItem */
 
 	/* custom props */
-	IDProperty *prop;
+	struct PointerRNA *ptr; /* rna pointer to access properties from layer type */
+	IDProperty *prop;       /* custom props for all layers */
 } LayerTreeItem;
 
 typedef struct LayerTypeObject {
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index addfc6c..200fd39 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -311,6 +311,7 @@ extern StructRNA RNA_LaplacianSmoothModifier;
 extern StructRNA RNA_Lattice;
 extern StructRNA RNA_LatticeModifier;
 extern StructRNA RNA_LatticePoint;
+extern StructRNA RNA_LayerProperties;
 extern StructRNA RNA_LayerTree;
 extern StructRNA RNA_LayerTreeItem;
 extern StructRNA RNA_Library;
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 1ad552c..151cf44 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -423,6 +423,7 @@ EnumPropertyItem rna_enum_bake_pass_filter_type_items[] = {
 #include "BKE_global.h"
 #include "BKE_idprop.h"
 #include "BKE_image.h"
+#include "BKE_layer.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
 #include "BKE_pointcache.h"
@@ -802,6 +803,22 @@ static IDProperty *rna_LayerTreeItem_idprops(PointerRNA *ptr, bool create)
 	return litem->prop;
 }
 
+static PointerRNA rna_Layer_properties_get(PointerRNA *ptr)
+{
+	LayerTreeItem *litem = ptr->data;
+	return rna_pointer_inherit_refine(ptr, litem->type->srna, litem->prop);
+}
+
+static IDProperty *rna_LayerProperties_idprops(PointerRNA *ptr, bool create)
+{
+	if (create && !ptr->data) {
+		IDPropertyTemplate val = {0};
+		ptr->data = IDP_New(IDP_GROUP, &val, "RNA_LayerProperties group");
+	}
+
+	return ptr->data;
+}
+
 static void rna_layer_tree_items_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
 	LayerTree *ltree = ptr->data;
@@ -6443,13 +6460,23 @@ static void rna_def_display_safe_areas(BlenderRNA *brna)
 
 static void rna_def_layer_tree_item(BlenderRNA *brna)
 {
+	PropertyRNA *prop;
 	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);
 	RNA_def_property_ui_text(prop, "Name", "Name of the item");
+
+	prop = RNA_def_property(srna, "properties", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "prop");
+	RNA_def_property_flag(prop, PROP_NEVER_NULL);
+	RNA_def_property_struct_type(prop, "LayerProperties");
+	RNA_def_property_ui_text(prop, "Properties", "");
+	RNA_def_property_pointer_funcs(prop, "rna_Layer_properties_get", NULL, NULL, NULL);
+
+	srna = RNA_def_struct(brna, "LayerProperties", NULL);
+	RNA_def_struct_ui_text(srna, "Layer Properties", "Input properties of a layer");
+	RNA_def_struct_idprops_func(srna, "rna_LayerProperties_idprops");
 }
 
 static void rna_def_layer_tree(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list