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