diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-11-25 01:37:57 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-11-25 02:40:52 +0400 |
commit | d305df2226ccdf371d127d1c4f39690042f483bd (patch) | |
tree | 320b2bd0c33b100f9df44854374101704243e624 /source | |
parent | 710f3746fcb4c599b7f833e5df66371566caa56b (diff) |
Transform: old todo, removing an orientation now checks all screens.
also fix for using uninitialized matrix when an out-of-range index is
set for custom orientations.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_screen.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/screen.c | 33 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 8 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.h | 2 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_manipulator.c | 5 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_orientations.c | 104 |
6 files changed, 80 insertions, 74 deletions
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 3c0928d38a0..9702b2ee30f 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -282,6 +282,8 @@ struct ScrArea *BKE_screen_find_big_area(struct bScreen *sc, const int spacetype void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene); void BKE_screen_view3d_scene_sync(struct bScreen *sc); void BKE_screen_view3d_main_sync(ListBase *screen_lb, struct Scene *scene); +void BKE_screen_view3d_twmode_remove(struct View3D *v3d, const int i); +void BKE_screen_view3d_main_twmode_remove(ListBase *screen_lb, struct Scene *scene, const int i); /* zoom factor conversion */ float BKE_screen_view3d_zoom_to_fac(float camzoom); diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index c41c66ef561..5b1bb7854a5 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -417,7 +417,7 @@ ScrArea *BKE_screen_find_big_area(bScreen *sc, const int spacetype, const short return big; } -void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene) +void BKE_screen_view3d_sync(View3D *v3d, struct Scene *scene) { int bit; @@ -481,6 +481,37 @@ void BKE_screen_view3d_main_sync(ListBase *screen_lb, Scene *scene) } } +void BKE_screen_view3d_twmode_remove(View3D *v3d, const int i) +{ + const int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM); + if (selected_index == i) { + v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */ + } + else if (selected_index > i) { + v3d->twmode--; + } +} + +void BKE_screen_view3d_main_twmode_remove(ListBase *screen_lb, Scene *scene, const int i) +{ + bScreen *sc; + + for (sc = screen_lb->first; sc; sc = sc->id.next) { + if (sc->scene == scene) { + ScrArea *sa; + for (sa = sc->areabase.first; sa; sa = sa->next) { + SpaceLink *sl; + for (sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + BKE_screen_view3d_twmode_remove(v3d, i); + } + } + } + } + } +} + /* magic zoom calculation, no idea what * it signifies, if you find out, tell me! -zr */ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index ad3b0df3ad8..c7e82c1fe7f 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5944,14 +5944,6 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc /* not very nice, but could help */ if ((v3d->layact & v3d->lay) == 0) v3d->layact = v3d->lay; - - /* its possible the current transform orientation has been removed */ - if (v3d->twmode >= V3D_MANIP_CUSTOM) { - const int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM); - if (!BLI_findlink(&sc->scene->transform_spaces, selected_index)) { - v3d->twmode = V3D_MANIP_GLOBAL; - } - } /* free render engines for now */ for (ar = sa->regionbase.first; ar; ar = ar->next) { diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 164ad742a0d..1e7052926b3 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -650,7 +650,7 @@ bool createSpaceNormalTangent(float mat[3][3], const float normal[3], const floa struct TransformOrientation *addMatrixSpace(struct bContext *C, float mat[3][3], const char *name, const bool overwrite); -void applyTransformOrientation(const struct bContext *C, float mat[3][3], char r_name[64]); +bool applyTransformOrientation(const struct bContext *C, float mat[3][3], char r_name[64]); #define ORIENTATION_NONE 0 #define ORIENTATION_NORMAL 1 diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c index 132a46441e6..5ac97ed4e26 100644 --- a/source/blender/editors/transform/transform_manipulator.c +++ b/source/blender/editors/transform/transform_manipulator.c @@ -642,8 +642,9 @@ int calc_manipulator_stats(const bContext *C) default: /* V3D_MANIP_CUSTOM */ { float mat[3][3]; - applyTransformOrientation(C, mat, NULL); - copy_m4_m3(rv3d->twmat, mat); + if (applyTransformOrientation(C, mat, NULL)) { + copy_m4_m3(rv3d->twmat, mat); + } break; } } diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 9a50c0c73da..c8b6144d0f1 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -26,6 +26,7 @@ #include <string.h> +#include <stddef.h> #include <ctype.h> #include "MEM_guardedalloc.h" @@ -40,7 +41,9 @@ #include "DNA_view3d_types.h" #include "BLI_math.h" -#include "BLI_blenlib.h" +#include "BLI_listbase.h" +#include "BLI_string.h" +#include "BLI_path_util.h" #include "BLI_utildefines.h" #include "BKE_action.h" @@ -49,6 +52,8 @@ #include "BKE_context.h" #include "BKE_editmesh.h" #include "BKE_report.h" +#include "BKE_main.h" +#include "BKE_screen.h" #include "BLF_translation.h" @@ -349,29 +354,15 @@ TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target) { - ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; + Scene *scene = CTX_data_scene(C); + ListBase *transform_spaces = &scene->transform_spaces; TransformOrientation *ts; - int i; - - for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) { - if (ts == target) { - View3D *v3d = CTX_wm_view3d(C); - if (v3d) { - int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM); - - // Transform_fix_me NEED TO DO THIS FOR ALL VIEW3D - if (selected_index == i) { - v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */ - } - else if (selected_index > i) { - v3d->twmode--; - } - - } + const int i = BLI_findindex(transform_spaces, target); - BLI_freelinkN(transform_spaces, ts); - break; - } + if (i != -1) { + Main *bmain = CTX_data_main(C); + BKE_screen_view3d_main_twmode_remove(&bmain->screen, scene, i); + BLI_freelinkN(transform_spaces, ts); } } @@ -381,36 +372,18 @@ void BIF_removeTransformOrientationIndex(bContext *C, int index) TransformOrientation *ts = BLI_findlink(transform_spaces, index); if (ts) { - View3D *v3d = CTX_wm_view3d(C); - if (v3d) { - int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM); - - // Transform_fix_me NEED TO DO THIS FOR ALL VIEW3D - if (selected_index == index) { - v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */ - } - else if (selected_index > index) { - v3d->twmode--; - } - - } - - BLI_freelinkN(transform_spaces, ts); + BIF_removeTransformOrientation(C, ts); } } void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) { ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; - View3D *v3d = CTX_wm_view3d(C); - TransformOrientation *ts; - int i; - - for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) { - if (ts == target) { - v3d->twmode = V3D_MANIP_CUSTOM + i; - break; - } + const int i = BLI_findindex(transform_spaces, target); + + if (i != -1) { + View3D *v3d = CTX_wm_view3d(C); + v3d->twmode = V3D_MANIP_CUSTOM + i; } } @@ -427,25 +400,27 @@ int BIF_countTransformOrientation(const bContext *C) return BLI_countlist(transform_spaces); } -void applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name) +bool applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name) { - TransformOrientation *ts; View3D *v3d = CTX_wm_view3d(C); int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM); - int i; - - if (selected_index >= 0) { - for (i = 0, ts = CTX_data_scene(C)->transform_spaces.first; ts; ts = ts->next, i++) { - if (selected_index == i) { - - if (r_name) { - BLI_strncpy(r_name, ts->name, MAX_NAME); - } - - copy_m3_m3(mat, ts->mat); - break; - } + + ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; + TransformOrientation *ts = BLI_findlink(transform_spaces, selected_index); + + BLI_assert(selected_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; } } @@ -529,7 +504,12 @@ void initTransformOrientation(bContext *C, TransInfo *t) } break; default: /* V3D_MANIP_CUSTOM */ - applyTransformOrientation(C, t->spacemtx, t->spacename); + if (applyTransformOrientation(C, t->spacemtx, t->spacename)) { + /* pass */ + } + else { + unit_m3(t->spacemtx); + } break; } } |