Object Mode: remove Scene.obedit
authorCampbell Barton <ideasman42@gmail.com>
Tue, 13 Feb 2018 09:35:29 +0000 (20:35 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 13 Feb 2018 09:55:12 +0000 (20:55 +1100)
Add ED_screen_window_find, BKE_workspace_edit_object

27 files changed:
source/blender/blenkernel/BKE_workspace.h
source/blender/blenkernel/intern/object_dupli.c
source/blender/blenkernel/intern/object_update.c
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/workspace.c
source/blender/editors/animation/anim_channels_edit.c
source/blender/editors/curve/editcurve.c
source/blender/editors/curve/editcurve_paint.c
source/blender/editors/gpencil/gpencil_convert.c
source/blender/editors/include/ED_screen.h
source/blender/editors/mesh/editmesh_path.c
source/blender/editors/mesh/meshtools.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_modifier.c
source/blender/editors/render/render_internal.c
source/blender/editors/screen/screen_context.c
source/blender/editors/screen/screen_edit.c
source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c
source/blender/editors/space_info/info_stats.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/editors/space_view3d/view3d_draw_legacy.c
source/blender/editors/transform/transform_manipulator.c
source/blender/editors/transform/transform_snap_object.c
source/blender/makesdna/DNA_scene_types.h
source/blender/modifiers/intern/MOD_meshdeform.c
source/blender/modifiers/intern/MOD_surfacedeform.c

index f839d4cdf769f08e664fe89cc349610854d9a032..b309ae838d66aa9c1a198f494b3a3f97345be80f 100644 (file)
@@ -133,6 +133,9 @@ void BKE_workspace_update_object_mode(
         struct EvaluationContext *eval_ctx,
         struct WorkSpace *workspace);
 
+struct Object *BKE_workspace_edit_object(
+        struct WorkSpace *workspace, struct Scene *scene);
+
 #undef GETTER_ATTRS
 #undef SETTER_ATTRS
 
index f9f6b0aab40599fc724b109c7d3d667091982ac2..2d655913b3e447bb7d1a00fa75601c464ed5a82a 100644 (file)
@@ -74,6 +74,7 @@ typedef struct DupliContext {
        bool do_update;
        bool animated;
        Group *group; /* XXX child objects are selected from this group if set, could be nicer */
+       Object *obedit; /* Only to check if the object is in edit-mode. */
 
        Scene *scene;
        ViewLayer *view_layer;
@@ -107,6 +108,7 @@ static void init_context(DupliContext *r_ctx, const EvaluationContext *eval_ctx,
        r_ctx->animated = false;
        r_ctx->group = NULL;
 
+       r_ctx->obedit = OBEDIT_FROM_EVAL_CTX(eval_ctx);
        r_ctx->object = ob;
        if (space_mat)
                copy_m4_m4(r_ctx->space_mat, space_mat);
@@ -241,14 +243,13 @@ static bool is_child(const Object *ob, const Object *parent)
 static void make_child_duplis(const DupliContext *ctx, void *userdata, MakeChildDuplisFunc make_child_duplis_cb)
 {
        Object *parent = ctx->object;
-       Object *obedit = ctx->scene->obedit;
 
        if (ctx->group) {
                int groupid = 0;
                FOREACH_GROUP_BASE(ctx->group, base)
                {
                        Object *ob = base->object;
-                       if ((base->flag & BASE_VISIBLED) && ob != obedit && is_child(ob, parent)) {
+                       if ((base->flag & BASE_VISIBLED) && ob != ctx->obedit && is_child(ob, parent)) {
                                DupliContext pctx;
                                copy_dupli_context(&pctx, ctx, ctx->object, NULL, groupid, false);
 
@@ -267,7 +268,7 @@ static void make_child_duplis(const DupliContext *ctx, void *userdata, MakeChild
                ViewLayer *view_layer = ctx->view_layer;
                for (Base *base = view_layer->object_bases.first; base; base = base->next, baseid++) {
                        Object *ob = base->object;
-                       if (ob != obedit && is_child(ob, parent)) {
+                       if ((ob != ctx->obedit) && is_child(ob, parent)) {
                                DupliContext pctx;
                                copy_dupli_context(&pctx, ctx, ctx->object, NULL, baseid, false);
 
index bc183ba95a64424e2acd52539c4a8719858ccc46..52c85011b6ac555e517de241049d3b944c2b0cdb 100644 (file)
@@ -173,7 +173,7 @@ void BKE_object_handle_data_update(
        switch (ob->type) {
                case OB_MESH:
                {
-                       BMEditMesh *em = (ob == scene->obedit) ? BKE_editmesh_from_object(ob) : NULL;
+                       BMEditMesh *em = (eval_ctx->object_mode & OB_MODE_EDIT) ? BKE_editmesh_from_object(ob) : NULL;
                        uint64_t data_mask = scene->customdata_mask | CD_MASK_BAREMESH;
 #ifdef WITH_FREESTYLE
                        /* make sure Freestyle edge/face marks appear in DM for render (see T40315) */
@@ -223,7 +223,7 @@ void BKE_object_handle_data_update(
        }
 
        /* particles */
-       if (ob != scene->obedit && ob->particlesystem.first) {
+       if ((ob != OBEDIT_FROM_EVAL_CTX(eval_ctx)) && ob->particlesystem.first) {
                ParticleSystem *tpsys, *psys;
                DerivedMesh *dm;
                ob->transflag &= ~OB_DUPLIPARTS;
index a4ccf3b9bba4ffc2c888241eae20bd14761f4b7d..074d7b9c90dd286bd5e35cf5b79ffff4a5ecb0bf 100644 (file)
@@ -1380,7 +1380,7 @@ static bool check_rendered_viewport_visible(Main *bmain)
        return false;
 }
 
-static void prepare_mesh_for_viewport_render(Main *bmain, Scene *scene)
+static void prepare_mesh_for_viewport_render(Main *bmain, const EvaluationContext *eval_ctx)
 {
        /* This is needed to prepare mesh to be used by the render
         * engine from the viewport rendering. We do loading here
@@ -1391,7 +1391,7 @@ static void prepare_mesh_for_viewport_render(Main *bmain, Scene *scene)
         * call loading of the edit data for the mesh objects.
         */
 
-       Object *obedit = scene->obedit;
+       Object *obedit = OBEDIT_FROM_EVAL_CTX(eval_ctx);
        if (obedit) {
                Mesh *mesh = obedit->data;
                if ((obedit->type == OB_MESH) &&
@@ -1429,7 +1429,7 @@ void BKE_scene_graph_update_tagged(EvaluationContext *eval_ctx,
        /* Uncomment this to check if graph was properly tagged for update. */
        // DEG_debug_graph_relations_validate(depsgraph, bmain, scene);
        /* Flush editing data if needed. */
-       prepare_mesh_for_viewport_render(bmain, scene);
+       prepare_mesh_for_viewport_render(bmain, eval_ctx);
        /* Flush recalc flags to dependencies. */
        DEG_graph_flush_update(bmain, depsgraph);
        /* Update all objects: drivers, matrices, displists, etc. flags set
index dcd4183210d58cb58e1dcac7aee589d3c9fbb877..bc5731b957425c85978e4961f900f811f85c30f7 100644 (file)
@@ -38,6 +38,7 @@
 #include "BKE_main.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h"
+#include "BKE_object.h"
 #include "BKE_workspace.h"
 
 #include "DNA_object_types.h"
@@ -517,4 +518,20 @@ void BKE_workspace_update_object_mode(
         * for now without this 'bmain->eval_ctx' is never set. */
 
        eval_ctx->object_mode = workspace->object_mode;
-}
\ No newline at end of file
+}
+
+Object *BKE_workspace_edit_object(WorkSpace *workspace, Scene *scene)
+{
+       if (workspace->object_mode & OB_MODE_EDIT) {
+               ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene);
+               if (view_layer) {
+                       Object *obedit = OBACT(view_layer);
+                       if (obedit) {
+                               BLI_assert(BKE_object_is_in_editmode(obedit));
+                               return obedit;
+                       }
+               }
+       }
+       return NULL;
+}
+
index 5d5990b9a0a2b39dc1461855bb5240c0e8be4970..d137e5f1c74c4b5496aab4b68921bbf5ce4512fe 100644 (file)
@@ -2683,8 +2683,10 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index,
                }
                case ANIMTYPE_OBJECT:
                {
+#if 0
                        bDopeSheet *ads = (bDopeSheet *)ac->data;
                        Scene *sce = (Scene *)ads->source;
+#endif
                        ViewLayer *view_layer = ac->view_layer;
                        Base *base = (Base *)ale->data;
                        Object *ob = base->object;
@@ -2723,7 +2725,7 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index,
                                        adt->flag |= ADT_UI_ACTIVE;
 
                                /* ensure we exit editmode on whatever object was active before to avoid getting stuck there - T48747 */
-                               if (ob != sce->obedit)
+                               if (ob != CTX_data_edit_object(C))
                                        ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO);
 
                                notifierFlags |= (ND_ANIMCHAN | NA_SELECTED);
index 4b578ba389ebc1f1f387cd5fc06f94ed368e2d59..c3e92589791c0dadeb1ea8e767f169823f43a405 100644 (file)
@@ -5027,7 +5027,7 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
                                snap_context,
                                SCE_SELECT_FACE,
                                &(const struct SnapObjectParams){
-                                   .snap_select = (vc.scene->obedit != NULL) ? SNAP_NOT_ACTIVE : SNAP_ALL,
+                                   .snap_select = (vc.obedit != NULL) ? SNAP_NOT_ACTIVE : SNAP_ALL,
                                    .use_object_edit_cage = false,
                                },
                                mval, NULL, true,
index 062b9c94a1bb866a1efd5f4ba535e4accb15e5a5..0d2514ec27e6abf8813f28fb37ca8b2c32a4ed74 100644 (file)
@@ -788,7 +788,7 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
        struct CurveDrawData *cdd = op->customdata;
 
        const CurvePaintSettings *cps = &cdd->vc.scene->toolsettings->curve_paint_settings;
-       Object *obedit = cdd->vc.scene->obedit;
+       Object *obedit = cdd->vc.obedit;
        Curve *cu = obedit->data;
        ListBase *nurblist = object_editcurve_get(obedit);
 
index d2ae8bc3ce7011d13d67e087a6938a75c49d2a03..8d45c6af686425e6ab51f417a784ee373ebd3c64 100644 (file)
@@ -55,6 +55,7 @@
 #include "DNA_space_types.h"
 #include "DNA_view3d_types.h"
 #include "DNA_gpencil_types.h"
+#include "DNA_workspace_types.h"
 
 #include "BKE_collection.h"
 #include "BKE_context.h"
@@ -1293,6 +1294,7 @@ static int gp_convert_poll(bContext *C)
        bGPDframe *gpf = NULL;
        ScrArea *sa = CTX_wm_area(C);
        Scene *scene = CTX_data_scene(C);
+       const WorkSpace *workspace = CTX_wm_workspace(C);
        
        /* only if the current view is 3D View, if there's valid data (i.e. at least one stroke!),
         * and if we are not in edit mode!
@@ -1301,7 +1303,7 @@ static int gp_convert_poll(bContext *C)
                (gpl = BKE_gpencil_layer_getactive(gpd)) &&
                (gpf = BKE_gpencil_layer_getframe(gpl, CFRA, 0)) &&
                (gpf->strokes.first) &&
-               (scene->obedit == NULL));
+               ((workspace->object_mode & OB_MODE_EDIT) == 0));
 }
 
 static int gp_convert_layer_exec(bContext *C, wmOperator *op)
index 18480d01ed7d93d8d43fe443f5e8f2703cf0d6dd..8fa043499f894c663749919b65a6b79d542255d2 100644 (file)
@@ -148,6 +148,7 @@ void    ED_screens_header_tools_menu_create(struct bContext *C, struct uiLayout
 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);
+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();
 
 /* workspaces */
index b71dd029bf23d2effcdaeeffa1cc32a5ed9fc9fa..795c7b6aa530b1bae943364c5393d3e121dbd5f7 100644 (file)
@@ -121,10 +121,9 @@ static void verttag_set_cb(BMVert *v, bool val, void *user_data_v)
 }
 
 static void mouse_mesh_shortest_path_vert(
-        Scene *scene, const struct PathSelectParams *op_params,
+        Scene *UNUSED(scene), Object *obedit, const struct PathSelectParams *op_params,
         BMVert *v_act, BMVert *v_dst)
 {
-       Object *obedit = scene->obedit;
        BMEditMesh *em = BKE_editmesh_from_object(obedit);
        BMesh *bm = em->bm;
 
@@ -280,11 +279,11 @@ static void edgetag_set_cb(BMEdge *e, bool val, void *user_data_v)
        }
 }
 
-static void edgetag_ensure_cd_flag(Scene *scene, Mesh *me)
+static void edgetag_ensure_cd_flag(Mesh *me, const char edge_mode)
 {
        BMesh *bm = me->edit_btmesh->bm;
 
-       switch (scene->toolsettings->edge_mode) {
+       switch (edge_mode) {
                case EDGE_MODE_TAG_CREASE:
                        BM_mesh_cd_flag_ensure(bm, me, ME_CDFLAG_EDGE_CREASE);
                        break;
@@ -307,10 +306,9 @@ static void edgetag_ensure_cd_flag(Scene *scene, Mesh *me)
 
 /* since you want to create paths with multiple selects, it doesn't have extend option */
 static void mouse_mesh_shortest_path_edge(
-        Scene *scene, const struct PathSelectParams *op_params,
+        Scene *scene, Object *obedit, const struct PathSelectParams *op_params,
         BMEdge *e_act, BMEdge *e_dst)
 {
-       Object *obedit = scene->obedit;
        BMEditMesh *em = BKE_editmesh_from_object(obedit);
        BMesh *bm = em->bm;
 
@@ -319,7 +317,7 @@ static void mouse_mesh_shortest_path_edge(
        Mesh *me = obedit->data;
        bool is_path_ordered = false;
 
-       edgetag_ensure_cd_flag(scene, obedit->data);
+       edgetag_ensure_cd_flag(obedit->data, op_params->edge_mode);
 
        if (e_act && (e_act != e_dst)) {
                if (op_params->use_fill) {
@@ -377,7 +375,7 @@ static void mouse_mesh_shortest_path_edge(
        }
        else {
                const bool is_act = !edgetag_test_cb(e_dst, &user_data);
-               edgetag_ensure_cd_flag(scene, obedit->data);
+               edgetag_ensure_cd_flag(obedit->data, op_params->edge_mode);
                edgetag_set_cb(e_dst, is_act, &user_data); /* switch the edge option */
        }
 
@@ -452,10 +450,9 @@ static void facetag_set_cb(BMFace *f, bool val, void *user_data_v)
 }
 
 static void mouse_mesh_shortest_path_face(
-        Scene *scene, const struct PathSelectParams *op_params,
+        Scene *UNUSED(scene), Object *obedit, const struct PathSelectParams *op_params,
         BMFace *f_act, BMFace *f_dst)
 {
-       Object *obedit = scene->obedit;
        BMEditMesh *em = BKE_editmesh_from_object(obedit);
        BMesh *bm = em->bm;
 
@@ -547,7 +544,7 @@ static void mouse_mesh_shortest_path_face(
 /* Main Operator for vert/edge/face tag */
 
 static bool edbm_shortest_path_pick_ex(
-        Scene *scene, const struct PathSelectParams *op_params,
+        Scene *scene, Object *obedit, const struct PathSelectParams *op_params,
         BMElem *ele_src, BMElem *ele_dst)
 {
 
@@ -555,15 +552,15 @@ static bool edbm_shortest_path_pick_ex(
                /* pass */
        }
        else if (ele_src->head.htype == BM_VERT) {
-               mouse_mesh_shortest_path_vert(scene, op_params, (BMVert *)ele_src, (BMVert *)ele_dst);
+               mouse_mesh_shortest_path_vert(scene, obedit, op_params, (BMVert *)ele_src, (BMVert *)ele_dst);
                return true;
        }
        else if (ele_src->head.htype == BM_EDGE) {
-               mouse_mesh_shortest_path_edge(scene, op_params, (BMEdge *)ele_src, (BMEdge *)ele_dst);
+               mouse_mesh_shortest_path_edge(scene, obedit, op_params, (BMEdge *)ele_src, (BMEdge *)ele_dst);
                return true;
        }
        else if (ele_src->head.htype == BM_FACE) {
-               mouse_mesh_shortest_path_face(scene, op_params, (BMFace *)ele_src, (BMFace *)ele_dst);
+               mouse_mesh_shortest_path_face(scene, obedit, op_params, (BMFace *)ele_src, (BMFace *)ele_dst);
                return true;
        }
 
@@ -644,7 +641,7 @@ static int edbm_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmE
        op_params.track_active = track_active;
        op_params.edge_mode = vc.scene->toolsettings->edge_mode;
 
-       if (!edbm_shortest_path_pick_ex(vc.scene, &op_params, ele_src, ele_dst)) {
+       if (!edbm_shortest_path_pick_ex(vc.scene, vc.obedit, &op_params, ele_src, ele_dst)) {
                return OPERATOR_PASS_THROUGH;
        }
 
@@ -681,7 +678,7 @@ static int edbm_shortest_path_pick_exec(bContext *C, wmOperator *op)
        op_params.track_active = true;
        op_params.edge_mode = scene->toolsettings->edge_mode;
 
-       if (!edbm_shortest_path_pick_ex(scene, &op_params, ele_src, ele_dst)) {
+       if (!edbm_shortest_path_pick_ex(scene, obedit, &op_params, ele_src, ele_dst)) {
                return OPERATOR_CANCELLED;
        }
 
@@ -720,8 +717,8 @@ void MESH_OT_shortest_path_pick(wmOperatorType *ot)
 static int edbm_shortest_path_select_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
-       Object *ob = CTX_data_edit_object(C);
-       BMEditMesh *em = BKE_editmesh_from_object(ob);
+       Object *obedit = CTX_data_edit_object(C);
+       BMEditMesh *em = BKE_editmesh_from_object(obedit);
        BMesh *bm = em->bm;
        BMIter iter;
        BMEditSelection *ese_src, *ese_dst;
@@ -773,7 +770,7 @@ static int edbm_shortest_path_select_exec(bContext *C, wmOperator *op)
                struct PathSelectParams op_params;
                path_select_params_from_op(op, &op_params);
 
-               edbm_shortest_path_pick_ex(scene, &op_params, ele_src, ele_dst);
+               edbm_shortest_path_pick_ex(scene, obedit, &op_params, ele_src, ele_dst);
 
                return OPERATOR_FINISHED;
        }
index 85b1c70fde3ae65306f9acbd960e1223e7d5356b..64b6f5b80100ef112a6257233a9141a31765d552 100644 (file)
@@ -42,6 +42,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_view3d_types.h"
+#include "DNA_workspace_types.h"
 
 #include "BLI_math.h"
 #include "BLI_blenlib.h"
@@ -275,6 +276,7 @@ static void join_mesh_single(
 
 int join_mesh_exec(bContext *C, wmOperator *op)
 {
+       const WorkSpace *workspace = CTX_wm_workspace(C);
        Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
        Object *ob = CTX_data_active_object(C);
@@ -294,7 +296,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
        bDeformGroup *dg, *odg;
        CustomData vdata, edata, fdata, ldata, pdata;
 
-       if (scene->obedit) {
+       if (workspace->object_mode & OB_MODE_EDIT) {
                BKE_report(op->reports, RPT_WARNING, "Cannot join while in edit mode");
                return OPERATOR_CANCELLED;
        }
index 18c18f10c136f4860d7ba14d0530014dc6fafc54..c4bad6f76c9d00b43158503c36814b46d8069e5e 100644 (file)
@@ -1673,7 +1673,7 @@ static int convert_poll(bContext *C)
        Base *base_act = CTX_data_active_base(C);
        Object *obact = base_act ? base_act->object : NULL;
 
-       return (!ID_IS_LINKED(scene) && obact && scene->obedit != obact &&
+       return (!ID_IS_LINKED(scene) && obact && (BKE_object_is_in_editmode(obact) == false) &&
                (base_act->flag & BASE_SELECTED) && !ID_IS_LINKED(obact));
 }
 
@@ -2529,10 +2529,10 @@ static int join_poll(bContext *C)
 
 static int join_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene = CTX_data_scene(C);
+       const WorkSpace *workspace = CTX_wm_workspace(C);
        Object *ob = CTX_data_active_object(C);
 
-       if (scene->obedit) {
+       if (workspace->object_mode & OB_MODE_EDIT) {
                BKE_report(op->reports, RPT_ERROR, "This data does not support joining in edit mode");
                return OPERATOR_CANCELLED;
        }
@@ -2583,10 +2583,10 @@ static int join_shapes_poll(bContext *C)
 
 static int join_shapes_exec(bContext *C, wmOperator *op)
 {
-       Scene *scene = CTX_data_scene(C);
+       const WorkSpace *workspace = CTX_wm_workspace(C);
        Object *ob = CTX_data_active_object(C);
 
-       if (scene->obedit) {
+       if (workspace->object_mode & OB_MODE_EDIT) {
                BKE_report(op->reports, RPT_ERROR, "This data does not support joining in edit mode");
                return OPERATOR_CANCELLED;
        }
index ca96e1c67988ca047f4878a6515c56f403cff439..a74af68ca7d899fec3ce74a6f5282d9460304449 100644 (file)
@@ -84,6 +84,7 @@
 #include "BKE_modifier.h"
 #include "BKE_editmesh.h"
 #include "BKE_report.h"
+#include "BKE_object.h"
 #include "BKE_workspace.h"
 
 #include "DEG_depsgraph.h"
@@ -703,7 +704,7 @@ static void copy_attr(Main *bmain, Scene *scene, ViewLayer *view_layer, short ev
 
        if (!(ob = OBACT(view_layer))) return;
        
-       if (scene->obedit) { // XXX get from context
+       if (BKE_object_is_in_editmode(ob)) {
                /* obedit_copymenu(); */
                return;
        }
@@ -942,7 +943,7 @@ static void copy_attr(Main *bmain, Scene *scene, ViewLayer *view_layer, short ev
                DEG_relations_tag_update(bmain);
 }
 
-static void UNUSED_FUNCTION(copy_attr_menu) (Main *bmain, Scene *scene, ViewLayer *view_layer)
+static void UNUSED_FUNCTION(copy_attr_menu) (Main *bmain, Scene *scene, ViewLayer *view_layer, Object *obedit)
 {
        Object *ob;
        short event;
@@ -950,7 +951,7 @@ static void UNUSED_FUNCTION(copy_attr_menu) (Main *bmain, Scene *scene, ViewLaye
        
        if (!(ob = OBACT(view_layer))) return;
        
-       if (scene->obedit) { /* XXX get from context */
+       if (obedit) {
 /*             if (ob->type == OB_MESH) */
 /* XXX                 mesh_copy_menu(); */
                return;
@@ -1367,7 +1368,7 @@ void OBJECT_OT_shade_smooth(wmOperatorType *ot)
 
 /* ********************** */
 
-static void UNUSED_FUNCTION(image_aspect) (Scene *scene, ViewLayer *view_layer)
+static void UNUSED_FUNCTION(image_aspect) (Scene *scene, ViewLayer *view_layer, Object *obedit)
 {
        /* all selected objects with an image map: scale in image aspect */
        Base *base;
@@ -1377,7 +1378,7 @@ static void UNUSED_FUNCTION(image_aspect) (Scene *scene, ViewLayer *view_layer)
        float x, y, space;
        int a, b, done;
        
-       if (scene->obedit) return;  // XXX get from context
+       if (obedit) return;
        if (ID_IS_LINKED(scene)) return;
        
        for (base = FIRSTBASE(view_layer); base; base = base->next) {
index 78554713f4d1894bad99eb21aa847a9957659330..9d1792e9f16f07a529565258e331b1331b098265 100644 (file)
@@ -693,7 +693,7 @@ int ED_object_modifier_apply(ReportList *reports, const bContext *C, Scene *scen
        const WorkSpace *workspace = CTX_wm_workspace(C);
        int prev_mode;
 
-       if (scene->obedit) {
+       if (BKE_object_is_in_editmode(ob)) {
                BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied in edit mode");
                return 0;
        }
index 8e410a3abbb7528c72657818a147be4dba597472..d4fd62c6dac4e06928261e43f87b3e960cd92240 100644 (file)
@@ -1444,8 +1444,10 @@ static bool render_view3d_flag_changed(RenderEngine *engine, const bContext *C)
                job_update_flag |= PR_UPDATE_DATABASE;
 
                /* load editmesh */
-               if (scene->obedit)
-                       ED_object_editmode_load(scene->obedit);
+               Object *obedit = CTX_data_edit_object(C);
+               if (obedit) {
+                       ED_object_editmode_load(obedit);
+               }
        }
        
        engine->update_flag = 0;
index bb92ea35ad07a448a4fbc2bf506ee7aa36e9c23b..2a48ae46b1222cfbdc8ec715e3dadbceca8013b7 100644 (file)
@@ -92,8 +92,8 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
        Scene *scene = WM_window_get_active_scene(win);
        WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
        ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
-       Object *obedit = scene->obedit;
        Object *obact = (view_layer && view_layer->basact) ? view_layer->basact->object : NULL;
+       Object *obedit = BKE_workspace_edit_object(workspace, scene);
 
        if (CTX_data_dir(member)) {
                CTX_data_dir_set(result, screen_context_dir);
index 604a86a151909224d3dcf5e515723122082ace93..0d9fc7c60e324b21788e6005bf20916b1716f6c9 100644 (file)
@@ -1871,3 +1871,14 @@ Scene *ED_screen_scene_find(const bScreen *screen, const wmWindowManager *wm)
 {
        return ED_screen_scene_find_with_window(screen, wm, NULL);
 }
+
+
+wmWindow *ED_screen_window_find(const bScreen *screen, const wmWindowManager *wm)
+{
+       for (wmWindow *win = wm->windows.first; win; win = win->next) {
+               if (WM_window_get_active_screen(win) == screen) {
+                       return win;
+               }
+       }
+       return NULL;
+}
index 4d70d82d5c6e49234d686362bdbc7c361849d800..51cd759b260458170634a468b0c4eea973412916 100644 (file)
@@ -43,6 +43,7 @@
 #include "BKE_modifier.h"
 #include "BKE_object_deform.h"
 #include "BKE_report.h"
+#include "BKE_object.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -58,7 +59,6 @@ bool ED_wpaint_ensure_data(
         bContext *C, struct ReportList *reports,
         enum eWPaintFlag flag, struct WPaintVGroupIndex *vgroup_index)
 {
-       Scene *scene = CTX_data_scene(C);
        Object *ob = CTX_data_active_object(C);
        Mesh *me = BKE_mesh_from_object(ob);
 
@@ -67,7 +67,7 @@ bool ED_wpaint_ensure_data(
                vgroup_index->mirror = -1;
        }
 
-       if (scene->obedit) {
+       if (BKE_object_is_in_editmode(ob)) {
                return false;
        }
 
@@ -308,4 +308,4 @@ float ED_wpaint_blend_tool(
        }
 }
 
-/** \} */
\ No newline at end of file
+/** \} */
index 118be88216e1d8c7761f07aea9f056f243cb51fb..800560c380c67b07dff99bc3745d91b8a2746bb0 100644 (file)
@@ -54,6 +54,7 @@
 #include "BKE_paint.h"
 #include "BKE_particle.h"
 #include "BKE_editmesh.h"
+#include "BKE_object.h"
 
 #include "ED_info.h"
 #include "ED_armature.h"
@@ -374,15 +375,15 @@ static bool stats_is_object_dynamic_topology_sculpt(Object *ob, const eObjectMod
 }
 
 /* Statistics displayed in info header. Called regularly on scene changes. */
-static void stats_update(Scene *scene, ViewLayer *view_layer, const eObjectMode object_mode)
+static void stats_update(ViewLayer *view_layer, Object *obedit, const eObjectMode object_mode)
 {
        SceneStats stats = {0};
        Object *ob = (view_layer->basact) ? view_layer->basact->object : NULL;
        Base *base;
-       
-       if (scene->obedit) {
+
+       if (obedit) {
                /* Edit Mode */
-               stats_object_edit(scene->obedit, &stats);
+               stats_object_edit(ob, &stats);
        }
        else if (ob && (object_mode & OB_MODE_POSE)) {
                /* Pose Mode */
@@ -407,7 +408,7 @@ static void stats_update(Scene *scene, ViewLayer *view_layer, const eObjectMode
        *(view_layer->stats) = stats;
 }
 
-static void stats_string(Scene *scene, ViewLayer *view_layer, const eObjectMode object_mode)
+static void stats_string(ViewLayer *view_layer, Object *obedit, const eObjectMode object_mode)
 {
 #define MAX_INFO_MEM_LEN  64
        SceneStats *stats = view_layer->stats;
@@ -473,17 +474,17 @@ static void stats_string(Scene *scene, ViewLayer *view_layer, const eObjectMode
 
        ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, "%s | ", versionstr);
 
-       if (scene->obedit) {
-               if (BKE_keyblock_from_object(scene->obedit))
+       if (obedit) {
+               if (BKE_keyblock_from_object(obedit))
                        ofs += BLI_strncpy_rlen(s + ofs, IFACE_("(Key) "), MAX_INFO_LEN - ofs);
 
-               if (scene->obedit->type == OB_MESH) {
+               if (obedit->type == OB_MESH) {
                        ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs,
                                            IFACE_("Verts:%s/%s | Edges:%s/%s | Faces:%s/%s | Tris:%s"),
                                            stats_fmt.totvertsel, stats_fmt.totvert, stats_fmt.totedgesel, stats_fmt.totedge,
                                            stats_fmt.totfacesel, stats_fmt.totface, stats_fmt.tottri);
                }
-               else if (scene->obedit->type == OB_ARMATURE) {
+               else if (obedit->type == OB_ARMATURE) {
                        ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Verts:%s/%s | Bones:%s/%s"), stats_fmt.totvertsel,
                                            stats_fmt.totvert, stats_fmt.totbonesel, stats_fmt.totbone);
                }
@@ -527,12 +528,16 @@ void ED_info_stats_clear(ViewLayer *view_layer)
        }
 }
 
-const char *ED_info_stats_string(Scene *scene, WorkSpace *workspace, ViewLayer *view_layer)
+const char *ED_info_stats_string(Scene *UNUSED(scene), WorkSpace *workspace, ViewLayer *view_layer)
 {
+       Object *obact = (view_layer->basact) ? view_layer->basact->object : NULL;
+       Object *obedit = (obact && (workspace->object_mode & OB_MODE_EDIT) &&
+                         BKE_object_is_in_editmode(obact)) ? obact : NULL;
+
        if (!view_layer->stats) {
-               stats_update(scene, view_layer, workspace->object_mode);
+               stats_update(view_layer, obedit, workspace->object_mode);
        }
-       stats_string(scene, view_layer, workspace->object_mode);
+       stats_string(view_layer, obedit, workspace->object_mode);
 
        return view_layer->stats->infostr;
 }
index 3941ea85efd32e992eb5f3afff9d709dab4d59c3..73fd3f562be04a5530ee1fb68af70d2c30f8af30 100644 (file)
@@ -915,10 +915,10 @@ static void view3d_main_region_listener(
                                case ND_SELECT:
                                {
                                        WM_manipulatormap_tag_refresh(mmap);
-                                       if (scene->obedit) {
-                                               Object *ob = scene->obedit;
+                                       Object *obedit = OBEDIT_FROM_WINDOW(wmn->window);
+                                       if (obedit) {
                                                /* TODO(sergey): Notifiers shouldn't really be doing DEG tags. */
-                                               DEG_id_tag_update((ID *)ob->data, DEG_TAG_SELECT_UPDATE);
+                                               DEG_id_tag_update((ID *)obedit->data, DEG_TAG_SELECT_UPDATE);
                                        }
                                        ATTR_FALLTHROUGH;
                                }
index a21b3fd7e455ef835b2f098eb66d1fd5c9796bd9..aeb2cd11e39ca6a0cf8039d1dd89c6a034cac0b0 100644 (file)
@@ -1614,7 +1614,7 @@ static void view3d_draw_objects(
                /* draw selected and editmode */
                for (base = view_layer->object_bases.first; base; base = base->next) {
                        if ((base->flag & BASE_VISIBLED) != 0) {
-                               if ((base->object == scene->obedit) || (base->flag & BASE_SELECTED)) {
+                               if (base->object == obedit || (base->flag & BASE_SELECTED)) {
                                        draw_object(eval_ctx, scene, view_layer, ar, v3d, base, 0);
                                }
                        }
index 459727ad531b1322742ac65b4d5fbba88916dad5..1839583015c841539b1413b47cb0beaf0deca857 100644 (file)
@@ -1069,7 +1069,7 @@ static void manipulator_prepare_mat(
                        bGPdata *gpd = CTX_data_gpencil_data(C);
                        Object *ob = OBACT(view_layer);
 
-                       if (((v3d->around == V3D_AROUND_ACTIVE) && (scene->obedit == NULL)) &&
+                       if (((v3d->around == V3D_AROUND_ACTIVE) && ((workspace->object_mode & OB_MODE_EDIT) == 0)) &&
                            ((gpd == NULL) || !(gpd->flag & GP_DATA_STROKE_EDITMODE)) &&
                            (!(workspace->object_mode & OB_MODE_POSE)))
                        {
index 82da9991dda81df8e6feea6e9d6f1d86cf85784f..14cd4bcc7ac34cb9853f7e3102691ae3f595f1da 100644 (file)
@@ -822,7 +822,7 @@ static bool raycastObjects(
         Object **r_ob, float r_obmat[4][4],
         ListBase *r_hit_list)
 {
-       Object *obedit = use_object_edit_cage ? sctx->scene->obedit : NULL;
+       Object *obedit = use_object_edit_cage ? OBEDIT_FROM_EVAL_CTX(&sctx->eval_ctx) : NULL;
 
        struct RaycastObjUserData data = {
                .ray_start = ray_start,
@@ -2060,7 +2060,7 @@ static bool snapObjectsRay(
         float r_loc[3], float r_no[3],
         Object **r_ob, float r_obmat[4][4])
 {
-       Object *obedit = use_object_edit_cage ? sctx->scene->obedit : NULL;
+       Object *obedit = use_object_edit_cage ? OBEDIT_FROM_EVAL_CTX(&sctx->eval_ctx) : NULL;
 
        struct SnapObjUserData data = {
                .snapdata = snapdata,
index 4ed23f2dbe145e645601595ead0e34e03548504a..bf5f7c1d0dacf206a6d9104b74e43751df93d6fb 100644 (file)
@@ -1944,9 +1944,14 @@ extern const char *RE_engine_id_CYCLES;
 #define BASACT(_view_layer)     ((_view_layer)->basact)
 #define OBACT(_view_layer)      (BASACT(_view_layer) ? BASACT(_view_layer)->object: NULL)
 
+#define OBEDIT_FROM_WORKSPACE(workspace, _view_layer) \
+       (((workspace)->object_mode & OD_MODE_EDIT) ? OBACT(_view_layer) : NULL)
 #define OBEDIT_FROM_EVAL_CTX(eval_ctx) \
        (((eval_ctx)->object_mode & OB_MODE_EDIT) ? OBACT((eval_ctx)->view_layer) : NULL)
 
+#define OBEDIT_FROM_WINDOW(window) \
+       BKE_workspace_edit_object(WM_window_get_active_workspace(window), WM_window_get_active_scene(window))
+
 #define V3D_CAMERA_LOCAL(v3d) ((!(v3d)->scenelock && (v3d)->camera) ? (v3d)->camera : NULL)
 #define V3D_CAMERA_SCENE(scene, v3d) ((!(v3d)->scenelock && (v3d)->camera) ? (v3d)->camera : (scene)->camera)
 
index da233a18d0af1a544fd9526d5ee8f875c83f43dc..e8fc832b597e378def475a38b487b59d3eabbbfe 100644 (file)
@@ -49,6 +49,8 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DEG_depsgraph.h"
+
 #include "MOD_util.h"
 
 #ifdef __SSE2__
@@ -300,7 +302,7 @@ static void meshdeformModifier_do(
         *
         * We'll support this case once granular dependency graph is landed.
         */
-       if (mmd->object == md->scene->obedit) {
+       if (mmd->object == OBEDIT_FROM_EVAL_CTX(eval_ctx)) {
                BMEditMesh *em = BKE_editmesh_from_object(mmd->object);
                tmpdm = editbmesh_get_derived_cage_and_final(eval_ctx, md->scene, mmd->object, em, 0, &cagedm);
                if (tmpdm)
index 046a0ab27bf1a91abdbd4288d0bd9459b2585cfd..85347288872b504b0a61f0e4efb2b938beb3e585 100644 (file)
@@ -11,6 +11,8 @@
 #include "BKE_library_query.h"
 #include "BKE_modifier.h"
 
+#include "DEG_depsgraph.h"
+
 #include "MEM_guardedalloc.h"
 
 #include "MOD_util.h"
@@ -1097,7 +1099,9 @@ static void deformVert(
        }
 }
 
-static void surfacedeformModifier_do(ModifierData *md, float (*vertexCos)[3], unsigned int numverts, Object *ob)
+static void surfacedeformModifier_do(
+        ModifierData *md, const EvaluationContext *eval_ctx,
+        float (*vertexCos)[3], unsigned int numverts, Object *ob)
 {
        SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
        DerivedMesh *tdm;
@@ -1110,7 +1114,7 @@ static void surfacedeformModifier_do(ModifierData *md, float (*vertexCos)[3], un
        }
 
        /* Handle target mesh both in and out of edit mode */
-       if (smd->target == md->scene->obedit) {
+       if (smd->target == OBEDIT_FROM_EVAL_CTX(eval_ctx)) {
                BMEditMesh *em = BKE_editmesh_from_object(smd->target);
                tdm = em->derivedFinal;
        }
@@ -1180,20 +1184,22 @@ static void surfacedeformModifier_do(ModifierData *md, float (*vertexCos)[3], un
        }
 }
 
-static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx),
-                        Object *ob, DerivedMesh *UNUSED(derivedData),
-                        float (*vertexCos)[3], int numVerts,
-                        ModifierApplyFlag UNUSED(flag))
+static void deformVerts(
+        ModifierData *md, const struct EvaluationContext *eval_ctx,
+        Object *ob, DerivedMesh *UNUSED(derivedData),
+        float (*vertexCos)[3], int numVerts,
+        ModifierApplyFlag UNUSED(flag))
 {
-       surfacedeformModifier_do(md, vertexCos, numVerts, ob);
+       surfacedeformModifier_do(md, eval_ctx, vertexCos, numVerts, ob);
 }
 
-static void deformVertsEM(ModifierData *md, const struct EvaluationContext *UNUSED(eval_ctx),
-                          Object *ob, struct BMEditMesh *UNUSED(editData),
-                          DerivedMesh *UNUSED(derivedData),
-                          float (*vertexCos)[3], int numVerts)
+static void deformVertsEM(
+        ModifierData *md, const struct EvaluationContext *eval_ctx,
+        Object *ob, struct BMEditMesh *UNUSED(editData),
+        DerivedMesh *UNUSED(derivedData),
+        float (*vertexCos)[3], int numVerts)
 {
-       surfacedeformModifier_do(md, vertexCos, numVerts, ob);
+       surfacedeformModifier_do(md, eval_ctx, vertexCos, numVerts, ob);
 }
 
 static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))