diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-03-21 18:12:04 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-03-21 18:12:04 +0400 |
commit | 401fdf5065bf8180833cf789ac4e5bfbc6ce1a8c (patch) | |
tree | 8f08cdd7e0f6c07e456756fd0bd1b3e1aa282801 | |
parent | fa0e2603f507f14fb341f1e6b0a8d30d798cf274 (diff) |
py api: add Object.update_from_editmode(),
Useful for python exporters to avoid toggling editmode on export, moved into own function ED_object_editmode_load(obedit).
-rw-r--r-- | source/blender/editors/include/ED_object.h | 1 | ||||
-rw-r--r-- | source/blender/editors/io/io_collada.c | 2 | ||||
-rw-r--r-- | source/blender/editors/object/object_bake.c | 2 | ||||
-rw-r--r-- | source/blender/editors/object/object_edit.c | 56 | ||||
-rw-r--r-- | source/blender/editors/render/render_internal.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object_api.c | 13 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 4 |
7 files changed, 57 insertions, 23 deletions
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 43bff7ce9ee..8a37b1bf4ad 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -130,6 +130,7 @@ void ED_object_toggle_modes(struct bContext *C, int mode); #define EM_IGNORE_LAYER 16 void ED_object_exit_editmode(struct bContext *C, int flag); void ED_object_enter_editmode(struct bContext *C, int flag); +bool ED_object_editmode_load(struct Object *obedit); void ED_object_location_from_view(struct bContext *C, float loc[3]); void ED_object_rotation_from_view(struct bContext *C, float rot[3]); diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index c673e0fb2b0..a1bb7a8ae88 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -127,7 +127,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) second_life = RNA_boolean_get(op->ptr, "second_life"); /* get editmode results */ - ED_object_exit_editmode(C, 0); /* 0 = does not exit editmode */ + ED_object_editmode_load(CTX_data_edit_object(C)); if (collada_export(CTX_data_scene(C), filepath, diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c index dc54207b4e6..8c8e4878166 100644 --- a/source/blender/editors/object/object_bake.c +++ b/source/blender/editors/object/object_bake.c @@ -572,7 +572,7 @@ static void init_bake_internal(BakeRender *bkr, bContext *C) bScreen *sc = CTX_wm_screen(C); /* get editmode results */ - ED_object_exit_editmode(C, 0); /* 0 = does not exit editmode */ + ED_object_editmode_load(CTX_data_edit_object(C)); bkr->sa = sc ? BKE_screen_find_big_area(sc, SPACE_IMAGE, 10) : NULL; /* can be NULL */ bkr->main = CTX_data_main(C); diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index ca57ab76c57..b21bbdb0b92 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -312,29 +312,26 @@ void OBJECT_OT_hide_render_set(wmOperatorType *ot) /* ******************* toggle editmode operator ***************** */ -void ED_object_exit_editmode(bContext *C, int flag) +/** + * Load EditMode data back into the object, + * optionally freeing the editmode data. + */ +static bool ED_object_editmode_load_ex(Object *obedit, const bool freedata) { - /* Note! only in exceptional cases should 'EM_DO_UNDO' NOT be in the flag */ + if (obedit == NULL) { + return false; + } - Scene *scene = CTX_data_scene(C); - Object *obedit = CTX_data_edit_object(C); - int freedata = flag & EM_FREEDATA; - - if (obedit == NULL) return; - - if (flag & EM_WAITCURSOR) waitcursor(1); if (obedit->type == OB_MESH) { Mesh *me = obedit->data; - -// if (EM_texFaceCheck()) - + if (me->edit_btmesh->bm->totvert > MESH_MAX_VERTS) { error("Too many vertices"); - return; + return false; } - + EDBM_mesh_load(obedit); - + if (freedata) { EDBM_mesh_free(me->edit_btmesh); MEM_freeN(me->edit_btmesh); @@ -367,6 +364,29 @@ void ED_object_exit_editmode(bContext *C, int flag) if (freedata) free_editMball(obedit); } + return true; +} + +bool ED_object_editmode_load(Object *obedit) +{ + return ED_object_editmode_load_ex(obedit, false); +} + +void ED_object_exit_editmode(bContext *C, int flag) +{ + /* Note! only in exceptional cases should 'EM_DO_UNDO' NOT be in the flag */ + /* Note! if 'EM_FREEDATA' isn't in the flag, use ED_object_editmode_load directly */ + Scene *scene = CTX_data_scene(C); + Object *obedit = CTX_data_edit_object(C); + const bool freedata = (flag & EM_FREEDATA) != 0; + + if (flag & EM_WAITCURSOR) waitcursor(1); + + if (ED_object_editmode_load_ex(obedit, freedata) == false) { + if (flag & EM_WAITCURSOR) waitcursor(0); + return; + } + /* freedata only 0 now on file saves and render */ if (freedata) { ListBase pidlist; @@ -390,13 +410,13 @@ void ED_object_exit_editmode(bContext *C, int flag) if (flag & EM_DO_UNDO) ED_undo_push(C, "Editmode"); - - if (flag & EM_WAITCURSOR) waitcursor(0); - + WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene); obedit->mode &= ~OB_MODE_EDIT; } + + if (flag & EM_WAITCURSOR) waitcursor(0); } diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index b138bc63a68..1268d577f44 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -542,7 +542,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even BKE_sequencer_cache_cleanup(); /* get editmode results */ - ED_object_exit_editmode(C, 0); /* 0 = does not exit editmode */ + ED_object_editmode_load(CTX_data_edit_object(C)); // store spare // get view3d layer, local layer, make this nice api call to render diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 2b7df1ca317..e7e8821a2f9 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -391,6 +391,14 @@ void rna_Object_dm_info(struct Object *ob, int type, char *result) } } } + +static int rna_Object_update_from_editmode(Object *ob) +{ + if (ob->mode & OB_MODE_EDIT) { + return ED_object_editmode_load(ob); + } + return false; +} #endif /* NDEBUG */ #else /* RNA_RUNTIME */ @@ -567,6 +575,11 @@ void RNA_api_object(StructRNA *srna) RNA_def_property_flag(parm, PROP_THICK_WRAP); /* needed for string return value */ RNA_def_function_output(func, parm); #endif /* NDEBUG */ + + func = RNA_def_function(srna, "update_from_editmode", "rna_Object_update_from_editmode"); + RNA_def_function_ui_description(func, "Load the objects edit-mode data intp the object data"); + parm = RNA_def_boolean(func, "result", 0, "", "Success"); + RNA_def_function_return(func, parm); } diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 66f6dc7de92..7152adb4a11 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -829,8 +829,8 @@ int wm_file_write(bContext *C, const char *target, int fileflags, ReportList *re if (G.fileflags & G_AUTOPACK) { packAll(G.main, reports); } - - ED_object_exit_editmode(C, EM_DO_UNDO); + + ED_object_editmode_load(CTX_data_edit_object(C)); ED_sculpt_force_update(C); /* don't forget not to return without! */ |