[Bf-blender-cvs] [5e5285baf62] master: View 3D: move picking arguments into a struct & minor refactor

Campbell Barton noreply at git.blender.org
Wed Mar 16 04:49:59 CET 2022


Commit: 5e5285baf621a0c225cb5fc06fcec6ffed8302d7
Author: Campbell Barton
Date:   Tue Mar 15 21:03:04 2022 +1100
Branches: master
https://developer.blender.org/rB5e5285baf621a0c225cb5fc06fcec6ffed8302d7

View 3D: move picking arguments into a struct & minor refactor

- Add SelectPick_Params struct to make picking logic more
  straightforward and easier to extend.

- Use `eSelectOp` instead of booleans (extend, deselect, toggle)
  which were used to represent 4 states (which wasn't obvious).

- Handle deselect_all when pocking instead of view3d_select_exec,
  de-duplicate de-selection which was already needed in when replacing
  the selection in picking functions.

- Handle outliner update & notifiers in the picking functions
  instead of view3d_select_exec.

- Fix particle select deselect_all option which did nothing.

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

M	source/blender/editors/armature/armature_select.c
M	source/blender/editors/armature/pose_select.c
M	source/blender/editors/curve/editcurve.c
M	source/blender/editors/curve/editfont.c
M	source/blender/editors/include/ED_armature.h
M	source/blender/editors/include/ED_curve.h
M	source/blender/editors/include/ED_lattice.h
M	source/blender/editors/include/ED_mball.h
M	source/blender/editors/include/ED_mesh.h
M	source/blender/editors/include/ED_particle.h
M	source/blender/editors/include/ED_select_utils.h
M	source/blender/editors/lattice/editlattice_select.c
M	source/blender/editors/mesh/editface.c
M	source/blender/editors/mesh/editmesh_path.c
M	source/blender/editors/mesh/editmesh_select.c
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/editors/metaball/mball_edit.c
M	source/blender/editors/physics/particle_edit.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/editors/util/select_utils.c

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

diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c
index d7240782840..d1a5c128c35 100644
--- a/source/blender/editors/armature/armature_select.c
+++ b/source/blender/editors/armature/armature_select.c
@@ -951,127 +951,174 @@ bool ED_armature_edit_select_pick_bone(bContext *C,
                                        Base *basact,
                                        EditBone *ebone,
                                        const int selmask,
-                                       const bool extend,
-                                       const bool deselect,
-                                       const bool toggle)
+                                       const struct SelectPick_Params *params)
 {
-  if (!ebone) {
-    return false;
-  }
-
   ViewLayer *view_layer = CTX_data_view_layer(C);
   View3D *v3d = CTX_wm_view3d(C);
+  bool changed = false;
+  bool found = false;
 
-  BLI_assert(BKE_object_is_in_editmode(basact->object));
-  bArmature *arm = basact->object->data;
-
-  if (!EBONE_SELECTABLE(arm, ebone)) {
-    return false;
+  if (ebone) {
+    bArmature *arm = basact->object->data;
+    if (EBONE_SELECTABLE(arm, ebone)) {
+      found = true;
+    }
   }
 
-  if (!extend && !deselect && !toggle) {
+  if ((params->sel_op == SEL_OP_SET) && (found || params->deselect_all)) {
+    /* Deselect everything. */
     uint bases_len = 0;
     Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
         view_layer, v3d, &bases_len);
     ED_armature_edit_deselect_all_multi_ex(bases, bases_len);
     MEM_freeN(bases);
+    changed = true;
   }
 
-  /* By definition the non-root connected bones have no root point drawn,
-   * so a root selection needs to be delivered to the parent tip. */
+  if (found) {
+    BLI_assert(BKE_object_is_in_editmode(basact->object));
+    bArmature *arm = basact->object->data;
 
-  if (selmask & BONE_SELECTED) {
-    if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
-      /* Bone is in a chain. */
-      if (extend) {
-        /* Select this bone. */
-        ebone->flag |= BONE_TIPSEL;
-        ebone->parent->flag |= BONE_TIPSEL;
-      }
-      else if (deselect) {
-        /* Deselect this bone. */
-        ebone->flag &= ~(BONE_TIPSEL | BONE_SELECTED);
-        /* Only deselect parent tip if it is not selected. */
-        if (!(ebone->parent->flag & BONE_SELECTED)) {
-          ebone->parent->flag &= ~BONE_TIPSEL;
-        }
-      }
-      else if (toggle) {
-        /* Toggle inverts this bone's selection. */
-        if (ebone->flag & BONE_SELECTED) {
-          /* Deselect this bone. */
-          ebone->flag &= ~(BONE_TIPSEL | BONE_SELECTED);
-          /* Only deselect parent tip if it is not selected. */
-          if (!(ebone->parent->flag & BONE_SELECTED)) {
-            ebone->parent->flag &= ~BONE_TIPSEL;
+    /* By definition the non-root connected bones have no root point drawn,
+     * so a root selection needs to be delivered to the parent tip. */
+
+    if (selmask & BONE_SELECTED) {
+      if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
+
+        /* Bone is in a chain. */
+        switch (params->sel_op) {
+          case SEL_OP_ADD: {
+            /* Select this bone. */
+            ebone->flag |= BONE_TIPSEL;
+            ebone->parent->flag |= BONE_TIPSEL;
+            break;
+          }
+          case SEL_OP_SUB: {
+            /* Deselect this bone. */
+            ebone->flag &= ~(BONE_TIPSEL | BONE_SELECTED);
+            /* Only deselect parent tip if it is not selected. */
+            if (!(ebone->parent->flag & BONE_SELECTED)) {
+              ebone->parent->flag &= ~BONE_TIPSEL;
+            }
+            break;
+          }
+          case SEL_OP_XOR: {
+            /* Toggle inverts this bone's selection. */
+            if (ebone->flag & BONE_SELECTED) {
+              /* Deselect this bone. */
+              ebone->flag &= ~(BONE_TIPSEL | BONE_SELECTED);
+              /* Only deselect parent tip if it is not selected. */
+              if (!(ebone->parent->flag & BONE_SELECTED)) {
+                ebone->parent->flag &= ~BONE_TIPSEL;
+              }
+            }
+            else {
+              /* Select this bone. */
+              ebone->flag |= BONE_TIPSEL;
+              ebone->parent->flag |= BONE_TIPSEL;
+            }
+            break;
+          }
+          case SEL_OP_SET: {
+            /* Select this bone. */
+            ebone->flag |= BONE_TIPSEL;
+            ebone->parent->flag |= BONE_TIPSEL;
+            break;
+          }
+          case SEL_OP_AND: {
+            BLI_assert_unreachable(); /* Doesn't make sense for picking. */
+            break;
           }
-        }
-        else {
-          /* Select this bone. */
-          ebone->flag |= BONE_TIPSEL;
-          ebone->parent->flag |= BONE_TIPSEL;
         }
       }
       else {
-        /* Select this bone. */
-        ebone->flag |= BONE_TIPSEL;
-        ebone->parent->flag |= BONE_TIPSEL;
+        switch (params->sel_op) {
+          case SEL_OP_ADD: {
+            ebone->flag |= (BONE_TIPSEL | BONE_ROOTSEL);
+            break;
+          }
+          case SEL_OP_SUB: {
+            ebone->flag &= ~(BONE_TIPSEL | BONE_ROOTSEL);
+            break;
+          }
+          case SEL_OP_XOR: {
+            /* Toggle inverts this bone's selection. */
+            if (ebone->flag & BONE_SELECTED) {
+              ebone->flag &= ~(BONE_TIPSEL | BONE_ROOTSEL);
+            }
+            else {
+              ebone->flag |= (BONE_TIPSEL | BONE_ROOTSEL);
+            }
+            break;
+          }
+          case SEL_OP_SET: {
+            ebone->flag |= (BONE_TIPSEL | BONE_ROOTSEL);
+            break;
+          }
+          case SEL_OP_AND: {
+            BLI_assert_unreachable(); /* Doesn't make sense for picking. */
+            break;
+          }
+        }
       }
     }
     else {
-      if (extend) {
-        ebone->flag |= (BONE_TIPSEL | BONE_ROOTSEL);
-      }
-      else if (deselect) {
-        ebone->flag &= ~(BONE_TIPSEL | BONE_ROOTSEL);
-      }
-      else if (toggle) {
-        /* Toggle inverts this bone's selection. */
-        if (ebone->flag & BONE_SELECTED) {
-          ebone->flag &= ~(BONE_TIPSEL | BONE_ROOTSEL);
+      switch (params->sel_op) {
+        case SEL_OP_ADD: {
+          ebone->flag |= selmask;
+          break;
         }
-        else {
-          ebone->flag |= (BONE_TIPSEL | BONE_ROOTSEL);
+        case SEL_OP_SUB: {
+          ebone->flag &= ~selmask;
+          break;
+        }
+        case SEL_OP_XOR: {
+          if (ebone->flag & selmask) {
+            ebone->flag &= ~selmask;
+          }
+          else {
+            ebone->flag |= selmask;
+          }
+          break;
+        }
+        case SEL_OP_SET: {
+          ebone->flag |= selmask;
+          break;
+        }
+        case SEL_OP_AND: {
+          BLI_assert_unreachable(); /* Doesn't make sense for picking. */
+          break;
         }
-      }
-      else {
-        ebone->flag |= (BONE_TIPSEL | BONE_ROOTSEL);
       }
     }
-  }
-  else {
-    if (extend) {
-      ebone->flag |= selmask;
-    }
-    else if (deselect) {
-      ebone->flag &= ~selmask;
-    }
-    else if (toggle && (ebone->flag & selmask)) {
-      ebone->flag &= ~selmask;
-    }
-    else {
-      ebone->flag |= selmask;
+
+    ED_armature_edit_sync_selection(arm->edbo);
+
+    /* Then now check for active status. */
+    if (ED_armature_ebone_selectflag_get(ebone)) {
+      arm->act_edbone = ebone;
     }
-  }
 
-  ED_armature_edit_sync_selection(arm->edbo);
+    if (view_layer->basact != basact) {
+      ED_object_base_activate(C, basact);
+    }
 
-  /* Then now check for active status. */
-  if (ED_armature_ebone_selectflag_get(ebone)) {
-    arm->act_edbone = ebone;
+    WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, basact->object);
+    DEG_id_tag_update(&arm->id, ID_RECALC_COPY_ON_WRITE);
+    changed = true;
   }
 
-  if (view_layer->basact != basact) {
-    ED_object_base_activate(C, basact);
+  if (changed) {
+    ED_outliner_select_sync_from_edit_bone_tag(C);
   }
 
-  WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, basact->object);
-  DEG_id_tag_update(&arm->id, ID_RECALC_COPY_ON_WRITE);
-  return true;
+  return changed || found;
 }
 
-bool ED_armature_edit_select_pick(
-    bContext *C, const int mval[2], bool extend, bool deselect, bool toggle)
+bool ED_armature_edit_select_pick(bContext *C,
+                                  const int mval[2],
+                                  const struct SelectPick_Params *params)
+
 {
   Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
   ViewContext vc;
@@ -1084,7 +1131,7 @@ bool ED_armature_edit_select_pick(
   vc.mval[1] = mval[1];
 
   nearBone = get_nearest_editbonepoint(&vc, true, true, &basact, &selmask);
-  return ED_armature_edit_select_pick_bone(C, basact, nearBone, selmask, extend, deselect, toggle);
+  return ED_armature_edit_select_pick_bone(C, basact, nearBone, selmask, params);
 }
 
 /** \} */
diff --git a/source/blender/editors/armature/pose_select.c b/source/blender/editors/armature/pose_select.c
index 12238280b06..1cf56389580 100644
--- a/source/blender/editors/armature/pose_select.c
+++ b/source/blender/editors/armature/pose_select.c
@@ -121,104 +121,120 @@ void ED_pose_bone_select(Object *ob, bPoseChannel *pchan, bool select)
   }
 }
 
-void ED_armature_pose_select_pick_bone(ViewLayer *view_layer,
+bool ED_armature_pose_select_pick_bone(ViewLayer *view_layer,
                                        View3D *v3d,
                                        Object *ob,
                                        Bone *bone,
-                                       const bool extend,
-                                       const bool deselect,
-                                       const bool toggle)
+                                       const struct SelectPick_Params *params)
 {
-  if (!ob || !ob->pose) {
-    return;
-  }
-
-  Object *ob_act = OBACT(view_layer);
-  BLI_assert(OBEDIT_FROM_VIEW_LAYER(view_layer) == NULL);
-
-  /* If the bone cannot be affected, don't do anything. */
-  if (bone == NULL || (bone->fl

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list