change VIEW3D_OT_camera_to_view_selected poll function so it can be called from a script (without a view3d).

This commit is contained in:
Campbell Barton 2013-08-13 04:35:14 +00:00
parent d23b383af0
commit 730b9c283e
3 changed files with 20 additions and 25 deletions

@ -462,7 +462,7 @@ typedef struct CameraViewFrameData {
unsigned int tot;
} CameraViewFrameData;
static void BKE_camera_to_frame_view_cb(const float co[3], void *user_data)
static void camera_to_frame_view_cb(const float co[3], void *user_data)
{
CameraViewFrameData *data = (CameraViewFrameData *)user_data;
unsigned int i;
@ -526,7 +526,7 @@ int BKE_camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object
data_cb.tot = 0;
/* run callback on all visible points */
BKE_scene_foreach_display_point(scene, v3d, BA_SELECT,
BKE_camera_to_frame_view_cb, &data_cb);
camera_to_frame_view_cb, &data_cb);
if (data_cb.tot <= 1) {
return FALSE;

@ -2543,7 +2543,7 @@ void BKE_scene_foreach_display_point(
Object *ob;
for (base = FIRSTBASE; base; base = base->next) {
if (BASE_VISIBLE(v3d, base) && (base->flag & flag) == flag) {
if (BASE_VISIBLE_BGMODE(v3d, scene, base) && (base->flag & flag) == flag) {
ob = base->object;
if ((ob->transflag & OB_DUPLI) == 0) {

@ -444,14 +444,27 @@ void VIEW3D_OT_camera_to_view(wmOperatorType *ot)
/* unlike VIEW3D_OT_view_selected this is for framing a render and not
* meant to take into account vertex/bone selection for eg. */
static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
Object *camera_ob = v3d->camera;
View3D *v3d = CTX_wm_view3d(C); /* can be NULL */
Object *camera_ob = v3d ? v3d->camera : scene->camera;
float r_co[3]; /* the new location to apply */
if (camera_ob == NULL) {
BKE_report(op->reports, RPT_ERROR, "No active camera");
return OPERATOR_CANCELLED;
}
else if (camera_ob->type != OB_CAMERA) {
BKE_report(op->reports, RPT_ERROR, "Object not a camera");
return OPERATOR_CANCELLED;
}
else if (((Camera *)camera_ob->data)->type == R_ORTHO) {
BKE_report(op->reports, RPT_ERROR, "Orthographic cameras not supported");
return OPERATOR_CANCELLED;
}
/* this function does all the important stuff */
if (BKE_camera_view_frame_fit_to_scene(scene, v3d, camera_ob, r_co)) {
@ -476,24 +489,6 @@ static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *UNUSED(o
}
}
static int view3d_camera_to_view_selected_poll(bContext *C)
{
View3D *v3d = CTX_wm_view3d(C);
if (v3d && v3d->camera && v3d->camera->id.lib == NULL) {
RegionView3D *rv3d = CTX_wm_region_view3d(C);
if (rv3d) {
if (rv3d->is_persp == false) {
CTX_wm_operator_poll_msg_set(C, "Only valid for a perspective camera view");
}
else if (!rv3d->viewlock) {
return 1;
}
}
}
return 0;
}
void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot)
{
/* identifiers */
@ -503,7 +498,7 @@ void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot)
/* api callbacks */
ot->exec = view3d_camera_to_view_selected_exec;
ot->poll = view3d_camera_to_view_selected_poll;
ot->poll = ED_operator_scene_editable;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;