merge with/from trunk at r35190
[blender.git] / source / blender / editors / space_view3d / space_view3d.c
index 8fbe764c633277143fc2d803782538e3fed13688..dd3b5f42b894c37b3eeffd0ce56c5f50cff9c222 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_rand.h"
+#include "BLI_utildefines.h"
 
+#include "BKE_object.h"
 #include "BKE_context.h"
 #include "BKE_screen.h"
 
+#include "ED_space_api.h"
 #include "ED_screen.h"
 #include "ED_object.h"
 
@@ -191,21 +194,24 @@ static SpaceLink *view3d_new(const bContext *C)
                v3d->lay= v3d->layact= scene->lay;
                v3d->camera= scene->camera;
        }
-       v3d->scenelock= 1;
+       v3d->scenelock= TRUE;
        v3d->grid= 1.0f;
        v3d->gridlines= 16;
        v3d->gridsubdiv = 10;
-       v3d->drawtype= OB_WIRE;
+       v3d->drawtype= OB_SOLID;
        
        v3d->gridflag |= V3D_SHOW_X;
        v3d->gridflag |= V3D_SHOW_Y;
        v3d->gridflag |= V3D_SHOW_FLOOR;
        v3d->gridflag &= ~V3D_SHOW_Z;
        
+       v3d->flag |= V3D_SELECT_OUTLINE;
+       
        v3d->lens= 35.0f;
        v3d->near= 0.01f;
        v3d->far= 500.0f;
 
+       v3d->twflag |= U.tw_flag & V3D_USE_MANIPULATOR;
        v3d->twtype= V3D_MANIP_TRANSLATE;
        v3d->around= V3D_CENTROID;
        
@@ -249,8 +255,8 @@ static SpaceLink *view3d_new(const bContext *C)
        ar->regiondata= MEM_callocN(sizeof(RegionView3D), "region view3d");
        rv3d= ar->regiondata;
        rv3d->viewquat[0]= 1.0f;
-       rv3d->persp= 1;
-       rv3d->view= 7;
+       rv3d->persp= RV3D_PERSP;
+       rv3d->view= RV3D_VIEW_PERSPORTHO;
        rv3d->dist= 10.0;
        
        return (SpaceLink *)v3d;
@@ -274,7 +280,7 @@ static void view3d_free(SpaceLink *sl)
 
 
 /* spacetype; init callback */
-static void view3d_init(struct wmWindowManager *wm, ScrArea *sa)
+static void view3d_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
 {
 
 }
@@ -316,6 +322,10 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar)
 
        /* object ops. */
        
+       /* important to be before Pose keymap since they can both be enabled at once */
+       keymap= WM_keymap_find(wm->defaultconf, "Face Mask", 0, 0);
+       WM_event_add_keymap_handler(&ar->handlers, keymap);
+       
        /* pose is not modal, operator poll checks for this */
        keymap= WM_keymap_find(wm->defaultconf, "Pose", 0, 0);
        WM_event_add_keymap_handler(&ar->handlers, keymap);
@@ -331,9 +341,6 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar)
 
        keymap= WM_keymap_find(wm->defaultconf, "Weight Paint", 0, 0);
        WM_event_add_keymap_handler(&ar->handlers, keymap);
-       
-       keymap= WM_keymap_find(wm->defaultconf, "Face Mask", 0, 0);
-       WM_event_add_keymap_handler(&ar->handlers, keymap);
 
        keymap= WM_keymap_find(wm->defaultconf, "Sculpt", 0, 0);
        WM_event_add_keymap_handler(&ar->handlers, keymap);
@@ -387,7 +394,7 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar)
        
 }
 
-static int view3d_ob_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
+static int view3d_ob_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
 {
        if(drag->type==WM_DRAG_ID) {
                ID *id= (ID *)drag->poin;
@@ -397,7 +404,7 @@ static int view3d_ob_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
        return 0;
 }
 
-static int view3d_mat_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
+static int view3d_mat_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
 {
        if(drag->type==WM_DRAG_ID) {
                ID *id= (ID *)drag->poin;
@@ -407,26 +414,27 @@ static int view3d_mat_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
        return 0;
 }
 
-static int view3d_ima_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
+static int view3d_ima_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
 {
-               if(drag->type==WM_DRAG_ID) {
-                       ID *id= (ID *)drag->poin;
-                       if( GS(id->name)==ID_IM )
-                               return 1;
-               }
-               else if(drag->type==WM_DRAG_PATH){
-                       if(ELEM(drag->icon, 0, ICON_FILE_IMAGE))        /* rule might not work? */
-                               return 1;
-               }
-       return 0;
+       if(drag->type==WM_DRAG_ID) {
+               ID *id= (ID *)drag->poin;
+               if( GS(id->name)==ID_IM )
+                       return 1;
        }
+       else if(drag->type==WM_DRAG_PATH){
+               if(ELEM(drag->icon, 0, ICON_FILE_IMAGE))        /* rule might not work? */
+                       return 1;
+       }
+       return 0;
+}
 
 
 static int view3d_ima_bg_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
 {
        if( ED_view3d_give_base_under_cursor(C, event->mval) ) {
-       return 0;
-}
+               return 0;
+       }
+
        return view3d_ima_drop_poll(C, drag, event);
 }
 
@@ -477,7 +485,7 @@ static void view3d_dropboxes(void)
        WM_dropbox_add(lb, "OBJECT_OT_add_named_cursor", view3d_ob_drop_poll, view3d_ob_drop_copy);
        WM_dropbox_add(lb, "OBJECT_OT_drop_named_material", view3d_mat_drop_poll, view3d_id_drop_copy);
        WM_dropbox_add(lb, "MESH_OT_drop_named_image", view3d_ima_ob_drop_poll, view3d_id_path_drop_copy);
-       WM_dropbox_add(lb, "VIEW3D_OT_add_background_image", view3d_ima_bg_drop_poll, view3d_id_path_drop_copy);
+       WM_dropbox_add(lb, "VIEW3D_OT_background_image_add", view3d_ima_bg_drop_poll, view3d_id_path_drop_copy);
 }
 
 
@@ -529,39 +537,40 @@ static void *view3d_main_area_duplicate(void *poin)
        return NULL;
 }
 
-static void view3d_recalc_used_layers(ARegion *ar, wmNotifier *wmn)
+static void view3d_recalc_used_layers(ARegion *ar, wmNotifier *wmn, Scene *scene)
 {
        wmWindow *win= wmn->wm->winactive;
        ScrArea *sa;
+       unsigned int lay_used= 0;
+       Base *base;
 
        if (!win) return;
 
-       sa= win->screen->areabase.first;
-
-       while(sa) {
-               if(sa->spacetype == SPACE_VIEW3D)
-                       if(BLI_findindex(&sa->regionbase, ar) >= 0) {
-                               View3D *v3d= sa->spacedata.first;
-                               Scene *scene= wmn->reference;
-                               Base *base;
+       base= scene->base.first;
+       while(base) {
+               lay_used |= base->lay & ((1<<20)-1); /* ignore localview */
 
-                               v3d->lay_used= 0;
-                               base= scene->base.first;
-                               while(base) {
-                                       v3d->lay_used|= base->lay;
+               if (lay_used == (1<<20)-1)
+                       break;
 
-                                       base= base->next;
-                               }
+               base= base->next;
+       }
 
+       for(sa= win->screen->areabase.first; sa; sa= sa->next) {
+               if(sa->spacetype == SPACE_VIEW3D) {
+                       if(BLI_findindex(&sa->regionbase, ar) != -1) {
+                               View3D *v3d= sa->spacedata.first;
+                               v3d->lay_used= lay_used;
                                break;
                        }
-
-               sa= sa->next;
+               }
        }
 }
 
 static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
 {
+       bScreen *sc;
+
        /* context changes */
        switch(wmn->category) {
                case NC_ANIMATION:
@@ -584,18 +593,22 @@ static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
                case NC_SCENE:
                        switch(wmn->data) {
                                case ND_LAYER_CONTENT:
-                                       view3d_recalc_used_layers(ar, wmn);
+                                       view3d_recalc_used_layers(ar, wmn, wmn->reference);
                                        ED_region_tag_redraw(ar);
                                        break;
                                case ND_FRAME:
                                case ND_TRANSFORM:
                                case ND_OB_ACTIVE:
                                case ND_OB_SELECT:
+                               case ND_OB_VISIBLE:
                                case ND_LAYER:
                                case ND_RENDER_OPTIONS:
                                case ND_MODE:
                                        ED_region_tag_redraw(ar);
                                        break;
+                               case ND_WORLD:
+                                       /* handled by space_view3d_listener() for v3d access */
+                                       break;
                        }
                        if (wmn->action == NA_EDITED)
                                ED_region_tag_redraw(ar);
@@ -614,6 +627,11 @@ static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
                                        ED_region_tag_redraw(ar);
                                        break;
                        }
+                       switch(wmn->action) {
+                               case NA_ADDED:
+                                       ED_region_tag_redraw(ar);
+                                       break;
+                       }
                        break;
                case NC_GEOM:
                        switch(wmn->data) {
@@ -646,8 +664,15 @@ static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
                case NC_WORLD:
                        switch(wmn->data) {
                                case ND_WORLD_DRAW:
-                                       ED_region_tag_redraw(ar);
+                                       /* handled by space_view3d_listener() for v3d access */
                                        break;
+                               case ND_WORLD_STARS:
+                               {
+                                       RegionView3D *rv3d= ar->regiondata;
+                                       if(rv3d->persp == RV3D_CAMOB) {
+                                               ED_region_tag_redraw(ar);
+                                       }
+                               }
                        }
                        break;
                case NC_LAMP:
@@ -680,16 +705,29 @@ static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
                                ED_region_tag_redraw(ar);
                        break;
                case NC_SCREEN:
-                       if(wmn->data == ND_GPENCIL)     
-                               ED_region_tag_redraw(ar);
-                       else if(wmn->data==ND_ANIMPLAY)
-                               ED_region_tag_redraw(ar);
+                       switch(wmn->data) {
+                               case ND_GPENCIL:
+                               case ND_ANIMPLAY:
+                               case ND_SKETCH:
+                                       ED_region_tag_redraw(ar);
+                                       break;
+                               case ND_SCREENBROWSE:
+                               case ND_SCREENDELETE:
+                               case ND_SCREENSET:
+                                       /* screen was changed, need to update used layers due to NC_SCENE|ND_LAYER_CONTENT */
+                                       /* updates used layers only for View3D in active screen */
+                                       sc= wmn->reference;
+                                       view3d_recalc_used_layers(ar, wmn, sc->scene);
+                                       ED_region_tag_redraw(ar);
+                                       break;
+                       }
+
                        break;
        }
 }
 
 /* concept is to retrieve cursor type context-less */
-static void view3d_main_area_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
+static void view3d_main_area_cursor(wmWindow *win, ScrArea *UNUSED(sa), ARegion *UNUSED(ar))
 {
        Scene *scene= win->screen->scene;
 
@@ -725,6 +763,7 @@ static void view3d_header_area_listener(ARegion *ar, wmNotifier *wmn)
                                case ND_FRAME:
                                case ND_OB_ACTIVE:
                                case ND_OB_SELECT:
+                               case ND_OB_VISIBLE:
                                case ND_MODE:
                                case ND_LAYER:
                                case ND_TOOLSETTINGS:
@@ -778,6 +817,7 @@ static void view3d_buttons_area_listener(ARegion *ar, wmNotifier *wmn)
                                case ND_FRAME:
                                case ND_OB_ACTIVE:
                                case ND_OB_SELECT:
+                               case ND_OB_VISIBLE:
                                case ND_MODE:
                                case ND_LAYER:
                                case ND_LAYER_CONTENT:
@@ -871,20 +911,61 @@ static void view3d_props_area_listener(ARegion *ar, wmNotifier *wmn)
        }
 }
 
+/*area (not region) level listener*/
+static void space_view3d_listener(struct ScrArea *sa, struct wmNotifier *wmn)
+{
+       View3D *v3d = sa->spacedata.first;
+
+       /* context changes */
+       switch(wmn->category) {
+               case NC_SCENE:
+                       switch(wmn->data) {
+                               case ND_WORLD:
+                                       if(v3d->flag2 & V3D_RENDER_OVERRIDE)
+                                               ED_area_tag_redraw_regiontype(sa, RGN_TYPE_WINDOW);
+                                       break;
+                       }
+                       break;
+               case NC_WORLD:
+                       switch(wmn->data) {
+                               case ND_WORLD_DRAW:
+                                       if(v3d->flag2 & V3D_RENDER_OVERRIDE)
+                                               ED_area_tag_redraw_regiontype(sa, RGN_TYPE_WINDOW);
+                                       break;
+                       }
+                       break;
+
+       }
+
+#if 0 // removed since BKE_image_user_calc_frame is now called in draw_bgpic because screen_ops doesnt call the notifier.
+       if (wmn->category == NC_SCENE && wmn->data == ND_FRAME) {
+               View3D *v3d = area->spacedata.first;
+               BGpic *bgpic = v3d->bgpicbase.first;
+
+               for (; bgpic; bgpic = bgpic->next) {
+                       if (bgpic->ima) {
+                               Scene *scene = wmn->reference;
+                               BKE_image_user_calc_frame(&bgpic->iuser, scene->r.cfra, 0);
+                       }
+               }
+       }
+#endif
+}
+
+const char *view3d_context_dir[] = {
+       "selected_objects", "selected_bases", "selected_editable_objects",
+       "selected_editable_bases", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
+       "active_base", "active_object", NULL};
+
 static int view3d_context(const bContext *C, const char *member, bContextDataResult *result)
 {
        View3D *v3d= CTX_wm_view3d(C);
        Scene *scene= CTX_data_scene(C);
        Base *base;
-       int lay = v3d ? v3d->lay:scene->lay; /* fallback to the scene layer, allows duplicate and other oject operators to run outside the 3d view */
+       unsigned int lay = v3d ? v3d->lay:scene->lay; /* fallback to the scene layer, allows duplicate and other oject operators to run outside the 3d view */
 
        if(CTX_data_dir(member)) {
-               static const char *dir[] = {
-                       "selected_objects", "selected_bases", "selected_editable_objects",
-                       "selected_editable_bases", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
-                       "active_base", "active_object", NULL};
-
-               CTX_data_dir_set(result, dir);
+               CTX_data_dir_set(result, view3d_context_dir);
        }
        else if(CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) {
                int selected_objects= CTX_data_equals(member, "selected_objects");
@@ -973,23 +1054,6 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
        return -1; /* found but not available */
 }
 
-/*area (not region) level listener*/
-#if 0 // removed since BKE_image_user_calc_frame is now called in draw_bgpic because screen_ops doesnt call the notifier.
-void space_view3d_listener(struct ScrArea *area, struct wmNotifier *wmn)
-{
-       if (wmn->category == NC_SCENE && wmn->data == ND_FRAME) {
-               View3D *v3d = area->spacedata.first;
-               BGpic *bgpic = v3d->bgpicbase.first;
-
-               for (; bgpic; bgpic = bgpic->next) {
-                       if (bgpic->ima) {
-                               Scene *scene = wmn->reference;
-                               BKE_image_user_calc_frame(&bgpic->iuser, scene->r.cfra, 0);
-                       }
-               }
-       }
-}
-#endif
 
 /* only called once, from space/spacetypes.c */
 void ED_spacetype_view3d(void)
@@ -1003,7 +1067,7 @@ void ED_spacetype_view3d(void)
        st->new= view3d_new;
        st->free= view3d_free;
        st->init= view3d_init;
-//     st->listener = space_view3d_listener;
+       st->listener = space_view3d_listener;
        st->duplicate= view3d_duplicate;
        st->operatortypes= view3d_operatortypes;
        st->keymap= view3d_keymap;