diff options
Diffstat (limited to 'source/blender/editors/util')
-rw-r--r-- | source/blender/editors/util/CMakeLists.txt | 3 | ||||
-rw-r--r-- | source/blender/editors/util/ed_transverts.c | 5 | ||||
-rw-r--r-- | source/blender/editors/util/ed_util.c | 128 | ||||
-rw-r--r-- | source/blender/editors/util/editmode_undo.c | 5 | ||||
-rw-r--r-- | source/blender/editors/util/undo.c | 51 |
5 files changed, 123 insertions, 69 deletions
diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index c0b30f93939..71a3322cb50 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -24,6 +24,7 @@ set(INC ../../blenlib ../../blentranslation ../../bmesh + ../../depsgraph ../../imbuf ../../gpu ../../makesdna @@ -64,6 +65,7 @@ set(SRC ../include/ED_lattice.h ../include/ED_logic.h ../include/ED_markers.h + ../include/ED_manipulator_library.h ../include/ED_mask.h ../include/ED_mball.h ../include/ED_mesh.h @@ -75,6 +77,7 @@ set(SRC ../include/ED_particle.h ../include/ED_physics.h ../include/ED_render.h + ../include/ED_scene.h ../include/ED_screen.h ../include/ED_screen_types.h ../include/ED_sculpt.h diff --git a/source/blender/editors/util/ed_transverts.c b/source/blender/editors/util/ed_transverts.c index b0970cdfd48..872810c5cf2 100644 --- a/source/blender/editors/util/ed_transverts.c +++ b/source/blender/editors/util/ed_transverts.c @@ -39,12 +39,13 @@ #include "BLI_math.h" #include "BKE_curve.h" -#include "BKE_depsgraph.h" #include "BKE_lattice.h" #include "BKE_editmesh.h" #include "BKE_DerivedMesh.h" #include "BKE_context.h" +#include "DEG_depsgraph.h" + #include "ED_armature.h" #include "ED_transverts.h" /* own include */ @@ -56,7 +57,7 @@ void ED_transverts_update_obedit(TransVertStore *tvs, Object *obedit) const int mode = tvs->mode; BLI_assert(ED_transverts_check_obedit(obedit) == true); - DAG_id_tag_update(obedit->data, 0); + DEG_id_tag_update(obedit->data, 0); if (obedit->type == OB_MESH) { BMEditMesh *em = BKE_editmesh_from_object(obedit); diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 57ff8b6db01..7a5b8bfbda1 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -35,12 +35,14 @@ #include "MEM_guardedalloc.h" +#include "DNA_armature_types.h" #include "DNA_mesh_types.h" #include "DNA_object_types.h" #include "DNA_screen_types.h" #include "DNA_space_types.h" #include "DNA_scene_types.h" #include "DNA_packedFile_types.h" +#include "DNA_workspace_types.h" #include "BLI_utildefines.h" #include "BLI_string.h" @@ -58,6 +60,8 @@ #include "BKE_packedFile.h" #include "BKE_paint.h" #include "BKE_screen.h" +#include "BKE_workspace.h" +#include "BKE_layer.h" #include "ED_armature.h" #include "ED_buttons.h" @@ -70,6 +74,10 @@ #include "ED_space_api.h" #include "ED_util.h" +#include "DEG_depsgraph.h" + +#include "GPU_immediate.h" + #include "UI_interface.h" #include "UI_resources.h" @@ -84,10 +92,6 @@ void ED_editors_init(bContext *C) { wmWindowManager *wm = CTX_wm_manager(C); - Main *bmain = CTX_data_main(C); - Scene *sce = CTX_data_scene(C); - Object *ob, *obact = (sce && sce->basact) ? sce->basact->object : NULL; - ID *data; /* This is called during initialization, so we don't want to store any reports */ ReportList *reports = CTX_wm_reports(C); @@ -95,24 +99,45 @@ void ED_editors_init(bContext *C) SWAP(int, reports->flag, reports_flag_prev); + /* toggle on modes for objects that were saved with these enabled. for * e.g. linked objects we have to ensure that they are actually the * active object in this scene. */ - for (ob = bmain->object.first; ob; ob = ob->id.next) { - int mode = ob->mode; - - if (!ELEM(mode, OB_MODE_OBJECT, OB_MODE_POSE)) { - ob->mode = OB_MODE_OBJECT; - data = ob->data; - - if (ob == obact && !ID_IS_LINKED(ob) && !(data && ID_IS_LINKED(data))) - ED_object_mode_toggle(C, mode); + { + wmWindow *win_orig = CTX_wm_window(C); + CTX_wm_window_set(C, NULL); + for (wmWindow *win = wm->windows.first; win; win = win->next) { + WorkSpace *workspace = WM_window_get_active_workspace(win); + Scene *scene = WM_window_get_active_scene(win); + ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace); + Object *obact = view_layer ? OBACT(view_layer) : NULL; + eObjectMode object_mode = workspace->object_mode; + workspace->object_mode = OB_MODE_OBJECT; + if (view_layer && obact) { + const ID *data = obact->data; + if (!ELEM(object_mode, OB_MODE_OBJECT, OB_MODE_POSE)) { + if (!ID_IS_LINKED(obact) && !(data && ID_IS_LINKED(data))) { + CTX_wm_window_set(C, win); + ED_object_mode_toggle(C, object_mode); + CTX_wm_window_set(C, NULL); + } + } + else if (object_mode == OB_MODE_POSE) { + if (!ID_IS_LINKED(obact) && (obact->type == OB_ARMATURE)) { + workspace->object_mode = object_mode; + } + } + } } + CTX_wm_window_set(C, win_orig); } /* image editor paint mode */ - if (sce) { - ED_space_image_paint_update(wm, sce); + { + Scene *sce = CTX_data_scene(C); + if (sce) { + ED_space_image_paint_update(wm, sce); + } } SWAP(int, reports->flag, reports_flag_prev); @@ -122,7 +147,6 @@ void ED_editors_init(bContext *C) void ED_editors_exit(bContext *C) { Main *bmain = CTX_data_main(C); - Scene *sce; if (!bmain) return; @@ -130,23 +154,20 @@ void ED_editors_exit(bContext *C) /* frees all editmode undos */ undo_editmode_clear(); ED_undo_paint_free(); - - for (sce = bmain->scene.first; sce; sce = sce->id.next) { - if (sce->obedit) { - Object *ob = sce->obedit; - - if (ob) { - if (ob->type == OB_MESH) { - Mesh *me = ob->data; - if (me->edit_btmesh) { - EDBM_mesh_free(me->edit_btmesh); - MEM_freeN(me->edit_btmesh); - me->edit_btmesh = NULL; - } - } - else if (ob->type == OB_ARMATURE) { - ED_armature_edit_free(ob->data); - } + + for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { + if (ob->type == OB_MESH) { + Mesh *me = ob->data; + if (me->edit_btmesh) { + EDBM_mesh_free(me->edit_btmesh); + MEM_freeN(me->edit_btmesh); + me->edit_btmesh = NULL; + } + } + else if (ob->type == OB_ARMATURE) { + bArmature *arm = ob->data; + if (arm->edbo) { + ED_armature_edit_free(ob->data); } } } @@ -164,11 +185,16 @@ bool ED_editors_flush_edits(const bContext *C, bool for_render) Object *ob; Main *bmain = CTX_data_main(C); + eObjectMode object_mode = WM_windows_object_mode_get(bmain->wm.first); + if ((object_mode & (OB_MODE_SCULPT | OB_MODE_EDIT)) == 0) { + return has_edited; + } + /* loop through all data to find edit mode or object mode, because during * exiting we might not have a context for edit object and multiple sculpt * objects can exist at the same time */ for (ob = bmain->object.first; ob; ob = ob->id.next) { - if (ob->mode & OB_MODE_SCULPT) { + if (object_mode & OB_MODE_SCULPT) { /* Don't allow flushing while in the middle of a stroke (frees data in use). * Auto-save prevents this from happening but scripts may cause a flush on saving: T53986. */ if ((ob->sculpt && ob->sculpt->cache) == 0) { @@ -187,7 +213,7 @@ bool ED_editors_flush_edits(const bContext *C, bool for_render) } } } - else if (ob->mode & OB_MODE_EDIT) { + else if (object_mode & OB_MODE_EDIT) { /* get editmode results */ has_edited = true; ED_object_editmode_load(ob); @@ -317,16 +343,28 @@ void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *ar, void *arg_info { wmWindow *win = CTX_wm_window(C); const float *mval_src = (float *)arg_info; - const int mval_dst[2] = {win->eventstate->x - ar->winrct.xmin, - win->eventstate->y - ar->winrct.ymin}; - - UI_ThemeColor(TH_VIEW_OVERLAY); - setlinestyle(3); - glBegin(GL_LINES); - glVertex2iv(mval_dst); - glVertex2fv(mval_src); - glEnd(); - setlinestyle(0); + const float mval_dst[2] = {win->eventstate->x - ar->winrct.xmin, + win->eventstate->y - ar->winrct.ymin}; + + const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); + + float viewport_size[4]; + glGetFloatv(GL_VIEWPORT, viewport_size); + immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); + + immUniform1i("num_colors", 0); /* "simple" mode */ + immUniformThemeColor(TH_VIEW_OVERLAY); + immUniform1f("dash_width", 6.0f); + immUniform1f("dash_factor", 0.5f); + + immBegin(GWN_PRIM_LINES, 2); + immVertex2fv(shdr_pos, mval_src); + immVertex2fv(shdr_pos, mval_dst); + immEnd(); + + immUnbindProgram(); } /** diff --git a/source/blender/editors/util/editmode_undo.c b/source/blender/editors/util/editmode_undo.c index fa697a0f006..43d1bfe1e6c 100644 --- a/source/blender/editors/util/editmode_undo.c +++ b/source/blender/editors/util/editmode_undo.c @@ -42,9 +42,10 @@ #include "BKE_blender_undo.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_global.h" +#include "DEG_depsgraph.h" + #include "ED_util.h" #include "ED_mesh.h" @@ -268,7 +269,7 @@ void undo_editmode_step(bContext *C, int step) EDBM_selectmode_to_scene(C); } - DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); + DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); /* XXX notifiers */ } diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c index d791818331e..b7101e7ae99 100644 --- a/source/blender/editors/util/undo.c +++ b/source/blender/editors/util/undo.c @@ -45,9 +45,12 @@ #include "BKE_blender_undo.h" #include "BKE_context.h" #include "BKE_global.h" +#include "BKE_library_override.h" #include "BKE_main.h" #include "BKE_screen.h" +#include "DEG_depsgraph.h" + #include "ED_armature.h" #include "ED_particle.h" #include "ED_curve.h" @@ -77,12 +80,16 @@ void ED_undo_push(bContext *C, const char *str) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *obedit = CTX_data_edit_object(C); Object *obact = CTX_data_active_object(C); if (G.debug & G_DEBUG) printf("%s: %s\n", __func__, str); + /* Always do it for now, this might need to be refined... */ + BKE_main_override_static_operations_create(CTX_data_main(C)); + if (obedit) { if (U.undosteps == 0) return; @@ -99,12 +106,12 @@ void ED_undo_push(bContext *C, const char *str) else if (obedit->type == OB_ARMATURE) undo_push_armature(C, str); } - else if (obact && obact->mode & OB_MODE_PARTICLE_EDIT) { + else if (obact && workspace->object_mode & OB_MODE_PARTICLE_EDIT) { if (U.undosteps == 0) return; - PE_undo_push(CTX_data_scene(C), str); + PE_undo_push(CTX_data_scene(C), CTX_data_view_layer(C), str); } - else if (obact && obact->mode & OB_MODE_SCULPT) { + else if (obact && workspace->object_mode & OB_MODE_SCULPT) { /* do nothing for now */ } else { @@ -117,10 +124,12 @@ void ED_undo_push(bContext *C, const char *str) /* note: also check undo_history_exec() in bottom if you change notifiers */ static int ed_undo_step(bContext *C, int step, const char *undoname) { + const WorkSpace *workspace = CTX_wm_workspace(C); wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win = CTX_wm_window(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); Object *obedit = CTX_data_edit_object(C); Object *obact = CTX_data_active_object(C); ScrArea *sa = CTX_wm_area(C); @@ -139,7 +148,7 @@ static int ed_undo_step(bContext *C, int step, const char *undoname) if (sa && (sa->spacetype == SPACE_IMAGE)) { SpaceImage *sima = (SpaceImage *)sa->spacedata.first; - if ((obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) || (sima->mode == SI_MODE_PAINT)) { + if ((obact && (workspace->object_mode & OB_MODE_TEXTURE_PAINT)) || (sima->mode == SI_MODE_PAINT)) { if (!ED_undo_paint_step(C, UNDO_PAINT_IMAGE, step, undoname) && undoname) { if (U.uiflag & USER_GLOBALUNDO) { ED_viewport_render_kill_jobs(wm, bmain, true); @@ -173,17 +182,17 @@ static int ed_undo_step(bContext *C, int step, const char *undoname) * That was inconsistent with editmode, and also makes for * unecessarily tricky interaction with the other undo * systems. */ - if (obact && obact->mode & OB_MODE_TEXTURE_PAINT) { + if (obact && workspace->object_mode & OB_MODE_TEXTURE_PAINT) { ED_undo_paint_step(C, UNDO_PAINT_IMAGE, step, undoname); } - else if (obact && obact->mode & OB_MODE_SCULPT) { + else if (obact && workspace->object_mode & OB_MODE_SCULPT) { ED_undo_paint_step(C, UNDO_PAINT_MESH, step, undoname); } - else if (obact && obact->mode & OB_MODE_PARTICLE_EDIT) { + else if (obact && workspace->object_mode & OB_MODE_PARTICLE_EDIT) { if (step == 1) - PE_undo(scene); + PE_undo(scene, view_layer); else - PE_redo(scene); + PE_redo(scene, view_layer); } else if (U.uiflag & USER_GLOBALUNDO) { // note python defines not valid here anymore. @@ -265,6 +274,7 @@ void ED_undo_pop_op(bContext *C, wmOperator *op) /* name optionally, function used to check for operator redo panel */ bool ED_undo_is_valid(const bContext *C, const char *undoname) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *obedit = CTX_data_edit_object(C); Object *obact = CTX_data_active_object(C); ScrArea *sa = CTX_wm_area(C); @@ -272,7 +282,7 @@ bool ED_undo_is_valid(const bContext *C, const char *undoname) if (sa && sa->spacetype == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)sa->spacedata.first; - if ((obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) || (sima->mode == SI_MODE_PAINT)) { + if ((obact && (workspace->object_mode & OB_MODE_TEXTURE_PAINT)) || (sima->mode == SI_MODE_PAINT)) { return 1; } } @@ -289,16 +299,16 @@ bool ED_undo_is_valid(const bContext *C, const char *undoname) /* if below tests fail, global undo gets executed */ - if (obact && obact->mode & OB_MODE_TEXTURE_PAINT) { + if (obact && workspace->object_mode & OB_MODE_TEXTURE_PAINT) { if (ED_undo_paint_is_valid(UNDO_PAINT_IMAGE, undoname)) return 1; } - else if (obact && obact->mode & OB_MODE_SCULPT) { + else if (obact && workspace->object_mode & OB_MODE_SCULPT) { if (ED_undo_paint_is_valid(UNDO_PAINT_MESH, undoname)) return 1; } - else if (obact && obact->mode & OB_MODE_PARTICLE_EDIT) { - return PE_undo_is_valid(CTX_data_scene(C)); + else if (obact && workspace->object_mode & OB_MODE_PARTICLE_EDIT) { + return PE_undo_is_valid(CTX_data_scene(C), CTX_data_view_layer(C)); } if (U.uiflag & USER_GLOBALUNDO) { @@ -493,6 +503,7 @@ enum { static int get_undo_system(bContext *C) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *obact = CTX_data_active_object(C); Object *obedit = CTX_data_edit_object(C); ScrArea *sa = CTX_wm_area(C); @@ -501,7 +512,7 @@ static int get_undo_system(bContext *C) if (sa && (sa->spacetype == SPACE_IMAGE)) { SpaceImage *sima = (SpaceImage *)sa->spacedata.first; - if ((obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) || (sima->mode == SI_MODE_PAINT)) { + if ((obact && (workspace->object_mode & OB_MODE_TEXTURE_PAINT)) || (sima->mode == SI_MODE_PAINT)) { if (!ED_undo_paint_empty(UNDO_PAINT_IMAGE)) return UNDOSYSTEM_IMAPAINT; } @@ -514,13 +525,13 @@ static int get_undo_system(bContext *C) } else { if (obact) { - if (obact->mode & OB_MODE_PARTICLE_EDIT) + if (workspace->object_mode & OB_MODE_PARTICLE_EDIT) return UNDOSYSTEM_PARTICLE; - else if (obact->mode & OB_MODE_TEXTURE_PAINT) { + else if (workspace->object_mode & OB_MODE_TEXTURE_PAINT) { if (!ED_undo_paint_empty(UNDO_PAINT_IMAGE)) return UNDOSYSTEM_IMAPAINT; } - else if (obact->mode & OB_MODE_SCULPT) { + else if (workspace->object_mode & OB_MODE_SCULPT) { if (!ED_undo_paint_empty(UNDO_PAINT_MESH)) return UNDOSYSTEM_SCULPT; } @@ -543,7 +554,7 @@ static const EnumPropertyItem *rna_undo_itemf(bContext *C, int undosys, int *tot const char *name = NULL; if (undosys == UNDOSYSTEM_PARTICLE) { - name = PE_undo_get_name(CTX_data_scene(C), i, &active); + name = PE_undo_get_name(CTX_data_scene(C), CTX_data_view_layer(C), i, &active); } else if (undosys == UNDOSYSTEM_EDITMODE) { name = undo_editmode_get_name(C, i, &active); @@ -626,7 +637,7 @@ static int undo_history_exec(bContext *C, wmOperator *op) int item = RNA_int_get(op->ptr, "item"); if (undosys == UNDOSYSTEM_PARTICLE) { - PE_undo_number(CTX_data_scene(C), item); + PE_undo_number(CTX_data_scene(C), CTX_data_view_layer(C), item); } else if (undosys == UNDOSYSTEM_EDITMODE) { undo_editmode_number(C, item + 1); |