doxygen: add newline after \file
[blender.git] / source / blender / blenkernel / BKE_layer.h
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 #ifndef __BKE_LAYER_H__
18 #define __BKE_LAYER_H__
19
20 /** \file
21  * \ingroup bke
22  */
23
24 #include "BKE_collection.h"
25
26 #include "DNA_listBase.h"
27 #include "DNA_scene_types.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #define TODO_LAYER_OVERRIDE /* CollectionOverride */
34 #define TODO_LAYER_OPERATORS /* collection mamanger and property panel operators */
35 #define TODO_LAYER /* generic todo */
36
37 struct Base;
38 struct Collection;
39 struct Depsgraph;
40 struct ID;
41 struct IDProperty;
42 struct LayerCollection;
43 struct ListBase;
44 struct Main;
45 struct Object;
46 struct RenderEngine;
47 struct Scene;
48 struct View3D;
49 struct ViewLayer;
50 struct WorkSpace;
51
52 struct ViewLayer *BKE_view_layer_default_view(const struct Scene *scene);
53 struct ViewLayer *BKE_view_layer_default_render(const struct Scene *scene);
54 struct ViewLayer *BKE_view_layer_find(const struct Scene *scene, const char *layer_name);
55 struct ViewLayer *BKE_view_layer_add(struct Scene *scene, const char *name);
56
57 /* DEPRECATED */
58 struct ViewLayer *BKE_view_layer_context_active_PLACEHOLDER(const struct Scene *scene);
59
60 void BKE_view_layer_free(struct ViewLayer *view_layer);
61 void BKE_view_layer_free_ex(struct ViewLayer *view_layer, const bool do_id_user);
62
63 void BKE_view_layer_selected_objects_tag(struct ViewLayer *view_layer, const int tag);
64
65 struct Object *BKE_view_layer_camera_find(struct ViewLayer *view_layer);
66 struct ViewLayer *BKE_view_layer_find_from_collection(const struct Scene *scene, struct LayerCollection *lc);
67 struct Base *BKE_view_layer_base_find(struct ViewLayer *view_layer, struct Object *ob);
68 void BKE_view_layer_base_deselect_all(struct ViewLayer *view_layer);
69
70 void BKE_view_layer_base_select(struct Base *selbase);
71 void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, struct Base *selbase);
72
73 void BKE_view_layer_copy_data(
74         struct Scene *scene_dst, const struct Scene *scene_src,
75         struct ViewLayer *view_layer_dst, const struct ViewLayer *view_layer_src,
76         const int flag);
77
78 void BKE_view_layer_rename(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, const char *name);
79
80 struct LayerCollection *BKE_layer_collection_get_active(struct ViewLayer *view_layer);
81 bool BKE_layer_collection_activate(struct ViewLayer *view_layer, struct LayerCollection *lc);
82 struct LayerCollection *BKE_layer_collection_activate_parent(struct ViewLayer *view_layer, struct LayerCollection *lc);
83
84 int BKE_layer_collection_count(struct ViewLayer *view_layer);
85
86 struct LayerCollection *BKE_layer_collection_from_index(struct ViewLayer *view_layer, const int index);
87 int BKE_layer_collection_findindex(struct ViewLayer *view_layer, const struct LayerCollection *lc);
88
89 void BKE_main_collection_sync(const struct Main *bmain);
90 void BKE_scene_collection_sync(const struct Scene *scene);
91 void BKE_layer_collection_sync(const struct Scene *scene, struct ViewLayer *view_layer);
92
93 void BKE_main_collection_sync_remap(const struct Main *bmain);
94
95 struct LayerCollection *BKE_layer_collection_first_from_scene_collection(
96         struct ViewLayer *view_layer, const struct Collection *collection);
97 bool BKE_view_layer_has_collection(
98         struct ViewLayer *view_layer, const struct Collection *collection);
99 bool BKE_scene_has_object(
100         struct Scene *scene, struct Object *ob);
101
102 /* selection and hiding */
103
104 bool BKE_layer_collection_objects_select(
105         struct ViewLayer *view_layer, struct LayerCollection *lc, bool deselect);
106 bool BKE_layer_collection_has_selected_objects(
107         struct ViewLayer *view_layer, struct LayerCollection *lc);
108 bool BKE_layer_collection_has_layer_collection(
109         struct LayerCollection *lc_parent, struct LayerCollection *lc_child);
110
111 void BKE_base_set_visible(struct Scene *scene, struct ViewLayer *view_layer, struct Base *base, bool extend);
112 bool BKE_layer_collection_isolate(struct Scene *scene, struct ViewLayer *view_layer, struct LayerCollection *lc, bool extend);
113 bool BKE_layer_collection_set_visible(struct ViewLayer *view_layer, struct LayerCollection *lc, const bool visible, const bool hierarchy);
114
115 /* evaluation */
116
117 void BKE_layer_eval_view_layer(
118         struct Depsgraph *depsgraph,
119         struct Scene *scene,
120         struct ViewLayer *view_layer);
121
122 void BKE_layer_eval_view_layer_indexed(
123         struct Depsgraph *depsgraph,
124         struct Scene *scene,
125         int view_layer_index);
126
127 /* iterators */
128
129 typedef struct ObjectsVisibleIteratorData {
130         struct ViewLayer *view_layer;
131         struct View3D *v3d;
132 } ObjectsVisibleIteratorData;
133
134 void BKE_view_layer_selected_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
135 void BKE_view_layer_selected_objects_iterator_next(BLI_Iterator *iter);
136 void BKE_view_layer_selected_objects_iterator_end(BLI_Iterator *iter);
137
138 void BKE_view_layer_visible_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
139 void BKE_view_layer_visible_objects_iterator_next(BLI_Iterator *iter);
140 void BKE_view_layer_visible_objects_iterator_end(BLI_Iterator *iter);
141
142 void BKE_view_layer_selected_editable_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
143 void BKE_view_layer_selected_editable_objects_iterator_next(BLI_Iterator *iter);
144 void BKE_view_layer_selected_editable_objects_iterator_end(BLI_Iterator *iter);
145
146 struct ObjectsInModeIteratorData {
147         int object_mode;
148         int object_type;
149         struct ViewLayer *view_layer;
150         struct View3D *v3d;
151         struct Base *base_active;
152 };
153
154 void BKE_view_layer_bases_in_mode_iterator_begin(BLI_Iterator *iter, void *data_in);
155 void BKE_view_layer_bases_in_mode_iterator_next(BLI_Iterator *iter);
156 void BKE_view_layer_bases_in_mode_iterator_end(BLI_Iterator *iter);
157
158 void BKE_view_layer_selected_bases_iterator_begin(BLI_Iterator *iter, void *data_in);
159 void BKE_view_layer_selected_bases_iterator_next(BLI_Iterator *iter);
160 void BKE_view_layer_selected_bases_iterator_end(BLI_Iterator *iter);
161
162 void BKE_view_layer_visible_bases_iterator_begin(BLI_Iterator *iter, void *data_in);
163 void BKE_view_layer_visible_bases_iterator_next(BLI_Iterator *iter);
164 void BKE_view_layer_visible_bases_iterator_end(BLI_Iterator *iter);
165
166 #define FOREACH_SELECTED_OBJECT_BEGIN(_view_layer, _v3d, _instance)           \
167 { \
168         struct ObjectsVisibleIteratorData data_ = {                               \
169                 .view_layer = _view_layer,                                            \
170                 .v3d = _v3d,                                                          \
171         };                                                                        \
172         ITER_BEGIN(BKE_view_layer_selected_objects_iterator_begin,                \
173                    BKE_view_layer_selected_objects_iterator_next,                 \
174                    BKE_view_layer_selected_objects_iterator_end,                  \
175                    &data_, Object *, _instance)
176
177 #define FOREACH_SELECTED_OBJECT_END                                           \
178         ITER_END;                                                                 \
179 } ((void)0)
180
181 #define FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN(_view_layer, _v3d, _instance)  \
182 { \
183         struct ObjectsVisibleIteratorData data_ = {                               \
184                 .view_layer = _view_layer,                                            \
185                 .v3d = _v3d,                                                          \
186         };                                                                        \
187         ITER_BEGIN(BKE_view_layer_selected_editable_objects_iterator_begin,       \
188                    BKE_view_layer_selected_editable_objects_iterator_next,        \
189                    BKE_view_layer_selected_editable_objects_iterator_end,         \
190                    &data_, Object *, _instance)
191
192 #define FOREACH_SELECTED_EDITABLE_OBJECT_END                                  \
193         ITER_END;                                                                 \
194 } ((void)0)
195
196 #define FOREACH_VISIBLE_OBJECT_BEGIN(_view_layer, _v3d, _instance)            \
197 { \
198         struct ObjectsVisibleIteratorData data_ = {                               \
199                 .view_layer = _view_layer,                                            \
200                 .v3d = _v3d,                                                          \
201         };                                                                        \
202         ITER_BEGIN(BKE_view_layer_visible_objects_iterator_begin,                 \
203                    BKE_view_layer_visible_objects_iterator_next,                  \
204                    BKE_view_layer_visible_objects_iterator_end,                   \
205                    &data_, Object *, _instance)
206
207 #define FOREACH_VISIBLE_OBJECT_END                                            \
208         ITER_END;                                                                 \
209 } ((void)0)
210
211 #define FOREACH_BASE_IN_MODE_BEGIN(_view_layer, _v3d, _object_type, _object_mode, _instance) \
212 { \
213         struct ObjectsInModeIteratorData data_ = {                                \
214                 .object_mode = _object_mode,                                          \
215                 .object_type = _object_type,                                          \
216                 .view_layer = _view_layer,                                            \
217                 .v3d = _v3d,                                                          \
218                 .base_active = _view_layer->basact,                                   \
219         };                                                                        \
220         ITER_BEGIN(BKE_view_layer_bases_in_mode_iterator_begin,                   \
221                    BKE_view_layer_bases_in_mode_iterator_next,                    \
222                    BKE_view_layer_bases_in_mode_iterator_end,                     \
223                    &data_, Base *, _instance)
224
225 #define FOREACH_BASE_IN_MODE_END                                              \
226         ITER_END;                                                                 \
227 } ((void)0)
228
229 #define FOREACH_BASE_IN_EDIT_MODE_BEGIN(_view_layer, _v3d, _instance)         \
230         FOREACH_BASE_IN_MODE_BEGIN(_view_layer, _v3d, -1, OB_MODE_EDIT, _instance)
231
232 #define FOREACH_BASE_IN_EDIT_MODE_END                                         \
233         FOREACH_BASE_IN_MODE_END
234
235 #define FOREACH_OBJECT_IN_MODE_BEGIN(_view_layer, _v3d, _object_type, _object_mode, _instance) \
236         FOREACH_BASE_IN_MODE_BEGIN(_view_layer, _v3d, _object_type, _object_mode, _base) {      \
237                 Object *_instance = _base->object;
238
239 #define FOREACH_OBJECT_IN_MODE_END                                            \
240         } FOREACH_BASE_IN_MODE_END
241
242 #define FOREACH_OBJECT_IN_EDIT_MODE_BEGIN(_view_layer, _v3d, _instance)       \
243         FOREACH_BASE_IN_EDIT_MODE_BEGIN(_view_layer, _v3d, _base) {               \
244                 Object *_instance = _base->object;
245
246 #define FOREACH_OBJECT_IN_EDIT_MODE_END                                       \
247         } FOREACH_BASE_IN_EDIT_MODE_END
248
249 #define FOREACH_SELECTED_BASE_BEGIN(view_layer, _instance)                    \
250         ITER_BEGIN(BKE_view_layer_selected_bases_iterator_begin,                  \
251                    BKE_view_layer_selected_bases_iterator_next,                   \
252                    BKE_view_layer_selected_bases_iterator_end,                    \
253                    view_layer, Base *, _instance)
254
255 #define FOREACH_SELECTED_BASE_END                                             \
256         ITER_END
257
258 #define FOREACH_VISIBLE_BASE_BEGIN(_view_layer, _v3d, _instance)              \
259 { \
260         struct ObjectsVisibleIteratorData data_ = {                               \
261                 .view_layer = _view_layer,                                            \
262                 .v3d = _v3d,                                                          \
263         };                                                                        \
264         ITER_BEGIN(BKE_view_layer_visible_bases_iterator_begin,                   \
265                    BKE_view_layer_visible_bases_iterator_next,                    \
266                    BKE_view_layer_visible_bases_iterator_end,                     \
267                    &data_, Base *, _instance)
268
269 #define FOREACH_VISIBLE_BASE_END                                              \
270         ITER_END;                                                                 \
271 } ((void)0)
272
273
274 #define FOREACH_OBJECT_BEGIN(view_layer, _instance)                           \
275 {                                                                             \
276         Object *_instance;                                                        \
277         Base *_base;                                                              \
278         for (_base = (view_layer)->object_bases.first; _base; _base = _base->next) { \
279                 _instance = _base->object;
280
281 #define FOREACH_OBJECT_END                                                    \
282     }                                                                         \
283 } ((void)0)
284
285 #define FOREACH_OBJECT_FLAG_BEGIN(scene, _view_layer, _v3d, flag, _instance)  \
286 {                                                                             \
287         IteratorBeginCb func_begin;                                               \
288         IteratorCb func_next, func_end;                                           \
289         void *data_in;                                                            \
290         struct ObjectsVisibleIteratorData data_ = {                               \
291                 .view_layer = _view_layer,                                            \
292                 .v3d = _v3d,                                                          \
293         };                                                                        \
294                                                                                   \
295         if (flag == SELECT) {                                                     \
296             func_begin = &BKE_view_layer_selected_objects_iterator_begin;         \
297             func_next = &BKE_view_layer_selected_objects_iterator_next;           \
298             func_end = &BKE_view_layer_selected_objects_iterator_end;             \
299             data_in = &data_;                                                     \
300         }                                                                         \
301         else {                                                                    \
302             func_begin = BKE_scene_objects_iterator_begin;                        \
303             func_next = BKE_scene_objects_iterator_next;                          \
304             func_end = BKE_scene_objects_iterator_end;                            \
305             data_in = (scene);                                                    \
306         }                                                                         \
307         ITER_BEGIN(func_begin, func_next, func_end, data_in, Object *, _instance)
308
309
310 #define FOREACH_OBJECT_FLAG_END                                               \
311         ITER_END;                                                                 \
312 } ((void)0)
313
314 /* layer_utils.c */
315
316 struct ObjectsInModeParams {
317         int object_mode;
318         uint no_dup_data : 1;
319
320         bool (*filter_fn)(struct Object *ob, void *user_data);
321         void  *filter_userdata;
322 };
323
324 Base **BKE_view_layer_array_from_bases_in_mode_params(
325         struct ViewLayer *view_layer, struct View3D *v3d, uint *r_len,
326         const struct ObjectsInModeParams *params);
327
328 struct Object **BKE_view_layer_array_from_objects_in_mode_params(
329         struct ViewLayer *view_layer, struct View3D *v3d, uint *len,
330         const struct ObjectsInModeParams *params);
331
332 #define BKE_view_layer_array_from_objects_in_mode(view_layer, v3d, r_len, ...) \
333         BKE_view_layer_array_from_objects_in_mode_params( \
334                 view_layer, v3d, r_len, \
335                 &(const struct ObjectsInModeParams)__VA_ARGS__)
336
337 #define BKE_view_layer_array_from_bases_in_mode(view_layer, v3d, r_len, ...) \
338         BKE_view_layer_array_from_bases_in_mode_params( \
339                 view_layer, v3d, r_len, \
340                 &(const struct ObjectsInModeParams)__VA_ARGS__)
341
342 bool BKE_view_layer_filter_edit_mesh_has_uvs(struct Object *ob, void *user_data);
343 bool BKE_view_layer_filter_edit_mesh_has_edges(struct Object *ob, void *user_data);
344
345 /* Utility macros that wrap common args (add more as needed). */
346
347 #define BKE_view_layer_array_from_objects_in_edit_mode(view_layer, v3d, r_len) \
348         BKE_view_layer_array_from_objects_in_mode( \
349         view_layer, v3d, r_len, { \
350                 .object_mode = OB_MODE_EDIT});
351
352 #define BKE_view_layer_array_from_bases_in_edit_mode(view_layer, v3d, r_len) \
353         BKE_view_layer_array_from_bases_in_mode( \
354         view_layer, v3d, r_len, { \
355                 .object_mode = OB_MODE_EDIT});
356
357 #define BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, v3d, r_len) \
358         BKE_view_layer_array_from_objects_in_mode( \
359         view_layer, v3d, r_len, { \
360                 .object_mode = OB_MODE_EDIT, \
361                 .no_dup_data = true});
362
363 #define BKE_view_layer_array_from_bases_in_edit_mode_unique_data(view_layer, v3d, r_len) \
364         BKE_view_layer_array_from_bases_in_mode( \
365         view_layer, v3d, r_len, { \
366                 .object_mode = OB_MODE_EDIT, \
367                 .no_dup_data = true});
368
369 #define BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, v3d, r_len) \
370         BKE_view_layer_array_from_objects_in_mode( \
371         view_layer, v3d, r_len, { \
372                 .object_mode = OB_MODE_EDIT, \
373                 .no_dup_data = true, \
374                 .filter_fn = BKE_view_layer_filter_edit_mesh_has_uvs});
375
376 #define BKE_view_layer_array_from_objects_in_mode_unique_data(view_layer, v3d, r_len, mode) \
377         BKE_view_layer_array_from_objects_in_mode( \
378         view_layer, v3d, r_len, { \
379                 .object_mode = mode, \
380                 .no_dup_data = true});
381
382 #ifdef __cplusplus
383 }
384 #endif
385
386 #endif /* __BKE_LAYER_H__ */