Util function to free CollectionEngineSettings
[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): 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 /* syncing of SceneCollection and LayerCollection trees*/
37 #define TODO_LAYER_SYNC_FILTER /* syncing of filter_objects across all trees */
38 #define TODO_LAYER_OVERRIDE /* CollectionOverride */
39 #define TODO_LAYER_CONTEXT /* get/set current (context) SceneLayer */
40 #define TODO_LAYER_BASE /* Base to ObjectBase related TODO */
41 #define TODO_LAYER_OPERATORS /* collection mamanger and property panel operators */
42 #define TODO_LAYER /* generic todo */
43
44 struct CollectionEngineSettings;
45 struct LayerCollection;
46 struct ID;
47 struct ListBase;
48 struct Main;
49 struct Object;
50 struct ObjectBase;
51 struct RenderEngine;
52 struct Scene;
53 struct SceneCollection;
54 struct SceneLayer;
55
56 struct SceneLayer *BKE_scene_layer_add(struct Scene *scene, const char *name);
57
58 bool BKE_scene_layer_remove(struct Main *bmain, struct Scene *scene, struct SceneLayer *sl);
59
60 void BKE_scene_layer_free(struct SceneLayer *sl);
61
62 void BKE_scene_layer_engine_set(struct SceneLayer *sl, const char *engine);
63
64 void BKE_scene_layer_selected_objects_tag(struct SceneLayer *sl, const int tag);
65
66 struct SceneLayer *BKE_scene_layer_find_from_collection(struct Scene *scene, struct LayerCollection *lc);
67 struct ObjectBase *BKE_scene_layer_base_find(struct SceneLayer *sl, struct Object *ob);
68 void BKE_scene_layer_base_deselect_all(struct SceneLayer *sl);
69 void BKE_scene_layer_base_select(struct SceneLayer *sl, struct ObjectBase *selbase);
70 void BKE_scene_layer_base_flag_recalculate(struct SceneLayer *sl);
71
72 void BKE_layer_collection_free(struct SceneLayer *sl, struct LayerCollection *lc);
73
74 struct LayerCollection *BKE_layer_collection_active(struct SceneLayer *sl);
75
76 int BKE_layer_collection_count(struct SceneLayer *sl);
77
78 int BKE_layer_collection_findindex(struct SceneLayer *sl, struct LayerCollection *lc);
79
80 struct LayerCollection *BKE_collection_link(struct SceneLayer *sl, struct SceneCollection *sc);
81
82 void BKE_collection_unlink(struct SceneLayer *sl, struct LayerCollection *lc);
83
84 bool BKE_scene_layer_has_collection(struct SceneLayer *sl, struct SceneCollection *sc);
85 bool BKE_scene_has_object(struct Scene *scene, struct Object *ob);
86
87 /* syncing */
88
89 void BKE_layer_sync_new_scene_collection(struct Scene *scene, const struct SceneCollection *sc_parent, struct SceneCollection *sc);
90 void BKE_layer_sync_object_link(struct Scene *scene, struct SceneCollection *sc, struct Object *ob);
91 void BKE_layer_sync_object_unlink(struct Scene *scene, struct SceneCollection *sc, struct Object *ob);
92
93 /* override */
94
95 void BKE_collection_override_datablock_add(struct LayerCollection *lc, const char *data_path, struct ID *id);
96
97 /* engine settings */
98 typedef void (*CollectionEngineSettingsCB)(struct RenderEngine *engine, struct CollectionEngineSettings *ces);
99 struct CollectionEngineSettings *BKE_layer_collection_engine_get(struct LayerCollection *lc, const char *engine_name);
100 void BKE_layer_collection_engine_settings_callback_register(struct Main *bmain, const char *engine_name, CollectionEngineSettingsCB func);
101 void BKE_layer_collection_engine_settings_callback_free(void);
102 void BKE_layer_collection_engine_settings_free(struct ListBase *lb);
103
104 void BKE_collection_engine_property_add_float(struct CollectionEngineSettings *ces, const char *name, float value);
105 void BKE_collection_engine_property_add_int(struct CollectionEngineSettings *ces, const char *name, int value);
106 struct CollectionEngineProperty *BKE_collection_engine_property_get(struct CollectionEngineSettings *ces, const char *name);
107
108 /* iterators */
109
110 void BKE_selected_objects_Iterator_begin(Iterator *iter, void *data_in);
111 void BKE_selected_objects_Iterator_next(Iterator *iter);
112 void BKE_selected_objects_Iterator_end(Iterator *iter);
113
114 void BKE_visible_objects_Iterator_begin(Iterator *iter, void *data_in);
115 void BKE_visible_objects_Iterator_next(Iterator *iter);
116 void BKE_visible_objects_Iterator_end(Iterator *iter);
117
118 void BKE_visible_bases_Iterator_begin(Iterator *iter, void *data_in);
119 void BKE_visible_bases_Iterator_next(Iterator *iter);
120 void BKE_visible_bases_Iterator_end(Iterator *iter);
121
122 #define FOREACH_SELECTED_OBJECT(sl, _ob)                                      \
123         ITER_BEGIN(BKE_selected_objects_Iterator_begin,                           \
124                    BKE_selected_objects_Iterator_next,                            \
125                    BKE_selected_objects_Iterator_end,                             \
126                    sl, _ob)
127
128 #define FOREACH_SELECTED_OBJECT_END                                           \
129         ITER_END
130
131 #define FOREACH_VISIBLE_OBJECT(sl, _ob)                                       \
132         ITER_BEGIN(BKE_visible_objects_Iterator_begin,                            \
133                    BKE_visible_objects_Iterator_next,                             \
134                    BKE_visible_objects_Iterator_end,                              \
135                    sl, _ob)
136
137 #define FOREACH_VISIBLE_OBJECT_END                                            \
138         ITER_END
139
140
141 #define FOREACH_VISIBLE_BASE(sl, _object_base)                                \
142         ITER_BEGIN(BKE_visible_bases_Iterator_begin,                              \
143                    BKE_visible_bases_Iterator_next,                               \
144                    BKE_visible_bases_Iterator_end,                                \
145                    sl, _object_base)
146
147 #define FOREACH_VISIBLE_BASE_END                                              \
148         ITER_END
149
150
151 #define FOREACH_OBJECT(sl, _ob)                                               \
152 {                                                                             \
153         ObjectBase *base;                                                         \
154         for (base = sl->object_bases.first; base; base = base->next) {            \
155             _ob = base->object;
156
157 #define FOREACH_OBJECT_END                                                    \
158     }                                                                         \
159 }
160
161 #define FOREACH_OBJECT_FLAG(scene, sl, flag, _ob)                             \
162 {                                                                             \
163         IteratorBeginCb func_begin;                                               \
164         IteratorCb func_next, func_end;                                           \
165         void *data_in;                                                            \
166                                                                                   \
167         if (flag == SELECT) {                                                     \
168             func_begin = &BKE_selected_objects_Iterator_begin;                    \
169             func_next = &BKE_selected_objects_Iterator_next;                      \
170             func_end = &BKE_selected_objects_Iterator_end;                        \
171             data_in = sl;                                                         \
172     }                                                                         \
173         else {                                                                    \
174             func_begin = BKE_scene_objects_Iterator_begin;                        \
175             func_next = BKE_scene_objects_Iterator_next;                          \
176             func_end = BKE_scene_objects_Iterator_end;                            \
177             data_in = scene;                                                      \
178     }                                                                         \
179         ITER_BEGIN(func_begin, func_next, func_end, data_in, _ob)
180
181
182 #define FOREACH_OBJECT_FLAG_END                                               \
183         ITER_END                                                                  \
184 }
185
186 /* temporary hacky solution waiting for final depsgraph evaluation */
187 #define DEG_OBJECT_ITER(sl_, ob_)                                             \
188 {                                                                             \
189         /* flush all the data to objects*/                                        \
190         ObjectBase *base_;                                                                            \
191         for (base_ = sl->object_bases.first; base_; base_ = base_->next) {        \
192             ob_ = base_->object;                                                              \
193             ob_->base_flag = base_->flag;
194
195 #define DEG_OBJECT_ITER_END                                                   \
196     }                                                                         \
197 }
198
199 #ifdef __cplusplus
200 }
201 #endif
202
203 #endif /* __BKE_LAYER_H__ */