Merge branch 'master' into blender2.8
[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 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #define TODO_LAYER_SYNC_FILTER /* syncing of filter_objects across all trees */
37 #define TODO_LAYER_OVERRIDE /* CollectionOverride */
38 #define TODO_LAYER_OPERATORS /* collection mamanger and property panel operators */
39 #define TODO_LAYER /* generic todo */
40
41 #define ROOT_PROP "root"
42
43 struct Base;
44 struct EvaluationContext;
45 struct ID;
46 struct IDProperty;
47 struct LayerCollection;
48 struct ListBase;
49 struct Main;
50 struct Object;
51 struct RenderEngine;
52 struct Scene;
53 struct SceneCollection;
54 struct SceneLayer;
55 struct WorkSpace;
56
57 void BKE_layer_exit(void);
58
59 struct SceneLayer *BKE_scene_layer_from_scene_get(const struct Scene *scene);
60 struct SceneLayer *BKE_scene_layer_from_workspace_get(const struct Scene *scene, const struct WorkSpace *workspace);
61 struct SceneLayer *BKE_scene_layer_add(struct Scene *scene, const char *name);
62
63 /* DEPRECATED */
64 struct SceneLayer *BKE_scene_layer_context_active_PLACEHOLDER(const struct Scene *scene);
65
66 void BKE_scene_layer_free(struct SceneLayer *sl);
67
68 void BKE_scene_layer_selected_objects_tag(struct SceneLayer *sl, const int tag);
69
70 struct Object *BKE_scene_layer_camera_find(struct SceneLayer *sl);
71 struct SceneLayer *BKE_scene_layer_find_from_collection(const struct Scene *scene, struct LayerCollection *lc);
72 struct Base *BKE_scene_layer_base_find(struct SceneLayer *sl, struct Object *ob);
73 struct Base *BKE_scene_layer_base_find_by_name(struct SceneLayer *sl, struct Object *ob);
74 void BKE_scene_layer_base_deselect_all(struct SceneLayer *sl);
75 void BKE_scene_layer_base_select(struct SceneLayer *sl, struct Base *selbase);
76
77 void BKE_layer_collection_free(struct SceneLayer *sl, struct LayerCollection *lc);
78
79 struct LayerCollection *BKE_layer_collection_get_active(struct SceneLayer *sl);
80 struct LayerCollection *BKE_layer_collection_get_active_ensure(struct Scene *scene, struct SceneLayer *sl);
81
82 int BKE_layer_collection_count(struct SceneLayer *sl);
83
84 struct LayerCollection *BKE_layer_collection_from_index(struct SceneLayer *sl, const int index);
85 int BKE_layer_collection_findindex(struct SceneLayer *sl, const struct LayerCollection *lc);
86
87 bool BKE_layer_collection_move_above(const struct Scene *scene, struct LayerCollection *lc_dst, struct LayerCollection *lc_src);
88 bool BKE_layer_collection_move_below(const struct Scene *scene, struct LayerCollection *lc_dst, struct LayerCollection *lc_src);
89 bool BKE_layer_collection_move_into(const struct Scene *scene, struct LayerCollection *lc_dst, struct LayerCollection *lc_src);
90
91 void BKE_layer_collection_resync(const struct Scene *scene, const struct SceneCollection *sc);
92
93 struct LayerCollection *BKE_collection_link(struct SceneLayer *sl, struct SceneCollection *sc);
94
95 void BKE_collection_unlink(struct SceneLayer *sl, struct LayerCollection *lc);
96
97 void BKE_collection_enable(struct SceneLayer *sl, struct LayerCollection *lc);
98 void BKE_collection_disable(struct SceneLayer *sl, struct LayerCollection *lc);
99
100 bool BKE_scene_layer_has_collection(struct SceneLayer *sl, const struct SceneCollection *sc);
101 bool BKE_scene_has_object(struct Scene *scene, struct Object *ob);
102
103 /* syncing */
104
105 void BKE_layer_sync_new_scene_collection(struct Scene *scene, const struct SceneCollection *sc_parent, struct SceneCollection *sc);
106 void BKE_layer_sync_object_link(const struct Scene *scene, struct SceneCollection *sc, struct Object *ob);
107 void BKE_layer_sync_object_unlink(const struct Scene *scene, struct SceneCollection *sc, struct Object *ob);
108
109 /* override */
110
111 void BKE_override_scene_layer_datablock_add(struct SceneLayer *scene_layer, int id_type, const char *data_path, const struct ID *id);
112 void BKE_override_scene_layer_int_add(struct SceneLayer *scene_layer, int id_type, const char *data_path, const int value);
113
114 void BKE_override_layer_collection_boolean_add(struct LayerCollection *layer_collection, int id_type, const char *data_path, const bool value);
115
116 /* engine settings */
117 typedef void (*EngineSettingsCB)(struct RenderEngine *engine, struct IDProperty *props);
118
119 struct IDProperty *BKE_layer_collection_engine_evaluated_get(struct Object *ob, const int type, const char *engine_name);
120 struct IDProperty *BKE_layer_collection_engine_collection_get(struct LayerCollection *lc, const int type, const char *engine_name);
121 struct IDProperty *BKE_layer_collection_engine_scene_get(struct Scene *scene, const int type, const char *engine_name);
122 void BKE_layer_collection_engine_settings_callback_register(struct Main *bmain, const char *engine_name, EngineSettingsCB func);
123 void BKE_layer_collection_engine_settings_callback_free(void);
124 void BKE_layer_collection_engine_settings_create(struct IDProperty *root);
125 void BKE_layer_collection_engine_settings_validate_scene(struct Scene *scene);
126 void BKE_layer_collection_engine_settings_validate_collection(struct LayerCollection *lc);
127
128 struct IDProperty *BKE_scene_layer_engine_evaluated_get(struct SceneLayer *sl, const int type, const char *engine_name);
129 struct IDProperty *BKE_scene_layer_engine_layer_get(struct SceneLayer *sl, const int type, const char *engine_name);
130 struct IDProperty *BKE_scene_layer_engine_scene_get(struct Scene *scene, const int type, const char *engine_name);
131 void BKE_scene_layer_engine_settings_callback_register(struct Main *bmain, const char *engine_name, EngineSettingsCB func);
132 void BKE_scene_layer_engine_settings_callback_free(void);
133 void BKE_scene_layer_engine_settings_validate_scene(struct Scene *scene);
134 void BKE_scene_layer_engine_settings_validate_layer(struct SceneLayer *sl);
135 void BKE_scene_layer_engine_settings_create(struct IDProperty *root);
136
137 void BKE_collection_engine_property_add_float(struct IDProperty *props, const char *name, float value);
138 void BKE_collection_engine_property_add_float_array(
139         struct IDProperty *props, const char *name, const float *values, const int array_length);
140 void BKE_collection_engine_property_add_int(struct IDProperty *props, const char *name, int value);
141 void BKE_collection_engine_property_add_bool(struct IDProperty *props, const char *name, bool value);
142
143 int BKE_collection_engine_property_value_get_int(struct IDProperty *props, const char *name);
144 float BKE_collection_engine_property_value_get_float(struct IDProperty *props, const char *name);
145 const float *BKE_collection_engine_property_value_get_float_array(struct IDProperty *props, const char *name);
146 bool BKE_collection_engine_property_value_get_bool(struct IDProperty *props, const char *name);
147 void BKE_collection_engine_property_value_set_int(struct IDProperty *props, const char *name, int value);
148 void BKE_collection_engine_property_value_set_float(struct IDProperty *props, const char *name, float value);
149 void BKE_collection_engine_property_value_set_float_array(struct IDProperty *props, const char *name, const float *values);
150 void BKE_collection_engine_property_value_set_bool(struct IDProperty *props, const char *name, bool value);
151
152 /* evaluation */
153
154 void BKE_layer_eval_layer_collection_pre(const struct EvaluationContext *eval_ctx,
155                                          struct Scene *scene,
156                                          struct SceneLayer *scene_layer);
157 void BKE_layer_eval_layer_collection(const struct EvaluationContext *eval_ctx,
158                                      struct LayerCollection *layer_collection,
159                                      struct LayerCollection *parent_layer_collection);
160 void BKE_layer_eval_layer_collection_post(const struct EvaluationContext *eval_ctx,
161                                           struct SceneLayer *scene_layer);
162
163 /* iterators */
164
165 void BKE_selected_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
166 void BKE_selected_objects_iterator_next(BLI_Iterator *iter);
167 void BKE_selected_objects_iterator_end(BLI_Iterator *iter);
168
169 void BKE_visible_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
170 void BKE_visible_objects_iterator_next(BLI_Iterator *iter);
171 void BKE_visible_objects_iterator_end(BLI_Iterator *iter);
172
173 void BKE_renderable_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
174 void BKE_renderable_objects_iterator_next(BLI_Iterator *iter);
175 void BKE_renderable_objects_iterator_end(BLI_Iterator *iter);
176
177 void BKE_selected_bases_iterator_begin(BLI_Iterator *iter, void *data_in);
178 void BKE_selected_bases_iterator_next(BLI_Iterator *iter);
179 void BKE_selected_bases_iterator_end(BLI_Iterator *iter);
180
181 void BKE_visible_bases_iterator_begin(BLI_Iterator *iter, void *data_in);
182 void BKE_visible_bases_iterator_next(BLI_Iterator *iter);
183 void BKE_visible_bases_iterator_end(BLI_Iterator *iter);
184
185 #define FOREACH_SELECTED_OBJECT(sl, _instance)                                \
186         ITER_BEGIN(BKE_selected_objects_iterator_begin,                           \
187                    BKE_selected_objects_iterator_next,                            \
188                    BKE_selected_objects_iterator_end,                             \
189                    sl, Object *, _instance)
190
191 #define FOREACH_SELECTED_OBJECT_END                                           \
192         ITER_END
193
194 #define FOREACH_VISIBLE_OBJECT(sl, _instance)                                 \
195         ITER_BEGIN(BKE_visible_objects_iterator_begin,                            \
196                    BKE_visible_objects_iterator_next,                             \
197                    BKE_visible_objects_iterator_end,                              \
198                    sl, Object *, _instance)
199
200 #define FOREACH_VISIBLE_OBJECT_END                                            \
201         ITER_END
202
203 #define FOREACH_SELECTED_BASE(sl, _instance)                                   \
204         ITER_BEGIN(BKE_selected_bases_iterator_begin,                              \
205                    BKE_selected_bases_iterator_next,                               \
206                    BKE_selected_bases_iterator_end,                                \
207                    sl, Base *, _instance)
208
209 #define FOREACH_SELECTED_BASE_END                                              \
210         ITER_END
211
212 #define FOREACH_VISIBLE_BASE(sl, _instance)                                   \
213         ITER_BEGIN(BKE_visible_bases_iterator_begin,                              \
214                    BKE_visible_bases_iterator_next,                               \
215                    BKE_visible_bases_iterator_end,                                \
216                    sl, Base *, _instance)
217
218 #define FOREACH_VISIBLE_BASE_END                                              \
219         ITER_END
220
221
222 #define FOREACH_OBJECT(sl, _instance)                                         \
223 {                                                                             \
224         Object *_instance;                                                        \
225         Base *base;                                                               \
226         for (base = (sl)->object_bases.first; base; base = base->next) {          \
227                 _instance = base->object;
228
229 #define FOREACH_OBJECT_END                                                    \
230     }                                                                         \
231 }
232
233 #define FOREACH_OBJECT_FLAG(scene, sl, flag, _instance)                       \
234 {                                                                             \
235         IteratorBeginCb func_begin;                                               \
236         IteratorCb func_next, func_end;                                           \
237         void *data_in;                                                            \
238                                                                                   \
239         if (flag == SELECT) {                                                     \
240             func_begin = &BKE_selected_objects_iterator_begin;                    \
241             func_next = &BKE_selected_objects_iterator_next;                      \
242             func_end = &BKE_selected_objects_iterator_end;                        \
243             data_in = (sl);                                                       \
244         }                                                                         \
245         else {                                                                    \
246             func_begin = BKE_scene_objects_iterator_begin;                        \
247             func_next = BKE_scene_objects_iterator_next;                          \
248             func_end = BKE_scene_objects_iterator_end;                            \
249             data_in = (scene);                                                    \
250         }                                                                         \
251         ITER_BEGIN(func_begin, func_next, func_end, data_in, Object *, _instance)
252
253
254 #define FOREACH_OBJECT_FLAG_END                                               \
255         ITER_END                                                                  \
256 }
257
258 typedef struct ObjectsRenderableIteratorData {
259         struct Scene *scene;
260
261         struct {
262                 struct SceneLayer *scene_layer;
263                 struct Base *base;
264                 struct Scene *set;
265         } iter;
266 } ObjectsRenderableIteratorData;
267
268 #define FOREACH_OBJECT_RENDERABLE(scene_, _instance)                          \
269         ObjectsRenderableIteratorData data_ = {                                   \
270             .scene = (scene_),                                                    \
271         };                                                                        \
272         ITER_BEGIN(BKE_renderable_objects_iterator_begin,                         \
273                    BKE_renderable_objects_iterator_next,                          \
274                    BKE_renderable_objects_iterator_end,                           \
275                    &data_, Object *, _instance)
276
277
278 #define FOREACH_OBJECT_RENDERABLE_END                                         \
279         ITER_END
280
281 #ifdef __cplusplus
282 }
283 #endif
284
285 #endif /* __BKE_LAYER_H__ */