Blender V5.0
tree_display_override_library_properties.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_listbase.h"
11
12#include "BKE_main.hh"
13
14#include "DNA_space_types.h"
15
16#include "../outliner_intern.hh"
17#include "common.hh"
18#include "tree_display.hh"
19
20namespace blender::ed::outliner {
21
22/* Convenience/readability. */
23template<typename T> using List = ListBaseWrapper<T>;
24
30
32{
33 ListBase tree = add_library_contents(*source_data.bmain);
34
35 for (TreeElement *top_level_te : List<TreeElement>(tree)) {
36 TreeStoreElem *tselem = TREESTORE(top_level_te);
37 if (!tselem->used) {
38 tselem->flag &= ~TSE_CLOSED;
39 }
40 }
41
42 return tree;
43}
44
45ListBase TreeDisplayOverrideLibraryProperties::add_library_contents(Main &mainvar)
46{
47 ListBase tree = {nullptr};
48
49 const short filter_id_type = id_filter_get();
50
51 Vector<ListBase *> lbarray;
52 if (filter_id_type) {
54 }
55 else {
56 lbarray.extend(BKE_main_lists_get(mainvar));
57 }
58
59 for (int a = 0; a < lbarray.size(); a++) {
60 if (!lbarray[a] || !lbarray[a]->first) {
61 continue;
62 }
63
64 ID *id = nullptr;
65
66 /* check if there's data in current id list */
67 for (ID *id_iter : List<ID>(lbarray[a])) {
68 if (ID_IS_OVERRIDE_LIBRARY_REAL(id_iter) && !ID_IS_LINKED(id_iter)) {
69 id = id_iter;
70 break;
71 }
72 }
73
74 if (id == nullptr) {
75 continue;
76 }
77
78 /* Create data-block list parent element on demand. */
79 TreeElement *id_base_te = nullptr;
80 ListBase *lb_to_expand = &tree;
81
82 if (!filter_id_type) {
83 id_base_te = add_element(&tree, nullptr, lbarray[a], nullptr, TSE_ID_BASE, 0);
84 id_base_te->directdata = lbarray[a];
85 id_base_te->name = outliner_idcode_to_plural(GS(id->name));
86
87 lb_to_expand = &id_base_te->subtree;
88 }
89
90 for (ID *id : List<ID>(lbarray[a])) {
92 TreeElement *override_tree_element = add_element(
93 lb_to_expand, id, nullptr, id_base_te, TSE_LIBRARY_OVERRIDE_BASE, 0);
94
95 if (BLI_listbase_is_empty(&override_tree_element->subtree)) {
96 outliner_free_tree_element(override_tree_element, lb_to_expand);
97 }
98 }
99 }
100 }
101
102 /* Remove ID base elements that turn out to be empty. */
103 LISTBASE_FOREACH_MUTABLE (TreeElement *, te, &tree) {
104 if (BLI_listbase_is_empty(&te->subtree)) {
106 }
107 }
108
109 return tree;
110}
111
112short TreeDisplayOverrideLibraryProperties::id_filter_get() const
113{
114 if (space_outliner_.filter & SO_FILTER_ID_TYPE) {
115 return space_outliner_.filter_id_type;
116 }
117 return 0;
118}
119
120} // namespace blender::ed::outliner
MainListsArray BKE_main_lists_get(Main &bmain)
Definition main.cc:987
ListBase * which_libbase(Main *bmain, short type)
Definition main.cc:902
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
#define ID_IS_OVERRIDE_LIBRARY_REAL(_id)
Definition DNA_ID.h:723
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:694
struct ID ID
struct ListBase ListBase
@ TSE_LIBRARY_OVERRIDE_BASE
@ TSE_ID_BASE
@ TSE_CLOSED
@ SO_FILTER_ID_TYPE
int64_t size() const
void append(const T &value)
void extend(Span< T > array)
AbstractTreeDisplay(SpaceOutliner &space_outliner)
static TreeElement * add_element(SpaceOutliner *space_outliner, ListBase *lb, ID *owner_id, void *create_data, TreeElement *parent, short type, short index, const bool expand=true)
GPU_SHADER_INTERFACE_INFO(depth_2d_update_iface).smooth(Type fragColor push_constant(Type::float2_t, "extent") .push_constant(Type source_data
KDTree_3d * tree
#define GS(x)
void outliner_free_tree_element(TreeElement *element, ListBase *parent_subtree)
const char * outliner_idcode_to_plural(short idcode)
Definition common.cc:31
ListBaseWrapperTemplate< ListBase, T > ListBaseWrapper
#define TREESTORE(a)
char name[258]
Definition DNA_ID.h:432
The data to build the tree from.
Establish and manage Outliner trees for different display modes.