Merge branch 'master' into blender2.8
[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_dirty_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_dirty_geometry_get(PointerRNA *ptr)
187 {
188         ID *id = ptr->data;
189         if (id->recalc & ID_RECALC_GEOMETRY) {
190                 return false;
191         }
192         if (GS(id->name) != ID_OB) {
193                 return true;
194         }
195         Object *object = (Object *)id;
196         ID *data = object->data;
197         if (data == NULL) {
198                 return true;
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 static void rna_Depsgraph_object_instances_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
284 {
285         iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
286         DEGObjectIterData *data = MEM_callocN(sizeof(DEGObjectIterData), __func__);
287
288         data->graph = (Depsgraph *)ptr->data;
289         data->flag = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
290                      DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
291                      DEG_ITER_OBJECT_FLAG_VISIBLE |
292                      DEG_ITER_OBJECT_FLAG_DUPLI;
293
294         ((BLI_Iterator *)iter->internal.custom)->valid = true;
295         DEG_iterator_objects_begin(iter->internal.custom, data);
296         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
297 }
298
299 static void rna_Depsgraph_object_instances_next(CollectionPropertyIterator *iter)
300 {
301         DEG_iterator_objects_next(iter->internal.custom);
302         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
303 }
304
305 static void rna_Depsgraph_object_instances_end(CollectionPropertyIterator *iter)
306 {
307         DEG_iterator_objects_end(iter->internal.custom);
308         MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
309         MEM_freeN(iter->internal.custom);
310 }
311
312 static PointerRNA rna_Depsgraph_object_instances_get(CollectionPropertyIterator *iter)
313 {
314         BLI_Iterator *iterator = (BLI_Iterator *)iter->internal.custom;
315         return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphObjectInstance, iterator);
316 }
317
318 /* Iteration over evaluated IDs */
319
320 static void rna_Depsgraph_ids_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
321 {
322         iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
323         DEGIDIterData *data = MEM_callocN(sizeof(DEGIDIterData), __func__);
324
325         data->graph = (Depsgraph *)ptr->data;
326
327         ((BLI_Iterator *)iter->internal.custom)->valid = true;
328         DEG_iterator_ids_begin(iter->internal.custom, data);
329         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
330 }
331
332 static void rna_Depsgraph_ids_next(CollectionPropertyIterator *iter)
333 {
334         DEG_iterator_ids_next(iter->internal.custom);
335         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
336 }
337
338 static void rna_Depsgraph_ids_end(CollectionPropertyIterator *iter)
339 {
340         DEG_iterator_ids_end(iter->internal.custom);
341         MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
342         MEM_freeN(iter->internal.custom);
343 }
344
345 static PointerRNA rna_Depsgraph_ids_get(CollectionPropertyIterator *iter)
346 {
347         ID *id = ((BLI_Iterator *)iter->internal.custom)->current;
348         return rna_pointer_inherit_refine(&iter->parent, &RNA_ID, id);
349 }
350
351 static void rna_Depsgraph_updates_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
352 {
353         iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
354         DEGIDIterData *data = MEM_callocN(sizeof(DEGIDIterData), __func__);
355
356         data->graph = (Depsgraph *)ptr->data;
357         data->only_updated = true;
358
359         ((BLI_Iterator *)iter->internal.custom)->valid = true;
360         DEG_iterator_ids_begin(iter->internal.custom, data);
361         iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
362 }
363
364 static PointerRNA rna_Depsgraph_updates_get(CollectionPropertyIterator *iter)
365 {
366         ID *id = ((BLI_Iterator *)iter->internal.custom)->current;
367         return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphUpdate, id);
368 }
369
370 static ID *rna_Depsgraph_id_eval_get(Depsgraph *depsgraph, ID *id_orig)
371 {
372         return DEG_get_evaluated_id(depsgraph, id_orig);
373 }
374
375 static bool rna_Depsgraph_id_type_updated(Depsgraph *depsgraph, int id_type)
376 {
377         return DEG_id_type_updated(depsgraph, id_type);
378 }
379
380 static PointerRNA rna_Depsgraph_scene_get(PointerRNA *ptr)
381 {
382         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
383         Scene *scene = DEG_get_input_scene(depsgraph);
384         return rna_pointer_inherit_refine(ptr, &RNA_Scene, scene);
385 }
386
387 static PointerRNA rna_Depsgraph_view_layer_get(PointerRNA *ptr)
388 {
389         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
390         ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
391         return rna_pointer_inherit_refine(ptr, &RNA_ViewLayer, view_layer);
392 }
393
394 static PointerRNA rna_Depsgraph_scene_eval_get(PointerRNA *ptr)
395 {
396         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
397         Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
398         return rna_pointer_inherit_refine(ptr, &RNA_Scene, scene_eval);
399 }
400
401 static PointerRNA rna_Depsgraph_view_layer_eval_get(PointerRNA *ptr)
402 {
403         Depsgraph *depsgraph = (Depsgraph *)ptr->data;
404         ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
405         return rna_pointer_inherit_refine(ptr, &RNA_ViewLayer, view_layer_eval);
406 }
407
408 #else
409
410 static void rna_def_depsgraph_instance(BlenderRNA *brna)
411 {
412         StructRNA *srna;
413         PropertyRNA *prop;
414
415         srna = RNA_def_struct(brna, "DepsgraphObjectInstance", NULL);
416         RNA_def_struct_ui_text(srna, "Dependency Graph Object Instance",
417                                "Extended information about dependency graph object iterator "
418                                "(WARNING: all data here is *evaluated* one, not original .blend IDs...)");
419
420         prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
421         RNA_def_property_struct_type(prop, "Object");
422         RNA_def_property_ui_text(prop, "Object", "Evaluated object the iterator points to");
423         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
424         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_object_get", NULL, NULL, NULL);
425
426         prop = RNA_def_property(srna, "is_instance", PROP_BOOLEAN, PROP_NONE);
427         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
428         RNA_def_property_ui_text(prop, "Is Instance", "Denotes whether the object is coming from dupli-list");
429         RNA_def_property_boolean_funcs(prop, "rna_DepsgraphObjectInstance_is_instance_get", NULL);
430
431         prop = RNA_def_property(srna, "instance_object", PROP_POINTER, PROP_NONE);
432         RNA_def_property_struct_type(prop, "Object");
433         RNA_def_property_ui_text(prop, "Instance Object", "Evaluated object which is being instanced by this iterator");
434         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
435         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_instance_object_get", NULL, NULL, NULL);
436
437         prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
438         RNA_def_property_struct_type(prop, "Object");
439         RNA_def_property_ui_text(prop, "Parent", "Evaluated parent object of the duplication list");
440         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
441         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_parent_get", NULL, NULL, NULL);
442
443         prop = RNA_def_property(srna, "particle_system", PROP_POINTER, PROP_NONE);
444         RNA_def_property_struct_type(prop, "ParticleSystem");
445         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
446         RNA_def_property_ui_text(prop, "Particle System", "Evaluated particle system that this object was instanced from");
447         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphObjectInstance_particle_system_get", NULL, NULL, NULL);
448
449         prop = RNA_def_property(srna, "persistent_id", PROP_INT, PROP_NONE);
450         RNA_def_property_ui_text(prop, "Persistent ID",
451                                  "Persistent identifier for inter-frame matching of objects with motion blur");
452         RNA_def_property_array(prop, 2 * MAX_DUPLI_RECUR);
453         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
454         RNA_def_property_int_funcs(prop, "rna_DepsgraphObjectInstance_persistent_id_get", NULL, NULL);
455
456         prop = RNA_def_property(srna, "random_id", PROP_INT, PROP_UNSIGNED);
457         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
458         RNA_def_property_ui_text(prop, "Dupli random id", "Random id for this dupli object");
459         RNA_def_property_int_funcs(prop, "rna_DepsgraphObjectInstance_random_id_get", NULL, NULL);
460
461         prop = RNA_def_property(srna, "matrix_world", PROP_FLOAT, PROP_MATRIX);
462         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
463         RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
464         RNA_def_property_ui_text(prop, "Generated Matrix", "Generated transform matrix in world space");
465         RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_matrix_world_get", NULL, NULL);
466
467         prop = RNA_def_property(srna, "orco", PROP_FLOAT, PROP_TRANSLATION);
468         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
469         RNA_def_property_array(prop, 3);
470         RNA_def_property_ui_text(prop, "Generated Coordinates", "Generated coordinates in parent object space");
471         RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_orco_get", NULL, NULL);
472
473         prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_NONE);
474         RNA_def_property_ui_text(prop, "UV Coordinates", "UV coordinates in parent object space");
475         RNA_def_property_array(prop, 2);
476         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
477         RNA_def_property_float_funcs(prop, "rna_DepsgraphObjectInstance_uv_get", NULL, NULL);
478 }
479
480 static void rna_def_depsgraph_update(BlenderRNA *brna)
481 {
482         StructRNA *srna;
483         PropertyRNA *prop;
484
485         srna = RNA_def_struct(brna, "DepsgraphUpdate", NULL);
486         RNA_def_struct_ui_text(srna, "Dependency Graph Update",
487                                "Information about ID that was updated");
488
489         prop = RNA_def_property(srna, "id", PROP_POINTER, PROP_NONE);
490         RNA_def_property_struct_type(prop, "ID");
491         RNA_def_property_ui_text(prop, "ID", "Updated datablock");
492         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
493         RNA_def_property_pointer_funcs(prop, "rna_DepsgraphUpdate_id_get", NULL, NULL, NULL);
494
495         prop = RNA_def_property(srna, "is_dirty_transform", PROP_BOOLEAN, PROP_NONE);
496         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
497         RNA_def_property_ui_text(prop, "Transform", "Object transformation is not updated");
498         RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_dirty_transform_get", NULL);
499
500         prop = RNA_def_property(srna, "is_dirty_geometry", PROP_BOOLEAN, PROP_NONE);
501         RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
502         RNA_def_property_ui_text(prop, "Geometry", "Object geometry is not updated");
503         RNA_def_property_boolean_funcs(prop, "rna_DepsgraphUpdate_is_dirty_geometry_get", NULL);
504 }
505
506 static void rna_def_depsgraph(BlenderRNA *brna)
507 {
508         StructRNA *srna;
509         FunctionRNA *func;
510         PropertyRNA *parm;
511         PropertyRNA *prop;
512
513         static EnumPropertyItem enum_depsgraph_mode_items[] = {
514                 {DAG_EVAL_VIEWPORT, "VIEWPORT", 0, "Viewport", "Viewport non-rendered mode"},
515                 {DAG_EVAL_RENDER, "RENDER", 0, "Render", "Render"},
516                 {0, NULL, 0, NULL, NULL}
517         };
518
519         srna = RNA_def_struct(brna, "Depsgraph", NULL);
520         RNA_def_struct_ui_text(srna, "Dependency Graph", "");
521
522         prop = RNA_def_enum(srna, "mode", enum_depsgraph_mode_items, 0, "Mode", "Evaluation mode");
523         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
524         RNA_def_property_enum_funcs(prop, "rna_Depsgraph_mode_get", NULL, NULL);
525
526         /* Debug helpers. */
527
528         func = RNA_def_function(srna, "debug_relations_graphviz", "rna_Depsgraph_debug_relations_graphviz");
529         parm = RNA_def_string_file_path(func, "filename", NULL, FILE_MAX, "File Name",
530                                         "File in which to store graphviz debug output");
531         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
532
533         func = RNA_def_function(srna, "debug_stats_gnuplot", "rna_Depsgraph_debug_stats_gnuplot");
534         parm = RNA_def_string_file_path(func, "filename", NULL, FILE_MAX, "File Name",
535                                         "File in which to store graphviz debug output");
536         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
537         parm = RNA_def_string_file_path(func, "output_filename", NULL, FILE_MAX, "Output File Name",
538                                         "File name where gnuplot script will save the result");
539         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
540
541         func = RNA_def_function(srna, "debug_tag_update", "rna_Depsgraph_debug_tag_update");
542
543         func = RNA_def_function(srna, "debug_stats", "rna_Depsgraph_debug_stats");
544         RNA_def_function_ui_description(func, "Report the number of elements in the Dependency Graph");
545         /* weak!, no way to return dynamic string type */
546         parm = RNA_def_string(func, "result", NULL, STATS_MAX_SIZE, "result", "");
547         RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); /* needed for string return value */
548         RNA_def_function_output(func, parm);
549
550         /* Queries for original datablockls (the ones depsgraph is built for). */
551
552         prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
553         RNA_def_property_struct_type(prop, "Scene");
554         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_get", NULL, NULL, NULL);
555         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
556         RNA_def_property_ui_text(prop, "Scene", "Original scene dependency graph is built for");
557
558         prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
559         RNA_def_property_struct_type(prop, "ViewLayer");
560         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_view_layer_get", NULL, NULL, NULL);
561         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
562         RNA_def_property_ui_text(prop, "View Layer", "Original view layer dependency graph is built for");
563
564         /* Queries for evaluated datablockls (the ones depsgraph is evaluating). */
565
566         func = RNA_def_function(srna, "id_eval_get", "rna_Depsgraph_id_eval_get");
567         parm = RNA_def_pointer(func, "id", "ID", "", "Original ID to get evaluated complementary part for");
568         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
569         parm = RNA_def_pointer(func, "id_eval", "ID", "", "Evaluated ID for the given original one");
570         RNA_def_function_return(func, parm);
571
572         func = RNA_def_function(srna, "id_type_updated", "rna_Depsgraph_id_type_updated");
573         parm = RNA_def_enum(func, "id_type", rna_enum_id_type_items, 0, "ID Type", "");
574         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
575         parm = RNA_def_boolean(func, "updated", false, "Updated", "True if any datablock with this type was added, updated or removed");
576         RNA_def_function_return(func, parm);
577
578         prop = RNA_def_property(srna, "scene_eval", PROP_POINTER, PROP_NONE);
579         RNA_def_property_struct_type(prop, "Scene");
580         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_eval_get", NULL, NULL, NULL);
581         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
582         RNA_def_property_ui_text(prop, "Scene", "Original scene dependency graph is built for");
583
584         prop = RNA_def_property(srna, "view_layer_eval", PROP_POINTER, PROP_NONE);
585         RNA_def_property_struct_type(prop, "ViewLayer");
586         RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_view_layer_eval_get", NULL, NULL, NULL);
587         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
588         RNA_def_property_ui_text(prop, "View Layer", "Original view layer dependency graph is built for");
589
590         /* Iterators. */
591
592         prop = RNA_def_property(srna, "ids", PROP_COLLECTION, PROP_NONE);
593         RNA_def_property_struct_type(prop, "ID");
594         RNA_def_property_collection_funcs(prop,
595                                           "rna_Depsgraph_ids_begin",
596                                           "rna_Depsgraph_ids_next",
597                                           "rna_Depsgraph_ids_end",
598                                           "rna_Depsgraph_ids_get",
599                                           NULL, NULL, NULL, NULL);
600         RNA_def_property_ui_text(prop, "IDs", "All evaluated datablocks");
601
602         prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
603         RNA_def_property_struct_type(prop, "Object");
604         RNA_def_property_collection_funcs(prop,
605                                           "rna_Depsgraph_objects_begin",
606                                           "rna_Depsgraph_objects_next",
607                                           "rna_Depsgraph_objects_end",
608                                           "rna_Depsgraph_objects_get",
609                                           NULL, NULL, NULL, NULL);
610         RNA_def_property_ui_text(prop, "Objects", "Evaluated objects in the dependency graph");
611
612         prop = RNA_def_property(srna, "object_instances", PROP_COLLECTION, PROP_NONE);
613         RNA_def_property_struct_type(prop, "DepsgraphObjectInstance");
614         RNA_def_property_collection_funcs(prop,
615                                           "rna_Depsgraph_object_instances_begin",
616                                           "rna_Depsgraph_object_instances_next",
617                                           "rna_Depsgraph_object_instances_end",
618                                           "rna_Depsgraph_object_instances_get",
619                                           NULL, NULL, NULL, NULL);
620         RNA_def_property_ui_text(prop, "Object Instances", "All object instances to display or render");
621
622         prop = RNA_def_property(srna, "updates", PROP_COLLECTION, PROP_NONE);
623         RNA_def_property_struct_type(prop, "DepsgraphUpdate");
624         RNA_def_property_collection_funcs(prop,
625                                           "rna_Depsgraph_updates_begin",
626                                           "rna_Depsgraph_ids_next",
627                                           "rna_Depsgraph_ids_end",
628                                           "rna_Depsgraph_updates_get",
629                                           NULL, NULL, NULL, NULL);
630         RNA_def_property_ui_text(prop, "Updates", "Updates to datablocks");
631 }
632
633 void RNA_def_depsgraph(BlenderRNA *brna)
634 {
635         rna_def_depsgraph_instance(brna);
636         rna_def_depsgraph_update(brna);
637         rna_def_depsgraph(brna);
638 }
639
640 #endif