diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-03-02 06:55:53 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-03-02 06:55:53 +0300 |
commit | eee3a4d3ab7eaa9305b1751c25e3be5c9b9b4546 (patch) | |
tree | f2d32c4defa99ca08e1ad3ea1122cae466f6b048 /source/blender/editors | |
parent | da2d0fe43af030b5fe6e11226e7e691242f001aa (diff) |
Cleanup: move ED_object_mode_generic_* to object_modes.c
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_object.h | 19 | ||||
-rw-r--r-- | source/blender/editors/object/object_edit.c | 83 | ||||
-rw-r--r-- | source/blender/editors/object/object_modes.c | 106 |
3 files changed, 115 insertions, 93 deletions
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 6c53d24ef8c..33a8ee133ea 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -152,15 +152,6 @@ void ED_object_sculptmode_exit_ex( struct WorkSpace *workspace, struct Scene *scene, struct Object *ob); void ED_object_sculptmode_exit(struct bContext *C); -bool ED_object_mode_generic_enter( - struct bContext *C, eObjectMode object_mode); -void ED_object_mode_generic_exit( - const struct EvaluationContext *eval_ctx, - struct WorkSpace *workspace, struct Scene *scene, struct Object *ob); -bool ED_object_mode_generic_has_data( - const struct EvaluationContext *eval_ctx, - struct Object *ob); - void ED_object_location_from_view(struct bContext *C, float loc[3]); void ED_object_rotation_from_view(struct bContext *C, float rot[3], const char align_axis); void ED_object_base_init_transform(struct bContext *C, struct Base *base, const float loc[3], const float rot[3]); @@ -214,10 +205,20 @@ void undo_push_lattice(struct bContext *C, const char *name); void ED_lattice_flags_set(struct Object *obedit, int flag); +/* object_modes.c */ bool ED_object_mode_compat_test(const struct Object *ob, eObjectMode mode); bool ED_object_mode_compat_set(struct bContext *C, struct WorkSpace *workspace, eObjectMode mode, struct ReportList *reports); void ED_object_mode_toggle(struct bContext *C, eObjectMode mode); +bool ED_object_mode_generic_enter( + struct bContext *C, eObjectMode object_mode); +void ED_object_mode_generic_exit( + const struct EvaluationContext *eval_ctx, + struct WorkSpace *workspace, struct Scene *scene, struct Object *ob); +bool ED_object_mode_generic_has_data( + const struct EvaluationContext *eval_ctx, + struct Object *ob); + /* object_modifier.c */ enum { MODIFIER_APPLY_DATA = 1, diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index db646472af5..cbfad27f8a2 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -1977,89 +1977,6 @@ void OBJECT_OT_game_physics_copy(struct wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -/* generic utility function */ - -bool ED_object_mode_generic_enter( - struct bContext *C, eObjectMode object_mode) -{ - WorkSpace *workspace = CTX_wm_workspace(C); - if (workspace->object_mode == object_mode) { - return true; - } - wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_mode_set", false); - PointerRNA ptr; - WM_operator_properties_create_ptr(&ptr, ot); - RNA_enum_set(&ptr, "mode", object_mode); - WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr); - WM_operator_properties_free(&ptr); - return (workspace->object_mode == object_mode); -} - -/** - * Use for changing works-paces or changing active object. - * Caller can check #OB_MODE_ALL_MODE_DATA to test if this needs to be run. - */ -static bool ed_object_mode_generic_exit_ex( - const struct EvaluationContext *eval_ctx, - struct WorkSpace *workspace, struct Scene *scene, struct Object *ob, - bool only_test) -{ - if (eval_ctx->object_mode & OB_MODE_EDIT) { - if (BKE_object_is_in_editmode(ob)) { - if (only_test) { - return true; - } - ED_object_editmode_exit_ex(NULL, workspace, scene, ob, EM_FREEDATA); - } - } - else if (eval_ctx->object_mode & OB_MODE_VERTEX_PAINT) { - if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_VERTEX_PAINT)) { - if (only_test) { - return true; - } - ED_object_vpaintmode_exit_ex(workspace, ob); - } - } - else if (eval_ctx->object_mode & OB_MODE_WEIGHT_PAINT) { - if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_WEIGHT_PAINT)) { - if (only_test) { - return true; - } - ED_object_wpaintmode_exit_ex(workspace, ob); - } - } - else if (eval_ctx->object_mode & OB_MODE_SCULPT) { - if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_SCULPT)) { - if (only_test) { - return true; - } - ED_object_sculptmode_exit_ex(eval_ctx, workspace, scene, ob); - } - } - else { - if (only_test) { - return false; - } - BLI_assert((eval_ctx->object_mode & OB_MODE_ALL_MODE_DATA) == 0); - } - - return false; -} - -void ED_object_mode_generic_exit( - const struct EvaluationContext *eval_ctx, - struct WorkSpace *workspace, struct Scene *scene, struct Object *ob) -{ - ed_object_mode_generic_exit_ex(eval_ctx, workspace, scene, ob, false); -} - -bool ED_object_mode_generic_has_data( - const struct EvaluationContext *eval_ctx, - struct Object *ob) -{ - return ed_object_mode_generic_exit_ex(eval_ctx, NULL, NULL, ob, true); -} - bool ED_object_editmode_calc_active_center(Object *obedit, const bool select_only, float r_center[3]) { switch (obedit->type) { diff --git a/source/blender/editors/object/object_modes.c b/source/blender/editors/object/object_modes.c index 3dd496336ce..8cdec2968b3 100644 --- a/source/blender/editors/object/object_modes.c +++ b/source/blender/editors/object/object_modes.c @@ -34,12 +34,23 @@ #include "BLI_utildefines.h" #include "BKE_context.h" +#include "BKE_object.h" +#include "BKE_paint.h" #include "BKE_report.h" #include "WM_api.h" #include "WM_types.h" -#include "ED_object.h" +#include "RNA_access.h" + +#include "DEG_depsgraph.h" + +#include "ED_object.h" /* own include */ + +/* -------------------------------------------------------------------- */ +/** \name High Level Mode Operations + * + * \{ */ static const char *object_mode_op_string(eObjectMode mode) { @@ -138,3 +149,96 @@ void ED_object_mode_toggle(bContext *C, eObjectMode mode) } } } + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Generic Mode Enter/Exit + * + * Supports exiting a mode without it being in the current context. + * This could be done for entering modes too if it's needed. + * + * \{ */ + +bool ED_object_mode_generic_enter( + struct bContext *C, eObjectMode object_mode) +{ + WorkSpace *workspace = CTX_wm_workspace(C); + if (workspace->object_mode == object_mode) { + return true; + } + wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_mode_set", false); + PointerRNA ptr; + WM_operator_properties_create_ptr(&ptr, ot); + RNA_enum_set(&ptr, "mode", object_mode); + WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr); + WM_operator_properties_free(&ptr); + return (workspace->object_mode == object_mode); +} + +/** + * Use for changing works-paces or changing active object. + * Caller can check #OB_MODE_ALL_MODE_DATA to test if this needs to be run. + */ +static bool ed_object_mode_generic_exit_ex( + const struct EvaluationContext *eval_ctx, + struct WorkSpace *workspace, struct Scene *scene, struct Object *ob, + bool only_test) +{ + if (eval_ctx->object_mode & OB_MODE_EDIT) { + if (BKE_object_is_in_editmode(ob)) { + if (only_test) { + return true; + } + ED_object_editmode_exit_ex(NULL, workspace, scene, ob, EM_FREEDATA); + } + } + else if (eval_ctx->object_mode & OB_MODE_VERTEX_PAINT) { + if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_VERTEX_PAINT)) { + if (only_test) { + return true; + } + ED_object_vpaintmode_exit_ex(workspace, ob); + } + } + else if (eval_ctx->object_mode & OB_MODE_WEIGHT_PAINT) { + if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_WEIGHT_PAINT)) { + if (only_test) { + return true; + } + ED_object_wpaintmode_exit_ex(workspace, ob); + } + } + else if (eval_ctx->object_mode & OB_MODE_SCULPT) { + if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_SCULPT)) { + if (only_test) { + return true; + } + ED_object_sculptmode_exit_ex(eval_ctx, workspace, scene, ob); + } + } + else { + if (only_test) { + return false; + } + BLI_assert((eval_ctx->object_mode & OB_MODE_ALL_MODE_DATA) == 0); + } + + return false; +} + +void ED_object_mode_generic_exit( + const struct EvaluationContext *eval_ctx, + struct WorkSpace *workspace, struct Scene *scene, struct Object *ob) +{ + ed_object_mode_generic_exit_ex(eval_ctx, workspace, scene, ob, false); +} + +bool ED_object_mode_generic_has_data( + const struct EvaluationContext *eval_ctx, + struct Object *ob) +{ + return ed_object_mode_generic_exit_ex(eval_ctx, NULL, NULL, ob, true); +} + +/** \} */ |