Blender  V2.93
BKE_collection.h
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 
17 #pragma once
18 
23 #include "BLI_compiler_compat.h"
24 #include "BLI_ghash.h"
25 #include "BLI_iterator.h"
26 #include "BLI_sys_types.h"
27 
28 #include "DNA_listBase.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* Structs */
35 
36 struct BLI_Iterator;
37 struct Base;
38 struct BlendDataReader;
39 struct BlendExpander;
40 struct BlendLibReader;
41 struct BlendWriter;
42 struct Collection;
43 struct Library;
44 struct Main;
45 struct Object;
46 struct Scene;
47 struct SceneCollection;
48 struct ViewLayer;
49 
50 typedef struct CollectionParent {
54 
55 /* Collections */
56 
57 struct Collection *BKE_collection_add(struct Main *bmain,
58  struct Collection *parent,
59  const char *name);
61  struct Scene *scene,
62  const struct Object *ob_src,
63  struct Collection *collection_dst);
64 void BKE_collection_add_from_collection(struct Main *bmain,
65  struct Scene *scene,
66  struct Collection *collection_src,
67  struct Collection *collection_dst);
68 void BKE_collection_free(struct Collection *collection);
69 bool BKE_collection_delete(struct Main *bmain, struct Collection *collection, bool hierarchy);
70 
72  struct Collection *parent,
73  struct Collection *collection,
74  const uint duplicate_flags,
75  const uint duplicate_options);
76 
77 /* Master Collection for Scene */
78 
80 
81 /* Collection Objects */
82 
83 bool BKE_collection_has_object(struct Collection *collection, const struct Object *ob);
84 bool BKE_collection_has_object_recursive(struct Collection *collection, struct Object *ob);
86  struct Object *ob);
87 struct Collection *BKE_collection_object_find(struct Main *bmain,
88  struct Scene *scene,
89  struct Collection *collection,
90  struct Object *ob);
91 bool BKE_collection_is_empty(const struct Collection *collection);
92 
93 bool BKE_collection_object_add(struct Main *bmain,
94  struct Collection *collection,
95  struct Object *ob);
96 void BKE_collection_object_add_from(struct Main *bmain,
97  struct Scene *scene,
98  struct Object *ob_src,
99  struct Object *ob_dst);
100 bool BKE_collection_object_remove(struct Main *bmain,
101  struct Collection *collection,
102  struct Object *object,
103  const bool free_us);
104 void BKE_collection_object_move(struct Main *bmain,
105  struct Scene *scene,
106  struct Collection *collection_dst,
107  struct Collection *collection_src,
108  struct Object *ob);
109 
110 bool BKE_scene_collections_object_remove(struct Main *bmain,
111  struct Scene *scene,
112  struct Object *object,
113  const bool free_us);
114 void BKE_collections_object_remove_nulls(struct Main *bmain);
115 void BKE_collections_child_remove_nulls(struct Main *bmain,
116  struct Collection *parent_collection,
117  struct Collection *child_collection);
118 
119 /* Dependencies. */
120 
121 bool BKE_collection_is_in_scene(struct Collection *collection);
122 void BKE_collections_after_lib_link(struct Main *bmain);
123 bool BKE_collection_object_cyclic_check(struct Main *bmain,
124  struct Object *object,
125  struct Collection *collection);
126 
127 /* Object list cache. */
128 
129 struct ListBase BKE_collection_object_cache_get(struct Collection *collection);
131 void BKE_collection_object_cache_free(struct Collection *collection);
132 
133 struct Base *BKE_collection_or_layer_objects(const struct ViewLayer *view_layer,
134  struct Collection *collection);
135 
136 /* Editing. */
137 
138 struct Collection *BKE_collection_from_index(struct Scene *scene, const int index);
139 void BKE_collection_new_name_get(struct Collection *collection_parent, char *rname);
140 const char *BKE_collection_ui_name_get(struct Collection *collection);
141 bool BKE_collection_objects_select(struct ViewLayer *view_layer,
142  struct Collection *collection,
143  bool deselect);
144 
145 /* Collection children */
146 
147 bool BKE_collection_child_add(struct Main *bmain,
148  struct Collection *parent,
149  struct Collection *child);
150 
151 bool BKE_collection_child_add_no_sync(struct Collection *parent, struct Collection *child);
152 
153 bool BKE_collection_child_remove(struct Main *bmain,
154  struct Collection *parent,
155  struct Collection *child);
156 
157 bool BKE_collection_move(struct Main *bmain,
158  struct Collection *to_parent,
159  struct Collection *from_parent,
160  struct Collection *relative,
161  bool relative_after,
162  struct Collection *collection);
163 
164 bool BKE_collection_cycle_find(struct Collection *new_ancestor, struct Collection *collection);
165 bool BKE_collection_cycles_fix(struct Main *bmain, struct Collection *collection);
166 
167 bool BKE_collection_has_collection(struct Collection *parent, struct Collection *collection);
168 
169 void BKE_collection_parent_relations_rebuild(struct Collection *collection);
171 
172 /* .blend file I/O */
173 
174 void BKE_collection_blend_write_nolib(struct BlendWriter *writer, struct Collection *collection);
175 void BKE_collection_blend_read_data(struct BlendDataReader *reader, struct Collection *collection);
176 void BKE_collection_blend_read_lib(struct BlendLibReader *reader, struct Collection *collection);
177 void BKE_collection_blend_read_expand(struct BlendExpander *expander,
178  struct Collection *collection);
179 
181  struct SceneCollection *sc);
183  struct Library *lib,
184  struct SceneCollection *sc);
186  struct SceneCollection *sc);
187 
188 /* Iteration callbacks. */
189 
190 typedef void (*BKE_scene_objects_Cb)(struct Object *ob, void *data);
191 typedef void (*BKE_scene_collections_Cb)(struct Collection *ob, void *data);
192 
193 /* Iteration over objects in collection. */
194 
195 #define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN(_collection, _object, _mode) \
196  { \
197  int _base_flag = (_mode == DAG_EVAL_VIEWPORT) ? BASE_ENABLED_VIEWPORT : BASE_ENABLED_RENDER; \
198  int _object_restrict_flag = (_mode == DAG_EVAL_VIEWPORT) ? OB_RESTRICT_VIEWPORT : \
199  OB_RESTRICT_RENDER; \
200  int _base_id = 0; \
201  for (Base *_base = (Base *)BKE_collection_object_cache_get(_collection).first; _base; \
202  _base = _base->next, _base_id++) { \
203  Object *_object = _base->object; \
204  if ((_base->flag & _base_flag) && (_object->restrictflag & _object_restrict_flag) == 0) {
205 
206 #define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END \
207  } \
208  } \
209  } \
210  ((void)0)
211 
212 #define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object) \
213  for (Base *_base = (Base *)BKE_collection_object_cache_get(_collection).first; _base; \
214  _base = _base->next) { \
215  Object *_object = _base->object; \
216  BLI_assert(_object != NULL);
217 
218 #define FOREACH_COLLECTION_OBJECT_RECURSIVE_END \
219  } \
220  ((void)0)
221 
222 /* Iteration over collections in scene. */
223 
224 void BKE_scene_collections_iterator_begin(struct BLI_Iterator *iter, void *data_in);
227 
228 void BKE_scene_objects_iterator_begin(struct BLI_Iterator *iter, void *data_in);
231 
232 struct GSet *BKE_scene_objects_as_gset(struct Scene *scene, struct GSet *objects_gset);
233 
234 #define FOREACH_SCENE_COLLECTION_BEGIN(scene, _instance) \
235  ITER_BEGIN (BKE_scene_collections_iterator_begin, \
236  BKE_scene_collections_iterator_next, \
237  BKE_scene_collections_iterator_end, \
238  scene, \
239  Collection *, \
240  _instance)
241 
242 #define FOREACH_SCENE_COLLECTION_END ITER_END
243 
244 #define FOREACH_COLLECTION_BEGIN(_bmain, _scene, Type, _instance) \
245  { \
246  Type _instance; \
247  Collection *_instance_next; \
248  bool is_scene_collection = (_scene) != NULL; \
249 \
250  if (_scene) { \
251  _instance_next = _scene->master_collection; \
252  } \
253  else { \
254  _instance_next = (_bmain)->collections.first; \
255  } \
256 \
257  while ((_instance = _instance_next)) { \
258  if (is_scene_collection) { \
259  _instance_next = (_bmain)->collections.first; \
260  is_scene_collection = false; \
261  } \
262  else { \
263  _instance_next = _instance->id.next; \
264  }
265 
266 #define FOREACH_COLLECTION_END \
267  } \
268  } \
269  ((void)0)
270 
271 #define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance) \
272  ITER_BEGIN (BKE_scene_objects_iterator_begin, \
273  BKE_scene_objects_iterator_next, \
274  BKE_scene_objects_iterator_end, \
275  scene, \
276  Object *, \
277  _instance)
278 
279 #define FOREACH_SCENE_OBJECT_END ITER_END
280 
281 #ifdef __cplusplus
282 }
283 #endif
struct Collection * BKE_collection_add(struct Main *bmain, struct Collection *parent, const char *name)
Definition: collection.c:435
void BKE_scene_objects_iterator_next(struct BLI_Iterator *iter)
Definition: collection.c:2145
bool BKE_collection_cycle_find(struct Collection *new_ancestor, struct Collection *collection)
Definition: collection.c:1450
struct ListBase BKE_collection_object_cache_get(struct Collection *collection)
Definition: collection.c:827
void(* BKE_scene_collections_Cb)(struct Collection *ob, void *data)
bool BKE_collection_child_add(struct Main *bmain, struct Collection *parent, struct Collection *child)
Definition: collection.c:1606
void BKE_collections_child_remove_nulls(struct Main *bmain, struct Collection *parent_collection, struct Collection *child_collection)
Definition: collection.c:1318
struct Collection * BKE_collection_object_find(struct Main *bmain, struct Scene *scene, struct Collection *collection, struct Object *ob)
Definition: collection.c:990
const char * BKE_collection_ui_name_get(struct Collection *collection)
Definition: collection.c:776
bool BKE_collection_cycles_fix(struct Main *bmain, struct Collection *collection)
Definition: collection.c:1519
void BKE_collection_object_cache_free(struct Collection *collection)
Definition: collection.c:872
void BKE_collection_object_add_from(struct Main *bmain, struct Scene *scene, struct Object *ob_src, struct Object *ob_dst)
Definition: collection.c:1168
bool BKE_collection_object_add(struct Main *bmain, struct Collection *collection, struct Object *ob)
Definition: collection.c:1134
void BKE_scene_collections_iterator_begin(struct BLI_Iterator *iter, void *data_in)
Definition: collection.c:2048
bool BKE_collection_has_object_recursive_instanced(struct Collection *collection, struct Object *ob)
Definition: collection.c:971
bool BKE_collection_object_cyclic_check(struct Main *bmain, struct Object *object, struct Collection *collection)
Definition: collection.c:938
struct GSet * BKE_scene_objects_as_gset(struct Scene *scene, struct GSet *objects_gset)
Definition: collection.c:2196
void BKE_collection_blend_read_data(struct BlendDataReader *reader, struct Collection *collection)
Definition: collection.c:244
void BKE_collection_compat_blend_read_lib(struct BlendLibReader *reader, struct Library *lib, struct SceneCollection *sc)
void BKE_collection_blend_read_lib(struct BlendLibReader *reader, struct Collection *collection)
Definition: collection.c:310
struct CollectionParent CollectionParent
void BKE_collection_compat_blend_read_expand(struct BlendExpander *expander, struct SceneCollection *sc)
void BKE_collection_add_from_object(struct Main *bmain, struct Scene *scene, const struct Object *ob_src, struct Collection *collection_dst)
bool BKE_collection_has_object(struct Collection *collection, const struct Object *ob)
bool BKE_collection_has_object_recursive(struct Collection *collection, struct Object *ob)
Definition: collection.c:961
bool BKE_collection_child_remove(struct Main *bmain, struct Collection *parent, struct Collection *child)
Definition: collection.c:1621
void BKE_collection_new_name_get(struct Collection *collection_parent, char *rname)
Definition: collection.c:751
void BKE_collection_compat_blend_read_data(struct BlendDataReader *reader, struct SceneCollection *sc)
void BKE_collection_add_from_collection(struct Main *bmain, struct Scene *scene, struct Collection *collection_src, struct Collection *collection_dst)
Definition: collection.c:476
void BKE_collections_object_remove_nulls(struct Main *bmain)
Definition: collection.c:1271
bool BKE_collection_is_in_scene(struct Collection *collection)
Definition: collection.c:1391
bool BKE_collection_has_collection(struct Collection *parent, struct Collection *collection)
Definition: collection.c:1545
struct Collection * BKE_collection_master_add(void)
Definition: collection.c:892
void BKE_collection_free(struct Collection *collection)
Definition: collection.c:510
bool BKE_collection_child_add_no_sync(struct Collection *parent, struct Collection *child)
Definition: collection.c:1616
void BKE_collection_blend_read_expand(struct BlendExpander *expander, struct Collection *collection)
Definition: collection.c:345
void BKE_scene_objects_iterator_end(struct BLI_Iterator *iter)
Definition: collection.c:2177
bool BKE_scene_collections_object_remove(struct Main *bmain, struct Scene *scene, struct Object *object, const bool free_us)
Definition: collection.c:1243
bool BKE_collection_is_empty(const struct Collection *collection)
bool BKE_collection_move(struct Main *bmain, struct Collection *to_parent, struct Collection *from_parent, struct Collection *relative, bool relative_after, struct Collection *collection)
Definition: collection.c:1918
bool BKE_collection_object_remove(struct Main *bmain, struct Collection *collection, struct Object *object, const bool free_us)
Definition: collection.c:1193
void(* BKE_scene_objects_Cb)(struct Object *ob, void *data)
void BKE_collections_after_lib_link(struct Main *bmain)
Definition: collection.c:1406
bool BKE_collection_delete(struct Main *bmain, struct Collection *collection, bool hierarchy)
Definition: collection.c:520
void BKE_scene_collections_iterator_end(struct BLI_Iterator *iter)
Definition: collection.c:2077
void BKE_scene_collections_iterator_next(struct BLI_Iterator *iter)
Definition: collection.c:2065
struct Base * BKE_collection_or_layer_objects(const struct ViewLayer *view_layer, struct Collection *collection)
void BKE_scene_objects_iterator_begin(struct BLI_Iterator *iter, void *data_in)
Definition: collection.c:2122
struct Collection * BKE_collection_from_index(struct Scene *scene, const int index)
Definition: collection.c:1734
void BKE_collection_object_move(struct Main *bmain, struct Scene *scene, struct Collection *collection_dst, struct Collection *collection_src, struct Object *ob)
Definition: collection.c:1367
void BKE_collection_blend_write_nolib(struct BlendWriter *writer, struct Collection *collection)
Definition: collection.c:197
bool BKE_collection_objects_select(struct ViewLayer *view_layer, struct Collection *collection, bool deselect)
Definition: collection.c:1781
void BKE_collection_parent_relations_rebuild(struct Collection *collection)
Definition: collection.c:1636
void BKE_main_collections_parent_relations_rebuild(struct Main *bmain)
Definition: collection.c:1671
struct Collection * BKE_collection_duplicate(struct Main *bmain, struct Collection *parent, struct Collection *collection, const uint duplicate_flags, const uint duplicate_options)
ListBase BKE_collection_object_cache_instanced_get(struct Collection *collection)
Definition: collection.c:843
struct GSet GSet
Definition: BLI_ghash.h:189
unsigned int uint
Definition: BLI_sys_types.h:83
These structs are the foundation for all linked lists in the library system.
Scene scene
DRWShaderLibrary * lib
struct CollectionParent * prev
struct Collection * collection
struct CollectionParent * next
Definition: BKE_main.h:116