[Bf-blender-cvs] [31946bbd866] transform-snap-base: Fix: Scale operation and statusbar, Enable multi snappoints and snap inversion

Germano Cavalcante noreply at git.blender.org
Mon Nov 23 19:04:23 CET 2020


Commit: 31946bbd866cc67966500fddb712afd8f7169d67
Author: Germano Cavalcante
Date:   Tue Nov 17 10:29:32 2020 -0300
Branches: transform-snap-base
https://developer.blender.org/rB31946bbd866cc67966500fddb712afd8f7169d67

Fix: Scale operation and statusbar, Enable multi snappoints and snap inversion

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

M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_input.c
M	source/blender/editors/transform/transform_snap.c

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

diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 9a7a0ac0a94..10151291fa0 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -566,6 +566,20 @@ static void viewRedrawPost(bContext *C, TransInfo *t)
 static bool transform_modal_item_poll(const wmOperator *op, int value)
 {
   const TransInfo *t = op->customdata;
+  if (t->modifiers & MOD_EDIT_BASEPOINT) {
+    if (ELEM(value,
+             TFM_MODAL_CANCEL,
+             TFM_MODAL_CONFIRM,
+             TFM_MODAL_SNAP_INV_ON,
+             TFM_MODAL_SNAP_INV_OFF,
+             TFM_MODAL_ADD_SNAP,
+             TFM_MODAL_REMOVE_SNAP,
+             TFM_MODAL_EDIT_SNAPWITH)) {
+      return true;
+    }
+    return false;
+  }
+
   switch (value) {
     case TFM_MODAL_CANCEL: {
       /* TODO: Canceling with LMB is not possible when the operator is activated
@@ -805,27 +819,27 @@ int transformEvent(TransInfo *t, const wmEvent *event)
     handled = true;
   }
   else if (event->type == MOUSEMOVE) {
-    if (t->modifiers & (MOD_CONSTRAINT_SELECT | MOD_CONSTRAINT_PLANE)) {
-      t->con.mode |= CON_SELECT;
-    }
+    if (t->mval[0] != event->mval[0] || t->mval[1] != event->mval[1]) {
+      if (t->modifiers & (MOD_CONSTRAINT_SELECT | MOD_CONSTRAINT_PLANE)) {
+        t->con.mode |= CON_SELECT;
+      }
 
-    copy_v2_v2_int(t->mval, event->mval);
+      copy_v2_v2_int(t->mval, event->mval);
 
-    /* Use this for soft redraw. Might cause flicker in object mode */
-    // t->redraw |= TREDRAW_SOFT;
-    t->redraw |= TREDRAW_HARD;
+      /* Use this for soft redraw. Might cause flicker in object mode */
+      // t->redraw |= TREDRAW_SOFT;
+      t->redraw |= TREDRAW_HARD;
 
-    if (t->state == TRANS_STARTING) {
-      t->state = TRANS_RUNNING;
-    }
+      if (t->state == TRANS_STARTING) {
+        t->state = TRANS_RUNNING;
+      }
 
-    if (!(t->modifiers & MOD_EDIT_BASEPOINT)) {
       applyMouseInput(t, &t->mouse, t->mval, t->values);
-    }
 
-    /* Snapping mouse move events. */
-    t->redraw |= handleSnapping(t, event);
-    handled = true;
+      /* Snapping mouse move events. */
+      t->redraw |= handleSnapping(t, event);
+      handled = true;
+    }
   }
   /* handle modal keymap first */
   /* enforce redraw of transform when modifiers are used */
@@ -1534,10 +1548,9 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
     }
   }
 
-#ifdef USE_SAVE_SCE_SNAP
   if (t->flag & T_MODAL) {
     /* do we check for parameter? */
-    if (transformModeUseSnap(t)) {
+    if (transformModeUseSnap(t) & !(t->modifiers & MOD_SNAP_TEMP)) {
       if (!(t->modifiers & MOD_SNAP) != !(ts->snap_flag & SCE_SNAP)) {
         if (t->modifiers & MOD_SNAP) {
           ts->snap_flag |= SCE_SNAP;
@@ -1549,7 +1562,6 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
       }
     }
   }
-#endif
 
   if ((prop = RNA_struct_find_property(op->ptr, "use_proportional_edit"))) {
     RNA_property_boolean_set(op->ptr, prop, use_prop_edit);
@@ -1934,11 +1946,10 @@ void transformApply(bContext *C, TransInfo *t)
     }
     else if (t->transform) {
       t->transform(t, t->mval); /* calls recalcData() */
-      t->redraw |= TREDRAW_SOFT;
     }
   }
 
-  if (t->redraw & TREDRAW_SOFT) {
+  if (t->redraw & (TREDRAW_HARD | TREDRAW_SOFT)) {
     viewRedrawForce(C, t);
     t->redraw = TREDRAW_NOTHING;
   }
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 3c10e560267..3fd4bacec28 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -160,7 +160,7 @@ typedef enum {
   MOD_PRECISION = 1 << 2,
   MOD_SNAP = 1 << 3,
   MOD_SNAP_INVERT = 1 << 4,
-  MOD_FORCE_SNAP = MOD_SNAP | (1 << 5),
+  MOD_SNAP_TEMP = MOD_SNAP | (1 << 5),
   MOD_EDIT_BASEPOINT = 1 << 6,
 } eTransModifiers;
 
@@ -191,7 +191,7 @@ typedef enum {
 
 /** #TransSnap.status */
 typedef enum {
-  SNAP_FORCED = 1 << 0,
+  CUSTOM_SNAPPOINT = 1 << 0,
   TARGET_INIT = 1 << 1,
   POINT_INIT = 1 << 2,
   MULTI_POINTS = 1 << 3,
diff --git a/source/blender/editors/transform/transform_input.c b/source/blender/editors/transform/transform_input.c
index 70ef5fcde7a..ae05376ade4 100644
--- a/source/blender/editors/transform/transform_input.c
+++ b/source/blender/editors/transform/transform_input.c
@@ -451,6 +451,10 @@ void setInputPostFct(MouseInput *mi, void (*post)(struct TransInfo *t, float val
 
 void applyMouseInput(TransInfo *t, MouseInput *mi, const int mval[2], float output[3])
 {
+  if (t->modifiers & MOD_EDIT_BASEPOINT) {
+    return;
+  }
+
   double mval_db[2];
 
   if (mi->use_virtual_mval) {
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 16fff160136..dfbcce9401b 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -128,19 +128,12 @@ bool validSnap(const TransInfo *t)
 
 bool activeSnap(const TransInfo *t)
 {
-  if (t->modifiers & MOD_EDIT_BASEPOINT) {
-    return true;
-  }
   return ((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP) ||
          ((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP_INVERT);
 }
 
 bool transformModeUseSnap(const TransInfo *t)
 {
-  if (t->modifiers & MOD_FORCE_SNAP) {
-    return true;
-  }
-
   ToolSettings *ts = t->settings;
   if (t->mode == TFM_TRANSLATION) {
     return (ts->snap_transform_mode_flag & SCE_SNAP_TRANSFORM_MODE_TRANSLATE) != 0;
@@ -184,9 +177,9 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
   activeCol[3] = 192;
 
   if (t->spacetype == SPACE_VIEW3D) {
-    bool draw_target = (t->modifiers & MOD_EDIT_BASEPOINT) ||
-                       (t->tsnap.status & TARGET_INIT) &&
-                           (t->scene->toolsettings->snap_mode & SCE_SNAP_MODE_EDGE_PERPENDICULAR);
+    bool draw_target = (t->tsnap.status & TARGET_INIT) &&
+                       ((t->modifiers & MOD_EDIT_BASEPOINT) ||
+                        (t->settings->snap_mode & SCE_SNAP_MODE_EDGE_PERPENDICULAR));
 
     if (draw_target || validSnap(t)) {
       const float *loc_cur = NULL;
@@ -230,7 +223,7 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
         loc_prev = t->tsnap.snapTarget;
       }
 
-      if (validSnap(t)) {
+      if ((t->tsnap.status & (POINT_INIT | TARGET_INIT)) == (POINT_INIT | TARGET_INIT)) {
         loc_cur = t->tsnap.snapPoint;
       }
 
@@ -439,19 +432,17 @@ void applyGridAbsolute(TransInfo *t)
 
 void applySnapping(TransInfo *t, float *vec)
 {
-  /* Each Trans Data already makes the snap to face */
-  if (doForceIncrementSnap(t)) {
+  if (!transformModeUseSnap(t) && !((t->modifiers & MOD_SNAP_TEMP) == MOD_SNAP_TEMP)) {
     return;
   }
 
   if (t->tsnap.project && t->tsnap.mode == SCE_SNAP_MODE_FACE) {
-    /* The snap has already been resolved for each transdata. */
+    /* The snap will be resolved for each transdata. */
     return;
   }
 
-  if (t->tsnap.status & SNAP_FORCED) {
+  if (t->tsnap.status & CUSTOM_SNAPPOINT) {
     t->tsnap.targetSnap(t);
-
     t->tsnap.applySnap(t, vec);
   }
   else if (((t->tsnap.mode & ~(SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)) != 0) &&
@@ -652,7 +643,7 @@ void initSnapping(TransInfo *t, wmOperator *op)
 
       if (RNA_struct_property_is_set(op->ptr, "snap_point")) {
         RNA_float_get_array(op->ptr, "snap_point", t->tsnap.snapPoint);
-        t->tsnap.status |= SNAP_FORCED | POINT_INIT;
+        t->tsnap.status |= CUSTOM_SNAPPOINT | POINT_INIT;
       }
 
       /* snap align only defined in specific cases */
@@ -818,6 +809,15 @@ void getSnapPoint(const TransInfo *t, float vec[3])
   }
 }
 
+static void transform_snap_multipoints_free(TransInfo *t)
+{
+  if (t->tsnap.status & MULTI_POINTS) {
+    BLI_freelistN(&t->tsnap.points);
+    t->tsnap.status &= ~MULTI_POINTS;
+    t->tsnap.selectedPoint = NULL;
+  }
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -1574,19 +1574,27 @@ void tranform_snap_editbasepoint_toggle(TransInfo *t)
   if (!(t->modifiers & MOD_EDIT_BASEPOINT)) {
     /* Init. */
     t->modifiers |= MOD_EDIT_BASEPOINT;
+    t->tsnap.status |= TARGET_INIT;
     t->tsnap.targetSnap = TargetSnapCustom;
-    t->tsnap.targetSnap(t);
     if ((t->tsnap.mode & ~(SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)) == 0) {
       /* Init basic snap modes. */
       t->tsnap.mode &= ~(SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID);
       t->tsnap.mode |= SCE_SNAP_MODE_FACE | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_VERTEX;
     }
+
+    if (!activeSnap(t)) {
+      t->modifiers |= MOD_SNAP_TEMP;
+    }
+
     restoreTransObjects(t);
     t->redraw |= TREDRAW_SOFT;
   }
   else if (t->modifiers & MOD_EDIT_BASEPOINT) {
     /* Cancel. */
     t->modifiers &= ~MOD_EDIT_BASEPOINT;
+    if (t->modifiers & MOD_SNAP_TEMP) {
+      t->modifiers &= ~MOD_SNAP_TEMP;
+    }
     initSnappingMode(t);
     setSnappingCallback(t);
   }
@@ -1595,13 +1603,20 @@ void tranform_snap_editbasepoint_toggle(TransInfo *t)
 void tranform_snap_editbasepoint_update(TransInfo *t)
 {
   BLI_assert(t->modifiers & MOD_EDIT_BASEPOINT);
-  double current = PIL_check_seconds_timer();
+  if (!activeSnap(t)) {
+    return;
+  }
 
   /* Time base quirky code to go around findnearest slowness */
   /* TODO: add exception for object mode, no need to slow it down then. */
+  double current = PIL_check_seconds_timer();
   if (current - t->tsnap.last >= 0.01) {
     t->tsnap.calcSnap(t, NULL);
     t->tsnap.last = current;
+
+    if (validSnap(t)) {
+      getSnapPoint(t, t->tsnap.snapTarget);
+    }
   }
 
   t->redraw |= TREDRAW_SOFT;
@@ -1610,26 +1625,13 @@ void tranform_snap_editbasepoint_update(TransInfo *t)
 void tranform_snap_editbasepoint_confirm(TransInfo *t)
 {
   BLI_assert(t->modifiers & MOD_EDIT_BASEPOINT);
-  float new_base_point[3];
-  getSnapPoint(t, new_base_point);
-
-  /* Force a reinit with a current #t->mval. */
-  initMouseInput(t, &t->mouse, t->center2d, t->mval, false);
-  applyMouseInput(t, &t->mouse, t->mval, t->values);
-
-  copy_v3_v3(t->tsnap.snapTarget, new_base_point);
   t->modifiers &= ~MO

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list