Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2018-02-02 02:11:59 +0300
committerDalai Felinto <dfelinto@gmail.com>2018-02-02 17:25:05 +0300
commitc7c070c2ece0f41772cbcfe3445f3e0be684dd1d (patch)
tree28f43537045a31a7a7b5c3d75d35035a73277de0 /source/blender/makesrna/intern/rna_layer.c
parenta4d2b102f313b8d427e6ff6066f38cc3a2394628 (diff)
Collections: Operator to duplicate a collection
When duplicating a layer collection directly linked to the view layer we copy the collection and link it. For all the not directly linked layer collectionns, we try to sync the layer collection flags, overrides, ... Also we make sure the new collection is right after the original collection. We also expose this in RNA, via collection.duplicate().
Diffstat (limited to 'source/blender/makesrna/intern/rna_layer.c')
-rw-r--r--source/blender/makesrna/intern/rna_layer.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c
index 68c4a15e06b..6930aa115c7 100644
--- a/source/blender/makesrna/intern/rna_layer.c
+++ b/source/blender/makesrna/intern/rna_layer.c
@@ -141,6 +141,23 @@ static int rna_SceneCollection_move_into(ID *id, SceneCollection *sc_src, Main *
return 1;
}
+static SceneCollection *rna_SceneCollection_duplicate(
+ ID *id, SceneCollection *scene_collection, Main *bmain, bContext *C, ReportList *reports)
+{
+ if (scene_collection == BKE_collection_master(id)) {
+ BKE_report(reports, RPT_ERROR, "The master collection can't be duplicated");
+ return NULL;
+ }
+
+ SceneCollection *scene_collection_new = BKE_collection_duplicate(id, scene_collection);
+
+ DEG_relations_tag_update(bmain);
+ /* Don't use id here, since the layer collection may come from a group. */
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, CTX_data_scene(C));
+
+ return scene_collection_new;
+}
+
static SceneCollection *rna_SceneCollection_new(
ID *id, SceneCollection *sc_parent, Main *bmain, const char *name)
{
@@ -717,6 +734,23 @@ static Group *rna_LayerCollection_create_group(
return group;
}
+static LayerCollection *rna_LayerCollection_duplicate(
+ ID *id, LayerCollection *layer_collection, Main *bmain, bContext *C, ReportList *reports)
+{
+ if (layer_collection->scene_collection == BKE_collection_master(id)) {
+ BKE_report(reports, RPT_ERROR, "The master collection can't be duplicated");
+ return NULL;
+ }
+
+ LayerCollection *layer_collection_new = BKE_layer_collection_duplicate(id, layer_collection);
+
+ DEG_relations_tag_update(bmain);
+ /* Don't use id here, since the layer collection may come from a group. */
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, CTX_data_scene(C));
+
+ return layer_collection_new;
+}
+
static int rna_LayerCollections_active_collection_index_get(PointerRNA *ptr)
{
ViewLayer *view_layer = (ViewLayer *)ptr->data;
@@ -1084,6 +1118,12 @@ static void rna_def_scene_collection(BlenderRNA *brna)
parm = RNA_def_pointer(func, "sc_dst", "SceneCollection", "Collection", "Collection to insert into");
parm = RNA_def_boolean(func, "result", false, "Result", "Whether the operation succeded");
RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "duplicate", "rna_SceneCollection_duplicate");
+ RNA_def_function_ui_description(func, "Create a copy of the 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", "SceneCollection", "", "Newly created collection");
+ RNA_def_function_return(func, parm);
}
static void rna_def_layer_collection_override(BlenderRNA *brna)
@@ -1998,6 +2038,12 @@ static void rna_def_layer_collection(BlenderRNA *brna)
parm = RNA_def_pointer(func, "result", "Group", "", "Newly created Group");
RNA_def_function_return(func, parm);
+ func = RNA_def_function(srna, "duplicate", "rna_LayerCollection_duplicate");
+ RNA_def_function_ui_description(func, "Create a copy of the 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", "LayerCollection", "", "Newly created collection");
+ RNA_def_function_return(func, parm);
+
/* Flags */
prop = RNA_def_property(srna, "selectable", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", COLLECTION_SELECTABLE);