Commit: 3772dda4ab1b071676a051e76324262a0d90dd49
Author: jon denning
Date:   Mon Jun 6 10:28:14 2022 -0400
Branches: master
https://developer.blender.org/rB3772dda4ab1b071676a051e76324262a0d90dd49

Refactor: Snap-related.  Clarified attribute names and refactored #defines into 
enums

The transformation snapping code contains a bunch of `#define`s, some 
ambiguously or incorrectly named attributes.  This patch contains refactored 
code to improve this.  This patch does (should) not change functionality of 
snapping.

Clarified ambiguously / incorrectly named attributes.

  - "Target" is used to refer to the part of the source that is to be snapped 
(Active, Median, Center, Closest), but several other areas of Blender use the 
term "target" to refer to the thing being snapped to and "source" to refer to 
the thing getting snapped.  Moreover, the implications of the previous terms do 
not match the descriptions.  For example: `SCE_SNAP_TARGET_CENTER` does not 
snap the grabbed geometry to the center of the target, but instead "Snap 
transforamtion center onto target".
  - "Select" refers to the condition for an object to be a possible target for 
snapping.
  - `SCE_SNAP_MODE_FACE` is renamed to `SCE_SNAP_MODE_FACE_RAYCAST` to better 
describe its affect and to make way for other face snapping methods (ex: 
nearest).

Refactored related `#define` into `enum`s.  In particular, constants relating 
to...

  - `ToolSettings.snap_flag` are now in `enum eSnapFlag`
  - `ToolSettings.snap_mode` are now in `enum eSnapMode`
  - `ToolSettings.snap_source` (was `snap_target`) are now in `enum 
eSnapSourceSelect`
  - `ToolSettings.snap_flag` (`SCE_SNAP_NO_SELF`) and `TransSnap.target_select` 
are now in `enum eSnapTargetSelect`

As the terms became more consistent and the constants were packed together into 
meaningful enumerations, some of the attribute names seemed ambiguous.  For 
example, it is unclear whether `SnapObjectParams.snap_select` referred to the 
target or the source.  This patch also adds a small amount of clarity.

This patch also swaps out generic types (ex: `char`, `short`, `ushort`) and 
unclear hard coded numbers (ex: `0`) used with snap-related enumerations with 
the actual `enum`s and values.

Note: I did leave myself some comments to follow-up with further refactoring.  
Specifically, using "target" and "source" consistently will mean the Python API 
will need to change (ex: `ToolSettings.snap_target` is not 
`ToolSettings.snap_source`).  If the API is going to change, it would be good 
to make sure that the used terms are descriptive enough.  For example, 
`bpy.ops.transform.translate` uses a `snap` argument to determine if snapping 
should be enabled while transforming.  Perhaps ` [...]

This patch is (mostly) a subset of D14591, as suggested by @mano-wii.

Task T69342 proposes to separate the `Absolute Grid Snap` option out from 
`Increment` snapping method into its own method.  Also, there might be reason 
to create additional snapping methods or options.  (Indeed, D14591 heads in 
this direction).  This patch can work along with these suggestions, as this 
patch is trying to clarify the snapping code and to prompt more work in this 
area.

Reviewed By: mano-wii

Differential Revision: https://developer.blender.org/D15037

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

M       source/blender/editors/curve/editcurve.c
M       source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c
M       source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c
M       source/blender/editors/gpencil/gpencil_utils.c
M       source/blender/editors/include/ED_gizmo_library.h
M       source/blender/editors/include/ED_transform_snap_object_context.h
M       source/blender/editors/include/ED_view3d.h
M       source/blender/editors/mesh/editmesh_utils.c
M       source/blender/editors/space_view3d/view3d_cursor_snap.c
M       source/blender/editors/space_view3d/view3d_edit.c
M       source/blender/editors/space_view3d/view3d_gizmo_ruler.c
M       source/blender/editors/space_view3d/view3d_navigate_walk.c
M       source/blender/editors/space_view3d/view3d_placement.c
M       source/blender/editors/transform/transform.c
M       source/blender/editors/transform/transform.h
M       source/blender/editors/transform/transform_mode.c
M       source/blender/editors/transform/transform_mode.h
M       source/blender/editors/transform/transform_mode_translate.c
M       source/blender/editors/transform/transform_ops.c
M       source/blender/editors/transform/transform_snap.c
M       source/blender/editors/transform/transform_snap.h
M       source/blender/editors/transform/transform_snap_object.cc
M       source/blender/makesdna/DNA_scene_types.h
M       source/blender/makesrna/RNA_enum_items.h
M       source/blender/makesrna/intern/rna_scene.c
M       source/blender/makesrna/intern/rna_scene_api.c
M       source/blender/windowmanager/xr/intern/wm_xr_operators.c

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

diff --git a/source/blender/editors/curve/editcurve.c 
b/source/blender/editors/curve/editcurve.c
index dc49a5ed531..4c0df48f65b 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -5597,7 +5597,8 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, 
const wmEvent *event)
           vc.v3d,
           SCE_SNAP_MODE_FACE,
           &(const struct SnapObjectParams){
-              .snap_select = (vc.obedit != NULL) ? SNAP_NOT_ACTIVE : SNAP_ALL,
+              .snap_target_select = (vc.obedit != NULL) ? 
SCE_SNAP_TARGET_NOT_ACTIVE :
+                                                          SCE_SNAP_TARGET_ALL,
               .edit_mode_type = SNAP_GEOM_FINAL,
           },
           mval,
diff --git a/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c 
b/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c
index 46fede8f6be..1ce67185c1e 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c
@@ -280,7 +280,7 @@ static int gizmo_move_modal(bContext *C,
               CTX_wm_view3d(C),
               (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE),
               &(const struct SnapObjectParams){
-                  .snap_select = SNAP_ALL,
+                  .snap_target_select = SCE_SNAP_TARGET_ALL,
                   .edit_mode_type = SNAP_GEOM_EDIT,
                   .use_occlusion_test = true,
               },
diff --git a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c 
b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c
index 1659afb1254..d468906f127 100644
--- a/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c
+++ b/source/blender/editors/gizmo_library/gizmo_types/snap3d_gizmo.c
@@ -96,7 +96,7 @@ void ED_gizmotypes_snap_3d_data_get(const struct bContext *C,
                                     float r_loc[3],
                                     float r_nor[3],
                                     int r_elem_index[3],
-                                    int *r_snap_elem)
+                                    eSnapMode *r_snap_elem)
 {
   if (C) {
     /* Snap values are updated too late at the cursor. Be sure to update ahead 
of time. */
@@ -283,7 +283,7 @@ static int snap_gizmo_test_select(bContext *C, wmGizmo *gz, 
const int mval[2])
   ED_view3d_cursor_snap_data_update(snap_gizmo->snap_state, C, x, y);
   V3DSnapCursorData *snap_data = ED_view3d_cursor_snap_data_get();
 
-  if (snap_data->snap_elem) {
+  if (snap_data->snap_elem != SCE_SNAP_MODE_NONE) {
     return 0;
   }
   return -1;
diff --git a/source/blender/editors/gpencil/gpencil_utils.c 
b/source/blender/editors/gpencil/gpencil_utils.c
index 5e8610c6b81..9a9461913fc 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1149,7 +1149,7 @@ void ED_gpencil_stroke_reproject(Depsgraph *depsgraph,
                                                depsgraph,
                                                v3d,
                                                &(const struct 
SnapObjectParams){
-                                                   .snap_select = SNAP_ALL,
+                                                   .snap_target_select = 
SCE_SNAP_TARGET_ALL,
                                                },
                                                &ray_start[0],
                                                &ray_normal[0],
diff --git a/source/blender/editors/include/ED_gizmo_library.h 
b/source/blender/editors/include/ED_gizmo_library.h
index 067e5ba4d7f..f8df4ba2a0c 100644
--- a/source/blender/editors/include/ED_gizmo_library.h
+++ b/source/blender/editors/include/ED_gizmo_library.h
@@ -14,6 +14,8 @@
 extern "C" {
 #endif
 
+#include "DNA_scene_types.h"
+
 /* initialize gizmos */
 void ED_gizmotypes_arrow_3d(void);
 void ED_gizmotypes_button_2d(void);
@@ -258,7 +260,7 @@ void ED_gizmotypes_snap_3d_data_get(const struct bContext 
*C,
                                     float r_loc[3],
                                     float r_nor[3],
                                     int r_elem_index[3],
-                                    int *r_snap_elem);
+                                    eSnapMode *r_snap_elem);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/editors/include/ED_transform_snap_object_context.h 
b/source/blender/editors/include/ED_transform_snap_object_context.h
index 2919001c5ce..20353c21f93 100644
--- a/source/blender/editors/include/ED_transform_snap_object_context.h
+++ b/source/blender/editors/include/ED_transform_snap_object_context.h
@@ -6,6 +6,8 @@
 
 #pragma once
 
+#include "DNA_scene_types.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -25,14 +27,6 @@ struct View3D;
 
 /* ED_transform_snap_object_*** API */
 
-typedef enum eSnapSelect {
-  SNAP_ALL = 0,
-  SNAP_NOT_SELECTED = 1,
-  SNAP_NOT_ACTIVE = 2,
-  SNAP_NOT_EDITED = 3,
-  SNAP_SELECTABLE = 4,
-} eSnapSelect;
-
 typedef enum eSnapEditType {
   SNAP_GEOM_FINAL = 0,
   SNAP_GEOM_CAGE = 1,
@@ -59,7 +53,7 @@ struct SnapObjectHitDepth {
 /** parameters that define which objects will be used to snap. */
 struct SnapObjectParams {
   /* Special context sensitive handling for the active or selected object. */
-  eSnapSelect snap_select;
+  eSnapTargetSelect snap_target_select;
   /* Geometry for snapping in edit mode. */
   eSnapEditType edit_mode_type;
   /* snap to the closest element, use when using more than one snap type */
@@ -120,21 +114,21 @@ bool 
ED_transform_snap_object_project_ray_all(SnapObjectContext *sctx,
                                               bool sort,
                                               struct ListBase *r_hit_list);
 
-short ED_transform_snap_object_project_view3d_ex(struct SnapObjectContext 
*sctx,
-                                                 struct Depsgraph *depsgraph,
-                                                 const ARegion *region,
-                                                 const View3D *v3d,
-                                                 unsigned short snap_to,
-                                                 const struct SnapObjectParams 
*params,
-                                                 const float mval[2],
-                                                 const float prev_co[3],
-                                                 float *dist_px,
-                                                 float r_loc[3],
-                                                 float r_no[3],
-                                                 int *r_index,
-                                                 struct Object **r_ob,
-                                                 float r_obmat[4][4],
-                                                 float r_face_nor[3]);
+eSnapMode ED_transform_snap_object_project_view3d_ex(struct SnapObjectContext 
*sctx,
+                                                     struct Depsgraph 
*depsgraph,
+                                                     const ARegion *region,
+                                                     const View3D *v3d,
+                                                     eSnapMode snap_to,
+                                                     const struct 
SnapObjectParams *params,
+                                                     const float mval[2],
+                                                     const float prev_co[3],
+                                                     float *dist_px,
+                                                     float r_loc[3],
+                                                     float r_no[3],
+                                                     int *r_index,
+                                                     struct Object **r_ob,
+                                                     float r_obmat[4][4],
+                                                     float r_face_nor[3]);
 /**
  * Convenience function for performing snapping.
  *
@@ -148,18 +142,18 @@ short ED_transform_snap_object_project_view3d_ex(struct 
SnapObjectContext *sctx,
  * \param r_no: hit normal (optional).
  * \return Snap success.
  */
-short ED_transform_snap_object_project_view3d(struct SnapObjectContext *sctx,
-                                              struct Depsgraph *depsgraph,
-                                              const ARegion *region,
-                                              const View3D *v3d,
-                                              unsigned short snap_to,
-                                              const struct SnapObjectParams 
*params,
-                                              const float mval[2],
-                                              const float prev_co[3],
-                                              float *dist_px,
-                                              /* return args */
-                                              float r_loc[3],
-                                              float r_no[3]);
+eSnapMode ED_transform_snap_object_project_view3d(struct SnapObjectContext 
*sctx,
+                                                  struct Depsgraph *depsgraph,
+                                                  const ARegion *region,
+                                                  const View3D *v3d,
+                                                  eSnapMode snap_to,
+                                                  const struct 
SnapObjectParams *params,
+                                                  const float mval[2],
+                                                  const float prev_co[3],
+                                                  float *dist_px,
+                                                  /* return args */
+                                                  float r_loc[3],
+                                                  float r_no[3]);
 
 /**
  * see: #ED_transform_snap_object_project_ray_all
diff --git a/source/blender/editors/include/ED_view3d.h 
b/source/blender/editors/include/ED_view3d.h
index 8695e03a57f..0298983ed26 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/sourc

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to