Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_orientations.c
| Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
| #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; | 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 232 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) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | BKE_workspace_transform_orientation_remove(CTX_wm_workspace(C), target); | ||||
| Scene *scene = CTX_data_scene(C); | |||||
| ListBase *transform_spaces = &scene->transform_spaces; | |||||
| BLI_assert(BLI_findindex(transform_spaces, target) != -1); | |||||
| BKE_workspaces_transform_orientation_remove(&bmain->workspaces, target); | |||||
| BLI_freelinkN(transform_spaces, target); | |||||
| } | } | ||||
| void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) | void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) | ||||
| { | { | ||||
| ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | WorkSpace *workspace = CTX_wm_workspace(C); | ||||
| const int i = BLI_findindex(transform_spaces, target); | ListBase *transform_orientations = BKE_workspace_transform_orientations_get(workspace); | ||||
| const int i = BLI_findindex(transform_orientations, target); | |||||
| if (i != -1) { | if (i != -1) { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| v3d->twmode = V3D_MANIP_CUSTOM + i; | v3d->twmode = V3D_MANIP_CUSTOM; | ||||
| v3d->custom_orientation = target; | v3d->custom_orientation = target; | ||||
| } | } | ||||
| } | } | ||||
| 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(WorkSpace *workspace, View3D *v3d, int orientation) | |||||
| { | { | ||||
| View3D *v3d = CTX_wm_view3d(C); | TransformOrientation *target = NULL; | ||||
| if (v3d) { /* currently using generic poll */ | if (orientation >= V3D_MANIP_CUSTOM) { | ||||
| Scene *scene = CTX_data_scene(C); | ListBase *transform_orientations = BKE_workspace_transform_orientations_get(workspace); | ||||
| TransformOrientation *target = BLI_findlink(&scene->transform_spaces, orientation - V3D_MANIP_CUSTOM); | |||||
| target = BLI_findlink(transform_orientations, orientation - V3D_MANIP_CUSTOM); | |||||
| orientation = V3D_MANIP_CUSTOM; | |||||
| } | |||||
| v3d->twmode = orientation; | v3d->twmode = orientation; | ||||
| v3d->custom_orientation = target; | 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 TransformOrientation *ts, float r_mat[3][3], char *r_name) | bool applyTransformOrientation(const TransformOrientation *ts, float r_mat[3][3], char *r_name) | ||||
| { | { | ||||
| if (ts) { | if (ts) { | ||||
| if (r_name) { | if (r_name) { | ||||
| BLI_strncpy(r_name, ts->name, MAX_NAME); | BLI_strncpy(r_name, ts->name, MAX_NAME); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 82 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: | ||||
| { | { | ||||
| TransformOrientation *ts = BLI_findlink( | BLI_strncpy(t->spacename, t->custom_orientation->name, sizeof(t->spacename)); | ||||
| &t->scene->transform_spaces, | |||||
| t->current_orientation - V3D_MANIP_CUSTOM); | |||||
| if (applyTransformOrientation(ts, t->spacemtx, 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 585 Lines • Show Last 20 Lines | |||||