Multi-Objects: POSE_OT_select_grouped > POSE_SEL_SAME_KEYINGSET 3/3
authorDalai Felinto <dfelinto@gmail.com>
Fri, 19 Oct 2018 18:44:04 +0000 (15:44 -0300)
committerDalai Felinto <dfelinto@gmail.com>
Fri, 19 Oct 2018 18:45:34 +0000 (15:45 -0300)
Note for posterity, I couldn't figure out a way to test this mode
properly. That said, it should be working with multiple-poses now.

source/blender/editors/armature/pose_select.c

index fcc57f8fa81fe83b871f5af18b9d00f76fc4f07c..d655d2e3679195599136e2415541ef31323b20dd 100644 (file)
@@ -856,15 +856,13 @@ cleanup:
        return changed;
 }
 
-static bool pose_select_same_keyingset(bContext *C, ReportList *reports, Object *ob, bool extend)
+static bool pose_select_same_keyingset(bContext *C, ReportList *reports, bool extend)
 {
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       bool changed_multi = false;
        KeyingSet *ks = ANIM_scene_get_active_keyingset(CTX_data_scene(C));
        KS_Path *ksp;
 
-       bArmature *arm = (ob) ? ob->data : NULL;
-       bPose *pose = (ob) ? ob->pose : NULL;
-       bool changed = false;
-
        /* sanity checks: validate Keying Set and object */
        if (ks == NULL) {
                BKE_report(reports, RPT_ERROR, "No active Keying Set to use");
@@ -884,9 +882,6 @@ static bool pose_select_same_keyingset(bContext *C, ReportList *reports, Object
                return false;
        }
 
-       if (ELEM(NULL, ob, pose, arm))
-               return false;
-
        /* if not extending selection, deselect all selected first */
        if (extend == false) {
                CTX_DATA_BEGIN (C, bPoseChannel *, pchan, visible_pose_bones)
@@ -897,34 +892,54 @@ static bool pose_select_same_keyingset(bContext *C, ReportList *reports, Object
                CTX_DATA_END;
        }
 
-       /* iterate over elements in the Keying Set, setting selection depending on whether
-        * that bone is visible or not...
-        */
-       for (ksp = ks->paths.first; ksp; ksp = ksp->next) {
-               /* only items related to this object will be relevant */
-               if ((ksp->id == &ob->id) && (ksp->rna_path != NULL)) {
-                       if (strstr(ksp->rna_path, "bones")) {
-                               char *boneName = BLI_str_quoted_substrN(ksp->rna_path, "bones[");
-
-                               if (boneName) {
-                                       bPoseChannel *pchan = BKE_pose_channel_find_name(pose, boneName);
-
-                                       if (pchan) {
-                                               /* select if bone is visible and can be affected */
-                                               if (PBONE_SELECTABLE(arm, pchan->bone)) {
-                                                       pchan->bone->flag |= BONE_SELECTED;
-                                                       changed = true;
+       uint objects_len = 0;
+       Object **objects = BKE_view_layer_array_from_objects_in_mode_unique_data(view_layer, &objects_len, OB_MODE_POSE);
+       for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+               Object *ob = BKE_object_pose_armature_get(objects[ob_index]);
+               bArmature *arm = (ob) ? ob->data : NULL;
+               bPose *pose = (ob) ? ob->pose : NULL;
+               bool changed = false;
+
+               /* Sanity checks. */
+               if (ELEM(NULL, ob, pose, arm)) {
+                       continue;
+               }
+
+               /* iterate over elements in the Keying Set, setting selection depending on whether
+                * that bone is visible or not...
+                */
+               for (ksp = ks->paths.first; ksp; ksp = ksp->next) {
+                       /* only items related to this object will be relevant */
+                       if ((ksp->id == &ob->id) && (ksp->rna_path != NULL)) {
+                               if (strstr(ksp->rna_path, "bones")) {
+                                       char *boneName = BLI_str_quoted_substrN(ksp->rna_path, "bones[");
+
+                                       if (boneName) {
+                                               bPoseChannel *pchan = BKE_pose_channel_find_name(pose, boneName);
+
+                                               if (pchan) {
+                                                       /* select if bone is visible and can be affected */
+                                                       if (PBONE_SELECTABLE(arm, pchan->bone)) {
+                                                               pchan->bone->flag |= BONE_SELECTED;
+                                                               changed = true;
+                                                       }
                                                }
-                                       }
 
-                                       /* free temp memory */
-                                       MEM_freeN(boneName);
+                                               /* free temp memory */
+                                               MEM_freeN(boneName);
+                                       }
                                }
                        }
                }
+
+               if (changed || !extend) {
+                       ED_pose_bone_select_tag_update(ob);
+                       changed_multi = true;
+               }
        }
+       MEM_freeN(objects);
 
-       return changed;
+       return changed_multi;
 }
 
 static int pose_select_grouped_exec(bContext *C, wmOperator *op)
@@ -934,11 +949,6 @@ static int pose_select_grouped_exec(bContext *C, wmOperator *op)
        const bool extend = RNA_boolean_get(op->ptr, "extend");
        bool changed = false;
 
-       if (type == POSE_SEL_SAME_KEYINGSET) {
-               BKE_report(op->reports, RPT_ERROR, "Mode not supported at the moment");
-               return OPERATOR_CANCELLED;
-       }
-
        /* sanity check */
        if (ob->pose == NULL)
                return OPERATOR_CANCELLED;
@@ -954,7 +964,7 @@ static int pose_select_grouped_exec(bContext *C, wmOperator *op)
                        break;
 
                case POSE_SEL_SAME_KEYINGSET: /* Keying Set */
-                       changed = pose_select_same_keyingset(C, op->reports, ob, extend);
+                       changed = pose_select_same_keyingset(C, op->reports, extend);
                        break;
 
                default: