1103e5c1f927abdea4b45c1251047106e4f9d8a4
[blender.git] / source / blender / makesrna / intern / rna_depsgraph.c
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 (2014).
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/makesrna/intern/rna_depsgraph.c
24  *  \ingroup RNA
25  */
26
27 #include <stdlib.h>
28
29 #include "BLI_utildefines.h"
30 #include "BLI_path_util.h"
31
32 #include "RNA_define.h"
33 #include "RNA_enum_types.h"
34
35 #include "rna_internal.h"
36
37 #include "DNA_object_types.h"
38
39 #include "DEG_depsgraph.h"
40
41 #define STATS_MAX_SIZE 16384
42
43 #ifdef RNA_RUNTIME
44
45 #include "BLI_iterator.h"
46 #include "BLI_math.h"
47
48 #include "BKE_anim.h"
49
50 #include "DEG_depsgraph_build.h"
51 #include "DEG_depsgraph_debug.h"
52 #include "DEG_depsgraph_query.h"
53
54 #include "MEM_guardedalloc.h"
55
56 /* **************** Object Instance **************** */
57
58 static PointerRNA rna_DepsgraphObjectInstance_object_get(PointerRNA *ptr)
59 {
60         BLI_Iterator *iterator = ptr->data;
61         return rna_pointer_inherit_refine(ptr, &RNA_Object, iterator->current);
62 }
63
64 static int rna_DepsgraphObjectInstance_is_instance_get(PointerRNA *ptr)
65 {
66         BLI_Iterator *iterator = ptr->data;
67         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
68         return (deg_iter->dupli_object_current != NULL);
69 }
70
71 static PointerRNA rna_DepsgraphObjectInstance_instance_object_get(PointerRNA *ptr)
72 {
73         BLI_Iterator *iterator = ptr->data;
74         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
75         Object *instance_object = NULL;
76         if (deg_iter->dupli_object_current != NULL) {
77                 instance_object = deg_iter->dupli_object_current->ob;
78         }
79         return rna_pointer_inherit_refine(ptr, &RNA_Object, instance_object);
80 }
81
82 static PointerRNA rna_DepsgraphObjectInstance_parent_get(PointerRNA *ptr)
83 {
84         BLI_Iterator *iterator = ptr->data;
85         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
86         Object *dupli_parent = NULL;
87         if (deg_iter->dupli_object_current != NULL) {
88                 dupli_parent = deg_iter->dupli_parent;
89         }
90         return rna_pointer_inherit_refine(ptr, &RNA_Object, dupli_parent);
91 }
92
93 static PointerRNA rna_DepsgraphObjectInstance_particle_system_get(PointerRNA *ptr)
94 {
95         BLI_Iterator *iterator = ptr->data;
96         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
97         struct ParticleSystem *particle_system = NULL;
98         if (deg_iter->dupli_object_current != NULL) {
99                 particle_system = deg_iter->dupli_object_current->particle_system;
100         }
101         return rna_pointer_inherit_refine(ptr, &RNA_ParticleSystem, particle_system);
102 }
103
104 static void rna_DepsgraphObjectInstance_persistent_id_get(PointerRNA *ptr, int *persistent_id)
105 {
106         BLI_Iterator *iterator = ptr->data;
107         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
108         if (deg_iter->dupli_object_current != NULL) {
109                 memcpy(persistent_id, deg_iter->dupli_object_current->persistent_id,
110                        sizeof(deg_iter->dupli_object_current->persistent_id));
111         }
112         else {
113                 memset(persistent_id, 0, sizeof(deg_iter->dupli_object_current->persistent_id));
114         }
115 }
116
117 static unsigned int rna_DepsgraphObjectInstance_random_id_get(PointerRNA *ptr)
118 {
119         BLI_Iterator *iterator = ptr->data;
120         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
121         if (deg_iter->dupli_object_current != NULL) {
122                 return deg_iter->dupli_object_current->random_id;
123         }
124         else {
125                 return 0;
126         }
127 }
128
129 static void rna_DepsgraphObjectInstance_matrix_world_get(PointerRNA *ptr, float *mat)
130 {
131         BLI_Iterator *iterator = ptr->data;
132         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
133         if (deg_iter->dupli_object_current != NULL) {
134                 copy_m4_m4((float(*)[4])mat, deg_iter->dupli_object_current->mat);
135         }
136         else {
137                 unit_m4((float(*)[4])mat);
138         }
139 }
140
141 static void rna_DepsgraphObjectInstance_orco_get(PointerRNA *ptr, float *orco)
142 {
143         BLI_Iterator *iterator = ptr->data;
144         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
145         if (deg_iter->dupli_object_current != NULL) {
146                 copy_v3_v3(orco, deg_iter->dupli_object_current->orco);
147         }
148         else {
149                 zero_v3(orco);
150         }
151 }
152
153 static void rna_DepsgraphObjectInstance_uv_get(PointerRNA *ptr, float *uv)
154 {
155         BLI_Iterator *iterator = ptr->data;
156         DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
157         if (deg_iter->dupli_object_current != NULL) {
158                 copy_v2_v2(uv, deg_iter->dupli_object_current->uv);
159         }
160         else {
161                 zero_v2(uv);
162         }
163 }
164
165 /* ******************** Sorted  ***************** */
166
167 static int rna_Depsgraph_mode_get(PointerRNA *ptr)
168 {
169         Depsgraph *depsgraph = ptr->data;
170         return DEG_get_mode(depsgraph);
171 }
172
173 /* ******************** Updates ***************** */
174
175 static PointerRNA rna_DepsgraphUpdate_id_get(PointerRNA *ptr)
176 {
177         return rna_pointer_inherit_refine(ptr, &RNA_ID, ptr->data);
178 }
179
180 static bool rna_DepsgraphUpdate_is_updated_transform_get(PointerRNA *ptr)
181 {
182         ID *id = ptr->data;
183         return ((id->recalc & ID_RECALC_TRANSFORM) != 0);
184 }
185
186 static bool rna_DepsgraphUpdate_is_updated_geometry_get(PointerRNA *ptr)
187 {
188         ID *id = ptr->data;
189         if (id->recalc & ID_RECALC_GEOMETRY) {
190                 return true;
191         }
192         if (GS(id->name) != ID_OB) {
193                 return false;
194         }
195         Object *object = (Object *)id;
196         ID *data = object->data;
197         if (data == NULL) {
198                 return false;
199         }
200         return ((data->recalc & ID_RECALC_ALL) != 0);
201 }
202
203 /* **************** Depsgraph **************** */
204
205 static void rna_Depsgraph_debug_relations_graphviz(Depsgraph *depsgraph,
206                                                    const char *filename)
207 {
208         FILE *f = fopen(filename, "w");
209         if (f == NULL) {
210                 return;
211         }
212         DEG_debug_relations_graphviz(depsgraph, f, "Depsgraph");
213         fclose(f);
214 }
215
216 static void rna_Depsgraph_debug_stats_gnuplot(Depsgraph *depsgraph,
217                                               const char *filename,
218                                               const char *output_filename)
219 {
220         FILE *f = fopen(filename, "w");
221         if (f == NULL) {
222                 return;
223         }
224         DEG_debug_stats_gnuplot(depsgraph, f, "Timing Statistics", output_filename);
225         fclose(f);
226 }
227
228 static void rna_Depsgraph_debug_tag_update(Depsgraph *depsgraph)
229 {
230         DEG_graph_tag_relations_update(depsgraph);
231 }
232
233 static void rna_Depsgraph_debug_stats(Depsgraph *depsgraph, char *result)
234 {
235         size_t outer, ops, rels;
236         DEG_stats_simple(depsgraph, &outer, &ops, &rels);
237         BLI_snprintf(result, STATS_MAX_SIZE,
238                     "Approx %lu Operations, %lu Relations, %lu Outer Nodes",
239                      ops, rels, outer);
240 }
241
242 /* Iteration over objects, simple version */
243
244 static void rna_Depsgraph_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
245 {
246         iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
247         DEGObjectIterData *data = MEM_callocN(sizeof(DEGObjectIterData), __func__);
248
249         data->graph = (Depsgraph *)ptr->data;
250         data->flag = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
251                      DEG_ITER_OBJECT_FLAG_VISIBLE |
252                      DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
253
254         ((BLI_Iterator *)iter->internal.custom)->valid = true;
255         DEG_iterator_objects_begin(iter->internal.custom, data);
256         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
257 }
258
259 static void rna_Depsgraph_objects_next(CollectionPropertyIterator *iter)
260 {
261         DEG_iterator_objects_next(iter->internal.custom);
262         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
263 }
264
265 static void rna_Depsgraph_objects_end(CollectionPropertyIterator *iter)
266 {
267         DEG_iterator_objects_end(iter->internal.custom);
268         MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
269         MEM_freeN(iter->internal.custom);
270 }
271
272 static PointerRNA rna_Depsgraph_objects_get(CollectionPropertyIterator *iter)
273 {
274         Object *ob = ((BLI_Iterator *)iter->internal.custom)->current;
275         return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ob);
276 }
277
278 /* Iteration over objects, extended version
279  *
280  * Contains extra information about duplicator and persistent ID.
281  */
282
283 /* XXX Ugly python seems to query next item of an iterator before using current one (see T57558).
284  * This forces us to use that nasty ping-pong game between two sets of iterator data, so that previous one remains
285  * valid memory for python to access to. Yuck.
286  */
287 typedef struct RNA_Depsgraph_Instances_Iterator
288 {
289         BLI_Iterator iterators[2];
290         DEGObjectIterData deg_data[2];
291         int counter;
292 } RNA_Depsgraph_Instances_Iterator;
293
294 static void rna_Depsgraph_object_instances_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
295 {
296         RNA_Depsgraph_Instances_Iterator *di_it = iter->internal.custom = MEM_callocN(sizeof(*di_it), __func__);
297
298         DEGObjectIterData *data = &di_it->deg_data[0];
299         data->graph = (Depsgraph *)ptr->data;
300         data->flag = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
301                      DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
302                      DEG_ITER_OBJECT_FLAG_VISIBLE |
303                      DEG_ITER_OBJECT_FLAG_DUPLI;
304
305         di_it->iterators[0].valid = true;
306         DEG_iterator_objects_begin(&di_it->iterators[0], data);
307         iter->valid = di_it->iterators[0].valid;
308 }
309
310 static void rna_Depsgraph_object_instances_next(CollectionPropertyIterator *iter)
311 {
312         RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *)iter->internal.custom;
313
314         /* We need to copy current iterator status to next one beeing worked on. */
315         di_it->iterators[(di_it->counter + 1) % 2] = di_it->iterators[di_it->counter % 2];
316         di_it->deg_data[(di_it->counter + 1) % 2] = di_it->deg_data[di_it->counter % 2];
317         di_it->counter++;
318
319         di_it->iterators[di_it->counter % 2].data = &di_it->deg_data[di_it->counter % 2];
320         DEG_iterator_objects_next(&di_it->iterators[di_it->counter % 2]);
321         iter->valid = di_it->iterators[di_it->counter % 2].valid;
322 }
323
324 static void rna_Depsgraph_object_instances_end(CollectionPropertyIterator *iter)
325 {
326         RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *)iter->internal.custom;
327         DEG_iterator_objects_end(&di_it->iterators[0]);
328         DEG_iterator_objects_end(&di_it->iterators[1]);
329         MEM_freeN(di_it);
330 }
331
332 static PointerRNA rna_Depsgraph_object_instances_get(CollectionPropertyIterator *iter)
333 {
334         RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *)iter->internal.custom;
335         BLI_Iterator *iterator = &di_it->iterators[di_it->counter % 2];
336         return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphObjectInstance, iterator);
337 }
338
339 /* Iteration over evaluated IDs */
340
341 static void rna_Depsgraph_ids_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
342 {
343         iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
344         DEGIDIterData *data = MEM_callocN(sizeof(DEGIDIterData), __func__);
345
346         data->graph = (Depsgraph *)ptr->data;
347
348         ((BLI_Iterator *)iter->internal.custom)->valid = true;
349         DEG_iterator_ids_begin(iter->internal.custom, data);
350         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
351 }
352
353 static void rna_Depsgraph_ids_next(CollectionPropertyIterator *iter)
354 {
355         DEG_iterator_ids_next(iter->internal.custom);
356         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
357 }
358
359 static void rna_Depsgraph_ids_end(CollectionPropertyIterator *iter)
360 {
361         DEG_iterator_ids_end(iter->internal.custom);
362         MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
363         MEM_freeN(iter->internal.custom);
364 }
365
366 static PointerRNA rna_Depsgraph_ids_get(CollectionPropertyIterator *iter)
367 {
368         ID *id = ((BLI_Iterator *)iter->internal.custom)->current;
369         return rna_pointer_inherit_refine(&iter->parent, &RNA_ID, id);
370 }
371
372 static void rna_Depsgraph_updates_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
373 {
374         iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
375         DEGIDIterData *data = MEM_callocN(sizeof(DEGIDIterData), __func__);
376
377         data->graph = (Depsgraph *)ptr->data;
378         data->only_updated = true;
379
380         ((BLI_Iterator *)iter->internal.custom)->valid = true;
381         DEG_iterator_ids_begin(iter->internal.custom, data);
382         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
383 }
384
385 static PointerRNA rna_Depsgraph_updates_get(CollectionPropertyIterator *iter)
386 {
387         ID *id = ((BLI_Iterator *)iter->internal.custom)->current;
388         return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphUpdate, id);
389 }
390
391 static ID *rna_Depsgraph_id_eval_get(Depsgraph *depsgraph, ID *id_orig)
392 {
393         return DEG_get_evaluated_id(depsgraph, id_orig);
394 }
395
396 static bool rna_Depsgraph_id_type_updated(Depsgraph *depsgraph, int id_type)
397 {
398         return DEG_id_type_updated(depsgraph, id_type);
399 }
400
401 static PointerRNA rna_Depsgraph_scene_get(PointerRNA *ptr)
402 {
403         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
404         Scene *scene = DEG_get_input_scene(depsgraph);
405         return rna_pointer_inherit_refine(ptr, &RNA_Scene, scene);
406 }
407
408 static PointerRNA rna_Depsgraph_view_layer_get(PointerRNA *ptr)
409 {
410         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
411         ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
412         return rna_pointer_inherit_refine(ptr, &RNA_ViewLayer, view_layer);
413 }
414
415 static PointerRNA rna_Depsgraph_scene_eval_get(PointerRNA *ptr)
416 {
417         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
418         Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
419         return rna_pointer_inherit_refine(ptr, &RNA_Scene, scene_eval);
420 }
421
422 static PointerRNA rna_Depsgraph_view_layer_eval_get(PointerRNA *ptr)
423 {
424         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
425         ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
426         return rna_pointer_inherit_refine(ptr, &RNA_ViewLayer, view_layer_eval);
427 }
428
429 #else
430
431 static void rna_def_depsgraph_instance(BlenderRNA *brna)
432 {
433         StructRNA *srna;
434         PropertyRNA *prop;
435
436         srna = RNA_def_struct(brna, "DepsgraphObjectInstance", NULL);
437         RNA_def_struct_ui_text(srna, "Dependency Graph Object Instance",
438                                "Extended information about dependency graph object iterator "
439                                "(WARNING: all data here is *evaluated* one, not original .blend IDs...)");
440
441         prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
442         RNA_def_property_struct_type(prop, "Object");
443         RNA_def_property_ui_text(prop, "Object", "Evaluated object the iterator points to");
444         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
445         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_object_get", NULL, NULL, NULL);
446
447         prop = RNA_def_property(srna, "is_instance", PROP_BOOLEAN, PROP_NONE);
448         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
449         RNA_def_property_ui_text(prop, "Is Instance", "Denotes whether the object is coming from dupli-list");
450         RNA_def_property_boolean_funcs(prop, "rna_DepsgraphObjectInstance_is_instance_get", NULL);
451
452         prop = RNA_def_property(srna, "instance_object", PROP_POINTER, PROP_NONE);
453         RNA_def_property_struct_type(prop, "Object");
454         RNA_def_property_ui_text(prop, "Instance Object", "Evaluated object which is being instanced by this iterator");
455         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
456         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_instance_object_get", NULL, NULL, NULL);
457
458         prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
459         RNA_def_property_struct_type(prop, "Object");
460         RNA_def_property_ui_text(prop, "Parent", "Evaluated parent object of the duplication list");
461         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
462         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_parent_get", NULL, NULL, NULL);
463
464         prop = RNA_def_property(srna, "particle_system", PROP_POINTER, PROP_NONE);
465         RNA_def_property_struct_type(prop, "ParticleSystem");
466         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
467         RNA_def_property_ui_text(prop, "Particle System", "Evaluated particle system that this object was instanced from");
468         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_particle_system_get", NULL, NULL, NULL);
469
470         prop = RNA_def_property(srna, "persistent_id", PROP_INT, PROP_NONE);
471         RNA_def_property_ui_text(prop, "Persistent ID",
472                                  "Persistent identifier for inter-frame matching of objects with motion blur");
473         RNA_def_property_array(prop, 2 * MAX_DUPLI_RECUR);
474         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
475         RNA_def_property_int_funcs(prop, "rna_DepsgraphObjectInstance_persistent_id_get", NULL, NULL);
476
477         prop = RNA_def_property(srna, "random_id", PROP_INT, PROP_UNSIGNED);
478         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
479         RNA_def_property_ui_text(prop, "Dupli random id", "Random id for this dupli object");
480         RNA_def_property_int_funcs(prop, "rna_DepsgraphObjectInstance_random_id_get", NULL, NULL);
481
482         prop = RNA_def_property(srna, "matrix_world", PROP_FLOAT, PROP_MATRIX);
483         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
484         RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
485         RNA_def_property_ui_text(prop, "Generated Matrix", "Generated transform matrix in world space");
486         RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_matrix_world_get", NULL, NULL);
487
488         prop = RNA_def_property(srna, "orco", PROP_FLOAT, PROP_TRANSLATION);
489         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
490         RNA_def_property_array(prop, 3);
491         RNA_def_property_ui_text(prop, "Generated Coordinates", "Generated coordinates in parent object space");
492         RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_orco_get", NULL, NULL);
493
494         prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_NONE);
495         RNA_def_property_ui_text(prop, "UV Coordinates", "UV coordinates in parent object space");
496         RNA_def_property_array(prop, 2);
497         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
498         RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_uv_get", NULL, NULL);
499 }
500
501 static void rna_def_depsgraph_update(BlenderRNA *brna)
502 {
503         StructRNA *srna;
504         PropertyRNA *prop;
505
506         srna = RNA_def_struct(brna, "DepsgraphUpdate", NULL);
507         RNA_def_struct_ui_text(srna, "Dependency Graph Update",
508                                "Information about ID that was updated");
509
510         prop = RNA_def_property(srna, "id", PROP_POINTER, PROP_NONE);
511         RNA_def_property_struct_type(prop, "ID");
512         RNA_def_property_ui_text(prop, "ID", "Updated datablock");
513         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
514         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphUpdate_id_get", NULL, NULL, NULL);
515
516         /* Use term 'is_updated' instead of 'is_dirty' here because this is a signal
517          * that users of the depsgraph may want to update their data (render engines for eg). */
518
519         prop = RNA_def_property(srna, "is_updated_transform", PROP_BOOLEAN, PROP_NONE);
520         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
521         RNA_def_property_ui_text(prop, "Transform", "Object transformation is updated");
522         RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_updated_transform_get", NULL);
523
524         prop = RNA_def_property(srna, "is_updated_geometry", PROP_BOOLEAN, PROP_NONE);
525         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
526         RNA_def_property_ui_text(prop, "Geometry", "Object geometry is updated");
527         RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_updated_geometry_get", NULL);
528 }
529
530 static void rna_def_depsgraph(BlenderRNA *brna)
531 {
532         StructRNA *srna;
533         FunctionRNA *func;
534         PropertyRNA *parm;
535         PropertyRNA *prop;
536
537         static EnumPropertyItem enum_depsgraph_mode_items[] = {
538                 {DAG_EVAL_VIEWPORT, "VIEWPORT", 0, "Viewport", "Viewport non-rendered mode"},
539                 {DAG_EVAL_RENDER, "RENDER", 0, "Render", "Render"},
540                 {0, NULL, 0, NULL, NULL}
541         };
542
543         srna = RNA_def_struct(brna, "Depsgraph", NULL);
544         RNA_def_struct_ui_text(srna, "Dependency Graph", "");
545
546         prop = RNA_def_enum(srna, "mode", enum_depsgraph_mode_items, 0, "Mode", "Evaluation mode");
547         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
548         RNA_def_property_enum_funcs(prop, "rna_Depsgraph_mode_get", NULL, NULL);
549
550         /* Debug helpers. */
551
552         func = RNA_def_function(srna, "debug_relations_graphviz", "rna_Depsgraph_debug_relations_graphviz");
553         parm = RNA_def_string_file_path(func, "filename", NULL, FILE_MAX, "File Name",
554                                         "File in which to store graphviz debug output");
555         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
556
557         func = RNA_def_function(srna, "debug_stats_gnuplot", "rna_Depsgraph_debug_stats_gnuplot");
558         parm = RNA_def_string_file_path(func, "filename", NULL, FILE_MAX, "File Name",
559                                         "File in which to store graphviz debug output");
560         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
561         parm = RNA_def_string_file_path(func, "output_filename", NULL, FILE_MAX, "Output File Name",
562                                         "File name where gnuplot script will save the result");
563         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
564
565         func = RNA_def_function(srna, "debug_tag_update", "rna_Depsgraph_debug_tag_update");
566
567         func = RNA_def_function(srna, "debug_stats", "rna_Depsgraph_debug_stats");
568         RNA_def_function_ui_description(func, "Report the number of elements in the Dependency Graph");
569         /* weak!, no way to return dynamic string type */
570         parm = RNA_def_string(func, "result", NULL, STATS_MAX_SIZE, "result", "");
571         RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); /* needed for string return value */
572         RNA_def_function_output(func, parm);
573
574         /* Queries for original datablockls (the ones depsgraph is built for). */
575
576         prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
577         RNA_def_property_struct_type(prop, "Scene");
578         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_get", NULL, NULL, NULL);
579         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
580         RNA_def_property_ui_text(prop, "Scene", "Original scene dependency graph is built for");
581
582         prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
583         RNA_def_property_struct_type(prop, "ViewLayer");
584         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_view_layer_get", NULL, NULL, NULL);
585         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
586         RNA_def_property_ui_text(prop, "View Layer", "Original view layer dependency graph is built for");
587
588         /* Queries for evaluated datablockls (the ones depsgraph is evaluating). */
589
590         func = RNA_def_function(srna, "id_eval_get", "rna_Depsgraph_id_eval_get");
591         parm = RNA_def_pointer(func, "id", "ID", "", "Original ID to get evaluated complementary part for");
592         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
593         parm = RNA_def_pointer(func, "id_eval", "ID", "", "Evaluated ID for the given original one");
594         RNA_def_function_return(func, parm);
595
596         func = RNA_def_function(srna, "id_type_updated", "rna_Depsgraph_id_type_updated");
597         parm = RNA_def_enum(func, "id_type", rna_enum_id_type_items, 0, "ID Type", "");
598         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
599         parm = RNA_def_boolean(func, "updated", false, "Updated", "True if any datablock with this type was added, updated or removed");
600         RNA_def_function_return(func, parm);
601
602         prop = RNA_def_property(srna, "scene_eval", PROP_POINTER, PROP_NONE);
603         RNA_def_property_struct_type(prop, "Scene");
604         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_eval_get", NULL, NULL, NULL);
605         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
606         RNA_def_property_ui_text(prop, "Scene", "Original scene dependency graph is built for");
607
608         prop = RNA_def_property(srna, "view_layer_eval", PROP_POINTER, PROP_NONE);
609         RNA_def_property_struct_type(prop, "ViewLayer");
610         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_view_layer_eval_get", NULL, NULL, NULL);
611         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
612         RNA_def_property_ui_text(prop, "View Layer", "Original view layer dependency graph is built for");
613
614         /* Iterators. */
615
616         prop = RNA_def_property(srna, "ids", PROP_COLLECTION, PROP_NONE);
617         RNA_def_property_struct_type(prop, "ID");
618         RNA_def_property_collection_funcs(prop,
619                                           "rna_Depsgraph_ids_begin",
620                                           "rna_Depsgraph_ids_next",
621                                           "rna_Depsgraph_ids_end",
622                                           "rna_Depsgraph_ids_get",
623                                           NULL, NULL, NULL, NULL);
624         RNA_def_property_ui_text(prop, "IDs", "All evaluated datablocks");
625
626         prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
627         RNA_def_property_struct_type(prop, "Object");
628         RNA_def_property_collection_funcs(prop,
629                                           "rna_Depsgraph_objects_begin",
630                                           "rna_Depsgraph_objects_next",
631                                           "rna_Depsgraph_objects_end",
632                                           "rna_Depsgraph_objects_get",
633                                           NULL, NULL, NULL, NULL);
634         RNA_def_property_ui_text(prop, "Objects", "Evaluated objects in the dependency graph");
635
636         prop = RNA_def_property(srna, "object_instances", PROP_COLLECTION, PROP_NONE);
637         RNA_def_property_struct_type(prop, "DepsgraphObjectInstance");
638         RNA_def_property_collection_funcs(prop,
639                                           "rna_Depsgraph_object_instances_begin",
640                                           "rna_Depsgraph_object_instances_next",
641                                           "rna_Depsgraph_object_instances_end",
642                                           "rna_Depsgraph_object_instances_get",
643                                           NULL, NULL, NULL, NULL);
644         RNA_def_property_ui_text(prop, "Object Instances", "All object instances to display or render");
645
646         prop = RNA_def_property(srna, "updates", PROP_COLLECTION, PROP_NONE);
647         RNA_def_property_struct_type(prop, "DepsgraphUpdate");
648         RNA_def_property_collection_funcs(prop,
649                                           "rna_Depsgraph_updates_begin",
650                                           "rna_Depsgraph_ids_next",
651                                           "rna_Depsgraph_ids_end",
652                                           "rna_Depsgraph_updates_get",
653                                           NULL, NULL, NULL, NULL);
654         RNA_def_property_ui_text(prop, "Updates", "Updates to datablocks");
655 }
656
657 void RNA_def_depsgraph(BlenderRNA *brna)
658 {
659         rna_def_depsgraph_instance(brna);
660         rna_def_depsgraph_update(brna);
661         rna_def_depsgraph(brna);
662 }
663
664 #endif