Blender  V3.3
tree_display_orphaned.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "DNA_ID.h"
8 #include "DNA_space_types.h"
9 
10 #include "BLI_listbase.h"
11 #include "BLI_listbase_wrapper.hh"
12 #include "BLI_utildefines.h"
13 
14 #include "BKE_main.h"
15 
16 #include "../outliner_intern.hh"
17 #include "common.hh"
18 #include "tree_display.hh"
19 #include "tree_element.hh"
20 
21 namespace blender::ed::outliner {
22 
23 template<typename T> using List = ListBaseWrapper<T>;
24 
26  : AbstractTreeDisplay(space_outliner)
27 {
28 }
29 
31 {
32  ListBase tree = {nullptr};
33  ListBase *lbarray[INDEX_ID_MAX];
34  short filter_id_type = (space_outliner_.filter & SO_FILTER_ID_TYPE) ?
36  0;
37 
38  int tot;
39  if (filter_id_type) {
40  lbarray[0] = which_libbase(source_data.bmain, filter_id_type);
41  tot = 1;
42  }
43  else {
44  tot = set_listbasepointers(source_data.bmain, lbarray);
45  }
46 
47  for (int a = 0; a < tot; a++) {
48  if (BLI_listbase_is_empty(lbarray[a])) {
49  continue;
50  }
51  if (!datablock_has_orphans(*lbarray[a])) {
52  continue;
53  }
54 
55  /* Header for this type of data-block. */
56  TreeElement *te = nullptr;
57  if (!filter_id_type) {
58  ID *id = (ID *)lbarray[a]->first;
59  te = outliner_add_element(&space_outliner_, &tree, lbarray[a], nullptr, TSE_ID_BASE, 0);
60  te->directdata = lbarray[a];
62  }
63 
64  /* Add the orphaned data-blocks - these will not be added with any subtrees attached. */
65  for (ID *id : List<ID>(lbarray[a])) {
66  if (ID_REAL_USERS(id) <= 0) {
68  &space_outliner_, (te) ? &te->subtree : &tree, id, te, TSE_SOME_ID, 0);
69  }
70  }
71  }
72 
73  return tree;
74 }
75 
76 bool TreeDisplayIDOrphans::datablock_has_orphans(ListBase &lb) const
77 {
78  for (ID *id : List<ID>(lb)) {
79  if (ID_REAL_USERS(id) <= 0) {
80  return true;
81  }
82  }
83  return false;
84 }
85 
86 } // namespace blender::ed::outliner
int set_listbasepointers(struct Main *main, struct ListBase *lb[])
Definition: main.c:654
struct ListBase * which_libbase(struct Main *bmain, short type)
Definition: main.c:567
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:269
ID and Library types, which are fundamental for sdna.
@ INDEX_ID_MAX
Definition: DNA_ID.h:1058
#define ID_REAL_USERS(id)
Definition: DNA_ID.h:553
@ TSE_ID_BASE
@ TSE_SOME_ID
@ SO_FILTER_ID_TYPE
Base Class For Tree-Displays.
Definition: tree_display.hh:62
ListBase buildTree(const TreeSourceData &source_data) override
TreeDisplayIDOrphans(SpaceOutliner &space_outliner)
const char * outliner_idcode_to_plural(short idcode)
Definition: common.cc:28
void * tree
#define GS(x)
Definition: iris.c:225
static unsigned a[3]
Definition: RandGen.cpp:78
TreeElement * outliner_add_element(SpaceOutliner *space_outliner, ListBase *lb, void *idv, TreeElement *parent, short type, short index, const bool expand)
ListBaseWrapper< T > List
Definition: DNA_ID.h:368
char name[66]
Definition: DNA_ID.h:378
ListBase subtree
const char * name
The data to build the tree from.
Definition: tree_display.hh:43
Establish and manage Outliner trees for different display modes.