diff options
Diffstat (limited to 'source/blender/editors/transform/transform_orientations.c')
-rw-r--r-- | source/blender/editors/transform/transform_orientations.c | 98 |
1 files changed, 37 insertions, 61 deletions
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 210ab0d45a8..fb3758d2b0b 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -34,7 +34,7 @@ #include "DNA_screen_types.h" #include "DNA_view3d_types.h" -#include "BKE_utildefines.h" + #include "BKE_armature.h" #include "BKE_context.h" #include "BKE_report.h" @@ -42,6 +42,7 @@ #include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" +#include "BLI_utildefines.h" //#include "BIF_editmesh.h" //#include "BIF_interface.h" @@ -72,13 +73,12 @@ void BIF_clearTransformOrientation(bContext *C) } } -TransformOrientation* findOrientationName(bContext *C, char *name) +static TransformOrientation* findOrientationName(ListBase *lb, const char *name) { - ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; TransformOrientation *ts= NULL; - for (ts = transform_spaces->first; ts; ts = ts->next) { - if (strncmp(ts->name, name, 35) == 0) { + for (ts= lb->first; ts; ts = ts->next) { + if (strncmp(ts->name, name, sizeof(ts->name)-1) == 0) { return ts; } } @@ -86,34 +86,14 @@ TransformOrientation* findOrientationName(bContext *C, char *name) return NULL; } -void uniqueOrientationName(bContext *C, char *name) +static int uniqueOrientationNameCheck(void *arg, const char *name) { - if (findOrientationName(C, name) != NULL) - { - char tempname[64]; - int number; - char *dot; - - - number = strlen(name); - - if (number && isdigit(name[number-1])) - { - dot = strrchr(name, '.'); // last occurrence - if (dot) - *dot=0; - } + return findOrientationName((ListBase *)arg, name) != NULL; +} - for (number = 1; number <= 999; number++) - { - sprintf(tempname, "%s.%03d", name, number); - if (findOrientationName(C, tempname) == NULL) - { - BLI_strncpy(name, tempname, 32); - break; - } - } - } +static void uniqueOrientationName(ListBase *lb, char *name) +{ + BLI_uniquename_cb(uniqueOrientationNameCheck, lb, "Space", '.', name, sizeof(((TransformOrientation *)NULL)->name)); } void BIF_createTransformOrientation(bContext *C, ReportList *reports, char *name, int use, int overwrite) @@ -141,7 +121,7 @@ void BIF_createTransformOrientation(bContext *C, ReportList *reports, char *name } } -TransformOrientation *createObjectSpace(bContext *C, ReportList *reports, char *name, int overwrite) { +TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(reports), char *name, int overwrite) { Base *base = CTX_data_active_base(C); Object *ob; float mat[3][3]; @@ -287,11 +267,11 @@ TransformOrientation* addMatrixSpace(bContext *C, float mat[3][3], char name[], if (overwrite) { - ts = findOrientationName(C, name); + ts = findOrientationName(transform_spaces, name); } else { - uniqueOrientationName(C, name); + uniqueOrientationName(transform_spaces, name); } /* if not, create a new one */ @@ -310,7 +290,7 @@ TransformOrientation* addMatrixSpace(bContext *C, float mat[3][3], char name[], void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target) { ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; - TransformOrientation *ts = transform_spaces->first; + TransformOrientation *ts; int i; for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) { @@ -337,35 +317,31 @@ void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target) { void BIF_removeTransformOrientationIndex(bContext *C, int index) { ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; - TransformOrientation *ts = transform_spaces->first; - int i; - - for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) { - if (i == index) { - 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--; - } - - } + TransformOrientation *ts= BLI_findlink(transform_spaces, index); - BLI_freelinkN(transform_spaces, ts); - break; + 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); } } void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) { ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; View3D *v3d = CTX_wm_view3d(C); - TransformOrientation *ts = transform_spaces->first; + TransformOrientation *ts; int i; for (i = 0, ts = transform_spaces->first; ts; ts = ts->next, i++) { @@ -425,7 +401,7 @@ EnumPropertyItem *BIF_enumTransformOrientation(bContext *C) return item; } -char * BIF_menustringTransformOrientation(const bContext *C, char *title) { +const char * BIF_menustringTransformOrientation(const bContext *C, const char *title) { char menu[] = "%t|Global%x0|Local%x1|Gimbal%x4|Normal%x2|View%x3"; ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; TransformOrientation *ts; @@ -830,14 +806,14 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], { if (ebone->flag & BONE_SELECTED) { - float mat[3][3]; + float tmat[3][3]; float vec[3]; sub_v3_v3v3(vec, ebone->tail, ebone->head); normalize_v3(vec); add_v3_v3(normal, vec); - vec_roll_to_mat3(vec, ebone->roll, mat); - add_v3_v3(plane, mat[2]); + vec_roll_to_mat3(vec, ebone->roll, tmat); + add_v3_v3(plane, tmat[2]); } } } @@ -894,7 +870,7 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3], result = ORIENTATION_EDGE; } } - else if(ob && (ob->mode & (OB_MODE_SCULPT|OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT|OB_MODE_PARTICLE_EDIT))) + else if(ob && (ob->mode & (OB_MODE_ALL_PAINT|OB_MODE_PARTICLE_EDIT))) { } else { |