2.5 - Clear Constraints Operators
Added some operators to clear all constraints on the active object or the selected bones.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user