Blender V4.3
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
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 ListBase *lbarray[INDEX_ID_MAX];
52 int tot;
53 if (filter_id_type) {
54 lbarray[0] = which_libbase(&mainvar, space_outliner_.filter_id_type);
55 tot = 1;
56 }
57 else {
58 tot = set_listbasepointers(&mainvar, lbarray);
59 }
60
61 for (int a = 0; a < tot; a++) {
62 if (!lbarray[a] || !lbarray[a]->first) {
63 continue;
64 }
65
66 ID *id = nullptr;
67
68 /* check if there's data in current id list */
69 for (ID *id_iter : List<ID>(lbarray[a])) {
70 if (ID_IS_OVERRIDE_LIBRARY_REAL(id_iter) && !ID_IS_LINKED(id_iter)) {
71 id = id_iter;
72 break;
73 }
74 }
75
76 if (id == nullptr) {
77 continue;
78 }
79
80 /* Create data-block list parent element on demand. */
81 TreeElement *id_base_te = nullptr;
82 ListBase *lb_to_expand = &tree;
83
84 if (!filter_id_type) {
85 id_base_te = add_element(&tree, nullptr, lbarray[a], nullptr, TSE_ID_BASE, 0);
86 id_base_te->directdata = lbarray[a];
87 id_base_te->name = outliner_idcode_to_plural(GS(id->name));
88
89 lb_to_expand = &id_base_te->subtree;
90 }
91
92 for (ID *id : List<ID>(lbarray[a])) {
94 TreeElement *override_tree_element = add_element(
95 lb_to_expand, id, nullptr, id_base_te, TSE_LIBRARY_OVERRIDE_BASE, 0);
96
97 if (BLI_listbase_is_empty(&override_tree_element->subtree)) {
98 outliner_free_tree_element(override_tree_element, lb_to_expand);
99 }
100 }
101 }
102 }
103
104 /* Remove ID base elements that turn out to be empty. */
105 LISTBASE_FOREACH_MUTABLE (TreeElement *, te, &tree) {
106 if (BLI_listbase_is_empty(&te->subtree)) {
108 }
109 }
110
111 return tree;
112}
113
114short TreeDisplayOverrideLibraryProperties::id_filter_get() const
115{
118 }
119 return 0;
120}
121
122} // namespace blender::ed::outliner
ListBase * which_libbase(Main *bmain, short type)
Definition main.cc:842
int set_listbasepointers(Main *bmain, ListBase *lb[])
Definition main.cc:929
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
#define ID_IS_OVERRIDE_LIBRARY_REAL(_id)
Definition DNA_ID.h:676
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:654
#define INDEX_ID_MAX
Definition DNA_ID.h:1328
@ TSE_LIBRARY_OVERRIDE_BASE
@ TSE_ID_BASE
@ SO_FILTER_ID_TYPE
Base Class For Tree-Displays.
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::VEC2, "extent") .push_constant(Type source_data
KDTree_3d * tree
#define GS(x)
Definition iris.cc:202
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)
Definition DNA_ID.h:413
The data to build the tree from.
Establish and manage Outliner trees for different display modes.