View3d: ensure locked views are on an axis - behavior wasn't well defined.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 12 Feb 2014 00:26:02 +0000 (11:26 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 12 Feb 2014 00:26:02 +0000 (11:26 +1100)
source/blender/editors/include/ED_view3d.h
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_view.c

index f84d42a89d95cc956c742a4ed01b6dacc60444c2..80328720aa818dac4f4b8d8307523a36a6345799 100644 (file)
@@ -308,6 +308,7 @@ void ED_view3d_offscreen_sky_color_get(struct Scene *scene, float sky_color[3]);
 struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
 void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, bool do_clip);
 void ED_view3d_update_viewmat(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, float viewmat[4][4], float winmat[4][4]);
+char ED_view3d_lock_view_from_index(int index);
 bool ED_view3d_lock(struct RegionView3D *rv3d);
 
 uint64_t ED_view3d_datamask(struct Scene *scene, struct View3D *v3d);
index 4c573463d147d63b39ba014561ca30ba5bb73508..799db37a51eab6785738f3134d5f9a549b291d55 100644 (file)
@@ -2896,6 +2896,7 @@ static int region_quadview_exec(bContext *C, wmOperator *op)
                /* lock views and set them */
                if (sa->spacetype == SPACE_VIEW3D) {
                        View3D *v3d = sa->spacedata.first;
+                       int index_qsplit = 0;
 
                        /* run ED_view3d_lock() so the correct 'rv3d->viewquat' is set,
                         * otherwise when restoring rv3d->localvd the 'viewquat' won't
@@ -2907,9 +2908,9 @@ static int region_quadview_exec(bContext *C, wmOperator *op)
                        const char viewlock = (rv3d->viewlock_quad & RV3D_VIEWLOCK_INIT) ?
                                              (rv3d->viewlock_quad & ~RV3D_VIEWLOCK_INIT) : RV3D_LOCKED;
 
-                       region_quadview_init_rv3d(sa, ar,              viewlock, RV3D_VIEW_FRONT, RV3D_ORTHO);
-                       region_quadview_init_rv3d(sa, (ar = ar->next), viewlock, RV3D_VIEW_TOP,   RV3D_ORTHO);
-                       region_quadview_init_rv3d(sa, (ar = ar->next), viewlock, RV3D_VIEW_RIGHT, RV3D_ORTHO);
+                       region_quadview_init_rv3d(sa, ar,              viewlock, ED_view3d_lock_view_from_index(index_qsplit++), RV3D_ORTHO);
+                       region_quadview_init_rv3d(sa, (ar = ar->next), viewlock, ED_view3d_lock_view_from_index(index_qsplit++), RV3D_ORTHO);
+                       region_quadview_init_rv3d(sa, (ar = ar->next), viewlock, ED_view3d_lock_view_from_index(index_qsplit++), RV3D_ORTHO);
                        if (v3d->camera) region_quadview_init_rv3d(sa, (ar = ar->next), 0, RV3D_VIEW_CAMERA,     RV3D_CAMOB);
                        else             region_quadview_init_rv3d(sa, (ar = ar->next), 0, RV3D_VIEW_PERSPORTHO, RV3D_PERSP);
 
index c055a2efb2139a5d9dae088026e26eeac8b523c4..fccc4d8e58536af12cbbde6c35cec667a2ffbe87 100644 (file)
 /* for ndof prints */
 // #define DEBUG_NDOF_MOTION
 
-/**
- * Mostly this function just checks ``rv3d->viewlock & RV3D_LOCKED`` however there is a
- * special case where the flag is set but the user already switched out of an axis locked view.
- *
- * The 'view' in the function name refers to #RegionView3D.view which we may be locked.
- *
- * Functions which change the 'view' should call this check first, or...
- * only apply to the user view (in the instance of a quad-view setup).
- */
-bool ED_view3d_view_lock_check(View3D *UNUSED(v3d), RegionView3D *rv3d)
-{
-       if (rv3d->viewlock & RV3D_LOCKED) {
-               if ((RV3D_VIEW_IS_AXIS(rv3d->view) || rv3d->view == RV3D_VIEW_CAMERA)) {
-                       return true;
-               }
-       }
-
-       return false;
-}
-
 bool ED_view3d_offset_lock_check(struct View3D *v3d, struct RegionView3D *rv3d)
 {
        return (rv3d->persp != RV3D_CAMOB) && (v3d->ob_centre_cursor || v3d->ob_centre);
@@ -410,6 +390,24 @@ void ED_view3d_quadview_update(ScrArea *sa, ARegion *ar, bool do_clip)
                view3d_boxview_copy(sa, ar_sync ? ar_sync : sa->regionbase.last);
        }
 
+       /* ensure locked regions have an axis, locked user views don't make much sense */
+       if (viewlock & RV3D_LOCKED) {
+               int index_qsplit = 0;
+               for (ar = sa->regionbase.first; ar; ar = ar->next) {
+                       if (ar->alignment == RGN_ALIGN_QSPLIT) {
+                               rv3d = ar->regiondata;
+                               if (rv3d->viewlock) {
+                                       if (!RV3D_VIEW_IS_AXIS(rv3d->view)) {
+                                               rv3d->view = ED_view3d_lock_view_from_index(index_qsplit);
+                                               rv3d->persp = RV3D_ORTHO;
+                                               ED_view3d_lock(rv3d);
+                                       }
+                               }
+                               index_qsplit++;
+                       }
+               }
+       }
+
        ED_area_tag_redraw(sa);
 }
 
@@ -1006,7 +1004,7 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
        vod = op->customdata;
 
        /* poll should check but in some cases fails, see poll func for details */
-       if (ED_view3d_view_lock_check(vod->v3d, vod->rv3d)) {
+       if (vod->rv3d->viewlock & RV3D_LOCKED) {
                viewops_data_free(C, op);
                return OPERATOR_PASS_THROUGH;
        }
@@ -2282,7 +2280,7 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
        vod = op->customdata;
 
        /* poll should check but in some cases fails, see poll func for details */
-       if (ED_view3d_view_lock_check(vod->v3d, vod->rv3d)) {
+       if (vod->rv3d->viewlock & RV3D_LOCKED) {
                viewops_data_free(C, op);
                return OPERATOR_PASS_THROUGH;
        }
index d06f7869f9c69ba0bd5d3faeecffae2ab8c03809..9944029a65b512eb6e04cddc7e0a9357a4d51233 100644 (file)
@@ -803,6 +803,17 @@ static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob)
        mat3_to_quat(rv3d->viewquat, tmat);
 }
 
+char ED_view3d_lock_view_from_index(int index)
+{
+       switch (index) {
+               case 0:  return RV3D_VIEW_FRONT;
+               case 1:  return RV3D_VIEW_TOP;
+               case 2:  return RV3D_VIEW_RIGHT;
+               default: return RV3D_VIEW_USER;
+       }
+
+}
+
 bool ED_view3d_lock(RegionView3D *rv3d)
 {
        switch (rv3d->view) {