2.5 - Bugfixes for Pose 'Clear' Operators
authorJoshua Leung <aligorith@gmail.com>
Thu, 5 Feb 2009 05:51:21 +0000 (05:51 +0000)
committerJoshua Leung <aligorith@gmail.com>
Thu, 5 Feb 2009 05:51:21 +0000 (05:51 +0000)
* Fixed context iterators for PoseChannels. The actual selection test was missing (but layer visibility was getting checked). Also added check for hidden bones here too.

* Removed unnecessary defines added by mfoxdogg in BKE_context.h

* Removed the old hacks in 'Clear ...' operators for ensuring that object animation (ipos/actions) don't overwrite poses. These are no longer necessary, since normal animation calculation is only done in a separate step on frame-changes now.
* Removed the manual checks for layer visibility from 'Clear ...' operators, since that's taken care of by context iterators.

source/blender/blenkernel/BKE_context.h
source/blender/editors/armature/armature_intern.h
source/blender/editors/armature/editarmature.c
source/blender/editors/space_view3d/space_view3d.c

index e9544cf4a6f59ec1bcd0c059f24a6e7fe10702d4..5af97a7d8d5e9aff4f984951c3f95ee3a7097498 100644 (file)
@@ -40,8 +40,6 @@ struct EditMesh;
 struct ListBase;
 struct Main;
 struct Object;
-struct Bone;
-struct bArmature;
 struct PointerRNA;
 struct ReportList;
 struct Scene;
index 2ee48e150061b405c199d909d005a3cbba484dfd..0d780b7c9e8fa98bf13fa1d307fa7109c1f78bfb 100644 (file)
@@ -33,7 +33,7 @@ struct wmOperatorType;
 
 /* editarmature.c */
 void armature_bone_rename(Object *ob, char *oldnamep, char *newnamep);
-EditBone *armature_bone_get_mirrored(ListBase *edbo, EditBone *ebo);
+EditBone *armature_bone_get_mirrored(ListBase *edbo, EditBone *ebo); // XXX this is needed for populating the context iterators
 
 void POSE_OT_hide(struct wmOperatorType *ot);
 void POSE_OT_reveil(struct wmOperatorType *ot);
index 803d9c63cf2fb6bdb1f59f97af7dfa6ed20c036f..a938520ffa86d792545aa6a40b3df1cc08b8f15d 100644 (file)
@@ -4012,32 +4012,27 @@ void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par)
        }
 } 
 /* ************* Clear Pose *****************************/
+
 static int pose_clear_scale_exec(bContext *C, wmOperator *op) 
 {
        Scene *scene = CTX_data_scene(C);
        Object *ob= CTX_data_active_object(C);
-       bArmature *arm= ob->data;
        
        /* only clear those channels that are not locked */
-       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans){
-               if (arm->layer & pchan->bone->layer) {
-                       if ((pchan->protectflag & OB_LOCK_SCALEX)==0)
-                               pchan->size[0]= 1.0f;
-                       if ((pchan->protectflag & OB_LOCK_SCALEY)==0)
-                               pchan->size[1]= 1.0f;
-                       if ((pchan->protectflag & OB_LOCK_SCALEZ)==0)
-                               pchan->size[2]= 1.0f;
-                       /* the current values from IPO's may not be zero, so tag as unkeyed */
-                       pchan->bone->flag |= BONE_UNKEYED;
-               }
+       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) {
+               if ((pchan->protectflag & OB_LOCK_SCALEX)==0)
+                       pchan->size[0]= 1.0f;
+               if ((pchan->protectflag & OB_LOCK_SCALEY)==0)
+                       pchan->size[1]= 1.0f;
+               if ((pchan->protectflag & OB_LOCK_SCALEZ)==0)
+                       pchan->size[2]= 1.0f;
+                       
+               /* the current values from IPO's may not be zero, so tag as unkeyed */
+               //pchan->bone->flag |= BONE_UNKEYED;
        }
        CTX_DATA_END;
-               
+       
        DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
-       /* no update for this object, this will execute the action again */
-       /* is weak... like for ipo editing which uses ctime now... */
-       where_is_pose (scene, ob);
-       ob->recalc= 0;
 
        /* note, notifier might evolve */
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
@@ -4064,28 +4059,22 @@ static int pose_clear_loc_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
        Object *ob= CTX_data_active_object(C);
-       bArmature *arm= ob->data;
        
        /* only clear those channels that are not locked */
-       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans){
-               if (arm->layer & pchan->bone->layer) {
-                       if ((pchan->protectflag & OB_LOCK_LOCX)==0)
-                               pchan->loc[0]= 0.0f;
-                       if ((pchan->protectflag & OB_LOCK_LOCY)==0)
-                               pchan->loc[1]= 0.0f;
-                       if ((pchan->protectflag & OB_LOCK_LOCZ)==0)
-                               pchan->loc[2]= 0.0f;
-                       /* the current values from IPO's may not be zero, so tag as unkeyed */
-                       pchan->bone->flag |= BONE_UNKEYED;
-               }
+       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) {
+               if ((pchan->protectflag & OB_LOCK_LOCX)==0)
+                       pchan->loc[0]= 0.0f;
+               if ((pchan->protectflag & OB_LOCK_LOCY)==0)
+                       pchan->loc[1]= 0.0f;
+               if ((pchan->protectflag & OB_LOCK_LOCZ)==0)
+                       pchan->loc[2]= 0.0f;
+                       
+               /* the current values from IPO's may not be zero, so tag as unkeyed */
+               //pchan->bone->flag |= BONE_UNKEYED;
        }
        CTX_DATA_END;
-               
+       
        DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
-       /* no update for this object, this will execute the action again */
-       /* is weak... like for ipo editing which uses ctime now... */
-       where_is_pose (scene, ob);
-       ob->recalc= 0;
 
        /* note, notifier might evolve */
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
@@ -4112,46 +4101,55 @@ static int pose_clear_rot_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
        Object *ob= CTX_data_active_object(C);
-       bArmature *arm= ob->data;
        
        /* only clear those channels that are not locked */
-       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans){
-               if (arm->layer & pchan->bone->layer) {
-                       if (pchan->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ)) {
-                               float eul[3], oldeul[3], quat1[4];
-                                       
+       CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) {
+               if (pchan->protectflag & (OB_LOCK_ROTX|OB_LOCK_ROTY|OB_LOCK_ROTZ)) {
+                       float eul[3], oldeul[3], quat1[4];
+                       
+                       if (pchan->rotmode == PCHAN_ROT_QUAT) {
                                QUATCOPY(quat1, pchan->quat);
                                QuatToEul(pchan->quat, oldeul);
-                               eul[0]= eul[1]= eul[2]= 0.0f;
-                               
-                               if (pchan->protectflag & OB_LOCK_ROTX)
-                                       eul[0]= oldeul[0];
-                               if (pchan->protectflag & OB_LOCK_ROTY)
-                                       eul[1]= oldeul[1];
-                               if (pchan->protectflag & OB_LOCK_ROTZ)
-                                       eul[2]= oldeul[2];
-                                                       
+                       }
+                       else {
+                               VECCOPY(oldeul, pchan->eul);
+                       }
+                       eul[0]= eul[1]= eul[2]= 0.0f;
+                       
+                       if (pchan->protectflag & OB_LOCK_ROTX)
+                               eul[0]= oldeul[0];
+                       if (pchan->protectflag & OB_LOCK_ROTY)
+                               eul[1]= oldeul[1];
+                       if (pchan->protectflag & OB_LOCK_ROTZ)
+                               eul[2]= oldeul[2];
+                       
+                       if (pchan->rotmode == PCHAN_ROT_QUAT) {
                                EulToQuat(eul, pchan->quat);
                                /* quaternions flip w sign to accumulate rotations correctly */
                                if ((quat1[0]<0.0f && pchan->quat[0]>0.0f) || (quat1[0]>0.0f && pchan->quat[0]<0.0f)) {
                                        QuatMulf(pchan->quat, -1.0f);
                                }
-                       }                                               
-                       else { 
-                               pchan->quat[1]=pchan->quat[2]=pchan->quat[3]=0.0F; 
-                               pchan->quat[0]=1.0F;
                        }
-                       /* the current values from IPO's may not be zero, so tag as unkeyed */
-                       pchan->bone->flag |= BONE_UNKEYED;
+                       else {
+                               VECCOPY(pchan->eul, eul);
+                       }
+               }                                               
+               else { 
+                       if (pchan->rotmode == PCHAN_ROT_QUAT) {
+                               pchan->quat[1]=pchan->quat[2]=pchan->quat[3]= 0.0f; 
+                               pchan->quat[0]= 1.0f;
+                       }
+                       else {
+                               pchan->eul[0]= pchan->eul[1]= pchan->eul[2]= 0.0f;
+                       }
                }
+               
+               /* the current values from IPO's may not be zero, so tag as unkeyed */
+               //pchan->bone->flag |= BONE_UNKEYED;
        }
        CTX_DATA_END;
-               
+       
        DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
-       /* no update for this object, this will execute the action again */
-       /* is weak... like for ipo editing which uses ctime now... */
-       where_is_pose (scene, ob);
-       ob->recalc= 0;
 
        /* note, notifier might evolve */
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
index cdc38879d56042f694da63887b072f09d6d67a04..167abac2f2938c612d4ac315f1a6ad3e0a30dbee 100644 (file)
@@ -507,8 +507,10 @@ static int view3d_context(const bContext *C, bContextDataMember member, bContext
                
                if (obact && arm) {
                        for (pchan= obact->pose->chanbase.first; pchan; pchan= pchan->next) {
-                               if ((pchan->bone) && (arm->layer & pchan->bone->layer)) {
-                                       CTX_data_list_add(result, pchan);
+                               /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */
+                               if ((pchan->bone) && (arm->layer & pchan->bone->layer) && !(pchan->bone->flag & BONE_HIDDEN_P)) {
+                                       if (pchan->bone->flag & (BONE_SELECTED|BONE_ACTIVE)) 
+                                               CTX_data_list_add(result, pchan);
                                }
                        }