Blender  V3.3
tree_display_override_library_properties.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BLI_listbase.h"
9 
10 #include "BKE_collection.h"
11 #include "BKE_main.h"
12 
13 #include "DNA_collection_types.h"
14 #include "DNA_space_types.h"
15 
16 #include "BLT_translation.h"
17 
18 #include "../outliner_intern.hh"
19 #include "common.hh"
20 #include "tree_display.hh"
21 #include "tree_element.hh"
22 
23 namespace blender::ed::outliner {
24 
25 /* Convenience/readability. */
26 template<typename T> using List = ListBaseWrapper<T>;
27 
29  SpaceOutliner &space_outliner)
30  : AbstractTreeDisplay(space_outliner)
31 {
32 }
33 
35 {
36  ListBase tree = add_library_contents(*source_data.bmain);
37 
38  for (TreeElement *top_level_te : List<TreeElement>(tree)) {
39  TreeStoreElem *tselem = TREESTORE(top_level_te);
40  if (!tselem->used) {
41  tselem->flag &= ~TSE_CLOSED;
42  }
43  }
44 
45  return tree;
46 }
47 
48 ListBase TreeDisplayOverrideLibraryProperties::add_library_contents(Main &mainvar)
49 {
50  ListBase tree = {nullptr};
51 
52  const short filter_id_type = id_filter_get();
53 
54  ListBase *lbarray[INDEX_ID_MAX];
55  int tot;
56  if (filter_id_type) {
57  lbarray[0] = which_libbase(&mainvar, space_outliner_.filter_id_type);
58  tot = 1;
59  }
60  else {
61  tot = set_listbasepointers(&mainvar, lbarray);
62  }
63 
64  for (int a = 0; a < tot; a++) {
65  if (!lbarray[a] || !lbarray[a]->first) {
66  continue;
67  }
68 
69  ID *id = nullptr;
70 
71  /* check if there's data in current id list */
72  for (ID *id_iter : List<ID>(lbarray[a])) {
73  if (ID_IS_OVERRIDE_LIBRARY_REAL(id_iter) && !ID_IS_LINKED(id_iter)) {
74  id = id_iter;
75  break;
76  }
77  }
78 
79  if (id == nullptr) {
80  continue;
81  }
82 
83  /* Create data-block list parent element on demand. */
84  TreeElement *id_base_te = nullptr;
85  ListBase *lb_to_expand = &tree;
86 
87  if (!filter_id_type) {
88  id_base_te = outliner_add_element(
89  &space_outliner_, &tree, lbarray[a], nullptr, TSE_ID_BASE, 0);
90  id_base_te->directdata = lbarray[a];
91  id_base_te->name = outliner_idcode_to_plural(GS(id->name));
92 
93  lb_to_expand = &id_base_te->subtree;
94  }
95 
96  for (ID *id : List<ID>(lbarray[a])) {
97  if (ID_IS_OVERRIDE_LIBRARY_REAL(id) && !ID_IS_LINKED(id)) {
98  TreeElement *override_tree_element = outliner_add_element(
99  &space_outliner_, lb_to_expand, id, id_base_te, TSE_LIBRARY_OVERRIDE_BASE, 0);
100 
101  if (BLI_listbase_is_empty(&override_tree_element->subtree)) {
102  outliner_free_tree_element(override_tree_element, lb_to_expand);
103  }
104  }
105  }
106  }
107 
108  /* Remove ID base elements that turn out to be empty. */
110  if (BLI_listbase_is_empty(&te->subtree)) {
112  }
113  }
114 
115  return tree;
116 }
117 
118 short TreeDisplayOverrideLibraryProperties::id_filter_get() const
119 {
122  }
123  return 0;
124 }
125 
126 } // 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
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
Definition: BLI_listbase.h:354
#define ID_IS_OVERRIDE_LIBRARY_REAL(_id)
Definition: DNA_ID.h:581
@ INDEX_ID_MAX
Definition: DNA_ID.h:1058
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:566
Object groups, one object can be in many groups at once.
@ TSE_LIBRARY_OVERRIDE_BASE
@ TSE_ID_BASE
@ TSE_CLOSED
@ SO_FILTER_ID_TYPE
Base Class For Tree-Displays.
Definition: tree_display.hh:62
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
#define TREESTORE(a)
void outliner_free_tree_element(TreeElement *element, ListBase *parent_subtree)
Definition: DNA_ID.h:368
char name[66]
Definition: DNA_ID.h:378
Definition: BKE_main.h:121
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.