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