feature request from VenomGfx- lock to active as an operator since its tedious setting the object and bone manually (especially if you have it right in front of you)

uses keys
- Shift+PadPeriod --- to set
- Alt+PadPeriod --- to clear (also clears cursor and camera locking)
This commit is contained in:
Campbell Barton 2012-05-05 16:38:23 +00:00
parent 1dccd4c98a
commit 9b37bf21f4
5 changed files with 109 additions and 1 deletions

View File

@ -377,6 +377,11 @@ class VIEW3D_MT_view_align(Menu):
layout.operator("view3d.view_selected")
layout.operator("view3d.view_center_cursor")
layout.separator()
layout.operator("view3d.view_lock_to_active")
layout.operator("view3d.view_lock_clear")
class VIEW3D_MT_view_align_selected(Menu):
bl_label = "Align View to Selected"

View File

@ -304,6 +304,8 @@ void ED_view3d_camera_lock_init(struct View3D *v3d, struct RegionView3D *rv3d);
/* copy the view to the camera, return TRUE if */
int ED_view3d_camera_lock_sync(struct View3D *v3d, struct RegionView3D *rv3d);
void ED_view3D_lock_clear(struct View3D *v3d);
struct BGpic *ED_view3D_background_image_new(struct View3D *v3d);
void ED_view3D_background_image_remove(struct View3D *v3d, struct BGpic *bgpic);
void ED_view3D_background_image_clear(struct View3D *v3d);

View File

@ -56,6 +56,8 @@
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_action.h"
#include "BKE_armature.h"
#include "BKE_depsgraph.h" /* for ED_view3d_camera_lock_sync */
@ -68,6 +70,7 @@
#include "RNA_access.h"
#include "RNA_define.h"
#include "ED_armature.h"
#include "ED_particle.h"
#include "ED_screen.h"
#include "ED_transform.h"
@ -2291,6 +2294,89 @@ void VIEW3D_OT_view_selected(wmOperatorType *ot)
ot->flag = 0;
}
static int view_lock_clear_exec(bContext *C, wmOperator *UNUSED(op))
{
View3D *v3d = CTX_wm_view3d(C);
if (v3d) {
ED_view3D_lock_clear(v3d);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
return OPERATOR_FINISHED;
}
else {
return OPERATOR_CANCELLED;
}
}
void VIEW3D_OT_view_lock_clear(wmOperatorType *ot)
{
/* identifiers */
ot->name = "View Lock Clear";
ot->description = "Clears all view locking";
ot->idname = "VIEW3D_OT_view_lock_clear";
/* api callbacks */
ot->exec = view_lock_clear_exec;
ot->poll = ED_operator_region_view3d_active;
/* flags */
ot->flag = 0;
}
static int view_lock_to_active_exec(bContext *C, wmOperator *UNUSED(op))
{
View3D *v3d = CTX_wm_view3d(C);
Object *obact = CTX_data_active_object(C);
if (v3d) {
ED_view3D_lock_clear(v3d);
v3d->ob_centre = obact; /* can be NULL */
if (obact && obact->type == OB_ARMATURE) {
if (obact->mode & OB_MODE_POSE) {
bPoseChannel *pcham_act = BKE_pose_channel_active(obact);
if (pcham_act) {
BLI_strncpy(v3d->ob_centre_bone, pcham_act->name, sizeof(v3d->ob_centre_bone));
}
}
else {
EditBone *ebone_act = ((bArmature *)obact->data)->act_edbone;
if (ebone_act) {
BLI_strncpy(v3d->ob_centre_bone, ebone_act->name, sizeof(v3d->ob_centre_bone));
}
}
}
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
return OPERATOR_FINISHED;
}
else {
return OPERATOR_CANCELLED;
}
}
void VIEW3D_OT_view_lock_to_active(wmOperatorType *ot)
{
/* identifiers */
ot->name = "View Lock to Active";
ot->description = "Lock the view to the active object/bone";
ot->idname = "VIEW3D_OT_view_lock_to_active";
/* api callbacks */
ot->exec = view_lock_to_active_exec;
ot->poll = ED_operator_region_view3d_active;
/* flags */
ot->flag = 0;
}
static int viewcenter_cursor_exec(bContext *C, wmOperator *UNUSED(op))
{
View3D *v3d = CTX_wm_view3d(C);
@ -3709,3 +3795,11 @@ void ED_view3D_background_image_clear(View3D *v3d)
bgpic = next_bgpic;
}
}
void ED_view3D_lock_clear(View3D *v3d)
{
v3d->ob_centre = NULL;
v3d->ob_centre_bone[0] = '\0';
v3d->ob_centre_cursor = FALSE;
v3d->flag2 &= ~V3D_LOCK_CAMERA;
}

View File

@ -78,6 +78,8 @@ void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot);
void VIEW3D_OT_view_all(struct wmOperatorType *ot);
void VIEW3D_OT_viewnumpad(struct wmOperatorType *ot);
void VIEW3D_OT_view_selected(struct wmOperatorType *ot);
void VIEW3D_OT_view_lock_clear(struct wmOperatorType *ot);
void VIEW3D_OT_view_lock_to_active(struct wmOperatorType *ot);
void VIEW3D_OT_view_center_cursor(struct wmOperatorType *ot);
void VIEW3D_OT_view_center_camera(struct wmOperatorType *ot);
void VIEW3D_OT_view_pan(struct wmOperatorType *ot);

View File

@ -72,6 +72,8 @@ void view3d_operatortypes(void)
WM_operatortype_append(VIEW3D_OT_background_image_add);
WM_operatortype_append(VIEW3D_OT_background_image_remove);
WM_operatortype_append(VIEW3D_OT_view_selected);
WM_operatortype_append(VIEW3D_OT_view_lock_clear);
WM_operatortype_append(VIEW3D_OT_view_lock_to_active);
WM_operatortype_append(VIEW3D_OT_view_center_cursor);
WM_operatortype_append(VIEW3D_OT_view_center_camera);
WM_operatortype_append(VIEW3D_OT_select);
@ -135,7 +137,10 @@ void view3d_keymap(wmKeyConfig *keyconf)
WM_keymap_verify_item(keymap, "VIEW3D_OT_dolly", MIDDLEMOUSE, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_view_center_cursor", PADPERIOD, KM_PRESS, KM_CTRL, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_view_lock_to_active", PADPERIOD, KM_PRESS, KM_SHIFT, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_view_lock_clear", PADPERIOD, KM_PRESS, KM_ALT, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_fly", FKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_smoothview", TIMER1, KM_ANY, KM_ANY, 0);