Fix T59713: Armature layer dots not updated on changes
authormano-wii <germano.costa@ig.com.br>
Wed, 17 Jul 2019 17:17:16 +0000 (14:17 -0300)
committermano-wii <germano.costa@ig.com.br>
Wed, 17 Jul 2019 17:17:34 +0000 (14:17 -0300)
`layer_used` runtime data, which controls the drawing of dots in the UI was not getting refreshed properly.
This used to happen in the drawing code, but was no longer working for reasons explained in:
{rB2b09062defa093a243b5fe64b099accb07b440a3}

The solution was to update each layer manually in the operators:
* ARMATURE_OT_bone_primitive_add
* ARMATURE_OT_delete
* ARMATURE_OT_dissolve
* ARMATURE_OT_fill
* ARMATURE_OT_merge
* ARMATURE_OT_separate
* ARMATURE_OT_bone_layers
* POSE_OT_bone_layers

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

source/blender/blenkernel/BKE_armature.h
source/blender/blenkernel/intern/armature.c
source/blender/editors/armature/armature_add.c
source/blender/editors/armature/armature_edit.c
source/blender/editors/armature/armature_relations.c
source/blender/editors/armature/armature_utils.c
source/blender/editors/armature/pose_edit.c
source/blender/editors/include/ED_armature.h
source/blender/makesrna/intern/rna_armature.c

index 6839e13ffe17bef8a5d78fdd38225168a080bffd..73e62f6a7b3464b0d39d3e91677ee12c039e5abf 100644 (file)
@@ -90,6 +90,8 @@ void BKE_armature_bone_hash_free(struct bArmature *arm);
 
 bool BKE_armature_bone_flag_test_recursive(const struct Bone *bone, int flag);
 
+void BKE_armature_refresh_layer_used(struct bArmature *arm);
+
 float distfactor_to_bone(
     const float vec[3], const float b1[3], const float b2[3], float r1, float r2, float rdist);
 
index 65de951b19024ba9f70567a90d64d61afdc03d4d..c36acd1eae1b2a330313a7384e689778ff6f407f 100644 (file)
@@ -324,6 +324,24 @@ bool BKE_armature_bone_flag_test_recursive(const Bone *bone, int flag)
   }
 }
 
+static void armature_refresh_layer_used_recursive(bArmature *arm, ListBase *bones)
+{
+  for (Bone *bone = bones->first; bone; bone = bone->next) {
+    arm->layer_used |= bone->layer;
+    armature_refresh_layer_used_recursive(arm, &bone->childbase);
+  }
+}
+
+/* Update the layers_used variable after bones are moved between layer
+ * NOTE: Used to be done in drawing code in 2.7, but that won't work with
+ *       Copy-on-Write, as drawing uses evaluated copies.
+ */
+void BKE_armature_refresh_layer_used(bArmature *arm)
+{
+  arm->layer_used = 0;
+  armature_refresh_layer_used_recursive(arm, &arm->bonebase);
+}
+
 /* Finds the best possible extension to the name on a particular axis. (For renaming, check for
  * unique names afterwards) strip_number: removes number extensions  (TODO: not used)
  * axis: the axis to name on
index d02e58d48a90fa0fc6a22c7b615654cc0cba8833..d2fa77f90befd96fdd2373b4ed30fd48c676cdd9 100644 (file)
@@ -1121,6 +1121,8 @@ static int armature_bone_primitive_add_exec(bContext *C, wmOperator *op)
     add_v3_v3v3(bone->tail, bone->head, imat[2]);  // bone with unit length 1, pointing up Z
   }
 
+  ED_armature_edit_refresh_layer_used(obedit->data);
+
   /* note, notifier might evolve */
   WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit);
 
index c5430e06b6e631b7a8e9b46c5bb575acbb745ab2..4e6661b1d15c8778f77503819486e3e39fd3ccb1 100644 (file)
@@ -862,6 +862,7 @@ static int armature_fill_bones_exec(bContext *C, wmOperator *op)
   }
 
   /* updates */
+  ED_armature_edit_refresh_layer_used(arm);
   WM_event_add_notifier(C, NC_OBJECT | ND_POSE, obedit);
 
   /* free points */
@@ -1053,6 +1054,7 @@ static int armature_merge_exec(bContext *C, wmOperator *op)
 
     /* updates */
     ED_armature_edit_sync_selection(arm->edbo);
+    ED_armature_edit_refresh_layer_used(arm);
     WM_event_add_notifier(C, NC_OBJECT | ND_POSE, obedit);
   }
   MEM_freeN(objects);
@@ -1460,8 +1462,8 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op))
       changed_multi = true;
 
       ED_armature_edit_sync_selection(arm->edbo);
+      ED_armature_edit_refresh_layer_used(arm);
       BKE_pose_tag_recalc(CTX_data_main(C), obedit->pose);
-
       WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit);
     }
   }
@@ -1635,6 +1637,7 @@ static int armature_dissolve_selected_exec(bContext *C, wmOperator *UNUSED(op))
     if (changed) {
       changed_multi = true;
       ED_armature_edit_sync_selection(arm->edbo);
+      ED_armature_edit_refresh_layer_used(arm);
       WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit);
     }
   }
index 2c61818d9026877a01d5872ea8a3a09523ffe6a8..8722e575d15ecc81487ca1f3725028acb1d77a84 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "BKE_action.h"
 #include "BKE_animsys.h"
+#include "BKE_armature.h"
 #include "BKE_constraint.h"
 #include "BKE_context.h"
 #include "BKE_fcurve.h"
@@ -426,6 +427,7 @@ int join_armature_exec(bContext *C, wmOperator *op)
   ED_armature_from_edit(bmain, arm);
   ED_armature_edit_free(arm);
 
+  BKE_armature_refresh_layer_used(arm);
   DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
   WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
 
@@ -671,6 +673,9 @@ static int separate_armature_exec(bContext *C, wmOperator *op)
 
     ED_armature_to_edit(obedit->data);
 
+    ED_armature_edit_refresh_layer_used(obedit->data);
+    BKE_armature_refresh_layer_used(newob->data);
+
     /* parents tips remain selected when connected children are removed. */
     ED_armature_edit_deselect_all(obedit);
 
index 5d4245942293c280e1edc8ce88e37f4d8baebb20..d8777b7e0b73e100aa4dc6e7f52a9574e9d1add4 100644 (file)
@@ -85,6 +85,18 @@ void ED_armature_edit_validate_active(struct bArmature *arm)
   }
 }
 
+/* Update the layers_used variable after bones are moved between layer
+ * NOTE: Used to be done in drawing code in 2.7, but that won't work with
+ *       Copy-on-Write, as drawing uses evaluated copies.
+ */
+void ED_armature_edit_refresh_layer_used(bArmature *arm)
+{
+  arm->layer_used = 0;
+  for (EditBone *ebo = arm->edbo->first; ebo; ebo = ebo->next) {
+    arm->layer_used |= ebo->layer;
+  }
+}
+
 /* *************************************************************** */
 /* Bone Operations */
 
index 745af06c7af4c98223741e8ca7f5ce28a6806d17..5daf6b584e5766b279029839c3bfe748da56e391 100644 (file)
@@ -872,6 +872,8 @@ static int pose_bone_layers_exec(bContext *C, wmOperator *op)
     RNA_boolean_set_array(&ptr, "layers", layers);
 
     if (prev_ob != ob) {
+      BKE_armature_refresh_layer_used(ob->data);
+
       /* Note, notifier might evolve. */
       WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
       DEG_id_tag_update((ID *)ob->data, ID_RECALC_COPY_ON_WRITE);
@@ -949,6 +951,8 @@ static int armature_bone_layers_exec(bContext *C, wmOperator *op)
   }
   CTX_DATA_END;
 
+  ED_armature_edit_refresh_layer_used(ob->data);
+
   /* note, notifier might evolve */
   WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
 
index aca59e2868fdd23d7c498c975270dafdf9a581ab..60634cbebbfbe0f6dc41672147b652ada8c773df 100644 (file)
@@ -184,6 +184,8 @@ EditBone *ED_armature_ebone_get_mirrored(const struct ListBase *edbo, EditBone *
 void ED_armature_edit_sync_selection(struct ListBase *edbo);
 void ED_armature_edit_validate_active(struct bArmature *arm);
 
+void ED_armature_edit_refresh_layer_used(struct bArmature *arm);
+
 struct Base *ED_armature_base_and_ebone_from_select_buffer(struct Base **bases,
                                                            uint bases_len,
                                                            int hit,
index aef35684ff706c34c1ecc672e33b9d2e3ee589df..6737363bae433eacb5bd8b83705f5d92be487577 100644 (file)
@@ -268,18 +268,6 @@ static IDProperty *rna_EditBone_idprops(PointerRNA *ptr, bool create)
   return ebone->prop;
 }
 
-/* Update the layers_used variable after bones are moved between layer
- * NOTE: Used to be done in drawing code in 2.7, but that won't work with
- *       Copy-on-Write, as drawing uses evaluated copies.
- */
-static void rna_Armature_layer_used_refresh(bArmature *arm, ListBase *bones)
-{
-  for (Bone *bone = bones->first; bone; bone = bone->next) {
-    arm->layer_used |= bone->layer;
-    rna_Armature_layer_used_refresh(arm, &bone->childbase);
-  }
-}
-
 static void rna_bone_layer_set(int *layer, const bool *values)
 {
   int i, tot = 0;
@@ -312,8 +300,7 @@ static void rna_Bone_layer_set(PointerRNA *ptr, const bool *values)
 
   rna_bone_layer_set(&bone->layer, values);
 
-  arm->layer_used = 0;
-  rna_Armature_layer_used_refresh(arm, &arm->bonebase);
+  BKE_armature_refresh_layer_used(arm);
 }
 
 static void rna_Armature_layer_set(PointerRNA *ptr, const bool *values)