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.
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.
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.
17 #ifndef __BKE_COLLECTION_H__
18 #define __BKE_COLLECTION_H__
24 #include "BLI_compiler_compat.h"
25 #include "BLI_ghash.h"
26 #include "BLI_iterator.h"
27 #include "DNA_listBase.h"
45 typedef struct CollectionParent {
46 struct CollectionParent *next, *prev;
47 struct Collection *collection;
52 struct Collection *BKE_collection_add(struct Main *bmain, struct Collection *parent, const char *name);
53 void BKE_collection_free(struct Collection *collection);
54 bool BKE_collection_delete(struct Main *bmain, struct Collection *collection, bool hierarchy);
56 struct Collection *BKE_collection_copy(struct Main *bmain, struct Collection *parent, struct Collection *collection);
57 struct Collection *BKE_collection_copy_master(struct Main *bmain, struct Collection *collection, const int flag);
58 void BKE_collection_copy_data(struct Main *bmain, struct Collection *collection_dst, const struct Collection *collection_src, const int flag);
59 void BKE_collection_copy_full(struct Main *bmain, struct Collection *collection);
60 void BKE_collection_make_local(struct Main *bmain, struct Collection *collection, const bool lib_local);
62 /* Master Collection for Scene */
64 struct Collection *BKE_collection_master(const struct Scene *scene);
65 struct Collection *BKE_collection_master_add(void);
67 /* Collection Objects */
69 bool BKE_collection_has_object(struct Collection *collection, struct Object *ob);
70 bool BKE_collection_has_object_recursive(struct Collection *collection, struct Object *ob);
71 struct Collection *BKE_collection_object_find(struct Main *bmain, struct Collection *collection, struct Object *ob);
72 bool BKE_collection_is_empty(struct Collection *collection);
74 bool BKE_collection_object_add(struct Main *bmain, struct Collection *collection, struct Object *ob);
75 void BKE_collection_object_add_from(struct Main *bmain, struct Scene *scene, struct Object *ob_src, struct Object *ob_dst);
76 bool BKE_collection_object_remove(struct Main *bmain, struct Collection *collection, struct Object *object, const bool free_us);
77 void BKE_collection_object_move(struct Main *bmain, struct Scene *scene, struct Collection *collection_dst, struct Collection *collection_src, struct Object *ob);
79 bool BKE_scene_collections_object_remove(struct Main *bmain, struct Scene *scene, struct Object *object, const bool free_us);
80 void BKE_collections_object_remove_nulls(struct Main *bmain);
81 void BKE_collections_child_remove_nulls(struct Main *bmain, struct Collection *old_collection);
85 bool BKE_collection_is_in_scene(struct Collection *collection);
86 void BKE_collections_after_lib_link(struct Main *bmain);
87 bool BKE_collection_object_cyclic_check(struct Main *bmain, struct Object *object, struct Collection *collection);
89 /* Object list cache. */
91 struct ListBase BKE_collection_object_cache_get(struct Collection *collection);
92 void BKE_collection_object_cache_free(struct Collection *collection);
94 struct Base *BKE_collection_or_layer_objects(const struct ViewLayer *view_layer, struct Collection *collection);
98 struct Collection *BKE_collection_from_index(struct Scene *scene, const int index);
99 void BKE_collection_new_name_get(struct Collection *collection_parent, char *rname);
100 const char *BKE_collection_ui_name_get(struct Collection *collection);
101 bool BKE_collection_objects_select(struct ViewLayer *view_layer, struct Collection *collection, bool deselect);
103 /* Collection children */
105 bool BKE_collection_child_add(struct Main *bmain,
106 struct Collection *parent,
107 struct Collection *child);
109 bool BKE_collection_child_remove(struct Main *bmain,
110 struct Collection *parent,
111 struct Collection *child);
113 bool BKE_collection_move(struct Main *bmain,
114 struct Collection *to_parent,
115 struct Collection *from_parent,
116 struct Collection *relative,
118 struct Collection *collection);
120 bool BKE_collection_find_cycle(struct Collection *new_ancestor,
121 struct Collection *collection);
124 /* Iteration callbacks. */
126 typedef void (*BKE_scene_objects_Cb)(struct Object *ob, void *data);
127 typedef void (*BKE_scene_collections_Cb)(struct Collection *ob, void *data);
129 /* Iteratorion over objects in collection. */
131 #define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN(_collection, _object, _mode) \
133 int _base_flag = (_mode == DAG_EVAL_VIEWPORT) ? \
134 BASE_ENABLED_VIEWPORT : BASE_ENABLED_RENDER; \
136 for (Base *_base = (Base*)BKE_collection_object_cache_get(_collection).first; \
138 _base = _base->next, _base_id++) \
140 if (_base->flag & _base_flag) { \
141 Object *_object = _base->object; \
143 #define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END \
148 #define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object) \
149 for (Base *_base = (Base*)BKE_collection_object_cache_get(_collection).first; \
151 _base = _base->next) \
153 Object *_object = _base->object; \
154 BLI_assert(_object != NULL);
156 #define FOREACH_COLLECTION_OBJECT_RECURSIVE_END \
159 /* Iteration over collections in scene. */
161 void BKE_scene_collections_iterator_begin(struct BLI_Iterator *iter, void *data_in);
162 void BKE_scene_collections_iterator_next(struct BLI_Iterator *iter);
163 void BKE_scene_collections_iterator_end(struct BLI_Iterator *iter);
165 void BKE_scene_objects_iterator_begin(struct BLI_Iterator *iter, void *data_in);
166 void BKE_scene_objects_iterator_next(struct BLI_Iterator *iter);
167 void BKE_scene_objects_iterator_end(struct BLI_Iterator *iter);
169 #define FOREACH_SCENE_COLLECTION_BEGIN(scene, _instance) \
170 ITER_BEGIN(BKE_scene_collections_iterator_begin, \
171 BKE_scene_collections_iterator_next, \
172 BKE_scene_collections_iterator_end, \
173 scene, Collection *, _instance)
175 #define FOREACH_SCENE_COLLECTION_END \
178 #define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance) \
179 ITER_BEGIN(BKE_scene_objects_iterator_begin, \
180 BKE_scene_objects_iterator_next, \
181 BKE_scene_objects_iterator_end, \
182 scene, Object *, _instance)
184 #define FOREACH_SCENE_OBJECT_END \
191 #endif /* __BKE_COLLECTION_H__ */