Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_orientations.c
| Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_workspace.h" | |||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "ED_armature.h" | #include "ED_armature.h" | ||||
| #include "transform.h" | #include "transform.h" | ||||
| /* *********************** TransSpace ************************** */ | /* *********************** TransSpace ************************** */ | ||||
| void BIF_clearTransformOrientation(bContext *C) | 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); | View3D *v3d = CTX_wm_view3d(C); | ||||
| ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | BLI_freelistN(transform_orientations); | ||||
| BLI_freelistN(transform_spaces); | |||||
| // Need to loop over all view3d | // Need to loop over all view3d | ||||
| if (v3d && v3d->twmode >= V3D_MANIP_CUSTOM) { | if (v3d && v3d->twmode == V3D_MANIP_CUSTOM) { | ||||
| v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */ | v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */ | ||||
| v3d->custom_orientation = NULL; | |||||
| } | } | ||||
| } | } | ||||
| static TransformOrientation *findOrientationName(ListBase *lb, const char *name) | static TransformOrientation *findOrientationName(ListBase *lb, const char *name) | ||||
| { | { | ||||
| return BLI_findstring(lb, name, offsetof(TransformOrientation, name)); | return BLI_findstring(lb, name, offsetof(TransformOrientation, name)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 231 Lines • ▼ Show 20 Lines | void BIF_createTransformOrientation(bContext *C, ReportList *reports, | ||||
| if (activate && ts != NULL) { | if (activate && ts != NULL) { | ||||
| BIF_selectTransformOrientation(C, ts); | BIF_selectTransformOrientation(C, ts); | ||||
| } | } | ||||
| } | } | ||||
| TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], | TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], | ||||
| const char *name, const bool overwrite) | const char *name, const bool overwrite) | ||||
| { | { | ||||
| ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | |||||
| TransformOrientation *ts = NULL; | TransformOrientation *ts = NULL; | ||||
| WorkSpace *workspace = CTX_wm_workspace(C); | |||||
| ListBase *transform_orientations = BKE_workspace_transform_orientations_get(workspace); | |||||
| char name_unique[sizeof(ts->name)]; | char name_unique[sizeof(ts->name)]; | ||||
| if (overwrite) { | if (overwrite) { | ||||
| ts = findOrientationName(transform_spaces, name); | ts = findOrientationName(transform_orientations, name); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_strncpy(name_unique, name, sizeof(name_unique)); | BLI_strncpy(name_unique, name, sizeof(name_unique)); | ||||
| uniqueOrientationName(transform_spaces, name_unique); | uniqueOrientationName(transform_orientations, name_unique); | ||||
| name = name_unique; | name = name_unique; | ||||
| } | } | ||||
| /* if not, create a new one */ | /* if not, create a new one */ | ||||
| if (ts == NULL) { | if (ts == NULL) { | ||||
| ts = MEM_callocN(sizeof(TransformOrientation), "UserTransSpace from matrix"); | 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)); | BLI_strncpy(ts->name, name, sizeof(ts->name)); | ||||
| } | } | ||||
| /* copy matrix into transform space */ | /* copy matrix into transform space */ | ||||
| copy_m3_m3(ts->mat, mat); | copy_m3_m3(ts->mat, mat); | ||||
| return ts; | return ts; | ||||
| } | } | ||||
| void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target) | void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | BKE_workspace_transform_orientation_remove(CTX_wm_workspace(C), target); | ||||
| 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); | |||||
| } | |||||
| } | } | ||||
| void BIF_removeTransformOrientationIndex(bContext *C, int index) | void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) | ||||
| { | { | ||||
| ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | View3D *v3d = CTX_wm_view3d(C); | ||||
| TransformOrientation *ts = BLI_findlink(transform_spaces, index); | |||||
| if (ts) { | BLI_assert(BLI_findindex(BKE_workspace_transform_orientations_get(CTX_wm_workspace(C)), target) != -1); | ||||
| BIF_removeTransformOrientation(C, ts); | |||||
| } | v3d->twmode = V3D_MANIP_CUSTOM; | ||||
| v3d->custom_orientation = target; | |||||
| } | } | ||||
| void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) | /** | ||||
| * 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(WorkSpace *workspace, View3D *v3d, int orientation) | |||||
| { | { | ||||
| ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | TransformOrientation *target = NULL; | ||||
| const int i = BLI_findindex(transform_spaces, target); | |||||
| if (i != -1) { | if (orientation >= V3D_MANIP_CUSTOM) { | ||||
| View3D *v3d = CTX_wm_view3d(C); | ListBase *transform_orientations = BKE_workspace_transform_orientations_get(workspace); | ||||
| v3d->twmode = V3D_MANIP_CUSTOM + i; | |||||
| } | |||||
| } | |||||
| void BIF_selectTransformOrientationValue(bContext *C, int orientation) | target = BLI_findlink(transform_orientations, orientation - V3D_MANIP_CUSTOM); | ||||
| { | orientation = V3D_MANIP_CUSTOM; | ||||
| View3D *v3d = CTX_wm_view3d(C); | } | ||||
| if (v3d) { /* currently using generic poll */ | |||||
| v3d->twmode = orientation; | v3d->twmode = orientation; | ||||
| } | v3d->custom_orientation = target; | ||||
| } | } | ||||
| int BIF_countTransformOrientation(const bContext *C) | int BIF_countTransformOrientation(const bContext *C) | ||||
| { | { | ||||
| ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | WorkSpace *workspace = CTX_wm_workspace(C); | ||||
| return BLI_listbase_count(transform_spaces); | 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) { | if (r_name) { | ||||
| BLI_strncpy(r_name, ts->name, MAX_NAME); | BLI_strncpy(r_name, ts->name, MAX_NAME); | ||||
| } | } | ||||
| copy_m3_m3(r_mat, ts->mat); | |||||
| copy_m3_m3(mat, ts->mat); | |||||
| return true; | return true; | ||||
| } | } | ||||
| else { | |||||
| /* invalid index, can happen sometimes */ | |||||
| return false; | |||||
| } | |||||
| } | |||||
| static int count_bone_select(bArmature *arm, ListBase *lb, const bool do_it) | static int count_bone_select(bArmature *arm, ListBase *lb, const bool do_it) | ||||
| { | { | ||||
| Bone *bone; | Bone *bone; | ||||
| bool do_next; | bool do_next; | ||||
| int total = 0; | int total = 0; | ||||
| for (bone = lb->first; bone; bone = bone->next) { | for (bone = lb->first; bone; bone = bone->next) { | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | case V3D_MANIP_VIEW: | ||||
| copy_m3_m4(mat, rv3d->viewinv); | copy_m3_m4(mat, rv3d->viewinv); | ||||
| normalize_m3(mat); | normalize_m3(mat); | ||||
| copy_m3_m3(t->spacemtx, mat); | copy_m3_m3(t->spacemtx, mat); | ||||
| } | } | ||||
| else { | else { | ||||
| unit_m3(t->spacemtx); | unit_m3(t->spacemtx); | ||||
| } | } | ||||
| break; | break; | ||||
| default: /* V3D_MANIP_CUSTOM */ | case V3D_MANIP_CUSTOM: | ||||
| if (applyTransformOrientation(C, t->spacemtx, t->spacename, t->current_orientation - V3D_MANIP_CUSTOM)) { | BLI_strncpy(t->spacename, t->custom_orientation->name, sizeof(t->spacename)); | ||||
| if (applyTransformOrientation(t->custom_orientation, t->spacemtx, t->spacename)) { | |||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else { | else { | ||||
| unit_m3(t->spacemtx); | unit_m3(t->spacemtx); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 584 Lines • Show Last 20 Lines | |||||