From 668b31c5d86002da0c4cb19ff034ca5dd802bb2b Mon Sep 17 00:00:00 2001 From: Almaz-Shinbay Date: Wed, 23 Aug 2023 18:17:14 +0200 Subject: [PATCH] Outliner: Port layer collection elements to new tree-element code design No user visible changes expected. Part of #96713, continuation of work started in 249e4df110 and 2e221de4ce. Refer to these for a motivation and design overview. Adds a new class for layer collection elements. Pull Request: https://projects.blender.org/blender/blender/pulls/111220 --- .../editors/space_outliner/CMakeLists.txt | 2 ++ .../editors/space_outliner/outliner_tree.cc | 6 ++++- .../tree/tree_display_view_layer.cc | 5 +--- .../space_outliner/tree/tree_element.cc | 4 +++ .../tree/tree_element_layer_collection.cc | 27 +++++++++++++++++++ .../tree/tree_element_layer_collection.hh | 22 +++++++++++++++ 6 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 source/blender/editors/space_outliner/tree/tree_element_layer_collection.cc create mode 100644 source/blender/editors/space_outliner/tree/tree_element_layer_collection.hh diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt index 4d671ba4ead..897a9dd1d8a 100644 --- a/source/blender/editors/space_outliner/CMakeLists.txt +++ b/source/blender/editors/space_outliner/CMakeLists.txt @@ -71,6 +71,7 @@ set(SRC tree/tree_element_id_scene.cc tree/tree_element_id_texture.cc tree/tree_element_label.cc + tree/tree_element_layer_collection.cc tree/tree_element_linked_object.cc tree/tree_element_nla.cc tree/tree_element_modifier.cc @@ -112,6 +113,7 @@ set(SRC tree/tree_element_id_scene.hh tree/tree_element_id_texture.hh tree/tree_element_label.hh + tree/tree_element_layer_collection.hh tree/tree_element_linked_object.hh tree/tree_element_nla.hh tree/tree_element_modifier.hh diff --git a/source/blender/editors/space_outliner/outliner_tree.cc b/source/blender/editors/space_outliner/outliner_tree.cc index f8263e96e23..5fd67bf061e 100644 --- a/source/blender/editors/space_outliner/outliner_tree.cc +++ b/source/blender/editors/space_outliner/outliner_tree.cc @@ -271,6 +271,9 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner, else if (type == TSE_R_LAYER) { id = &static_cast(idv)->scene->id; } + else if (type == TSE_LAYER_COLLECTION) { + id = &static_cast(idv)->collection->id; + } else if (type == TSE_MODIFIER) { id = &static_cast(idv)->object->id; } @@ -424,7 +427,8 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner, TSE_MODIFIER, TSE_MODIFIER_BASE, TSE_GREASE_PENCIL_NODE, - TSE_LINKED_OB)) + TSE_LINKED_OB, + TSE_LAYER_COLLECTION)) { BLI_assert_msg(false, "Element type should already use new AbstractTreeElement design"); } diff --git a/source/blender/editors/space_outliner/tree/tree_display_view_layer.cc b/source/blender/editors/space_outliner/tree/tree_display_view_layer.cc index 8949fc85940..9c9deb7bd1f 100644 --- a/source/blender/editors/space_outliner/tree/tree_display_view_layer.cc +++ b/source/blender/editors/space_outliner/tree/tree_display_view_layer.cc @@ -153,10 +153,7 @@ void TreeDisplayViewLayer::add_layer_collections_recursive(ListBase &tree, else { ID *id = &lc->collection->id; ten = outliner_add_element( - &space_outliner_, &tree, id, &parent_ten, TSE_LAYER_COLLECTION, 0); - - ten->name = id->name + 2; - ten->directdata = lc; + &space_outliner_, &tree, lc, &parent_ten, TSE_LAYER_COLLECTION, 0); /* Open by default, except linked collections, which may contain many elements. */ TreeStoreElem *tselem = TREESTORE(ten); diff --git a/source/blender/editors/space_outliner/tree/tree_element.cc b/source/blender/editors/space_outliner/tree/tree_element.cc index 58f32a0551b..4750a49d1e5 100644 --- a/source/blender/editors/space_outliner/tree/tree_element.cc +++ b/source/blender/editors/space_outliner/tree/tree_element.cc @@ -30,6 +30,7 @@ #include "tree_element_grease_pencil_node.hh" #include "tree_element_id.hh" #include "tree_element_label.hh" +#include "tree_element_layer_collection.hh" #include "tree_element_linked_object.hh" #include "tree_element_modifier.hh" #include "tree_element_nla.hh" @@ -178,6 +179,9 @@ std::unique_ptr AbstractTreeElement::createFromType(const i } case TSE_LINKED_OB: return std::make_unique(legacy_te, *static_cast(idv)); + case TSE_LAYER_COLLECTION: + return std::make_unique(legacy_te, + *static_cast(idv)); default: break; } diff --git a/source/blender/editors/space_outliner/tree/tree_element_layer_collection.cc b/source/blender/editors/space_outliner/tree/tree_element_layer_collection.cc new file mode 100644 index 00000000000..eef3641fd10 --- /dev/null +++ b/source/blender/editors/space_outliner/tree/tree_element_layer_collection.cc @@ -0,0 +1,27 @@ +/* SPDX-FileCopyrightText: 2023 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup spoutliner + */ + +#include "DNA_collection_types.h" +#include "DNA_outliner_types.h" +#include "DNA_scene_types.h" + +#include "../outliner_intern.hh" + +#include "tree_element_layer_collection.hh" + +namespace blender::ed::outliner { + +TreeElementLayerCollection::TreeElementLayerCollection(TreeElement &legacy_te, LayerCollection &lc) + : AbstractTreeElement(legacy_te), lc_(lc) +{ + BLI_assert(legacy_te.store_elem->type == TSE_LAYER_COLLECTION); + legacy_te.name = lc_.collection->id.name + 2; + legacy_te.directdata = &lc_; +} + +} // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/tree/tree_element_layer_collection.hh b/source/blender/editors/space_outliner/tree/tree_element_layer_collection.hh new file mode 100644 index 00000000000..6f2479d934c --- /dev/null +++ b/source/blender/editors/space_outliner/tree/tree_element_layer_collection.hh @@ -0,0 +1,22 @@ +/* SPDX-FileCopyrightText: 2023 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup spoutliner + */ + +#pragma once + +#include "tree_element.hh" + +namespace blender::ed::outliner { + +class TreeElementLayerCollection final : public AbstractTreeElement { + LayerCollection &lc_; + + public: + TreeElementLayerCollection(TreeElement &legacy_te, LayerCollection &lc); +}; + +} // namespace blender::ed::outliner