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