diff options
Diffstat (limited to 'source/blender/editors/transform/transform_orientations.c')
-rw-r--r-- | source/blender/editors/transform/transform_orientations.c | 131 |
1 files changed, 68 insertions, 63 deletions
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 8cd31c32911..447842e9bf0 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -38,6 +38,7 @@ #include "DNA_screen_types.h" #include "DNA_space_types.h" #include "DNA_view3d_types.h" +#include "DNA_workspace_types.h" #include "BLI_math.h" #include "BLI_listbase.h" @@ -52,6 +53,8 @@ #include "BKE_report.h" #include "BKE_main.h" #include "BKE_screen.h" +#include "BKE_scene.h" +#include "BKE_workspace.h" #include "BLT_translation.h" @@ -63,14 +66,15 @@ void BIF_clearTransformOrientation(bContext *C) { + Scene *scene = CTX_data_scene(C); + ListBase *transform_orientations = &scene->transform_spaces; View3D *v3d = CTX_wm_view3d(C); - ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; - BLI_freelistN(transform_spaces); + BLI_freelistN(transform_orientations); - // Need to loop over all view3d - if (v3d && v3d->twmode >= V3D_MANIP_CUSTOM) { - v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */ + if (v3d && scene->orientation_type == V3D_MANIP_CUSTOM) { + scene->orientation_type = V3D_MANIP_GLOBAL; /* fallback to global */ + scene->orientation_index_custom = -1; } } @@ -318,23 +322,24 @@ void BIF_createTransformOrientation(bContext *C, ReportList *reports, TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], const char *name, const bool overwrite) { - ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; TransformOrientation *ts = NULL; + Scene *scene = CTX_data_scene(C); + ListBase *transform_orientations = &scene->transform_spaces; char name_unique[sizeof(ts->name)]; if (overwrite) { - ts = findOrientationName(transform_spaces, name); + ts = findOrientationName(transform_orientations, name); } else { BLI_strncpy(name_unique, name, sizeof(name_unique)); - uniqueOrientationName(transform_spaces, name_unique); + uniqueOrientationName(transform_orientations, name_unique); name = name_unique; } /* if not, create a new one */ if (ts == NULL) { ts = MEM_callocN(sizeof(TransformOrientation), "UserTransSpace from matrix"); - BLI_addtail(transform_spaces, ts); + BLI_addtail(transform_orientations, ts); BLI_strncpy(ts->name, name, sizeof(ts->name)); } @@ -346,70 +351,54 @@ TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target) { - Scene *scene = CTX_data_scene(C); - ListBase *transform_spaces = &scene->transform_spaces; - const int i = BLI_findindex(transform_spaces, target); - - if (i != -1) { - Main *bmain = CTX_data_main(C); - BKE_screen_view3d_main_twmode_remove(&bmain->screen, scene, i); - BLI_freelinkN(transform_spaces, target); - } + BKE_scene_transform_orientation_remove(CTX_data_scene(C), target); } void BIF_removeTransformOrientationIndex(bContext *C, int index) { - ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; - TransformOrientation *ts = BLI_findlink(transform_spaces, index); - - if (ts) { - BIF_removeTransformOrientation(C, ts); - } + TransformOrientation *target = BKE_scene_transform_orientation_find(CTX_data_scene(C), index); + BIF_removeTransformOrientation(C, target); } void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) { - ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; - const int i = BLI_findindex(transform_spaces, target); + Scene *scene = CTX_data_scene(C); + int index = BKE_scene_transform_orientation_get_index(scene, target); - if (i != -1) { - View3D *v3d = CTX_wm_view3d(C); - v3d->twmode = V3D_MANIP_CUSTOM + i; - } + BLI_assert(index != -1); + + scene->orientation_type = V3D_MANIP_CUSTOM; + scene->orientation_index_custom = index; } -void BIF_selectTransformOrientationValue(bContext *C, int orientation) +/** + * Activate a transform orientation in a 3D view based on an enum value. + * + * \param orientation: If this is #V3D_MANIP_CUSTOM or greater, the custom transform orientation + * with index \a orientation - #V3D_MANIP_CUSTOM gets activated. + */ +void BIF_selectTransformOrientationValue(Scene *scene, int orientation) { - View3D *v3d = CTX_wm_view3d(C); - if (v3d) /* currently using generic poll */ - v3d->twmode = orientation; + const bool is_custom = orientation >= V3D_MANIP_CUSTOM; + scene->orientation_type = is_custom ? V3D_MANIP_CUSTOM : orientation; + scene->orientation_index_custom = is_custom ? (orientation - V3D_MANIP_CUSTOM) : -1; } int BIF_countTransformOrientation(const bContext *C) { - ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; - return BLI_listbase_count(transform_spaces); + Scene *scene = CTX_data_scene(C); + ListBase *transform_orientations = &scene->transform_spaces; + return BLI_listbase_count(transform_orientations); } -bool applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name, int index) +bool applyTransformOrientation(const TransformOrientation *ts, float r_mat[3][3], char *r_name) { - ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; - TransformOrientation *ts = BLI_findlink(transform_spaces, index); - - BLI_assert(index >= 0); - - if (ts) { - if (r_name) { - BLI_strncpy(r_name, ts->name, MAX_NAME); - } - - copy_m3_m3(mat, ts->mat); - return true; - } - else { - /* invalid index, can happen sometimes */ - return false; + if (r_name) { + BLI_strncpy(r_name, ts->name, MAX_NAME); } + copy_m3_m3(r_mat, ts->mat); + + return true; } static int count_bone_select(bArmature *arm, ListBase *lb, const bool do_it) @@ -492,8 +481,20 @@ void initTransformOrientation(bContext *C, TransInfo *t) unit_m3(t->spacemtx); } break; - default: /* V3D_MANIP_CUSTOM */ - if (applyTransformOrientation(C, t->spacemtx, t->spacename, t->current_orientation - V3D_MANIP_CUSTOM)) { + case V3D_MANIP_CURSOR: + { + BLI_strncpy(t->spacename, IFACE_("cursor"), sizeof(t->spacename)); + ED_view3d_cursor3d_calc_mat3(t->scene, CTX_wm_view3d(C), t->spacemtx); + break; + } + case V3D_MANIP_CUSTOM_MATRIX: + /* Already set. */ + BLI_strncpy(t->spacename, IFACE_("custom"), sizeof(t->spacename)); + break; + case V3D_MANIP_CUSTOM: + BLI_strncpy(t->spacename, t->custom_orientation->name, sizeof(t->spacename)); + + if (applyTransformOrientation(t->custom_orientation, t->spacemtx, t->spacename)) { /* pass */ } else { @@ -586,10 +587,10 @@ static unsigned int bm_mesh_faces_select_get_n(BMesh *bm, BMVert **elems, const int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3], const short around) { - Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); Object *obedit = CTX_data_edit_object(C); Base *base; - Object *ob = OBACT; + Object *ob = OBACT(view_layer); int result = ORIENTATION_NONE; const bool activeOnly = (around == V3D_AROUND_ACTIVE); @@ -838,7 +839,8 @@ int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3 } } else { - const bool use_handle = (cu->drawflag & CU_HIDE_HANDLES) == 0; + View3D *v3d = CTX_wm_view3d(C); + const bool use_handle = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_CU_HANDLES) != 0; for (nu = nurbs->first; nu; nu = nu->next) { /* only bezier has a normal */ @@ -1056,16 +1058,16 @@ int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3 } else { /* we need the one selected object, if its not active */ - View3D *v3d = CTX_wm_view3d(C); - ob = OBACT; - if (ob && (ob->flag & SELECT)) { + base = BASACT(view_layer); + ob = OBACT(view_layer); + if (base && ((base->flag & BASE_SELECTED) != 0)) { /* pass */ } else { /* first selected */ ob = NULL; - for (base = scene->base.first; base; base = base->next) { - if (TESTBASELIB(v3d, base)) { + for (base = view_layer->object_bases.first; base; base = base->next) { + if (TESTBASELIB(base)) { ob = base->object; break; } @@ -1125,6 +1127,9 @@ void ED_getTransformOrientationMatrix(const bContext *C, float orientation_mat[3 type = ORIENTATION_NONE; } break; + default: + BLI_assert(type == ORIENTATION_NONE); + break; } if (type == ORIENTATION_NONE) { |