Fix #23363: Layer buttons do not update when last object deleted
authorSergey Sharybin <sergey.vfx@gmail.com>
Sat, 28 Aug 2010 07:07:02 +0000 (07:07 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sat, 28 Aug 2010 07:07:02 +0000 (07:07 +0000)
This happend because of incorrect order of calculating used layer mask and drawing
header. Added layer content changed notifier to recalc used layers when needed.
This also fixes header redrawing in "Move to layer" operator and when user
changes Object.layers in properties view

source/blender/editors/object/object_add.c
source/blender/editors/object/object_relations.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/util/undo.c
source/blender/makesrna/intern/rna_object.c
source/blender/windowmanager/WM_types.h

index 4df3e0ee1de0566d0104679734e16705d6464a0c..924e72e264a0f4da7ad79747eb453c5607764758 100644 (file)
@@ -305,6 +305,8 @@ Object *ED_object_add_type(bContext *C, int type, float *loc, float *rot, int en
        if(enter_editmode)
                ED_object_enter_editmode(C, EM_IGNORE_LAYER);
 
+       WM_event_add_notifier(C, NC_SCENE|ND_LAYER_CONTENT, scene);
+
        return ob;
 }
 
@@ -825,7 +827,8 @@ static int object_delete_exec(bContext *C, wmOperator *op)
        DAG_scene_sort(bmain, scene);
        DAG_ids_flush_update(bmain, 0);
        
-       WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, CTX_data_scene(C));
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
+       WM_event_add_notifier(C, NC_SCENE|ND_LAYER_CONTENT, scene);
        
        return OPERATOR_FINISHED;
 }
index b8eebd161dc81c6dde9bd36752f6f42f903b5e30..2aaabebdb29278547dfe6f93a5f6dcfa5e554b78 100644 (file)
@@ -1109,6 +1109,8 @@ static int move_to_layer_exec(bContext *C, wmOperator *op)
        /* warning, active object may be hidden now */
        
        WM_event_add_notifier(C, NC_SCENE|NC_OBJECT|ND_DRAW, scene); /* is NC_SCENE needed ? */
+       WM_event_add_notifier(C, NC_SCENE|ND_LAYER_CONTENT, scene);
+
        DAG_scene_sort(bmain, scene);
 
        return OPERATOR_FINISHED;
index c49f4f48e108f5bc4751c8685fc85c0b571e0ea0..1e035797bead62b9a73d478191f0757abefb491d 100644 (file)
@@ -513,6 +513,37 @@ static void *view3d_main_area_duplicate(void *poin)
        return NULL;
 }
 
+static void view3d_recalc_used_layers(ARegion *ar, wmNotifier *wmn)
+{
+       wmWindow *win= wmn->wm->winactive;
+       ScrArea *sa;
+
+       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;
+
+                               v3d->lay_used= 0;
+                               base= scene->base.first;
+                               while(base) {
+                                       v3d->lay_used|= base->lay;
+
+                                       base= base->next;
+                               }
+
+                               break;
+                       }
+
+               sa= sa->next;
+       }
+}
+
 static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
 {
        /* context changes */
@@ -536,6 +567,10 @@ static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
                        break;
                case NC_SCENE:
                        switch(wmn->data) {
+                               case ND_LAYER_CONTENT:
+                                       view3d_recalc_used_layers(ar, wmn);
+                                       ED_region_tag_redraw(ar);
+                                       break;
                                case ND_FRAME:
                                case ND_TRANSFORM:
                                case ND_OB_ACTIVE:
@@ -677,6 +712,7 @@ static void view3d_header_area_listener(ARegion *ar, wmNotifier *wmn)
                                case ND_MODE:
                                case ND_LAYER:
                                case ND_TOOLSETTINGS:
+                               case ND_LAYER_CONTENT:
                                        ED_region_tag_redraw(ar);
                                        break;
                        }
@@ -728,6 +764,7 @@ static void view3d_buttons_area_listener(ARegion *ar, wmNotifier *wmn)
                                case ND_OB_SELECT:
                                case ND_MODE:
                                case ND_LAYER:
+                               case ND_LAYER_CONTENT:
                                        ED_region_tag_redraw(ar);
                                        break;
                        }
index f0aa54248da241eeffc5be2d76a424d2f265e579..56e66e21a720b0b91d9b963c2224618dbbb13d8c 100644 (file)
@@ -2367,14 +2367,9 @@ void view3d_main_area_draw(const bContext *C, ARegion *ar)
                
                /* Transp and X-ray afterdraw stuff for sets is done later */
        }
-       
-       /* extra service in layerbuttons, showing used layers */
-       v3d->lay_used = 0;
 
        /* then draw not selected and the duplis, but skip editmode object */
        for(base= scene->base.first; base; base= base->next) {
-               v3d->lay_used |= base->lay;
-               
                if(v3d->lay & base->lay) {
                        
                        /* dupli drawing */
index 283e2b49f0d68de7b9928bdc668efcb846a98052..e5128ea784a7681054bf8fdbc799542935de8b2f 100644 (file)
@@ -163,6 +163,8 @@ static int ed_undo_step(bContext *C, int step, const char *undoname)
                                        BKE_undo_name(C, undoname);
                                else
                                        BKE_undo_step(C, step);
+
+                               WM_event_add_notifier(C, NC_SCENE|ND_LAYER_CONTENT, CTX_data_scene(C));
                        }
                        
                }
index 45407a8e3754421dfe23685fa1ff24e13974f669..17074c7ec83eeb68ed1723868a69a0a2d412b370 100644 (file)
@@ -257,6 +257,8 @@ static void rna_Object_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 
        rna_Object_layer_update__internal(bmain, scene, base, ob);
        ob->lay= base->lay;
+
+       WM_main_add_notifier(NC_SCENE|ND_LAYER_CONTENT, scene);
 }
 
 static void rna_Base_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
@@ -266,6 +268,8 @@ static void rna_Base_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 
        rna_Object_layer_update__internal(bmain, scene, base, ob);
        ob->lay= base->lay;
+
+       WM_main_add_notifier(NC_SCENE|ND_LAYER_CONTENT, scene);
 }
 
 static int rna_Object_data_editable(PointerRNA *ptr)
index c84a5e648891b6e68cf74ba4624467ec31107a1f..807125765f78f21f3a30fa3a8a576c9496f15fa5 100644 (file)
@@ -184,6 +184,7 @@ typedef struct wmNotifier {
 #define ND_TOOLSETTINGS                (13<<16)
 #define ND_LAYER                       (14<<16)
 #define ND_FRAME_RANGE         (15<<16)
+#define ND_LAYER_CONTENT       (101<<16)
 
        /* NC_OBJECT Object */
 #define        ND_TRANSFORM            (16<<16)