[Bf-blender-cvs] [befe38fe1df] blender-v3.3-release: Fix T92099: No undo when moving viewport with camera locked to view

Pratik Borhade noreply at git.blender.org
Sat Aug 6 04:58:51 CEST 2022


Commit: befe38fe1dfbbdac9ed9ef61853800426e5966c5
Author: Pratik Borhade
Date:   Fri Aug 5 15:53:04 2022 +1000
Branches: blender-v3.3-release
https://developer.blender.org/rBbefe38fe1dfbbdac9ed9ef61853800426e5966c5

Fix T92099: No undo when moving viewport with camera locked to view

Supports undo step generation while navigating in locked camera view.
NDOF & track-pad navigation are not included for now.

Actions that uses smooth view can be supported but are outside
the scope of this change, includes undo push for:

- VIEW3D_OT_view_pan
- VIEW3D_OT_dolly
- VIEW3D_OT_fly
- VIEW3D_OT_move
- VIEW3D_OT_rotate
- VIEW3D_OT_walk
- VIEW3D_OT_zoom

Reviewed by: campbellbarton

Ref D15345

===================================================================

M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/space_view3d/view3d_navigate.c
M	source/blender/editors/space_view3d/view3d_navigate_dolly.c
M	source/blender/editors/space_view3d/view3d_navigate_fly.c
M	source/blender/editors/space_view3d/view3d_navigate_move.c
M	source/blender/editors/space_view3d/view3d_navigate_rotate.c
M	source/blender/editors/space_view3d/view3d_navigate_walk.c
M	source/blender/editors/space_view3d/view3d_navigate_zoom.c
M	source/blender/editors/space_view3d/view3d_utils.c

===================================================================

diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 0298983ed26..931bb7be8bf 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -1196,6 +1196,28 @@ bool ED_view3d_camera_lock_autokey(struct View3D *v3d,
 
 void ED_view3d_lock_clear(struct View3D *v3d);
 
+/**
+ * Create an undo step when the camera is locked to the view.
+ * \param str: The name of the undo step (typically #wmOperatorType.name should be used).
+ *
+ * \return true when the call to push an undo step was made.
+ */
+bool ED_view3d_camera_lock_undo_push(const char *str,
+                                     View3D *v3d,
+                                     struct RegionView3D *rv3d,
+                                     struct bContext *C);
+
+/**
+ * A version of #ED_view3d_camera_lock_undo_push that performs a grouped undo push.
+ *
+ * \note use for actions that are likely to be repeated such as mouse wheel to zoom,
+ * where adding a separate undo step each time isn't desirable.
+ */
+bool ED_view3d_camera_lock_undo_grouped_push(const char *str,
+                                             View3D *v3d,
+                                             struct RegionView3D *rv3d,
+                                             struct bContext *C);
+
 #define VIEW3D_MARGIN 1.4f
 #define VIEW3D_DIST_FALLBACK 1.0f
 
diff --git a/source/blender/editors/space_view3d/view3d_navigate.c b/source/blender/editors/space_view3d/view3d_navigate.c
index 50d7626a57d..88e004aac48 100644
--- a/source/blender/editors/space_view3d/view3d_navigate.c
+++ b/source/blender/editors/space_view3d/view3d_navigate.c
@@ -1554,6 +1554,7 @@ static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
   viewmove_apply(vod, vod->prev.event_xy[0] + x, vod->prev.event_xy[1] + y);
 
+  ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
   viewops_data_free(C, vod);
 
   return OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_view3d/view3d_navigate_dolly.c b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
index d45b0c436ac..376e8ba190b 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_dolly.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
@@ -181,6 +181,7 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event)
   }
 
   if (ret & OPERATOR_FINISHED) {
+    ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
     viewops_data_free(C, vod);
     op->customdata = NULL;
   }
diff --git a/source/blender/editors/space_view3d/view3d_navigate_fly.c b/source/blender/editors/space_view3d/view3d_navigate_fly.c
index 399f422f411..95114941d66 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_fly.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_fly.c
@@ -1079,6 +1079,7 @@ static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event)
   int exit_code;
   bool do_draw = false;
   FlyInfo *fly = op->customdata;
+  View3D *v3d = fly->v3d;
   RegionView3D *rv3d = fly->rv3d;
   Object *fly_object = ED_view3d_cameracontrol_object_get(fly->v3d_camera_control);
 
@@ -1102,6 +1103,9 @@ static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event)
 
   exit_code = flyEnd(C, fly);
 
+  if (exit_code == OPERATOR_FINISHED) {
+    ED_view3d_camera_lock_undo_push(op->type->name, v3d, rv3d, C);
+  }
   if (exit_code != OPERATOR_RUNNING_MODAL) {
     do_draw = true;
   }
diff --git a/source/blender/editors/space_view3d/view3d_navigate_move.c b/source/blender/editors/space_view3d/view3d_navigate_move.c
index e653b349a2f..e236b702fb8 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_move.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_move.c
@@ -140,6 +140,7 @@ static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
   }
 
   if (ret & OPERATOR_FINISHED) {
+    ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
     viewops_data_free(C, op->customdata);
     op->customdata = NULL;
   }
diff --git a/source/blender/editors/space_view3d/view3d_navigate_rotate.c b/source/blender/editors/space_view3d/view3d_navigate_rotate.c
index 989fa152acc..20385e15c48 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_rotate.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_rotate.c
@@ -375,6 +375,7 @@ static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event)
   }
 
   if (ret & OPERATOR_FINISHED) {
+    ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
     viewops_data_free(C, op->customdata);
     op->customdata = NULL;
   }
diff --git a/source/blender/editors/space_view3d/view3d_navigate_walk.c b/source/blender/editors/space_view3d/view3d_navigate_walk.c
index f1e9ac22882..69deaab7ebe 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_walk.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_walk.c
@@ -1386,6 +1386,7 @@ static int walk_modal(bContext *C, wmOperator *op, const wmEvent *event)
   int exit_code;
   bool do_draw = false;
   WalkInfo *walk = op->customdata;
+  View3D *v3d = walk->v3d;
   RegionView3D *rv3d = walk->rv3d;
   Object *walk_object = ED_view3d_cameracontrol_object_get(walk->v3d_camera_control);
 
@@ -1412,6 +1413,9 @@ static int walk_modal(bContext *C, wmOperator *op, const wmEvent *event)
   if (exit_code != OPERATOR_RUNNING_MODAL) {
     do_draw = true;
   }
+  if (exit_code == OPERATOR_FINISHED) {
+    ED_view3d_camera_lock_undo_push(op->type->name, v3d, rv3d, C);
+  }
 
   if (do_draw) {
     if (rv3d->persp == RV3D_CAMOB) {
diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom.c b/source/blender/editors/space_view3d/view3d_navigate_zoom.c
index a67c0850ad9..9230aa09b1a 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_zoom.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_zoom.c
@@ -425,6 +425,7 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
   }
 
   if (ret & OPERATOR_FINISHED) {
+    ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
     viewops_data_free(C, op->customdata);
     op->customdata = NULL;
   }
@@ -507,6 +508,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
 
   ED_region_tag_redraw(region);
 
+  ED_view3d_camera_lock_undo_grouped_push(op->type->name, v3d, rv3d, C);
   viewops_data_free(C, op->customdata);
   op->customdata = NULL;
 
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index 85b1af8e55d..99f8cbc975b 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -44,6 +44,7 @@
 
 #include "ED_keyframing.h"
 #include "ED_screen.h"
+#include "ED_undo.h"
 #include "ED_view3d.h"
 
 #include "UI_resources.h"
@@ -688,6 +689,43 @@ bool ED_view3d_camera_lock_autokey(View3D *v3d,
   return false;
 }
 
+/**
+ * Create a MEMFILE undo-step for locked camera movement when transforming the view.
+ * Edit and texture paint mode don't use MEMFILE undo so undo push is skipped for them.
+ * NDOF and track-pad navigation would create an undo step on every gesture and we may end up with
+ * unnecessary undo steps so undo push for them is not supported for now. Also operators that uses
+ * smooth view for navigation are excluded too, but they can be supported, see: D15345.
+ */
+static bool view3d_camera_lock_undo_ex(
+    const char *str, View3D *v3d, RegionView3D *rv3d, struct bContext *C, bool undo_group)
+{
+  if (ED_view3d_camera_lock_check(v3d, rv3d)) {
+    if (ED_undo_is_memfile_compatible(C)) {
+      if (undo_group) {
+        ED_undo_grouped_push(C, str);
+      }
+      else {
+        ED_undo_push(C, str);
+      }
+      return true;
+    }
+  }
+  return false;
+}
+
+bool ED_view3d_camera_lock_undo_push(const char *str, View3D *v3d, RegionView3D *rv3d, bContext *C)
+{
+  return view3d_camera_lock_undo_ex(str, v3d, rv3d, C, false);
+}
+
+bool ED_view3d_camera_lock_undo_grouped_push(const char *str,
+                                             View3D *v3d,
+                                             RegionView3D *rv3d,
+                                             bContext *C)
+{
+  return view3d_camera_lock_undo_ex(str, v3d, rv3d, C, true);
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */



More information about the Bf-blender-cvs mailing list