Depsgraph: fix debug print crash on IK constraint without target.
[blender.git] / source / blender / depsgraph / DEG_depsgraph_query.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  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup depsgraph
22  *
23  * Public API for Querying and Filtering Depsgraph.
24  */
25
26 #ifndef __DEG_DEPSGRAPH_QUERY_H__
27 #define __DEG_DEPSGRAPH_QUERY_H__
28
29 #include "DEG_depsgraph.h"
30 #include "DEG_depsgraph_build.h"
31
32 struct ID;
33
34 struct BLI_Iterator;
35 struct Base;
36 struct CustomData_MeshMasks;
37 struct Depsgraph;
38 struct DupliObject;
39 struct ListBase;
40 struct Scene;
41 struct ViewLayer;
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 /* *********************** DEG input data ********************* */
48
49 /* Get scene that depsgraph was built for. */
50 struct Scene *DEG_get_input_scene(const Depsgraph *graph);
51
52 /* Get view layer that depsgraph was built for. */
53 struct ViewLayer *DEG_get_input_view_layer(const Depsgraph *graph);
54
55 /* Get evaluation mode that depsgraph was built for. */
56 eEvaluationMode DEG_get_mode(const Depsgraph *graph);
57
58 /* Get time that depsgraph is being evaluated or was last evaluated at. */
59 float DEG_get_ctime(const Depsgraph *graph);
60
61 /* ********************* DEG evaluated data ******************* */
62
63 /* Check if given ID type was tagged for update. */
64 bool DEG_id_type_updated(const struct Depsgraph *depsgraph, short id_type);
65 bool DEG_id_type_any_updated(const struct Depsgraph *depsgraph);
66
67 /* Get additional evaluation flags for the given ID. */
68 uint32_t DEG_get_eval_flags_for_id(const struct Depsgraph *graph, struct ID *id);
69
70 /* Get additional mesh CustomData_MeshMasks flags for the given object. */
71 void DEG_get_customdata_mask_for_object(const struct Depsgraph *graph,
72                                         struct Object *object,
73                                         struct CustomData_MeshMasks *r_mask);
74
75 /* Get scene the despgraph is created for. */
76 struct Scene *DEG_get_evaluated_scene(const struct Depsgraph *graph);
77
78 /* Get scene layer the despgraph is created for. */
79 struct ViewLayer *DEG_get_evaluated_view_layer(const struct Depsgraph *graph);
80
81 /* Get evaluated version of object for given original one. */
82 struct Object *DEG_get_evaluated_object(const struct Depsgraph *depsgraph,
83                                         struct Object *object);
84
85 /* Get evaluated version of given ID datablock. */
86 struct ID *DEG_get_evaluated_id(const struct Depsgraph *depsgraph,
87                                 struct ID *id);
88
89 /* Get evaluated version of data pointed to by RNA pointer */
90 void DEG_get_evaluated_rna_pointer(const struct Depsgraph *depsgraph,
91                                    struct PointerRNA *ptr,
92                                    struct PointerRNA *r_ptr_eval);
93
94 /* Get original version of object for given evaluated one. */
95 struct Object *DEG_get_original_object(struct Object *object);
96
97 /* Get original version of given evaluated ID datablock. */
98 struct ID *DEG_get_original_id(struct ID *id);
99
100 /* ************************ DEG object iterators ********************* */
101
102 enum {
103         DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY   = (1 << 0),
104         DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY = (1 << 1),
105         DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET    = (1 << 2),
106         DEG_ITER_OBJECT_FLAG_VISIBLE           = (1 << 3),
107         DEG_ITER_OBJECT_FLAG_DUPLI             = (1 << 4),
108 };
109
110 typedef struct DEGObjectIterData {
111         struct Depsgraph *graph;
112         int flag;
113
114         struct Scene *scene;
115
116         eEvaluationMode eval_mode;
117
118         /* **** Iteration over dupli-list. *** */
119
120         /* Object which created the dupli-list. */
121         struct Object *dupli_parent;
122         /* List of duplicated objects. */
123         struct ListBase *dupli_list;
124         /* Next duplicated object to step into. */
125         struct DupliObject *dupli_object_next;
126         /* Corresponds to current object: current iterator object is evaluated from
127          * this duplicated object. */
128         struct DupliObject *dupli_object_current;
129         /* Temporary storage to report fully populated DNA to the render engine or
130          * other users of the iterator. */
131         struct Object temp_dupli_object;
132
133         /* **** Iteration over ID nodes **** */
134         size_t id_node_index;
135         size_t num_id_nodes;
136 } DEGObjectIterData;
137
138 void DEG_iterator_objects_begin(struct BLI_Iterator *iter, DEGObjectIterData *data);
139 void DEG_iterator_objects_next(struct BLI_Iterator *iter);
140 void DEG_iterator_objects_end(struct BLI_Iterator *iter);
141
142 /**
143  * Note: Be careful with DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY objects.
144  * Although they are available they have no overrides (collection_properties)
145  * and will crash if you try to access it.
146  */
147 #define DEG_OBJECT_ITER_BEGIN(graph_, instance_, flag_)                           \
148         {                                                                             \
149                 DEGObjectIterData data_ = {                                               \
150                         graph_,                                                               \
151                         flag_,                                                                \
152                 };                                                                        \
153                                                                                   \
154                 ITER_BEGIN(DEG_iterator_objects_begin,                                    \
155                            DEG_iterator_objects_next,                                     \
156                            DEG_iterator_objects_end,                                      \
157                            &data_, Object *, instance_)
158
159 #define DEG_OBJECT_ITER_END                                                       \
160                 ITER_END;                                                                 \
161         } ((void)0)
162
163 /**
164  * Depsgraph objects iterator for draw manager and final render
165  */
166 #define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(graph_, instance_)        \
167         DEG_OBJECT_ITER_BEGIN(graph_, instance_,                              \
168                 DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |                        \
169                 DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |                         \
170                 DEG_ITER_OBJECT_FLAG_VISIBLE |                                \
171                 DEG_ITER_OBJECT_FLAG_DUPLI)
172
173 #define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END                             \
174         DEG_OBJECT_ITER_END
175
176
177 /* ************************ DEG ID iterators ********************* */
178
179 typedef struct DEGIDIterData {
180         struct Depsgraph *graph;
181         bool only_updated;
182
183         size_t id_node_index;
184         size_t num_id_nodes;
185 } DEGIDIterData;
186
187 void DEG_iterator_ids_begin(struct BLI_Iterator *iter, DEGIDIterData *data);
188 void DEG_iterator_ids_next(struct BLI_Iterator *iter);
189 void DEG_iterator_ids_end(struct BLI_Iterator *iter);
190
191 /* ************************ DEG traversal ********************* */
192
193 typedef void (*DEGForeachIDCallback)(ID *id, void *user_data);
194
195 /* NOTE: Modifies runtime flags in depsgraph nodes, so can not be used in
196  * parallel. Keep an eye on that!
197  */
198 void DEG_foreach_ancestor_ID(const Depsgraph *depsgraph,
199                              const ID *id,
200                              DEGForeachIDCallback callback, void *user_data);
201 void DEG_foreach_dependent_ID(const Depsgraph *depsgraph,
202                               const ID *id,
203                               DEGForeachIDCallback callback, void *user_data);
204
205 void DEG_foreach_ID(const Depsgraph *depsgraph,
206                     DEGForeachIDCallback callback, void *user_data);
207
208 /* ********************* DEG graph filtering ****************** */
209
210 /* ComponentKey for nodes we want to be able to evaluate in the filtered graph */
211 typedef struct DEG_FilterTarget {
212         struct DEG_FilterTarget *next, *prev;
213
214         struct ID *id;
215         /* TODO: component identifiers - Component Type, Subdata/Component Name */
216 } DEG_FilterTarget;
217
218 typedef enum eDEG_FilterQuery_Granularity {
219         DEG_FILTER_NODES_ALL           = 0,
220         DEG_FILTER_NODES_NO_OPS        = 1,
221         DEG_FILTER_NODES_ID_ONLY       = 2,
222 } eDEG_FilterQuery_Granularity;
223
224
225 typedef struct DEG_FilterQuery {
226         /* List of DEG_FilterTarget's */
227         struct ListBase targets;
228
229         /* Level of detail in the resulting graph */
230         eDEG_FilterQuery_Granularity detail_level;
231 } DEG_FilterQuery;
232
233 /* Obtain a new graph instance that only contains the subset of desired nodes
234  * WARNING: Do NOT pass an already filtered depsgraph through this function again,
235  *          as we are currently unable to accurately recreate it.
236  */
237 Depsgraph *DEG_graph_filter(const Depsgraph *depsgraph, struct Main *bmain, DEG_FilterQuery *query);
238
239
240 #ifdef __cplusplus
241 } /* extern "C" */
242 #endif
243
244 #endif  /* __DEG_DEPSGRAPH_QUERY_H__ */