[Bf-blender-cvs] [019b3cf54ef] temp-group-collections: Support deleting group collection individual collections
Dalai Felinto
noreply at git.blender.org
Wed Nov 1 18:15:15 CET 2017
Commit: 019b3cf54ef5d20af64f7b060edad304d615d410
Author: Dalai Felinto
Date: Wed Nov 1 12:50:52 2017 -0200
Branches: temp-group-collections
https://developer.blender.org/rB019b3cf54ef5d20af64f7b060edad304d615d410
Support deleting group collection individual collections
===================================================================
M source/blender/blenkernel/BKE_collection.h
M source/blender/blenkernel/BKE_layer.h
M source/blender/blenkernel/intern/collection.c
M source/blender/blenkernel/intern/layer.c
M source/blender/blenloader/intern/versioning_280.c
M source/blender/editors/space_outliner/outliner_collections.c
M source/blender/editors/space_outliner/outliner_tools.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 78be290e14d..6ae98e3456a 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -47,7 +47,7 @@ struct Scene;
struct SceneCollection *BKE_collection_add(
struct ID *id, struct SceneCollection *sc_parent, const int type, const char *name);
-bool BKE_collection_remove(struct Scene *scene, struct SceneCollection *sc);
+bool BKE_collection_remove(struct ID *id, struct SceneCollection *sc);
void BKE_collection_copy_data(struct SceneCollection *sc_dst, struct SceneCollection *sc_src, const int flag);
struct SceneCollection *BKE_collection_master(const struct Scene *scene);
struct SceneCollection *BKE_collection_group_master(const struct Group *group);
diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
index fbc58c0026b..0ce8c4a4a2e 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -69,6 +69,7 @@ void BKE_scene_layer_free(struct SceneLayer *sl);
void BKE_scene_layer_selected_objects_tag(struct SceneLayer *sl, const int tag);
+struct SceneLayer *BKE_scene_layer_first_from_id(const struct ID *id);
struct SceneLayer *BKE_scene_layer_find_from_collection(const struct ID *id, struct LayerCollection *lc);
struct Base *BKE_scene_layer_base_find(struct SceneLayer *sl, struct Object *ob);
void BKE_scene_layer_base_deselect_all(struct SceneLayer *sl);
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index e1b520317a3..caedf40704c 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -165,25 +165,25 @@ static void layer_collection_remove(SceneLayer *sl, ListBase *lb, const SceneCol
/**
* Remove a collection from the scene, and syncronize all render layers
*/
-bool BKE_collection_remove(Scene *scene, SceneCollection *sc)
+bool BKE_collection_remove(ID *id, SceneCollection *sc)
{
- SceneCollection *sc_master = BKE_collection_master(scene);
+ SceneCollection *sc_master = collection_master_from_id(id);
- /* the master collection cannot be removed */
+ /* The master collection cannot be removed. */
if (sc == sc_master) {
return false;
}
- /* unlink from the respective collection tree */
+ /* Unlink from the respective collection tree. */
if (!collection_remlink(sc_master, sc)) {
BLI_assert(false);
}
- /* clear the collection items */
+ /* Clear the collection items. */
collection_free(sc, true);
/* check all layers that use this collection and clear them */
- for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) {
+ for (SceneLayer *sl = BKE_scene_layer_first_from_id(id); sl; sl = sl->next) {
layer_collection_remove(sl, &sl->layer_collections, sc);
sl->active_collection = 0;
}
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index 3292a18d090..492a58b089f 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -62,7 +62,6 @@ static void layer_collection_free(SceneLayer *sl, LayerCollection *lc);
static void layer_collection_objects_populate(SceneLayer *sl, LayerCollection *lc, ListBase *objects);
static LayerCollection *layer_collection_add(SceneLayer *sl, LayerCollection *parent, SceneCollection *sc);
static LayerCollection *find_layer_collection_by_scene_collection(LayerCollection *lc, const SceneCollection *sc);
-static SceneLayer *scene_layer_first_from_id(const ID *id);
static IDProperty *collection_engine_settings_create(struct EngineSettingsCB_Type *ces_type, const bool populate);
static IDProperty *collection_engine_get(IDProperty *root, const int type, const char *engine_name);
static void collection_engine_settings_init(IDProperty *root, const bool populate);
@@ -212,6 +211,23 @@ void BKE_scene_layer_selected_objects_tag(SceneLayer *sl, const int tag)
}
}
+/**
+ * Return the first SceneLayer for a given id
+ */
+SceneLayer *BKE_scene_layer_first_from_id(const ID *id)
+{
+ switch (GS(id->name)) {
+ case ID_SCE:
+ return ((Scene *)id)->render_layers.first;
+ case ID_GR:
+ return ((Group *)id)->scene_layer;
+ default:
+ BLI_assert(!"ID doesn't support scene layers");
+ return NULL;
+ }
+}
+
+
static bool find_scene_collection_in_scene_collections(ListBase *lb, const LayerCollection *lc)
{
for (LayerCollection *lcn = lb->first; lcn; lcn = lcn->next) {
@@ -919,7 +935,7 @@ static bool layer_collection_resync(SceneLayer *sl, LayerCollection *lc, const S
*/
void BKE_layer_collection_resync(const ID *id, const SceneCollection *sc)
{
- for (SceneLayer *sl = scene_layer_first_from_id(id); sl; sl = sl->next) {
+ for (SceneLayer *sl = BKE_scene_layer_first_from_id(id); sl; sl = sl->next) {
for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) {
layer_collection_resync(sl, lc, sc);
}
@@ -1130,25 +1146,12 @@ static LayerCollection *find_layer_collection_by_scene_collection(LayerCollectio
return NULL;
}
-static SceneLayer *scene_layer_first_from_id(const ID *id)
-{
- switch (GS(id->name)) {
- case ID_SCE:
- return ((Scene *)id)->render_layers.first;
- case ID_GR:
- return ((Group *)id)->scene_layer;
- default:
- BLI_assert(!"ID doesn't support scene layers");
- return NULL;
- }
-}
-
/**
* Add a new LayerCollection for all the SceneLayers that have sc_parent
*/
void BKE_layer_sync_new_scene_collection(ID *id, const SceneCollection *sc_parent, SceneCollection *sc)
{
- for (SceneLayer *sl = scene_layer_first_from_id(id); sl; sl = sl->next) {
+ for (SceneLayer *sl = BKE_scene_layer_first_from_id(id); sl; sl = sl->next) {
for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) {
LayerCollection *lc_parent = find_layer_collection_by_scene_collection(lc, sc_parent);
if (lc_parent) {
@@ -1163,7 +1166,7 @@ void BKE_layer_sync_new_scene_collection(ID *id, const SceneCollection *sc_paren
*/
void BKE_layer_sync_object_link(const ID *id, SceneCollection *sc, Object *ob)
{
- for (SceneLayer *sl = scene_layer_first_from_id(id); sl; sl = sl->next) {
+ for (SceneLayer *sl = BKE_scene_layer_first_from_id(id); sl; sl = sl->next) {
for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) {
LayerCollection *found = find_layer_collection_by_scene_collection(lc, sc);
if (found) {
@@ -1179,7 +1182,7 @@ void BKE_layer_sync_object_link(const ID *id, SceneCollection *sc, Object *ob)
*/
void BKE_layer_sync_object_unlink(const ID *id, SceneCollection *sc, Object *ob)
{
- for (SceneLayer *sl = scene_layer_first_from_id(id); sl; sl = sl->next) {
+ for (SceneLayer *sl = BKE_scene_layer_first_from_id(id); sl; sl = sl->next) {
for (LayerCollection *lc = sl->layer_collections.first; lc; lc = lc->next) {
LayerCollection *found = find_layer_collection_by_scene_collection(lc, sc);
if (found) {
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index a201062424d..cc6a1f0a4ae 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -274,7 +274,7 @@ void do_versions_after_linking_280(Main *main)
/* Cleanup */
for (int i = 0; i < 20; i++) {
if ((lay_used & (1 << i)) == 0) {
- BKE_collection_remove(scene, collections[i]);
+ BKE_collection_remove(&scene->id, collections[i]);
}
}
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c
index dc66beae24d..d0c1fb9c11f 100644
--- a/source/blender/editors/space_outliner/outliner_collections.c
+++ b/source/blender/editors/space_outliner/outliner_collections.c
@@ -396,7 +396,7 @@ static TreeTraversalAction collection_delete_cb(TreeElement *te, void *customdat
* when deleting multiple collections, so just do nothing */
}
else {
- BKE_collection_remove(data->scene, scene_collection);
+ BKE_collection_remove(&data->scene->id, scene_collection);
}
return TRAVERSE_CONTINUE;
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c
index 963be9e1d7a..eb1fd21054f 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -873,7 +873,7 @@ static void collection_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tsel
}
}
else if (event == OL_COLLECTION_OP_COLLECTION_DEL) {
- if (BKE_collection_remove(scene, sc)) {
+ if (BKE_collection_remove(id, sc)) {
DEG_relations_tag_update(CTX_data_main(C));
WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
}
@@ -1829,6 +1829,7 @@ static EnumPropertyItem prop_collection_op_none_types[] = {
static EnumPropertyItem prop_collection_op_group_internal_types[] = {
{OL_COLLECTION_OP_COLLECTION_NEW, "COLLECTION_NEW", ICON_NEW, "New Collection", "Add a new nested collection"},
+ {OL_COLLECTION_OP_COLLECTION_DEL, "COLLECTION_DEL", ICON_X, "Delete Collection", "Delete the collection"},
{0, NULL, 0, NULL, NULL}
};
diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c
index 5fd104104ff..9de42cb81d2 100644
--- a/source/blender/makesrna/intern/rna_layer.c
+++ b/source/blender/makesrna/intern/rna_layer.c
@@ -173,7 +173,6 @@ static SceneCollection *rna_SceneCollection_new(
static void rna_SceneCollection_remove(
ID *id, SceneCollection *sc_parent, Main *bmain, ReportList *reports, PointerRNA *sc_ptr)
{
- Scene *scene = (Scene *)id;
SceneCollection *sc = sc_ptr->data;
const int index = BLI_findindex(&sc_parent->scene_collections, sc);
@@ -183,7 +182,7 @@ static void rna_SceneCollection_remove(
return;
}
- if (!BKE_collection_remove(scene, sc)) {
+ if (!BKE_collection_remove(id, sc)) {
BKE_reportf(reports, RPT_ERROR, "Collection '%s' could not be removed from collection '%s'",
sc->name, sc_parent->name);
return;
More information about the Bf-blender-cvs
mailing list