[Bf-blender-cvs] [feb06b44182] temp-group-collections: RNA: layer_collection.create_group()
Dalai Felinto
noreply at git.blender.org
Wed Nov 1 18:14:37 CET 2017
Commit: feb06b44182aa19e04372c4f5262f544215ccfde
Author: Dalai Felinto
Date: Fri Oct 27 12:39:19 2017 -0200
Branches: temp-group-collections
https://developer.blender.org/rBfeb06b44182aa19e04372c4f5262f544215ccfde
RNA: layer_collection.create_group()
===================================================================
M source/blender/blenkernel/BKE_collection.h
M source/blender/blenkernel/intern/collection.c
M source/blender/makesrna/intern/rna_layer.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index f5a0270b6a1..418bab30082 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -61,7 +61,7 @@ bool BKE_collections_object_remove(struct Main *bmain, struct ID *id, struct Obj
void BKE_collection_object_move(struct Scene *scene, struct SceneCollection *sc_dst, struct SceneCollection *sc_src, struct Object *ob);
void BKE_collection_group_set(struct Scene *scene, struct SceneCollection *sc, struct Group *group);
-void BKE_collection_group_create(struct Main *bmain, struct Scene *scene, struct LayerCollection *lc);
+struct Group *BKE_collection_group_create(struct Main *bmain, struct Scene *scene, struct LayerCollection *lc);
void BKE_collection_reinsert_after(const struct Scene *scene, struct SceneCollection *sc_reinsert, struct SceneCollection *sc_after);
void BKE_collection_reinsert_into(struct SceneCollection *sc_reinsert, struct SceneCollection *sc_into);
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index c9bd5594001..3bdaa283997 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -503,26 +503,26 @@ static void collection_group_cleanup(Group *group)
* Any SceneLayer that may have this the related SceneCollection linked is converted
* to a Group Collection.
*/
-void BKE_collection_group_create(Main *bmain, Scene *scene, LayerCollection *lc_src)
+Group *BKE_collection_group_create(Main *bmain, Scene *scene, LayerCollection *lc_src)
{
SceneCollection *sc_dst, *sc_src = lc_src->scene_collection;
LayerCollection *lc_dst;
/* We can't convert group collections into groups. */
if (sc_src->type == COLLECTION_TYPE_GROUP) {
- return;
+ return NULL;
}
/* The master collection can't be converted. */
if (sc_src == BKE_collection_master(scene)) {
- return;
+ return NULL;
}
/* If a sub-collection of sc_dst is directly linked into a SceneLayer we can't convert. */
for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) {
for (LayerCollection *lc_child = sl->layer_collections.first; lc_child; lc_child = lc_child->next) {
if (is_collection_in_tree(lc_child->scene_collection, sc_src)) {
- return;
+ return NULL;
}
}
}
@@ -551,6 +551,8 @@ void BKE_collection_group_create(Main *bmain, Scene *scene, LayerCollection *lc_
sc_src->type = COLLECTION_TYPE_GROUP;
BKE_collection_group_set(scene, sc_src, group);
collection_free(sc_src, true);
+
+ return group;
}
/* ---------------------------------------------------------------------- */
diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c
index bb24b323c73..1e45020f4ec 100644
--- a/source/blender/makesrna/intern/rna_layer.c
+++ b/source/blender/makesrna/intern/rna_layer.c
@@ -63,6 +63,7 @@ const EnumPropertyItem rna_enum_collection_type_items[] = {
#ifdef RNA_RUNTIME
+#include "DNA_group_types.h"
#include "DNA_object_types.h"
#include "RNA_access.h"
@@ -744,6 +745,38 @@ static void rna_LayerCollection_enable_set(
WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);
}
+static Group *rna_LayerCollection_create_group(
+ ID *id, LayerCollection *layer_collection, Main *bmain, bContext *C, ReportList *reports)
+{
+ Group *group;
+ Scene *scene = (Scene *)id;
+ SceneCollection *scene_collection = layer_collection->scene_collection;
+
+ /* We can't convert group collections into groups. */
+ if (scene_collection->type == COLLECTION_TYPE_GROUP) {
+ BKE_reportf(reports, RPT_ERROR, "Collection %s is already a group collection", scene_collection->name);
+ return NULL;
+ }
+
+ /* The master collection can't be converted. */
+ if (scene_collection == BKE_collection_master(scene)) {
+ BKE_report(reports, RPT_ERROR, "The master collection can't be converted to group");
+ return NULL;
+ }
+
+ group = BKE_collection_group_create(bmain, scene, layer_collection);
+ if (group == NULL) {
+ BKE_reportf(reports, RPT_ERROR, "Failed to convert collection %s", scene_collection->name);
+ return NULL;
+ }
+
+ DEG_relations_tag_update(bmain);
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(&scene->id, 0);
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ return group;
+}
+
static int rna_LayerCollections_active_collection_index_get(PointerRNA *ptr)
{
SceneLayer *sl = (SceneLayer *)ptr->data;
@@ -2005,6 +2038,12 @@ static void rna_def_layer_collection(BlenderRNA *brna)
parm = RNA_def_boolean(func, "value", 1, "Enable", "");
RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+ func = RNA_def_function(srna, "create_group", "rna_LayerCollection_create_group");
+ RNA_def_function_ui_description(func, "Enable or disable a collection");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "result", "Group", "", "Newly created Group");
+ RNA_def_function_return(func, parm);
+
/* Flags */
prop = RNA_def_property(srna, "is_enabled", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", COLLECTION_DISABLED);
More information about the Bf-blender-cvs
mailing list