diff options
Diffstat (limited to 'source/blender/editors/transform/transform_orientations.c')
-rw-r--r-- | source/blender/editors/transform/transform_orientations.c | 128 |
1 files changed, 62 insertions, 66 deletions
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index f3078eb7824..63eea11212c 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,9 @@ #include "BKE_report.h" #include "BKE_main.h" #include "BKE_screen.h" +#include "BKE_workspace.h" + +#include "DEG_depsgraph.h" #include "BLT_translation.h" @@ -63,14 +67,16 @@ void BIF_clearTransformOrientation(bContext *C) { + WorkSpace *workspace = CTX_wm_workspace(C); + ListBase *transform_orientations = BKE_workspace_transform_orientations_get(workspace); 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 && v3d->twmode == V3D_MANIP_CUSTOM) { + v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */ + v3d->custom_orientation_index = -1; } } @@ -292,6 +298,7 @@ void BIF_createTransformOrientation(bContext *C, ReportList *reports, ts = createViewSpace(C, reports, name, overwrite); } else { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *obedit = CTX_data_edit_object(C); Object *ob = CTX_data_active_object(C); if (obedit) { @@ -302,7 +309,7 @@ void BIF_createTransformOrientation(bContext *C, ReportList *reports, else if (obedit->type == OB_CURVE) ts = createCurveSpace(C, reports, name, overwrite); } - else if (ob && (ob->mode & OB_MODE_POSE)) { + else if (ob && (workspace->object_mode & OB_MODE_POSE)) { ts = createBoneSpace(C, reports, name, overwrite); } else { @@ -318,23 +325,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; + WorkSpace *workspace = CTX_wm_workspace(C); + ListBase *transform_orientations = BKE_workspace_transform_orientations_get(workspace); 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 +354,55 @@ 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_workspace_transform_orientation_remove(CTX_wm_workspace(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_workspace_transform_orientation_find(CTX_wm_workspace(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); + int index = BKE_workspace_transform_orientation_get_index(CTX_wm_workspace(C), target); + View3D *v3d = CTX_wm_view3d(C); - if (i != -1) { - View3D *v3d = CTX_wm_view3d(C); - v3d->twmode = V3D_MANIP_CUSTOM + i; - } + BLI_assert(index != -1); + + v3d->twmode = V3D_MANIP_CUSTOM; + v3d->custom_orientation_index = 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(View3D *v3d, 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; + + v3d->twmode = is_custom ? V3D_MANIP_CUSTOM : orientation; + v3d->custom_orientation_index = 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); + WorkSpace *workspace = CTX_wm_workspace(C); + ListBase *transform_orientations = BKE_workspace_transform_orientations_get(workspace); + 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) @@ -451,13 +444,13 @@ void initTransformOrientation(bContext *C, TransInfo *t) case V3D_MANIP_GIMBAL: unit_m3(t->spacemtx); - if (ob && gimbal_axis(ob, t->spacemtx)) { + if (ob && gimbal_axis(ob, t->spacemtx, t->eval_ctx.object_mode)) { BLI_strncpy(t->spacename, IFACE_("gimbal"), sizeof(t->spacename)); break; } ATTR_FALLTHROUGH; /* no gimbal fallthrough to normal */ case V3D_MANIP_NORMAL: - if (obedit || (ob && ob->mode & OB_MODE_POSE)) { + if (obedit || (ob && t->eval_ctx.object_mode & OB_MODE_POSE)) { BLI_strncpy(t->spacename, IFACE_("normal"), sizeof(t->spacename)); ED_getTransformOrientationMatrix(C, t->spacemtx, t->around); break; @@ -492,8 +485,10 @@ 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_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 +581,11 @@ 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); + const WorkSpace *workspace = CTX_wm_workspace(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); @@ -1016,7 +1012,7 @@ int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3 mul_m3_v3(mat, plane); } } - else if (ob && (ob->mode & OB_MODE_POSE)) { + else if (ob && (workspace->object_mode & OB_MODE_POSE)) { bArmature *arm = ob->data; bPoseChannel *pchan; float imat[3][3], mat[3][3]; @@ -1056,21 +1052,21 @@ int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3 result = ORIENTATION_EDGE; } } - else if (ob && (ob->mode & (OB_MODE_ALL_PAINT | OB_MODE_PARTICLE_EDIT))) { + else if (ob && (workspace->object_mode & (OB_MODE_ALL_PAINT | OB_MODE_PARTICLE_EDIT))) { /* pass */ } 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; } |