[Bf-blender-cvs] [b5d41b1] render-layers: RNA: bpy.context.scene_collection

Dalai Felinto noreply at git.blender.org
Thu Jan 5 18:25:35 CET 2017


Commit: b5d41b1d719b9dc739d53d2e045c6ffdca3fafbf
Author: Dalai Felinto
Date:   Thu Jan 5 16:32:25 2017 +0100
Branches: render-layers
https://developer.blender.org/rBb5d41b1d719b9dc739d53d2e045c6ffdca3fafbf

RNA: bpy.context.scene_collection

We will need this for UI eventually, and now I need this to update the
Python add object routine.

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

M	source/blender/blenkernel/BKE_context.h
M	source/blender/blenkernel/intern/context.c
M	source/blender/makesrna/intern/rna_context.c

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

diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index 3db417e..60e9cf1 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -46,6 +46,7 @@ struct Object;
 struct PointerRNA;
 struct ReportList;
 struct Scene;
+struct SceneCollection;
 struct SceneLayer;
 struct ScrArea;
 struct SpaceLink;
@@ -240,6 +241,7 @@ int ctx_data_list_count(const bContext *C, int (*func)(const bContext *, ListBas
 
 struct Main *CTX_data_main(const bContext *C);
 struct Scene *CTX_data_scene(const bContext *C);
+struct SceneCollection *CTX_data_scene_collection(const bContext *C);
 struct SceneLayer *CTX_data_scene_layer(const bContext *C);
 struct ToolSettings *CTX_data_tool_settings(const bContext *C);
 
@@ -248,6 +250,7 @@ int CTX_data_mode_enum(const bContext *C);
 
 void CTX_data_main_set(bContext *C, struct Main *bmain);
 void CTX_data_scene_set(bContext *C, struct Scene *bmain);
+void CTX_data_scene_collection_set(bContext *C, struct SceneCollection *sc);
 void CTX_data_scene_layer_set(bContext *C, struct SceneLayer *sl);
 
 int CTX_data_selected_editable_objects(const bContext *C, ListBase *list);
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index d72e58c..577ad58 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -80,6 +80,7 @@ struct bContext {
 		struct Main *main;
 		struct Scene *scene;
 		struct SceneLayer *render_layer;
+		struct SceneCollection *scene_collection;
 
 		int recursion;
 		int py_init; /* true if python is initialized */
@@ -911,6 +912,18 @@ SceneLayer *CTX_data_scene_layer(const bContext *C)
 	}
 }
 
+SceneCollection *CTX_data_scene_collection(const bContext *C)
+{
+	SceneCollection *sc;
+
+	if (ctx_data_pointer_verify(C, "scene_collection", (void *)&sc)) {
+		return sc;
+	}
+	else {
+		return C->data.scene_collection;
+	}
+}
+
 int CTX_data_mode_enum(const bContext *C)
 {
 	Object *obedit = CTX_data_edit_object(C);
@@ -985,9 +998,18 @@ void CTX_data_scene_set(bContext *C, Scene *scene)
 	CTX_data_scene_layer_set(C, scene->render_layers.last);
 }
 
+void CTX_data_scene_collection_set(bContext *C, SceneCollection *sc)
+{
+	C->data.scene_collection = sc;
+}
+
 void CTX_data_scene_layer_set(bContext *C, SceneLayer *sl)
 {
 	C->data.render_layer = sl;
+
+	/* update the related data */
+	LayerCollection *lc = BKE_layer_collection_active(sl);
+	CTX_data_scene_collection_set(C, lc->scene_collection);
 }
 
 ToolSettings *CTX_data_tool_settings(const bContext *C)
diff --git a/source/blender/makesrna/intern/rna_context.c b/source/blender/makesrna/intern/rna_context.c
index f35a416..0d57ad7 100644
--- a/source/blender/makesrna/intern/rna_context.c
+++ b/source/blender/makesrna/intern/rna_context.c
@@ -113,6 +113,12 @@ static PointerRNA rna_Context_scene_layer_get(PointerRNA *ptr)
 	return rna_pointer_inherit_refine(ptr, &RNA_SceneLayer, CTX_data_scene_layer(C));
 }
 
+static PointerRNA rna_Context_scene_collection_get(PointerRNA *ptr)
+{
+	bContext *C = (bContext *)ptr->data;
+	return rna_pointer_inherit_refine(ptr, &RNA_SceneCollection, CTX_data_scene_collection(C));
+}
+
 static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr)
 {
 	bContext *C = (bContext *)ptr->data;
@@ -214,6 +220,11 @@ void RNA_def_context(BlenderRNA *brna)
 	RNA_def_property_struct_type(prop, "SceneLayer");
 	RNA_def_property_pointer_funcs(prop, "rna_Context_scene_layer_get", NULL, NULL, NULL);
 
+	prop = RNA_def_property(srna, "scene_collection", PROP_POINTER, PROP_NONE);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_struct_type(prop, "SceneCollection");
+	RNA_def_property_pointer_funcs(prop, "rna_Context_scene_collection_get", NULL, NULL, NULL);
+
 	prop = RNA_def_property(srna, "tool_settings", PROP_POINTER, PROP_NONE);
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_struct_type(prop, "ToolSettings");




More information about the Bf-blender-cvs mailing list