use objects rather then bases where possible, use context rather then OBACT macro

This commit is contained in:
Campbell Barton 2009-10-29 09:14:20 +00:00
parent 2aa2f53265
commit 40731af9d0
7 changed files with 88 additions and 108 deletions

@ -1187,9 +1187,8 @@ static int delete_key_v3d_exec (bContext *C, wmOperator *op)
float cfra= (float)CFRA; // XXX for now, don't bother about all the yucky offset crap
// XXX more comprehensive tests will be needed
CTX_DATA_BEGIN(C, Base*, base, selected_bases)
CTX_DATA_BEGIN(C, Object*, ob, selected_objects)
{
Object *ob= base->object;
ID *id= (ID *)ob;
FCurve *fcu, *fcn;
short success= 0;

@ -1238,10 +1238,8 @@ static short modifykey_get_context_v3d_data (bContext *C, ListBase *dsources, Ke
}
else {
/* Object Mode: Selected objects */
CTX_DATA_BEGIN(C, Base*, base, selected_bases)
{
Object *ob= base->object;
CTX_DATA_BEGIN(C, Object*, ob, selected_objects)
{
/* add a new keying-source */
cks= MEM_callocN(sizeof(bCommonKeySrc), "bCommonKeySrc");
BLI_addtail(dsources, cks);

@ -747,8 +747,7 @@ static void copy_object_set_idnew(bContext *C, int dupflag)
int a;
/* XXX check object pointers */
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob= base->object;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
relink_constraints(&ob->constraints);
if (ob->pose){
bPoseChannel *chan;

@ -1604,14 +1604,12 @@ void copy_attr_menu(Scene *scene, View3D *v3d)
static int shade_smooth_exec(bContext *C, wmOperator *op)
{
Object *ob;
Curve *cu;
Nurb *nu;
int clear= (strcmp(op->idname, "OBJECT_OT_shade_flat") == 0);
int done= 0;
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob= base->object;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob->type==OB_MESH) {
mesh_set_smooth_flag(ob, !clear);
@ -1867,7 +1865,6 @@ void auto_timeoffs(Scene *scene, View3D *v3d)
void ofs_timeoffs(Scene *scene, View3D *v3d)
{
Base *base;
float offset=0.0f;
if(BASACT==0 || v3d==NULL) return;
@ -1875,13 +1872,12 @@ void ofs_timeoffs(Scene *scene, View3D *v3d)
// XXX if(fbutton(&offset, -10000.0f, 10000.0f, 10, 10, "Offset")==0) return;
/* make array of all bases, xco yco (screen) */
for(base= FIRSTBASE; base; base= base->next) {
if(TESTBASELIB(v3d, base)) {
base->object->sf += offset;
if (base->object->sf < -MAXFRAMEF) base->object->sf = -MAXFRAMEF;
else if (base->object->sf > MAXFRAMEF) base->object->sf = MAXFRAMEF;
}
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
ob->sf += offset;
if (ob->sf < -MAXFRAMEF) ob->sf = -MAXFRAMEF;
else if (ob->sf > MAXFRAMEF) ob->sf = MAXFRAMEF;
}
CTX_DATA_END;
}

@ -915,28 +915,30 @@ static EnumPropertyItem prop_make_track_types[] = {
static int track_set_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
Object *obact= CTX_data_active_object(C);
int type= RNA_enum_get(op->ptr, "type");
if(type == 1) {
bConstraint *con;
bTrackToConstraint *data;
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
if(base!=BASACT) {
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob!=obact) {
con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
strcpy (con->name, "AutoTrack");
data = con->data;
data->tar = BASACT->object;
base->object->recalc |= OB_RECALC;
data->tar = obact;
ob->recalc |= OB_RECALC;
/* Lamp and Camera track differently by default */
if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
if (ob->type == OB_LAMP || ob->type == OB_CAMERA) {
data->reserved1 = TRACK_nZ;
data->reserved2 = UP_Y;
}
add_constraint_to_object(con, base->object);
add_constraint_to_object(con, ob);
}
}
CTX_DATA_END;
@ -945,31 +947,31 @@ static int track_set_exec(bContext *C, wmOperator *op)
bConstraint *con;
bLockTrackConstraint *data;
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
if(base!=BASACT) {
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob!=obact) {
con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
strcpy (con->name, "AutoTrack");
data = con->data;
data->tar = BASACT->object;
base->object->recalc |= OB_RECALC;
data->tar = obact;
ob->recalc |= OB_RECALC;
/* Lamp and Camera track differently by default */
if (base->object->type == OB_LAMP || base->object->type == OB_CAMERA) {
if (ob->type == OB_LAMP || ob->type == OB_CAMERA) {
data->trackflag = TRACK_nZ;
data->lockflag = LOCK_Y;
}
add_constraint_to_object(con, base->object);
add_constraint_to_object(con, ob);
}
}
CTX_DATA_END;
}
else {
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
if(base!=BASACT) {
base->object->track= BASACT->object;
base->object->recalc |= OB_RECALC;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob!=obact) {
ob->track= obact;
ob->recalc |= OB_RECALC;
}
}
CTX_DATA_END;

@ -347,7 +347,6 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo
{
Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
Object *ob;
bArmature *arm;
Mesh *me;
Curve *cu;
@ -359,8 +358,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo
int a, change = 0;
/* first check if we can execute */
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob= base->object;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob->type==OB_MESH) {
me= ob->data;
@ -394,8 +392,7 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo
CTX_DATA_END;
/* now execute */
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob= base->object;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
/* calculate rotation/scale matrix */
if(apply_scale && apply_rot)
@ -669,7 +666,6 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
ScrArea *sa= CTX_wm_area(C);
View3D *v3d= sa->spacedata.first;
Object *obedit= CTX_data_edit_object(C);
Object *ob;
Mesh *me, *tme;
Curve *cu;
/* BezTriple *bezt;
@ -733,8 +729,8 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
}
/* reset flags */
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
base->object->flag &= ~OB_DONE;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
ob->flag &= ~OB_DONE;
}
CTX_DATA_END;
@ -742,18 +738,18 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
me->flag &= ~ME_ISDONE;
}
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
if((base->object->flag & OB_DONE)==0) {
base->object->flag |= OB_DONE;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if((ob->flag & OB_DONE)==0) {
ob->flag |= OB_DONE;
if(obedit==NULL && (me=get_mesh(base->object)) ) {
if(obedit==NULL && (me=get_mesh(ob)) ) {
if (me->id.lib) {
tot_lib_error++;
} else {
if(centermode==2) {
VECCOPY(cent, give_cursor(scene, v3d));
Mat4Invert(base->object->imat, base->object->obmat);
Mat4MulVecfl(base->object->imat, cent);
Mat4Invert(ob->imat, ob->obmat);
Mat4MulVecfl(ob->imat, cent);
} else {
INIT_MINMAX(min, max);
mvert= me->mvert;
@ -785,37 +781,36 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
me->flag |= ME_ISDONE;
if(centermode) {
Mat3CpyMat4(omat, base->object->obmat);
Mat3CpyMat4(omat, ob->obmat);
VECCOPY(centn, cent);
Mat3MulVecfl(omat, centn);
base->object->loc[0]+= centn[0];
base->object->loc[1]+= centn[1];
base->object->loc[2]+= centn[2];
ob->loc[0]+= centn[0];
ob->loc[1]+= centn[1];
ob->loc[2]+= centn[2];
where_is_object(scene, base->object);
ignore_parent_tx(bmain, scene, base->object);
where_is_object(scene, ob);
ignore_parent_tx(bmain, scene, ob);
/* other users? */
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob = base->object;
if((ob->flag & OB_DONE)==0) {
tme= get_mesh(ob);
CTX_DATA_BEGIN(C, Object*, ob_other, selected_editable_objects) {
if((ob_other->flag & OB_DONE)==0) {
tme= get_mesh(ob_other);
if(tme==me) {
ob->flag |= OB_DONE;
ob->recalc= OB_RECALC_OB|OB_RECALC_DATA;
ob_other->flag |= OB_DONE;
ob_other->recalc= OB_RECALC_OB|OB_RECALC_DATA;
Mat3CpyMat4(omat, ob->obmat);
Mat3CpyMat4(omat, ob_other->obmat);
VECCOPY(centn, cent);
Mat3MulVecfl(omat, centn);
ob->loc[0]+= centn[0];
ob->loc[1]+= centn[1];
ob->loc[2]+= centn[2];
ob_other->loc[0]+= centn[0];
ob_other->loc[1]+= centn[1];
ob_other->loc[2]+= centn[2];
where_is_object(scene, ob);
ignore_parent_tx(bmain, scene, ob);
where_is_object(scene, ob_other);
ignore_parent_tx(bmain, scene, ob_other);
if(tme && (tme->flag & ME_ISDONE)==0) {
mvert= tme->mvert;
@ -838,25 +833,23 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
}
}
}
ob= ob->id.next;
}
CTX_DATA_END;
}
tot_change++;
}
}
else if (ELEM(base->object->type, OB_CURVE, OB_SURF)) {
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
/* weak code here... (ton) */
if(obedit==base->object) {
if(obedit==ob) {
ListBase *editnurb= curve_get_editcurve(obedit);
nu1= editnurb->first;
cu= obedit->data;
}
else {
cu= base->object->data;
cu= ob->data;
nu1= cu->nurb.first;
}
@ -865,8 +858,8 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
} else {
if(centermode==2) {
VECCOPY(cent, give_cursor(scene, v3d));
Mat4Invert(base->object->imat, base->object->obmat);
Mat4MulVecfl(base->object->imat, cent);
Mat4Invert(ob->imat, ob->obmat);
Mat4MulVecfl(ob->imat, cent);
/* don't allow Z change if curve is 2D */
if( !( cu->flag & CU_3D ) )
@ -904,16 +897,16 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
nu= nu->next;
}
if(centermode && obedit==0) {
Mat3CpyMat4(omat, base->object->obmat);
if(centermode && obedit==NULL) {
Mat3CpyMat4(omat, ob->obmat);
Mat3MulVecfl(omat, cent);
base->object->loc[0]+= cent[0];
base->object->loc[1]+= cent[1];
base->object->loc[2]+= cent[2];
ob->loc[0]+= cent[0];
ob->loc[1]+= cent[1];
ob->loc[2]+= cent[2];
where_is_object(scene, base->object);
ignore_parent_tx(bmain, scene, base->object);
where_is_object(scene, ob);
ignore_parent_tx(bmain, scene, ob);
}
tot_change++;
@ -925,12 +918,12 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
}
}
}
else if(base->object->type==OB_FONT) {
else if(ob->type==OB_FONT) {
/* get from bb */
cu= base->object->data;
cu= ob->data;
if(cu->bb==0) {
if(cu->bb==NULL) {
/* do nothing*/
} else if (cu->id.lib) {
tot_lib_error++;
@ -945,8 +938,8 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
tot_change++;
}
}
else if(base->object->type==OB_ARMATURE) {
bArmature *arm = base->object->data;
else if(ob->type==OB_ARMATURE) {
bArmature *arm = ob->data;
if (arm->id.lib) {
tot_lib_error++;
@ -958,17 +951,17 @@ static int object_center_set_exec(bContext *C, wmOperator *op)
/* Function to recenter armatures in editarmature.c
* Bone + object locations are handled there.
*/
docenter_armature(scene, v3d, base->object, centermode);
docenter_armature(scene, v3d, ob, centermode);
tot_change++;
where_is_object(scene, base->object);
ignore_parent_tx(bmain, scene, base->object);
where_is_object(scene, ob);
ignore_parent_tx(bmain, scene, ob);
if(obedit)
break;
}
}
base->object->recalc= OB_RECALC_OB|OB_RECALC_DATA;
ob->recalc= OB_RECALC_OB|OB_RECALC_DATA;
}
}
CTX_DATA_END;

@ -440,7 +440,6 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op)
Scene *scene= CTX_data_scene(C);
View3D *v3d= CTX_wm_view3d(C);
TransVert *tv;
Object *ob;
float gridf, imat[3][3], bmat[3][3], vec[3];
int a;
@ -479,9 +478,7 @@ static int snap_sel_to_grid(bContext *C, wmOperator *op)
}
else {
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob= base->object;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob->mode & OB_MODE_POSE) {
bPoseChannel *pchan;
bArmature *arm= ob->data;
@ -575,7 +572,6 @@ static int snap_sel_to_curs(bContext *C, wmOperator *op)
Scene *scene= CTX_data_scene(C);
View3D *v3d= CTX_wm_view3d(C);
TransVert *tv;
Object *ob;
float *curs, imat[3][3], bmat[3][3], vec[3];
int a;
@ -608,8 +604,7 @@ static int snap_sel_to_curs(bContext *C, wmOperator *op)
}
else {
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob= base->object;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob->mode & OB_MODE_POSE) {
bPoseChannel *pchan;
bArmature *arm= ob->data;
@ -776,7 +771,7 @@ static int snap_curs_to_sel(bContext *C, wmOperator *op)
transvmain= NULL;
}
else {
Object *ob= OBACT;
Object *ob= CTX_data_active_object(C);
if(ob && (ob->mode & OB_MODE_POSE)) {
bArmature *arm= ob->data;
@ -794,8 +789,8 @@ static int snap_curs_to_sel(bContext *C, wmOperator *op)
}
}
else {
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
VECCOPY(vec, base->object->obmat[3]);
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
VECCOPY(vec, ob->obmat[3]);
VecAddf(centroid, centroid, vec);
DO_MINMAX(vec, min, max);
count++;
@ -840,6 +835,7 @@ void VIEW3D_OT_snap_cursor_to_selected(wmOperatorType *ot)
static int snap_curs_to_active(bContext *C, wmOperator *op)
{
Object *obedit= CTX_data_edit_object(C);
Object *obact= CTX_data_active_object(C);
Scene *scene= CTX_data_scene(C);
View3D *v3d= CTX_wm_view3d(C);
float *curs;
@ -860,8 +856,8 @@ static int snap_curs_to_active(bContext *C, wmOperator *op)
}
}
else {
if (BASACT) {
VECCOPY(curs, BASACT->object->obmat[3]);
if (obact) {
VECCOPY(curs, obact->obmat[3]);
}
}
@ -894,7 +890,6 @@ static int snap_selected_to_center(bContext *C, wmOperator *op)
Scene *scene= CTX_data_scene(C);
View3D *v3d= CTX_wm_view3d(C);
TransVert *tv;
Object *ob;
float snaploc[3], imat[3][3], bmat[3][3], vec[3], min[3], max[3], centroid[3];
int count, a;
@ -938,8 +933,7 @@ static int snap_selected_to_center(bContext *C, wmOperator *op)
}
else {
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob= base->object;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob->mode & OB_MODE_POSE) {
bPoseChannel *pchan;
bArmature *arm= ob->data;
@ -957,7 +951,7 @@ static int snap_selected_to_center(bContext *C, wmOperator *op)
}
else {
/* not armature bones (i.e. objects) */
VECCOPY(vec, base->object->obmat[3]);
VECCOPY(vec, ob->obmat[3]);
VecAddf(centroid, centroid, vec);
DO_MINMAX(vec, min, max);
count++;
@ -1007,8 +1001,7 @@ static int snap_selected_to_center(bContext *C, wmOperator *op)
}
else {
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob= base->object;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob->mode & OB_MODE_POSE) {
bPoseChannel *pchan;
bArmature *arm= ob->data;