[Bf-blender-cvs] [b1b1a74af15] master: Cleanup: set 'op->customdata' out of 'viewops_data_create'

Germano Cavalcante noreply at git.blender.org
Sat Feb 5 00:39:33 CET 2022


Commit: b1b1a74af15b4eaa0757ad88acfbcac73b9a64fe
Author: Germano Cavalcante
Date:   Fri Feb 4 19:34:56 2022 -0300
Branches: master
https://developer.blender.org/rBb1b1a74af15b4eaa0757ad88acfbcac73b9a64fe

Cleanup: set 'op->customdata' out of 'viewops_data_create'

Setting the `op->customdata` out of `viewops_data_create` makes the usage of the function clearer thus making the code easier to read.

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

M	source/blender/editors/space_view3d/view3d_navigate.c
M	source/blender/editors/space_view3d/view3d_navigate.h
M	source/blender/editors/space_view3d/view3d_navigate_dolly.c
M	source/blender/editors/space_view3d/view3d_navigate_move.c
M	source/blender/editors/space_view3d/view3d_navigate_ndof.c
M	source/blender/editors/space_view3d/view3d_navigate_roll.c
M	source/blender/editors/space_view3d/view3d_navigate_rotate.c
M	source/blender/editors/space_view3d/view3d_navigate_zoom.c

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

diff --git a/source/blender/editors/space_view3d/view3d_navigate.c b/source/blender/editors/space_view3d/view3d_navigate.c
index e647e80ff36..98eef94d5fb 100644
--- a/source/blender/editors/space_view3d/view3d_navigate.c
+++ b/source/blender/editors/space_view3d/view3d_navigate.c
@@ -274,15 +274,11 @@ enum eViewOpsFlag viewops_flag_from_prefs(void)
                                 (U.uiflag & USER_DEPTH_NAVIGATE) != 0);
 }
 
-void viewops_data_create(bContext *C,
-                         wmOperator *op,
-                         const wmEvent *event,
-                         enum eViewOpsFlag viewops_flag)
+ViewOpsData *viewops_data_create(bContext *C, const wmEvent *event, enum eViewOpsFlag viewops_flag)
 {
   ViewOpsData *vod = MEM_callocN(sizeof(ViewOpsData), __func__);
 
   /* Store data. */
-  op->customdata = vod;
   vod->bmain = CTX_data_main(C);
   vod->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
   vod->scene = CTX_data_scene(C);
@@ -423,13 +419,14 @@ void viewops_data_create(bContext *C,
   }
 
   rv3d->rflag |= RV3D_NAVIGATING;
+
+  return vod;
 }
 
-void viewops_data_free(bContext *C, wmOperator *op)
+void viewops_data_free(bContext *C, ViewOpsData *vod)
 {
   ARegion *region;
-  if (op->customdata) {
-    ViewOpsData *vod = op->customdata;
+  if (vod) {
     region = vod->region;
     vod->rv3d->rflag &= ~RV3D_NAVIGATING;
 
@@ -442,7 +439,6 @@ void viewops_data_free(bContext *C, wmOperator *op)
     }
 
     MEM_freeN(vod);
-    op->customdata = NULL;
   }
   else {
     region = CTX_wm_region(C);
@@ -1565,12 +1561,12 @@ static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
     y = 25;
   }
 
-  viewops_data_create(C, op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT));
-  ViewOpsData *vod = op->customdata;
+  ViewOpsData *vod = viewops_data_create(
+      C, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT));
 
   viewmove_apply(vod, vod->prev.event_xy[0] + x, vod->prev.event_xy[1] + y);
 
-  viewops_data_free(C, op);
+  viewops_data_free(C, vod);
 
   return OPERATOR_FINISHED;
 }
diff --git a/source/blender/editors/space_view3d/view3d_navigate.h b/source/blender/editors/space_view3d/view3d_navigate.h
index 2f9a0ff603c..792d2a83bc2 100644
--- a/source/blender/editors/space_view3d/view3d_navigate.h
+++ b/source/blender/editors/space_view3d/view3d_navigate.h
@@ -166,15 +166,17 @@ bool view3d_orbit_calc_center(struct bContext *C, float r_dyn_ofs[3]);
 
 void view3d_operator_properties_common(struct wmOperatorType *ot, const enum eV3D_OpPropFlag flag);
 
-void viewops_data_free(struct bContext *C, struct wmOperator *op);
+/**
+ * Allocate and fill in context pointers for #ViewOpsData
+ */
+void viewops_data_free(struct bContext *C, ViewOpsData *vod);
 
 /**
  * Allocate, fill in context pointers and calculate the values for #ViewOpsData
  */
-void viewops_data_create(struct bContext *C,
-                         struct wmOperator *op,
-                         const struct wmEvent *event,
-                         enum eViewOpsFlag viewops_flag);
+ViewOpsData *viewops_data_create(struct bContext *C,
+                                 const struct wmEvent *event,
+                                 enum eViewOpsFlag viewops_flag);
 
 void VIEW3D_OT_view_all(struct wmOperatorType *ot);
 void VIEW3D_OT_view_selected(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_view3d/view3d_navigate_dolly.c b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
index 07099ea221e..02783c2a244 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_dolly.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
@@ -174,7 +174,8 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event)
   }
 
   if (ret & OPERATOR_FINISHED) {
-    viewops_data_free(C, op);
+    viewops_data_free(C, vod);
+    op->customdata = NULL;
   }
 
   return ret;
@@ -225,7 +226,8 @@ static int viewdolly_exec(bContext *C, wmOperator *op)
 
   ED_region_tag_redraw(region);
 
-  viewops_data_free(C, op);
+  viewops_data_free(C, op->customdata);
+  op->customdata = NULL;
 
   return OPERATOR_FINISHED;
 }
@@ -241,13 +243,11 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
   const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
 
-  /* makes op->customdata */
-  viewops_data_create(C,
-                      op,
-                      event,
-                      (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) |
-                          (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
-  vod = op->customdata;
+  vod = op->customdata = viewops_data_create(
+      C,
+      event,
+      (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) |
+          (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
 
   ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
 
@@ -294,7 +294,8 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
       }
       viewdolly_apply(vod, event->prev_xy, (U.uiflag & USER_ZOOM_INVERT) == 0);
 
-      viewops_data_free(C, op);
+      viewops_data_free(C, op->customdata);
+      op->customdata = NULL;
       return OPERATOR_FINISHED;
     }
 
@@ -307,7 +308,8 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
 static void viewdolly_cancel(bContext *C, wmOperator *op)
 {
-  viewops_data_free(C, op);
+  viewops_data_free(C, op->customdata);
+  op->customdata = NULL;
 }
 
 void VIEW3D_OT_dolly(wmOperatorType *ot)
diff --git a/source/blender/editors/space_view3d/view3d_navigate_move.c b/source/blender/editors/space_view3d/view3d_navigate_move.c
index a84da76b05f..90acf20d24f 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_move.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_move.c
@@ -119,7 +119,8 @@ static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
   }
 
   if (ret & OPERATOR_FINISHED) {
-    viewops_data_free(C, op);
+    viewops_data_free(C, op->customdata);
+    op->customdata = NULL;
   }
 
   return ret;
@@ -131,12 +132,11 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
   const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
 
-  /* makes op->customdata */
-  viewops_data_create(C,
-                      op,
-                      event,
-                      (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) |
-                          (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
+  vod = op->customdata = viewops_data_create(
+      C,
+      event,
+      (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) |
+          (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0));
   vod = op->customdata;
 
   ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
@@ -146,7 +146,8 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
     viewmove_apply(
         vod, 2 * event->xy[0] - event->prev_xy[0], 2 * event->xy[1] - event->prev_xy[1]);
 
-    viewops_data_free(C, op);
+    viewops_data_free(C, op->customdata);
+    op->customdata = NULL;
 
     return OPERATOR_FINISHED;
   }
@@ -159,7 +160,8 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
 static void viewmove_cancel(bContext *C, wmOperator *op)
 {
-  viewops_data_free(C, op);
+  viewops_data_free(C, op->customdata);
+  op->customdata = NULL;
 }
 
 void VIEW3D_OT_move(wmOperatorType *ot)
diff --git a/source/blender/editors/space_view3d/view3d_navigate_ndof.c b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
index 668a5288190..285d5c02db2 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_ndof.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
@@ -378,8 +378,8 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
   const wmNDOFMotionData *ndof = event->customdata;
 
-  viewops_data_create(C, op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE));
-  vod = op->customdata;
+  vod = op->customdata = viewops_data_create(
+      C, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE));
 
   ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
 
@@ -417,7 +417,8 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
   ED_region_tag_redraw(vod->region);
 
-  viewops_data_free(C, op);
+  viewops_data_free(C, op->customdata);
+  op->customdata = NULL;
 
   return OPERATOR_FINISHED;
 }
@@ -457,9 +458,8 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
 
   const wmNDOFMotionData *ndof = event->customdata;
 
-  viewops_data_create(C, op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE));
-
-  vod = op->customdata;
+  vod = op->customdata = viewops_data_create(
+      C, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE));
 
   ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region);
 
@@ -531,7 +531,8 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev
 
   ED_region_tag_redraw(vod->region);
 
-  viewops_data_free(C, op);
+  viewops_data_free(C, op->customdata);
+  op->customdata = NULL;
 
   return OPERATOR_FINISHED;
 }
diff --git a/source/blender/editors/space_view3d/view3d_navigate_roll.c b/source/blender/editors/space_view3d/view3d_navigate_roll.c
index 4675aad9af5..c9bfdc4412a 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_roll.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_roll.c
@@ -107,7 +107,8 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
     /* Note this does not remove auto-keys on locked cameras. */
     copy_qt_qt(vod->rv3d->viewquat, vod->init.quat);
     ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d);
-    viewops_data_free(C, op);
+    viewops_data_free(C, op->customdata);
+    op->customdata = NULL;
     return OPERATOR_CANCELLED;
   }
   else if (event->type == vod->init.event_type && event->val == KM_RELEASE) {
@@ -130,7 +131,8 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list