diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-13 02:41:12 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-13 02:52:25 +0300 |
commit | af0ab15e1dd84aadb32ee8d7a836a08fe6251474 (patch) | |
tree | 4eabb3847dc1a28e68d052837d74fa5d59bc177c | |
parent | 3ea7a5d8699c74ddf4ea7b359022145e44f62bc2 (diff) |
Fix T62436: New added Torus won't appear in Local View
Add Object.local_view_get/set
Alternate fix which supports removing from local view & checking
if an object is in local view.
Also avoids redundant refresh.
Matches 2.7x Object.layer_local_view capabilities more closely,
without exposing the flag directly.
-rw-r--r-- | release/scripts/modules/bpy_extras/object_utils.py | 5 | ||||
-rw-r--r-- | source/blender/editors/include/ED_screen.h | 2 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_edit.c | 18 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object_api.c | 73 |
4 files changed, 98 insertions, 0 deletions
diff --git a/release/scripts/modules/bpy_extras/object_utils.py b/release/scripts/modules/bpy_extras/object_utils.py index 5f3d6fbc50f..10132366981 100644 --- a/release/scripts/modules/bpy_extras/object_utils.py +++ b/release/scripts/modules/bpy_extras/object_utils.py @@ -133,6 +133,11 @@ def object_data_add(context, obdata, operator=None, name=None): obj_new.select_set(True) obj_new.matrix_world = add_object_align_init(context, operator) + space_data = context.space_data + if space_data.type == 'VIEW_3D': + if space_data.local_view: + obj_new.local_view_set(space_data, True) + if obj_act and obj_act.mode == 'EDIT' and obj_act.type == obj_new.type: bpy.ops.mesh.select_all(action='DESELECT') obj_act.select_set(True) diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 5d4f0919c44..363cea0c1c6 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -41,6 +41,7 @@ struct Main; struct MenuType; struct PropertyRNA; struct Scene; +struct SpaceLink; struct ViewLayer; struct WorkSpace; struct WorkSpaceInstanceHook; @@ -195,6 +196,7 @@ void ED_screens_navigation_bar_tools_menu_create(struct bContext *C, struct u bool ED_screen_stereo3d_required(const struct bScreen *screen, const struct Scene *scene); Scene *ED_screen_scene_find(const struct bScreen *screen, const struct wmWindowManager *wm); Scene *ED_screen_scene_find_with_window(const struct bScreen *screen, const struct wmWindowManager *wm, struct wmWindow **r_window); +ScrArea *ED_screen_area_find_with_spacedata(const bScreen *screen, const struct SpaceLink *sl, bool only_visible); struct wmWindow *ED_screen_window_find(const struct bScreen *screen, const struct wmWindowManager *wm); void ED_screen_preview_render(const struct bScreen *screen, int size_x, int size_y, unsigned int *r_rect) ATTR_NONNULL(); diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 8c38ba41821..e5d23457daf 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -1539,6 +1539,24 @@ Scene *ED_screen_scene_find_with_window(const bScreen *screen, const wmWindowMan return NULL; } +ScrArea *ED_screen_area_find_with_spacedata(const bScreen *screen, const SpaceLink *sl, const bool only_visible) +{ + if (only_visible) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + if (sa->spacedata.first == sl) { + return sa; + } + } + } + else { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + if (BLI_findindex(&sa->spacedata, sl) != -1) { + return sa; + } + } + } + return NULL; +} Scene *ED_screen_scene_find(const bScreen *screen, const wmWindowManager *wm) { diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index eeeac010261..c8e84c07b5c 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -74,6 +74,7 @@ static const EnumPropertyItem space_items[] = { #include "BKE_report.h" #include "ED_object.h" +#include "ED_screen.h" #include "DNA_curve_types.h" #include "DNA_mesh_types.h" @@ -216,6 +217,61 @@ static bool rna_Object_indirect_only_get(Object *ob, bContext *C, ReportList *re return ((base->flag & BASE_INDIRECT_ONLY) != 0); } +static Base *rna_Object_local_view_property_helper(bScreen *sc, View3D *v3d, Object *ob, ReportList *reports, Scene **r_scene) +{ + if (v3d->localvd == NULL) { + BKE_report(reports, RPT_ERROR, "Viewport not in local view"); + return NULL; + } + + wmWindow *win = ED_screen_window_find(sc, G_MAIN->wm.first); + ViewLayer *view_layer = WM_window_get_active_view_layer(win); + Base *base = BKE_view_layer_base_find(view_layer, ob); + if (base == NULL) { + BKE_reportf(reports, + RPT_WARNING, + "Object %s not in view layer %s", + ob->id.name + 2, + view_layer->name); + + } + if (r_scene) { + *r_scene = win->scene; + } + return base; +} + +static bool rna_Object_local_view_get(Object *ob, ReportList *reports, PointerRNA *v3d_ptr) +{ + bScreen *sc = v3d_ptr->id.data; + View3D *v3d = v3d_ptr->data; + Base *base = rna_Object_local_view_property_helper(sc, v3d, ob, reports, NULL); + if (base == NULL) { + return false; /* Error reported. */ + } + return (base->local_view_bits & v3d->local_view_uuid) != 0; +} + +static void rna_Object_local_view_set(Object *ob, ReportList *reports, PointerRNA *v3d_ptr, bool state) +{ + bScreen *sc = v3d_ptr->id.data; + View3D *v3d = v3d_ptr->data; + Scene *scene; + Base *base = rna_Object_local_view_property_helper(sc, v3d, ob, reports, &scene); + if (base == NULL) { + return; /* Error reported. */ + } + const short local_view_bits_prev = base->local_view_bits; + SET_FLAG_FROM_TEST(base->local_view_bits, state, v3d->local_view_uuid); + if (local_view_bits_prev != base->local_view_bits) { + DEG_id_tag_update(&scene->id, ID_RECALC_BASE_FLAGS); + ScrArea *sa = ED_screen_area_find_with_spacedata(sc, (SpaceLink *)v3d, true); + if (sa) { + ED_area_tag_redraw(sa); + } + } +} + /* Convert a given matrix from a space to another (using the object and/or a bone as reference). */ static void rna_Object_mat_convert_space(Object *ob, ReportList *reports, bPoseChannel *pchan, float *mat, float *mat_ret, int from, int to) @@ -611,6 +667,23 @@ void RNA_api_object(StructRNA *srna) parm = RNA_def_boolean(func, "result", 0, "", "Object indirect only"); RNA_def_function_return(func, parm); + /* Local View */ + func = RNA_def_function(srna, "local_view_get", "rna_Object_local_view_get"); + RNA_def_function_ui_description(func, "Get the local view state for this object"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + parm = RNA_def_pointer(func, "viewport", "SpaceView3D", "", "Viewport in local view"); + RNA_def_parameter_flags(parm, 0, PARM_RNAPTR | PARM_REQUIRED); + parm = RNA_def_boolean(func, "result", 0, "", "Object local view state"); + RNA_def_function_return(func, parm); + + func = RNA_def_function(srna, "local_view_set", "rna_Object_local_view_set"); + RNA_def_function_ui_description(func, "Set the local view state for this object"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + parm = RNA_def_pointer(func, "viewport", "SpaceView3D", "", "Viewport in local view"); + RNA_def_parameter_flags(parm, 0, PARM_RNAPTR | PARM_REQUIRED); + parm = RNA_def_boolean(func, "state", 0, "", "Local view state to define"); + RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); + /* Matrix space conversion */ func = RNA_def_function(srna, "convert_space", "rna_Object_mat_convert_space"); RNA_def_function_ui_description(func, "Convert (transform) the given matrix from one space to another"); |