2.5 - Clear Constraints Operators
authorJoshua Leung <aligorith@gmail.com>
Sun, 19 Jul 2009 07:20:21 +0000 (07:20 +0000)
committerJoshua Leung <aligorith@gmail.com>
Sun, 19 Jul 2009 07:20:21 +0000 (07:20 +0000)
Added some operators to clear all constraints on the active object or the selected bones.

source/blender/editors/armature/poseobject.c
source/blender/editors/object/editconstraint.c
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/editors/space_view3d/view3d_header.c

index f7d926ea18dce645e1b14347363fa5f14625f7b6..ccf82fbc7ac78c06f6fff52b402fdc14b173c528 100644 (file)
@@ -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)
 {
index f5feccb8e4c4df58245f670b7ae3a969e00a5345..a2f709b9dff2b8d069998857748ec58f717edcca 100644 (file)
@@ -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;
 }
index 5610a75d4d3576b2bd12cc343c445e31440c462b..99967858d8bfa5a6a2e40ca94b85e224cd12cee5 100644 (file)
@@ -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);
index b73030226ef138efc92e61f0f807ef5095ff4425..992cdabaa77222efac3e5d819e069e70ed086513 100644 (file)
@@ -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);
index 78b21ded2f5f079bc6bb196da5ecad57ca2c0c9c..ed127fd032a896d341b7896282ca556b4aadcf99 100644 (file)
@@ -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)