Blender  V2.93
tree_display_orphaned.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "DNA_ID.h"
22 
23 #include "BLI_listbase.h"
24 #include "BLI_listbase_wrapper.hh"
25 #include "BLI_utildefines.h"
26 
27 #include "BKE_main.h"
28 
29 #include "../outliner_intern.h"
30 #include "tree_display.hh"
31 
32 namespace blender::ed::outliner {
33 
34 /* Convenience/readability. */
35 template<typename T> using List = ListBaseWrapper<T>;
36 
38  : AbstractTreeDisplay(space_outliner)
39 {
40 }
41 
43 {
44  ListBase tree = {nullptr};
45  ListBase *lbarray[INDEX_ID_MAX];
46  short filter_id_type = (space_outliner_.filter & SO_FILTER_ID_TYPE) ?
48  0;
49 
50  int tot;
51  if (filter_id_type) {
52  lbarray[0] = which_libbase(source_data.bmain, filter_id_type);
53  tot = 1;
54  }
55  else {
56  tot = set_listbasepointers(source_data.bmain, lbarray);
57  }
58 
59  for (int a = 0; a < tot; a++) {
60  if (BLI_listbase_is_empty(lbarray[a])) {
61  continue;
62  }
63  if (!datablock_has_orphans(*lbarray[a])) {
64  continue;
65  }
66 
67  /* Header for this type of data-block. */
68  TreeElement *te = nullptr;
69  if (!filter_id_type) {
70  ID *id = (ID *)lbarray[a]->first;
71  te = outliner_add_element(&space_outliner_, &tree, lbarray[a], nullptr, TSE_ID_BASE, 0);
72  te->directdata = lbarray[a];
74  }
75 
76  /* Add the orphaned data-blocks - these will not be added with any subtrees attached. */
77  for (ID *id : List<ID>(lbarray[a])) {
78  if (ID_REAL_USERS(id) <= 0) {
80  &space_outliner_, (te) ? &te->subtree : &tree, id, te, TSE_SOME_ID, 0);
81  }
82  }
83  }
84 
85  return tree;
86 }
87 
88 bool TreeDisplayIDOrphans::datablock_has_orphans(ListBase &lb) const
89 {
90  for (ID *id : List<ID>(lb)) {
91  if (ID_REAL_USERS(id) <= 0) {
92  return true;
93  }
94  }
95  return false;
96 }
97 
98 } // namespace blender::ed::outliner
int set_listbasepointers(struct Main *main, struct ListBase *lb[])
struct ListBase * which_libbase(struct Main *bmain, short type)
Definition: main.c:447
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:124
ID and Library types, which are fundamental for sdna.
#define ID_REAL_USERS(id)
Definition: DNA_ID.h:413
@ INDEX_ID_MAX
Definition: DNA_ID.h:859
@ TSE_ID_BASE
@ TSE_SOME_ID
@ SO_FILTER_ID_TYPE
Base Class For Tree-Displays.
Definition: tree_display.hh:55
ListBase buildTree(const TreeSourceData &source_data) override
TreeDisplayIDOrphans(SpaceOutliner &space_outliner)
const char * outliner_idcode_to_plural(short idcode)
Definition: common.cc:33
void * tree
#define GS(x)
Definition: iris.c:241
static unsigned a[3]
Definition: RandGen.cpp:92
ListBaseWrapper< T > List
TreeElement * outliner_add_element(SpaceOutliner *space_outliner, ListBase *lb, void *idv, TreeElement *parent, short type, short index)
Definition: DNA_ID.h:273
char name[66]
Definition: DNA_ID.h:283
ListBase subtree
void * directdata
const char * name
The data to build the tree from.
Definition: tree_display.h:39
struct Main * bmain
Definition: tree_display.h:40
Establish and manage Outliner trees for different display modes.