2.5 - Made more operators for constraint buttons

* Move Up/Down and Delete are now operators 
* Made TrackTo constraint use expanded enum toggles for up axis too. 
--> BUG ALERT: specifying name and expand in the arguments to itemR doesn't work (name gets skipped)
This commit is contained in:
Joshua Leung 2009-07-11 12:54:17 +00:00
parent 10d14e7259
commit 0096a3dee2
6 changed files with 99 additions and 103 deletions

@ -109,7 +109,6 @@ class ConstraintButtonsPanel(bpy.types.Panel):
sub.itemR(con, "sizey", text="Y")
sub.itemR(con, "sizez", text="Z")
# Missing
row = layout.row()
row.itemO("CONSTRAINT_OT_childof_set_inverse")
row.itemO("CONSTRAINT_OT_childof_clear_inverse")
@ -122,6 +121,7 @@ class ConstraintButtonsPanel(bpy.types.Panel):
row.itemR(con, "track", expand=True)
row = layout.row()
#row.itemR(con, "up", text="Up", expand=True) # XXX: up and expand don't play nice together
row.itemR(con, "up", text="Up")
row.itemR(con, "target_z")

@ -82,9 +82,6 @@ void object_test_constraints(struct Object *ob);
void ED_object_constraint_rename(struct Object *ob, struct bConstraint *con, char *oldname);
void ED_object_constraint_set_active(struct Object *ob, struct bConstraint *con);
int ED_object_constraint_delete(struct ReportList *reports, struct Object *ob, struct bConstraint *con);
int ED_object_constraint_move_down(struct ReportList *reports, struct Object *ob, struct bConstraint *con);
int ED_object_constraint_move_up(struct ReportList *reports, struct Object *ob, struct bConstraint *con);
/* editlattice.c */
void mouse_lattice(struct bContext *C, short mval[2], int extend);

@ -616,12 +616,6 @@ static void constraint_active_func(bContext *C, void *ob_v, void *con_v)
ED_object_constraint_set_active(ob_v, con_v);
}
static void del_constraint_func (bContext *C, void *ob_v, void *con_v)
{
if(ED_object_constraint_delete(NULL, ob_v, con_v))
ED_undo_push(C, "Delete Constraint");
}
static void verify_constraint_name_func (bContext *C, void *con_v, void *name_v)
{
Object *ob= CTX_data_active_object(C);
@ -639,18 +633,6 @@ static void verify_constraint_name_func (bContext *C, void *con_v, void *name_v)
// XXX allqueue(REDRAWACTION, 0);
}
static void constraint_moveUp(bContext *C, void *ob_v, void *con_v)
{
if(ED_object_constraint_move_up(NULL, ob_v, con_v))
ED_undo_push(C, "Move Constraint");
}
static void constraint_moveDown(bContext *C, void *ob_v, void *con_v)
{
if(ED_object_constraint_move_down(NULL, ob_v, con_v))
ED_undo_push(C, "Move Constraint");
}
/* some commonly used macros in the constraints drawing code */
#define is_armature_target(target) (target && target->type==OB_ARMATURE)
#define is_armature_owner(ob) ((ob->type == OB_ARMATURE) && (ob->flag & OB_POSEMODE))
@ -828,25 +810,18 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
uiBlockBeginAlign(block);
uiBlockSetEmboss(block, UI_EMBOSS);
if (show_upbut) {
but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_UP, xco+width-50, yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint up in constraint stack");
uiButSetFunc(but, constraint_moveUp, ob, con);
}
if (show_upbut)
uiDefIconButO(block, BUT, "CONSTRAINT_OT_move_up", WM_OP_INVOKE_DEFAULT, VICON_MOVE_UP, xco+width-50, yco, 16, 18, "Move constraint up in constraint stack");
if (show_downbut) {
but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_DOWN, xco+width-50+18, yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint down in constraint stack");
uiButSetFunc(but, constraint_moveDown, ob, con);
}
if (show_downbut)
uiDefIconButO(block, BUT, "CONSTRAINT_OT_move_down", WM_OP_INVOKE_DEFAULT, VICON_MOVE_DOWN, xco+width-50+18, yco, 16, 18, "Move constraint down in constraint stack");
uiBlockEndAlign(block);
}
/* Close 'button' - emboss calls here disable drawing of 'button' behind X */
uiBlockSetEmboss(block, UI_EMBOSSN);
but = uiDefIconBut(block, BUT, B_CONSTRAINT_CHANGETARGET, ICON_X, xco+262, yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete constraint");
uiButSetFunc(but, del_constraint_func, ob, con);
uiDefIconButO(block, BUT, "CONSTRAINT_OT_delete", WM_OP_INVOKE_DEFAULT, ICON_X, xco+262, yco, 19, 19, "Delete constraint");
uiBlockSetEmboss(block, UI_EMBOSS);
}
@ -944,19 +919,6 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
}
break;
#endif /* DISABLE_PYTHON */
/*case CONSTRAINT_TYPE_CHILDOF:
{
// Inverse options
uiBlockBeginAlign(block);
but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Set Offset", xco, yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Calculate current Parent-Inverse Matrix (i.e. restore offset from parent)");
// XXX uiButSetFunc(but, childof_const_setinv, con, NULL);
but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Clear Offset", xco+((width/2)+10), yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Clear Parent-Inverse Matrix (i.e. clear offset from parent)");
// XXX uiButSetFunc(but, childof_const_clearinv, con, NULL);
uiBlockEndAlign(block);
}
break;
*/
/*case CONSTRAINT_TYPE_RIGIDBODYJOINT:
{

@ -81,7 +81,6 @@ static int pupmenu() {return 0;}
/* -------------- Get Active Constraint Data ---------------------- */
/* if object in posemode, active bone constraints, else object constraints */
ListBase *get_active_constraints (Object *ob)
{
@ -841,7 +840,6 @@ void ED_object_constraint_rename(Object *ob, bConstraint *con, char *oldname)
bConstraint *tcon;
ListBase *conlist= NULL;
int from_object= 0;
char *channame="";
/* get context by searching for con (primitive...) */
for (tcon= ob->constraints.first; tcon; tcon= tcon->next) {
@ -851,7 +849,6 @@ void ED_object_constraint_rename(Object *ob, bConstraint *con, char *oldname)
if (tcon) {
conlist= &ob->constraints;
channame= "Object";
from_object= 1;
}
else if (ob->pose) {
@ -868,7 +865,6 @@ void ED_object_constraint_rename(Object *ob, bConstraint *con, char *oldname)
if (tcon) {
conlist= &pchan->constraints;
channame= pchan->name;
}
}
@ -878,7 +874,7 @@ void ED_object_constraint_rename(Object *ob, bConstraint *con, char *oldname)
}
/* first make sure it's a unique name within context */
unique_constraint_name (con, conlist);
unique_constraint_name(con, conlist);
}
@ -901,77 +897,111 @@ void ED_object_constraint_set_active(Object *ob, bConstraint *con)
if(con==origcon) con->flag |= CONSTRAINT_ACTIVE;
else con->flag &= ~CONSTRAINT_ACTIVE;
}
/* make sure ipowin and buttons shows it */
if(ob->ipowin==ID_CO) {
// XXX allqueue(REDRAWIPO, ID_CO);
// XXX allspace(REMAKEIPO, 0);
// XXX allqueue(REDRAWNLA, 0);
}
// XXX allqueue(REDRAWBUTSOBJECT, 0);
}
int ED_object_constraint_delete(ReportList *reports, Object *ob, bConstraint *con)
static int constraint_delete_exec (bContext *C, wmOperator *op)
{
bConstraintChannel *chan;
PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
Object *ob= ptr.id.data;
bConstraint *con= ptr.data;
ListBase *lb;
/* remove ipo channel */
lb= NULL; // XXX get_active_constraint_channels(ob, 0);
if(lb) {
chan = NULL; // XXX get_constraint_channel(lb, con->name);
if(chan) {
if(chan->ipo) chan->ipo->id.us--;
BLI_freelinkN(lb, chan);
}
}
/* remove constraint itself */
lb= get_active_constraints(ob);
free_constraint_data(con);
BLI_freelinkN(lb, con);
ED_object_constraint_set_active(ob, NULL);
WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
return 1;
return OPERATOR_FINISHED;
}
int ED_object_constraint_move_down(ReportList *reports, Object *ob, bConstraint *constr)
void CONSTRAINT_OT_delete (wmOperatorType *ot)
{
bConstraint *con;
ListBase *conlist;
/* identifiers */
ot->name= "Delete Constraint";
ot->idname= "CONSTRAINT_OT_delete";
ot->description= "Remove constraitn from constraint stack.";
if(constr->next) {
conlist = get_active_constraints(ob);
for(con= conlist->first; con; con= con->next) {
if(con==constr) {
BLI_remlink(conlist, con);
BLI_insertlink(conlist, con->next, con);
return 1;
}
}
}
return 0;
/* callbacks */
ot->exec= constraint_delete_exec;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
int ED_object_constraint_move_up(ReportList *reports, Object *ob, bConstraint *constr)
static int constraint_move_down_exec (bContext *C, wmOperator *op)
{
bConstraint *con;
ListBase *conlist;
PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
Object *ob= ptr.id.data;
bConstraint *con= ptr.data;
if(constr->prev) {
conlist = get_active_constraints(ob);
for(con= conlist->first; con; con= con->next) {
if(con==constr) {
BLI_remlink(conlist, con);
BLI_insertlink(conlist, con->prev->prev, con);
return 1;
}
}
if (con->next) {
ListBase *conlist= get_active_constraints(ob);
bConstraint *nextCon= con->next;
/* insert the nominated constraint after the one that used to be after it */
BLI_remlink(conlist, con);
BLI_insertlinkafter(conlist, nextCon, con);
WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
}
return 0;
void CONSTRAINT_OT_move_down (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Move Constraint Down";
ot->idname= "CONSTRAINT_OT_move_down";
ot->description= "Move constraint down constraint stack.";
/* callbacks */
ot->exec= constraint_move_down_exec;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
static int constraint_move_up_exec (bContext *C, wmOperator *op)
{
PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
Object *ob= ptr.id.data;
bConstraint *con= ptr.data;
if (con->prev) {
ListBase *conlist= get_active_constraints(ob);
bConstraint *prevCon= con->prev;
/* insert the nominated constraint before the one that used to be before it */
BLI_remlink(conlist, con);
BLI_insertlinkbefore(conlist, prevCon, con);
WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
}
void CONSTRAINT_OT_move_up (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Move Constraint Up";
ot->idname= "CONSTRAINT_OT_move_up";
ot->description= "Move constraint up constraint stack.";
/* callbacks */
ot->exec= constraint_move_up_exec;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/***************************** OPERATORS ****************************/
@ -1015,10 +1045,10 @@ static int constraint_add_exec(bContext *C, wmOperator *op)
case CONSTRAINT_TYPE_RIGIDBODYJOINT:
{
bRigidBodyJointConstraint *data;
/* set selected first object as target - moved from new_constraint_data */
data = (bRigidBodyJointConstraint*)con->data;
CTX_DATA_BEGIN(C, Object*, selob, selected_objects) {
if(selob != ob) {
data->tar= selob;

@ -101,6 +101,10 @@ void OBJECT_OT_modifier_mdef_bind(struct wmOperatorType *ot);
/* editconstraint.c */
void OBJECT_OT_constraint_add(struct wmOperatorType *ot);
void CONSTRAINT_OT_delete(struct wmOperatorType *ot);
void CONSTRAINT_OT_move_up(struct wmOperatorType *ot);
void CONSTRAINT_OT_move_down(struct wmOperatorType *ot);
void CONSTRAINT_OT_childof_set_inverse(struct wmOperatorType *ot);
void CONSTRAINT_OT_childof_clear_inverse(struct wmOperatorType *ot);

@ -111,6 +111,9 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_modifier_mdef_bind);
WM_operatortype_append(OBJECT_OT_constraint_add);
WM_operatortype_append(CONSTRAINT_OT_delete);
WM_operatortype_append(CONSTRAINT_OT_move_up);
WM_operatortype_append(CONSTRAINT_OT_move_down);
WM_operatortype_append(CONSTRAINT_OT_childof_set_inverse);
WM_operatortype_append(CONSTRAINT_OT_childof_clear_inverse);