Operators: add a new flag stating that operator needs access to evaluated data.
authorBastien Montagne <montagne29@wanadoo.fr>
Fri, 3 Aug 2018 08:15:34 +0000 (10:15 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Fri, 3 Aug 2018 08:15:34 +0000 (10:15 +0200)
For now, that flag is only used in redo code, since after undo step
depsgraph is totally empty... We *may* want to add at least an assert in
op calling code too, though?

source/blender/editors/undo/ed_undo.c
source/blender/makesrna/intern/rna_wm.c
source/blender/windowmanager/WM_types.h

index 7c1dc148dde587024e6024e6c4ad6063a0fc1091..ffe4008f7d6a2ad9d9b2b20be05566d0d3452c9c 100644 (file)
@@ -48,6 +48,7 @@
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
+#include "BKE_scene.h"
 #include "BKE_screen.h"
 #include "BKE_layer.h"
 #include "BKE_undo_system.h"
@@ -414,6 +415,15 @@ int ED_undo_operator_repeat(bContext *C, wmOperator *op)
                                }
                        }
 
+                       if (op->type->flag & OPTYPE_USE_EVAL_DATA) {
+                               /* We need to force refresh of depsgraph after undo step,
+                                * redoing the operator *may* rely on some valid evaluated data. */
+                               Main *bmain = CTX_data_main(C);
+                               scene = CTX_data_scene(C);
+                               ViewLayer *view_layer = CTX_data_view_layer(C);
+                               BKE_scene_view_layer_graph_evaluated_ensure(bmain, scene, view_layer);
+                       }
+
                        retval = WM_operator_repeat(C, op);
                        if ((retval & OPERATOR_FINISHED) == 0) {
                                if (G.debug & G_DEBUG)
index 3432adc6eb3cbb7465a345fe270dba0d043e5939..a4c8dfbbdef868d6908255712761585b4516d71e 100644 (file)
@@ -432,6 +432,8 @@ static const EnumPropertyItem operator_flag_items[] = {
                              "is enabled"},
        {OPTYPE_PRESET, "PRESET", 0, "Preset", "Display a preset button with the operators settings"},
        {OPTYPE_INTERNAL, "INTERNAL", 0, "Internal", "Removes the operator from search results"},
+       {OPTYPE_USE_EVAL_DATA, "USE_EVAL_DATA", 0, "Use Evaluated Data",
+                              "Uses evaluated data (i.e. needs a valid depsgraph for current context)"},
        {0, NULL, 0, NULL, NULL}
 };
 #endif
index 60dd9ad2e7213dde1197e11b82435da528bba6a9..6b1bb8f4806b4449bf95a067f548dc184835eb9f 100644 (file)
@@ -145,6 +145,7 @@ enum {
 
        OPTYPE_LOCK_BYPASS  = (1 << 7),  /* Allow operator to run when interface is locked */
        OPTYPE_UNDO_GROUPED = (1 << 8),  /* Special type of undo which doesn't store itself multiple times */
+       OPTYPE_USE_EVAL_DATA = (1 << 9),  /* Need evaluated data (i.e. a valid, up-to-date depsgraph for current context) */
 };
 
 /* context to call operator in for WM_operator_name_call */