[Bf-blender-cvs] [c484599687b] master: Expose snap options in transform operators

jon denning noreply at git.blender.org
Wed Jul 13 13:10:20 CEST 2022


Commit: c484599687ba1757e3092f7fe2ffd0db56e9cbb6
Author: jon denning
Date:   Wed Jul 13 07:07:43 2022 -0400
Branches: master
https://developer.blender.org/rBc484599687ba1757e3092f7fe2ffd0db56e9cbb6

Expose snap options in transform operators

This commit exposes snap options in transform operators. These options
are needed for Python tools to control snapping without requiring the
tool settings to be adjusted.

The newly exposed options are:

- `snap_elements` for choosing which element(s) of target the source
  geometry should snap to (ex: Face Raycast).
- `use_snap_self`, `use_snap_edit`, `use_snap_nonedit`,
  `use_snap_selectable_only` for controlling target selection.
- `use_snap_project` for controlling Face Raycast snapping.
- `use_snap_to_same_target` and `snap_face_nearest_steps` for
  controlling Face Nearest snapping.

Reviewed by: Campbell Barton (campbellbarton)

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

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

M	source/blender/editors/transform/transform_ops.c

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

diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index a64eff8f981..7c94241f3e3 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -566,6 +566,17 @@ static bool transform_poll_property(const bContext *UNUSED(C),
     }
   }
 
+  /* Snapping. */
+  {
+    PropertyRNA *prop_snap = RNA_struct_find_property(op->ptr, "snap");
+    if (prop_snap && (prop_snap != prop) &&
+        (RNA_property_boolean_get(op->ptr, prop_snap) == false)) {
+      if (STRPREFIX(prop_id, "snap") || STRPREFIX(prop_id, "use_snap")) {
+        return false;
+      }
+    }
+  }
+
   return true;
 }
 
@@ -644,28 +655,63 @@ void Transform_Properties(struct wmOperatorType *ot, int flags)
   }
 
   if (flags & P_SNAP) {
-    prop = RNA_def_boolean(ot->srna, "snap", 0, "Use Snapping Options", "");
+    prop = RNA_def_boolean(ot->srna, "snap", false, "Use Snapping Options", "");
     RNA_def_property_flag(prop, PROP_HIDDEN);
 
+    prop = RNA_def_enum(ot->srna,
+                        "snap_elements",
+                        rna_enum_snap_element_items,
+                        SCE_SNAP_MODE_INCREMENT,
+                        "Snap to Elements",
+                        "");
+    RNA_def_property_flag(prop, PROP_ENUM_FLAG);
+
+    RNA_def_boolean(ot->srna, "use_snap_project", false, "Project Individual Elements", "");
+
     if (flags & P_GEO_SNAP) {
-      /* TODO(@gfxcoder): Rename `snap_target` to `snap_source` to avoid
-       * previous ambiguity of "target" (now, "source" is geometry to be moved and "target" is
-       * geometry to which moved geometry is snapped).  Use "Source snap point" and "Point on
-       * source that will snap to target" for name and description, respectively. */
-      prop = RNA_def_enum(ot->srna, "snap_target", rna_enum_snap_source_items, 0, "Target", "");
+      /* TODO(@gfxcoder): Rename `snap_target` to `snap_source` to avoid previous ambiguity of
+       * "target" (now, "source" is geometry to be moved and "target" is geometry to which moved
+       * geometry is snapped).  Use "Source snap point" and "Point on source that will snap to
+       * target" for name and description, respectively. */
+      prop = RNA_def_enum(ot->srna, "snap_target", rna_enum_snap_source_items, 0, "Snap With", "");
+      RNA_def_property_flag(prop, PROP_HIDDEN);
+
+      /* Target selection. */
+      prop = RNA_def_boolean(ot->srna, "use_snap_self", true, "Target: Include Active", "");
       RNA_def_property_flag(prop, PROP_HIDDEN);
+      prop = RNA_def_boolean(ot->srna, "use_snap_edit", true, "Target: Include Edit", "");
+      RNA_def_property_flag(prop, PROP_HIDDEN);
+      prop = RNA_def_boolean(ot->srna, "use_snap_nonedit", true, "Target: Include Non-Edited", "");
+      RNA_def_property_flag(prop, PROP_HIDDEN);
+      prop = RNA_def_boolean(
+          ot->srna, "use_snap_selectable_only", false, "Target: Exclude Non-Selectable", "");
+      RNA_def_property_flag(prop, PROP_HIDDEN);
+
+      /* Face Nearest options */
+      prop = RNA_def_boolean(
+          ot->srna, "use_snap_to_same_target", false, "Snap to Same Target", "");
+      RNA_def_property_flag(prop, PROP_HIDDEN);
+      prop = RNA_def_int(
+          ot->srna, "snap_face_nearest_steps", 1, 1, 32767, "Face Nearest Steps", "", 1, 32767);
+      RNA_def_property_flag(prop, PROP_HIDDEN);
+
       prop = RNA_def_float_vector(
           ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
       RNA_def_property_flag(prop, PROP_HIDDEN);
 
       if (flags & P_ALIGN_SNAP) {
-        prop = RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
+        prop = RNA_def_boolean(ot->srna, "snap_align", false, "Align with Point Normal", "");
         RNA_def_property_flag(prop, PROP_HIDDEN);
         prop = RNA_def_float_vector(
             ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
         RNA_def_property_flag(prop, PROP_HIDDEN);
       }
     }
+    else {
+      prop = RNA_def_boolean(
+          ot->srna, "use_snap_selectable_only", false, "Target: Exclude Non-Selectable", "");
+      RNA_def_property_flag(prop, PROP_HIDDEN);
+    }
   }
 
   if (flags & P_GPENCIL_EDIT) {



More information about the Bf-blender-cvs mailing list