Blender V4.3
tree_display_orphaned.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 "DNA_ID.h"
10#include "DNA_space_types.h"
11
12#include "BLI_listbase.h"
14#include "BLI_utildefines.h"
15
16#include "BKE_idtype.hh"
17#include "BKE_main.hh"
18
19#include "../outliner_intern.hh"
20#include "common.hh"
21#include "tree_display.hh"
22
23namespace blender::ed::outliner {
24
25template<typename T> using List = ListBaseWrapper<T>;
26
31
33{
34 ListBase tree = {nullptr};
35 ListBase *lbarray[INDEX_ID_MAX];
36 short filter_id_type = (space_outliner_.filter & SO_FILTER_ID_TYPE) ?
38 0;
39
40 int tot;
41 if (filter_id_type) {
42 lbarray[0] = which_libbase(source_data.bmain, filter_id_type);
43 tot = 1;
44 }
45 else {
46 tot = set_listbasepointers(source_data.bmain, lbarray);
47 }
48
49 for (int a = 0; a < tot; a++) {
50 if (BLI_listbase_is_empty(lbarray[a])) {
51 continue;
52 }
53 if (!datablock_has_orphans(*lbarray[a])) {
54 continue;
55 }
56
57 /* Header for this type of data-block. */
58 TreeElement *te = nullptr;
59 if (!filter_id_type) {
60 ID *id = (ID *)lbarray[a]->first;
61 te = add_element(&tree, nullptr, lbarray[a], nullptr, TSE_ID_BASE, 0);
62 te->directdata = lbarray[a];
63 te->name = outliner_idcode_to_plural(GS(id->name));
64 }
65
66 /* Add the orphaned data-blocks - these will not be added with any subtrees attached. */
67 for (ID *id : List<ID>(lbarray[a])) {
68 if (ID_REFCOUNTING_USERS(id) <= 0) {
69 add_element((te) ? &te->subtree : &tree, id, nullptr, te, TSE_SOME_ID, 0, false);
70 }
71 }
72 }
73
74 return tree;
75}
76
77bool TreeDisplayIDOrphans::datablock_has_orphans(ListBase &lb) const
78{
79 if (BLI_listbase_is_empty(&lb)) {
80 return false;
81 }
82 const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(static_cast<ID *>(lb.first));
83 if (id_type->flags & IDTYPE_FLAGS_NEVER_UNUSED) {
84 /* These ID types are never unused. */
85 return false;
86 }
87
88 for (ID *id : List<ID>(lb)) {
89 if (ID_REFCOUNTING_USERS(id) <= 0) {
90 return true;
91 }
92 }
93 return false;
94}
95
96} // namespace blender::ed::outliner
@ IDTYPE_FLAGS_NEVER_UNUSED
Definition BKE_idtype.hh:64
const IDTypeInfo * BKE_idtype_get_info_from_id(const ID *id)
Definition idtype.cc:150
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)
ID and Library types, which are fundamental for SDNA.
#define ID_REFCOUNTING_USERS(id)
Definition DNA_ID.h:642
#define INDEX_ID_MAX
Definition DNA_ID.h:1328
@ TSE_ID_BASE
@ TSE_SOME_ID
@ 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)
ListBase build_tree(const TreeSourceData &source_data) override
TreeDisplayIDOrphans(SpaceOutliner &space_outliner)
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
const char * outliner_idcode_to_plural(short idcode)
Definition common.cc:31
ListBaseWrapperTemplate< ListBase, T > ListBaseWrapper
uint32_t flags
Definition DNA_ID.h:413
void * first
The data to build the tree from.
Establish and manage Outliner trees for different display modes.