diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-07-19 11:20:21 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-07-19 11:20:21 +0400 |
commit | 8ced84eec9ae9fd311789935901f52d5073eb0fb (patch) | |
tree | c076738d35ffe660f4f5965f2504d7699896940d /source | |
parent | 388af9d827ccae97f24c6d65f7ab2da22ee8ea79 (diff) |
2.5 - Clear Constraints Operators
Added some operators to clear all constraints on the active object or the selected bones.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/armature/poseobject.c | 32 | ||||
-rw-r--r-- | source/blender/editors/object/editconstraint.c | 90 | ||||
-rw-r--r-- | source/blender/editors/object/object_intern.h | 4 | ||||
-rw-r--r-- | source/blender/editors/object/object_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_header.c | 8 |
5 files changed, 74 insertions, 62 deletions
diff --git a/source/blender/editors/armature/poseobject.c b/source/blender/editors/armature/poseobject.c index f7d926ea18d..ccf82fbc7ac 100644 --- a/source/blender/editors/armature/poseobject.c +++ b/source/blender/editors/armature/poseobject.c @@ -640,38 +640,6 @@ void pose_clear_IK(Scene *scene) BIF_undo_push("Remove IK constraint(s)"); } -void pose_clear_constraints(Scene *scene) -{ - Object *obedit= scene->obedit; // XXX context - Object *ob= OBACT; - bArmature *arm= ob->data; - bPoseChannel *pchan; - - /* paranoia checks */ - if(!ob && !ob->pose) return; - if(ob==obedit || (ob->flag & OB_POSEMODE)==0) return; - - if(pose_has_protected_selected(ob, 0, 1)) - return; - - if(okee("Remove Constraints")==0) return; - - /* find active */ - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if(arm->layer & pchan->bone->layer) { - if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) { - free_constraints(&pchan->constraints); - pchan->constflag= 0; - } - } - } - - DAG_object_flush_update(scene, ob, OB_RECALC_DATA); // and all its relations - - BIF_undo_push("Remove Constraint(s)"); - -} - void pose_copy_menu(Scene *scene) { diff --git a/source/blender/editors/object/editconstraint.c b/source/blender/editors/object/editconstraint.c index f5feccb8e4c..a2f709b9dff 100644 --- a/source/blender/editors/object/editconstraint.c +++ b/source/blender/editors/object/editconstraint.c @@ -519,28 +519,6 @@ void add_constraint (Scene *scene, View3D *v3d, short only_IK) } -/* Remove all constraints from the active object */ -void ob_clear_constraints (Scene *scene) -{ - Object *ob= OBACT; - - /* paranoia checks */ - if ((ob==NULL) || (ob==scene->obedit) || (ob->flag & OB_POSEMODE)) - return; - - /* get user permission */ - if (okee("Clear Constraints")==0) - return; - - /* do freeing */ - free_constraints(&ob->constraints); - - /* do updates */ - DAG_object_flush_update(scene, ob, OB_RECALC_OB); - - BIF_undo_push("Clear Constraint(s)"); -} - /* ------------- Constraint Sanity Testing ------------------- */ /* checks validity of object pointers, and NULLs, @@ -1006,7 +984,71 @@ void CONSTRAINT_OT_move_up (wmOperatorType *ot) /***************************** OPERATORS ****************************/ -/************************ add constraint operator *********************/ +/************************ remove constraint operators *********************/ + +static int pose_constraints_clear_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + + /* free constraints for all selected bones */ + CTX_DATA_BEGIN(C, bPoseChannel*, pchan, selected_pchans) + { + free_constraints(&pchan->constraints); + } + CTX_DATA_END; + + /* do updates */ + DAG_object_flush_update(scene, ob, OB_RECALC_OB); + WM_event_add_notifier(C, NC_OBJECT|ND_POSE|ND_CONSTRAINT|NA_REMOVED, ob); + + return OPERATOR_FINISHED; +} + +void POSE_OT_constraints_clear(wmOperatorType *ot) +{ + /* identifiers */ + //ot->name = "Clear Constraints"; + ot->idname= "POSE_OT_constraints_clear"; + ot->description= "Clear all the constraints for the selected bones."; + + /* callbacks */ + //ot->invoke= WM_menu_confirm; // XXX do we want confirmations on these things anymore? + ot->exec= pose_constraints_clear_exec; + ot->poll= ED_operator_posemode; // XXX - do we want to ensure there are selected bones too? +} + + +static int object_constraints_clear_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); + + /* do freeing */ + // TODO: we should free constraints for all selected objects instead (to be more consistent with bones) + free_constraints(&ob->constraints); + + /* do updates */ + DAG_object_flush_update(scene, ob, OB_RECALC_OB); + WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_REMOVED, ob); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_constraints_clear(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Clear Constraints"; + ot->idname= "OBJECT_OT_constraints_clear"; + ot->description= "Clear all the constraints for the active Object only."; + + /* callbacks */ + //ot->invoke= WM_menu_confirm; // XXX do we want confirmations on these things anymore? + ot->exec= object_constraints_clear_exec; + ot->poll= ED_operator_object_active; +} + +/************************ add constraint operators *********************/ static int constraint_add_exec(bContext *C, wmOperator *op, ListBase *list) { @@ -1071,7 +1113,7 @@ static int constraint_add_exec(bContext *C, wmOperator *op, ListBase *list) else DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob); + WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_ADDED, ob); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 5610a75d4d3..99967858d8b 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -103,6 +103,10 @@ void OBJECT_OT_modifier_mdef_bind(struct wmOperatorType *ot); /* editconstraint.c */ void OBJECT_OT_constraint_add(struct wmOperatorType *ot); void POSE_OT_constraint_add(struct wmOperatorType *ot); + +void OBJECT_OT_constraints_clear(struct wmOperatorType *ot); +void POSE_OT_constraints_clear(struct wmOperatorType *ot); + void CONSTRAINT_OT_delete(struct wmOperatorType *ot); void CONSTRAINT_OT_move_up(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index b73030226ef..992cdabaa77 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -113,6 +113,8 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_constraint_add); WM_operatortype_append(POSE_OT_constraint_add); + WM_operatortype_append(OBJECT_OT_constraints_clear); + WM_operatortype_append(POSE_OT_constraints_clear); WM_operatortype_append(CONSTRAINT_OT_delete); WM_operatortype_append(CONSTRAINT_OT_move_up); WM_operatortype_append(CONSTRAINT_OT_move_down); diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 78b21ded2f5..ed127fd032a 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -1978,12 +1978,8 @@ static void view3d_edit_object_trackmenu(bContext *C, uiLayout *layout, void *ar static void view3d_edit_object_constraintsmenu(bContext *C, uiLayout *layout, void *arg_unused) { -#if 0 - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Constraint...|Ctrl Alt C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, ""); - add_constraint(0); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Clear Constraints", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); - ob_clear_constraints(); -#endif + uiItemO(layout, NULL, 0, "OBJECT_OT_constraint_add"); // XXX it'd be better to have the version which sets links... + uiItemO(layout, NULL, 0, "OBJECT_OT_constraints_clear"); } static void view3d_edit_object_showhidemenu(bContext *C, uiLayout *layout, void *arg_unused) |