Commit: f51c34185ed424a5e3ea0a2fa2f34f8ec9d678b2
Author: Dalai Felinto
Date:   Mon Jan 30 18:07:14 2017 +0100
Branches: render-layers
https://developer.blender.org/rBf51c34185ed424a5e3ea0a2fa2f34f8ec9d678b2

bpy.context.layer_collection

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

M       source/blender/blenkernel/BKE_context.h
M       source/blender/blenkernel/intern/context.c
M       source/blender/makesrna/RNA_access.h
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 3f13105069..2fd11746fb 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -40,6 +40,7 @@ extern "C" {
 struct ARegion;
 struct bScreen;
 struct CacheFile;
+struct LayerCollection;
 struct ListBase;
 struct Main;
 struct Object;
@@ -243,6 +244,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 LayerCollection *CTX_data_layer_collection(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);
diff --git a/source/blender/blenkernel/intern/context.c 
b/source/blender/blenkernel/intern/context.c
index 85fa57f788..f079ec8f7b 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -928,20 +928,39 @@ SceneLayer *CTX_data_scene_layer(const bContext *C)
  * If the scene_collection is linked to the SceneLayer we use it.
  * Otherwise we fallback to the active one of the SceneLayer.
  */
-SceneCollection *CTX_data_scene_collection(const bContext *C)
+LayerCollection *CTX_data_layer_collection(const bContext *C)
 {
        SceneLayer *sl = CTX_data_scene_layer(C);
-       SceneCollection *sc;
+       LayerCollection *lc;
+
+       if (ctx_data_pointer_verify(C, "layer_collection", (void *)&lc)) {
+               if (BKE_scene_layer_has_collection(sl, lc->scene_collection)) {
+                       return lc;
+               }
+       }
+
+       /* fallback */
+       return BKE_layer_collection_active(sl);
+}
 
+SceneCollection *CTX_data_scene_collection(const bContext *C)
+{
+       SceneCollection *sc;
        if (ctx_data_pointer_verify(C, "scene_collection", (void *)&sc)) {
-               if (BKE_scene_layer_has_collection(sl, sc)) {
+               if (BKE_scene_layer_has_collection(CTX_data_scene_layer(C), 
sc)) {
                        return sc;
                }
        }
+       else {
+               LayerCollection *lc = CTX_data_layer_collection(C);
+               if (lc) {
+                       return lc->scene_collection;
+               }
+       }
 
        /* fallback */
-       LayerCollection *lc = BKE_layer_collection_active(sl);
-       return lc->scene_collection;
+       Scene *scene = CTX_data_scene(C);
+       return BKE_collection_master(scene);
 }
 
 int CTX_data_mode_enum(const bContext *C)
diff --git a/source/blender/makesrna/RNA_access.h 
b/source/blender/makesrna/RNA_access.h
index 48e20e7252..c07287abd1 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -317,6 +317,7 @@ extern StructRNA RNA_LaplacianSmoothModifier;
 extern StructRNA RNA_Lattice;
 extern StructRNA RNA_LatticeModifier;
 extern StructRNA RNA_LatticePoint;
+extern StructRNA RNA_LayerCollection;
 extern StructRNA RNA_Library;
 extern StructRNA RNA_LimitDistanceConstraint;
 extern StructRNA RNA_LimitLocationConstraint;
diff --git a/source/blender/makesrna/intern/rna_context.c 
b/source/blender/makesrna/intern/rna_context.c
index 9270cda0d2..27e88f592a 100644
--- a/source/blender/makesrna/intern/rna_context.c
+++ b/source/blender/makesrna/intern/rna_context.c
@@ -120,6 +120,13 @@ static PointerRNA 
rna_Context_scene_collection_get(PointerRNA *ptr)
        return rna_pointer_inherit_refine(ptr, &RNA_SceneCollection, 
CTX_data_scene_collection(C));
 }
 
+static PointerRNA rna_Context_layer_collection_get(PointerRNA *ptr)
+{
+       bContext *C = (bContext *)ptr->data;
+       ptr->id.data = CTX_data_scene(C);
+       return rna_pointer_inherit_refine(ptr, &RNA_LayerCollection, 
CTX_data_layer_collection(C));
+}
+
 static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr)
 {
        bContext *C = (bContext *)ptr->data;
@@ -226,6 +233,11 @@ void RNA_def_context(BlenderRNA *brna)
        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, "layer_collection", PROP_POINTER, 
PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_struct_type(prop, "LayerCollection");
+       RNA_def_property_pointer_funcs(prop, 
"rna_Context_layer_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");

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to