feature request from VenomGfx- lock to active as an operator since its tedious settin...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 5 May 2012 16:38:23 +0000 (16:38 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 5 May 2012 16:38:23 +0000 (16:38 +0000)
uses keys
- Shift+PadPeriod --- to set
- Alt+PadPeriod --- to clear (also clears cursor and camera locking)

release/scripts/startup/bl_ui/space_view3d.py
source/blender/editors/include/ED_view3d.h
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_intern.h
source/blender/editors/space_view3d/view3d_ops.c

index ca6da539884bd34124e5ddde9cefb2de5f00ea6c..6c2e98337a7ec7b8dbd7882dc8da9ec6ef840daf 100644 (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"
index 4b614085f8ea4aa2ce0f4d66ca9e6925bb7e8bb1..e3759ef5fde3bfe941c62ecf15c5ba8cec952604 100644 (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);
index b5933310a06e203855940d14638cb44da0f6bfa0..11afc5825a7d028428092d00cd001fa32024b0e7 100644 (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;
+}
index 66b8ceb7a85f2868fc1ad2bc9862d6fdf3336ae1..23de42ecc364502dd95d0ccc64baa5c57de76b34 100644 (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);
index 99da487f923222ffef4a57baa169bb97d4b66301..f760254e8d25a8e1a6fc4b40b23c1f132f7f579e 100644 (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);