Fixes localview and view-local layers

- Drawing grease pencil fail without scene-lock.
- Converting to curve failed without scene-lock.
- Outliner drag into viewport failed with local-view.
This commit is contained in:
Campbell Barton 2014-09-02 20:45:28 +10:00
parent daa17ef402
commit a1c628e503
6 changed files with 45 additions and 11 deletions

@ -53,6 +53,8 @@ struct wmNotifier;
struct wmWindow;
struct wmWindowManager;
#include "BLI_compiler_attrs.h"
#include "RNA_types.h"
/* spacetype has everything stored to get an editor working, it gets initialized via
@ -280,6 +282,11 @@ struct ARegion *BKE_area_find_region_type(struct ScrArea *sa, int type);
struct ARegion *BKE_area_find_region_active_win(struct ScrArea *sa);
struct ScrArea *BKE_screen_find_big_area(struct bScreen *sc, const int spacetype, const short min);
unsigned int BKE_screen_view3d_layer_active_ex(
const struct View3D *v3d, const struct Scene *scene, bool use_localvd) ATTR_NONNULL(2);
unsigned int BKE_screen_view3d_layer_active(
const struct View3D *v3d, const struct Scene *scene) ATTR_NONNULL(2);
void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene);
void BKE_screen_view3d_scene_sync(struct bScreen *sc);
void BKE_screen_view3d_main_sync(ListBase *screen_lb, struct Scene *scene);

@ -425,6 +425,32 @@ ScrArea *BKE_screen_find_big_area(bScreen *sc, const int spacetype, const short
return big;
}
/**
* Utility function to get the active layer to use when adding new objects.
*/
unsigned int BKE_screen_view3d_layer_active_ex(const View3D *v3d, const Scene *scene, bool use_localvd)
{
unsigned int lay;
if ((v3d == NULL) || (v3d->scenelock && !v3d->localvd)) {
lay = scene->layact;
}
else {
lay = v3d->layact;
}
if (use_localvd) {
if (v3d && v3d->localvd) {
lay |= v3d->lay;
}
}
return lay;
}
unsigned int BKE_screen_view3d_layer_active(const struct View3D *v3d, const struct Scene *scene)
{
return BKE_screen_view3d_layer_active_ex(v3d, scene, true);
}
void BKE_screen_view3d_sync(View3D *v3d, struct Scene *scene)
{
int bit;

@ -772,7 +772,7 @@ void ED_gpencil_draw_view3d(Scene *scene, View3D *v3d, ARegion *ar, bool only3d)
int offsx, offsy, winx, winy;
/* check that we have grease-pencil stuff to draw */
gpd = ED_gpencil_data_get_active_v3d(scene); // XXX
gpd = ED_gpencil_data_get_active_v3d(scene, v3d);
if (gpd == NULL) return;
/* when rendering to the offscreen buffer we don't want to

@ -62,6 +62,7 @@
#include "BKE_object.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_tracking.h"
#include "UI_interface.h"
@ -186,15 +187,15 @@ bGPdata *ED_gpencil_data_get_active(const bContext *C)
return (gpd_ptr) ? *(gpd_ptr) : NULL;
}
/* needed for offscreen rendering */
bGPdata *ED_gpencil_data_get_active_v3d(Scene *scene)
bGPdata *ED_gpencil_data_get_active_v3d(Scene *scene, View3D *v3d)
{
Base *base = scene->basact;
bGPdata *gpd = NULL;
/* We have to make sure active object is actually visible and selected, else we must use default scene gpd,
* to be consistent with ED_gpencil_data_get_active's behavior.
*/
if (base && (scene->lay & base->lay) && (base->object->flag & SELECT)) {
if (base && TESTBASE(v3d, base)) {
gpd = base->object->gpd;
}
return gpd ? gpd : scene->gpd;
@ -1399,6 +1400,7 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG
const bool norm_weights, const float rad_fac, const bool link_strokes, tGpTimingData *gtd)
{
struct Main *bmain = CTX_data_main(C);
View3D *v3d = CTX_wm_view3d(C); /* may be NULL */
Scene *scene = CTX_data_scene(C);
bGPDframe *gpf = gpencil_layer_getframe(gpl, CFRA, 0);
bGPDstroke *gps, *prev_gps = NULL;
@ -1493,7 +1495,7 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG
}
/* set the layer and select */
base_new->lay = ob->lay = base_orig ? base_orig->lay : scene->lay;
base_new->lay = ob->lay = base_orig ? base_orig->lay : BKE_screen_view3d_layer_active(v3d, scene);
base_new->flag = ob->flag = base_new->flag | SELECT;
}

@ -67,7 +67,7 @@ typedef struct tGPspoint {
struct bGPdata **ED_gpencil_data_get_pointers(const struct bContext *C, struct PointerRNA *ptr);
struct bGPdata *ED_gpencil_data_get_active(const struct bContext *C);
struct bGPdata *ED_gpencil_data_get_active_v3d(struct Scene *scene); /* for offscreen rendering */
struct bGPdata *ED_gpencil_data_get_active_v3d(struct Scene *scene, struct View3D *v3d);
/* ----------- Grease Pencil Operators ----------------- */

@ -84,6 +84,7 @@
#include "BKE_report.h"
#include "BKE_sca.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_speaker.h"
#include "BKE_texture.h"
@ -338,10 +339,7 @@ bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view
}
else {
Scene *scene = CTX_data_scene(C);
if (v3d)
*layer = (v3d->scenelock && !v3d->localvd) ? scene->layact : v3d->layact;
else
*layer = scene->layact;
*layer = BKE_screen_view3d_layer_active_ex(v3d, scene, false);
for (a = 0; a < 20; a++) {
layer_values[a] = *layer & (1 << a);
}
@ -2219,6 +2217,7 @@ static int add_named_exec(bContext *C, wmOperator *op)
wmWindow *win = CTX_wm_window(C);
const wmEvent *event = win ? win->eventstate : NULL;
Main *bmain = CTX_data_main(C);
View3D *v3d = CTX_wm_view3d(C); /* may be NULL */
Scene *scene = CTX_data_scene(C);
Base *basen, *base;
Object *ob;
@ -2251,7 +2250,7 @@ static int add_named_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
basen->lay = basen->object->lay = scene->lay;
basen->lay = basen->object->lay = BKE_screen_view3d_layer_active(v3d, scene);
basen->object->restrictflag &= ~OB_RESTRICT_VIEW;
if (event) {