04584c07d4b58ba7fb55ade1d8fd9dd01c8c2409
[blender.git] / source / blender / depsgraph / DEG_depsgraph_query.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  * The Original Code is Copyright (C) 2013 Blender Foundation.
19  * All rights reserved.
20  *
21  * Original Author: Joshua Leung
22  * Contributor(s): Sergey Sharybin
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/depsgraph/DEG_depsgraph_query.h
28  *  \ingroup depsgraph
29  *
30  * Public API for Querying and Filtering Depsgraph.
31  */
32
33 #ifndef __DEG_DEPSGRAPH_QUERY_H__
34 #define __DEG_DEPSGRAPH_QUERY_H__
35
36 #include "DEG_depsgraph.h"
37
38 struct ID;
39
40 struct Base;
41 struct BLI_Iterator;
42 struct Depsgraph;
43 struct DupliObject;
44 struct ListBase;
45 struct Scene;
46 struct SceneLayer;
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 /* Check if given ID type was tagged for update. */
53 bool DEG_id_type_tagged(struct Main *bmain, short idtype);
54
55 /* Get additional evaluation flags for the given ID. */
56 short DEG_get_eval_flags_for_id(struct Depsgraph *graph, struct ID *id);
57
58 /* Get scene the despgraph is created for. */
59 struct Scene *DEG_get_evaluated_scene(struct Depsgraph *graph);
60
61 /* Get scene layer the despgraph is created for. */
62 struct SceneLayer *DEG_get_evaluated_scene_layer(struct Depsgraph *graph);
63
64 /* Get evaluated version of object for given original one. */
65 struct Object *DEG_get_evaluated_object(struct Depsgraph *depsgraph, struct Object *object);
66
67 /* Get evaluated version of given ID datablock. */
68 struct ID *DEG_get_evaluated_id(struct Depsgraph *depsgraph, struct ID *id);
69
70 /* ************************ DAG iterators ********************* */
71
72 enum {
73         DEG_OBJECT_ITER_FLAG_SET = (1 << 0),
74         DEG_OBJECT_ITER_FLAG_DUPLI = (1 << 1),
75 };
76
77 #define DEG_OBJECT_ITER_FLAG_ALL (DEG_OBJECT_ITER_FLAG_SET | DEG_OBJECT_ITER_FLAG_DUPLI)
78
79 typedef struct DEGObjectsIteratorData {
80         struct Depsgraph *graph;
81         struct Scene *scene;
82         struct EvaluationContext eval_ctx;
83
84         /* TODO(sergey): Base should never be a thing coming FROM depsgraph. */
85         struct Base *base;
86         int base_flag;
87         int flag;
88
89         /* **** Iteration over dupli-list. *** */
90
91         /* Object which created the dupli-list. */
92         struct Object *dupli_parent;
93         /* List of duplicated objects. */
94         struct ListBase *dupli_list;
95         /* Next duplicated object to step into. */
96         struct DupliObject *dupli_object_next;
97         /* Corresponds to current object: current iterator object is evaluated from
98          * this duplicated object.
99          */
100         struct DupliObject *dupli_object_current;
101         /* Temporary storage to report fully populated DNA to the render engine or
102          * other users of the iterator.
103          */
104         struct Object temp_dupli_object;
105 } DEGObjectsIteratorData;
106
107 void DEG_objects_iterator_begin(struct BLI_Iterator *iter, DEGObjectsIteratorData *data);
108 void DEG_objects_iterator_next(struct BLI_Iterator *iter);
109 void DEG_objects_iterator_end(struct BLI_Iterator *iter);
110
111 /* Temporary hacky solution waiting for cow depsgraph implementation. */
112 #define DEG_OBJECT_ITER(graph_, instance_, flag_)                                 \
113         {                                                                             \
114                 DEGObjectsIteratorData data_ = {                                          \
115                         .graph = (graph_),                                                    \
116                         .flag = (flag_),                                                      \
117                 };                                                                        \
118                                                                                   \
119                 ITER_BEGIN(DEG_objects_iterator_begin,                                    \
120                            DEG_objects_iterator_next,                                     \
121                            DEG_objects_iterator_end,                                      \
122                            &data_, Object *, instance_)
123
124 #define DEG_OBJECT_ITER_END                                                       \
125                 ITER_END                                                                  \
126         }
127
128 #ifdef __cplusplus
129 } /* extern "C" */
130 #endif
131
132 #endif  /* __DEG_DEPSGRAPH_QUERY_H__ */