Transform: internal changes for orientations calculations.

- use (const char *) for the 'name'
- use bool where possible.
- remove unused return value for initTransInfo
This commit is contained in:
Campbell Barton 2013-11-25 07:49:49 +11:00
parent cbb5a12eb7
commit 4a6802b00b
5 changed files with 57 additions and 58 deletions

View File

@ -121,8 +121,9 @@ struct ReportList;
void BIF_clearTransformOrientation(struct bContext *C);
void BIF_removeTransformOrientation(struct bContext *C, struct TransformOrientation *ts);
void BIF_removeTransformOrientationIndex(struct bContext *C, int index);
void BIF_createTransformOrientation(struct bContext *C, struct ReportList *reports, char *name, int use_view,
int use, int overwrite);
void BIF_createTransformOrientation(struct bContext *C, struct ReportList *reports,
const char *name, const bool use_view,
const bool activate, const bool overwrite);
void BIF_selectTransformOrientation(struct bContext *C, struct TransformOrientation *ts);
void BIF_selectTransformOrientationValue(struct bContext *C, int orientation);

View File

@ -1468,7 +1468,7 @@ int calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], float
t->mode = TFM_DUMMY;
initTransInfo(C, t, NULL, NULL); // internal data, mouse, vectors
initTransInfo(C, t, NULL, NULL);
/* avoid doing connectivity lookups (when V3D_LOCAL is set) */
t->around = V3D_CENTER;
@ -1970,9 +1970,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
t->launch_event = LEFTMOUSE;
}
if (!initTransInfo(C, t, op, event)) { /* internal data, mouse, vectors */
return 0;
}
initTransInfo(C, t, op, event);
if (t->spacetype == SPACE_VIEW3D) {
//calc_manipulator_stats(curarea);

View File

@ -615,7 +615,7 @@ void setInputPostFct(MouseInput *mi, void (*post)(struct TransInfo *t, float val
/*********************** Generics ********************************/
int initTransInfo(struct bContext *C, TransInfo *t, struct wmOperator *op, const struct wmEvent *event);
void initTransInfo(struct bContext *C, TransInfo *t, struct wmOperator *op, const struct wmEvent *event);
void postTrans(struct bContext *C, TransInfo *t);
void resetTransModal(TransInfo *t);
void resetTransRestrictions(TransInfo *t);
@ -648,8 +648,9 @@ void initTransformOrientation(struct bContext *C, TransInfo *t);
bool createSpaceNormal(float mat[3][3], const float normal[3]);
bool createSpaceNormalTangent(float mat[3][3], const float normal[3], const float tangent[3]);
struct TransformOrientation *addMatrixSpace(struct bContext *C, float mat[3][3], char name[], int overwrite);
void applyTransformOrientation(const struct bContext *C, float mat[3][3], char *name);
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]);
#define ORIENTATION_NONE 0
#define ORIENTATION_NORMAL 1
@ -657,7 +658,7 @@ void applyTransformOrientation(const struct bContext *C, float mat[3][3], char *
#define ORIENTATION_EDGE 3
#define ORIENTATION_FACE 4
int getTransformOrientation(const struct bContext *C, float normal[3], float plane[3], int activeOnly);
int getTransformOrientation(const struct bContext *C, float normal[3], float plane[3], const bool activeOnly);
void freeEdgeSlideTempFaces(EdgeSlideData *sld);
void freeEdgeSlideVerts(TransInfo *t);

View File

@ -1029,8 +1029,12 @@ static int initTransInfo_edit_pet_to_flag(const int proportional)
}
}
/* the *op can be NULL */
int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event)
/**
* Setup internal data, mouse, vectors
*
* \note \a op and \a event can be NULL
*/
void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event)
{
Scene *sce = CTX_data_scene(C);
ToolSettings *ts = CTX_data_tool_settings(C);
@ -1321,8 +1325,6 @@ int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
setTransformViewMatrices(t);
initNumInput(&t->num);
return 1;
}
/* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */

View File

@ -78,15 +78,7 @@ void BIF_clearTransformOrientation(bContext *C)
static TransformOrientation *findOrientationName(ListBase *lb, const char *name)
{
TransformOrientation *ts = NULL;
for (ts = lb->first; ts; ts = ts->next) {
if (strncmp(ts->name, name, sizeof(ts->name) - 1) == 0) {
return ts;
}
}
return NULL;
return BLI_findstring(lb, name, offsetof(TransformOrientation, name));
}
static bool uniqueOrientationNameCheck(void *arg, const char *name)
@ -100,7 +92,8 @@ static void uniqueOrientationName(ListBase *lb, char *name)
sizeof(((TransformOrientation *)NULL)->name));
}
static TransformOrientation *createViewSpace(bContext *C, ReportList *UNUSED(reports), char *name, int overwrite)
static TransformOrientation *createViewSpace(bContext *C, ReportList *UNUSED(reports),
const char *name, const bool overwrite)
{
RegionView3D *rv3d = CTX_wm_region_view3d(C);
float mat[3][3];
@ -111,21 +104,22 @@ static TransformOrientation *createViewSpace(bContext *C, ReportList *UNUSED(rep
copy_m3_m4(mat, rv3d->viewinv);
normalize_m3(mat);
if (!name[0]) {
if (name[0] == 0) {
View3D *v3d = CTX_wm_view3d(C);
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
/* If an object is used as camera, then this space is the same as object space! */
BLI_strncpy(name, v3d->camera->id.name + 2, MAX_NAME);
name = v3d->camera->id.name + 2;
}
else {
strcpy(name, "Custom View");
name = "Custom View";
}
}
return addMatrixSpace(C, mat, name, overwrite);
}
static TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(reports), char *name, int overwrite)
static TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(reports),
const char *name, const bool overwrite)
{
Base *base = CTX_data_active_base(C);
Object *ob;
@ -141,13 +135,14 @@ static TransformOrientation *createObjectSpace(bContext *C, ReportList *UNUSED(r
/* use object name if no name is given */
if (name[0] == 0) {
BLI_strncpy(name, ob->id.name + 2, MAX_ID_NAME - 2);
name = ob->id.name + 2;
}
return addMatrixSpace(C, mat, name, overwrite);
}
static TransformOrientation *createBoneSpace(bContext *C, ReportList *reports, char *name, int overwrite)
static TransformOrientation *createBoneSpace(bContext *C, ReportList *reports,
const char *name, const bool overwrite)
{
float mat[3][3];
float normal[3], plane[3];
@ -160,13 +155,14 @@ static TransformOrientation *createBoneSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
strcpy(name, "Bone");
name = "Bone";
}
return addMatrixSpace(C, mat, name, overwrite);
}
static TransformOrientation *createCurveSpace(bContext *C, ReportList *reports, char *name, int overwrite)
static TransformOrientation *createCurveSpace(bContext *C, ReportList *reports,
const char *name, const bool overwrite)
{
float mat[3][3];
float normal[3], plane[3];
@ -179,14 +175,15 @@ static TransformOrientation *createCurveSpace(bContext *C, ReportList *reports,
}
if (name[0] == 0) {
strcpy(name, "Curve");
name = "Curve";
}
return addMatrixSpace(C, mat, name, overwrite);
}
static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, char *name, int overwrite)
static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports,
const char *name, const bool overwrite)
{
float mat[3][3];
float normal[3], plane[3];
@ -202,7 +199,7 @@ static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
strcpy(name, "Vertex");
name = "Vertex";
}
break;
case ORIENTATION_EDGE:
@ -212,7 +209,7 @@ static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
strcpy(name, "Edge");
name = "Edge";
}
break;
case ORIENTATION_FACE:
@ -222,7 +219,7 @@ static TransformOrientation *createMeshSpace(bContext *C, ReportList *reports, c
}
if (name[0] == 0) {
strcpy(name, "Face");
name = "Face";
}
break;
default:
@ -288,8 +285,9 @@ bool createSpaceNormalTangent(float mat[3][3], const float normal[3], const floa
return true;
}
/* name must be a MAX_NAME length string! */
void BIF_createTransformOrientation(bContext *C, ReportList *reports, char *name, int use_view, int use, int overwrite)
void BIF_createTransformOrientation(bContext *C, ReportList *reports,
const char *name, const bool use_view,
const bool activate, const bool overwrite)
{
TransformOrientation *ts = NULL;
@ -315,21 +313,25 @@ void BIF_createTransformOrientation(bContext *C, ReportList *reports, char *name
}
}
if (use && ts != NULL) {
if (activate && ts != NULL) {
BIF_selectTransformOrientation(C, ts);
}
}
TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], char name[], int overwrite)
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;
char name_unique[sizeof(ts->name)];
if (overwrite) {
ts = findOrientationName(transform_spaces, name);
}
else {
uniqueOrientationName(transform_spaces, name);
BLI_strncpy(name_unique, name, sizeof(name_unique));
uniqueOrientationName(transform_spaces, name_unique);
name = name_unique;
}
/* if not, create a new one */
@ -422,17 +424,10 @@ void BIF_selectTransformOrientationValue(bContext *C, int orientation)
int BIF_countTransformOrientation(const bContext *C)
{
ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
TransformOrientation *ts;
int count = 0;
for (ts = transform_spaces->first; ts; ts = ts->next) {
count++;
}
return count;
return BLI_countlist(transform_spaces);
}
void applyTransformOrientation(const bContext *C, float mat[3][3], char name[MAX_NAME])
void applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name)
{
TransformOrientation *ts;
View3D *v3d = CTX_wm_view3d(C);
@ -443,8 +438,8 @@ void applyTransformOrientation(const bContext *C, float mat[3][3], char name[MAX
for (i = 0, ts = CTX_data_scene(C)->transform_spaces.first; ts; ts = ts->next, i++) {
if (selected_index == i) {
if (name) {
BLI_strncpy(name, ts->name, MAX_NAME);
if (r_name) {
BLI_strncpy(r_name, ts->name, MAX_NAME);
}
copy_m3_m3(mat, ts->mat);
@ -454,10 +449,10 @@ void applyTransformOrientation(const bContext *C, float mat[3][3], char name[MAX
}
}
static int count_bone_select(bArmature *arm, ListBase *lb, int do_it)
static int count_bone_select(bArmature *arm, ListBase *lb, const bool do_it)
{
Bone *bone;
int do_next;
bool do_next;
int total = 0;
for (bone = lb->first; bone; bone = bone->next) {
@ -468,7 +463,9 @@ static int count_bone_select(bArmature *arm, ListBase *lb, int do_it)
if (bone->flag & BONE_SELECTED) {
bone->flag |= BONE_TRANSFORM;
total++;
do_next = FALSE; // no transform on children if one parent bone is selected
/* no transform on children if one parent bone is selected */
do_next = false;
}
}
}
@ -537,7 +534,7 @@ void initTransformOrientation(bContext *C, TransInfo *t)
}
}
int getTransformOrientation(const bContext *C, float normal[3], float plane[3], int activeOnly)
int getTransformOrientation(const bContext *C, float normal[3], float plane[3], const bool activeOnly)
{
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
@ -864,7 +861,7 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3],
else {
int totsel;
totsel = count_bone_select(arm, &arm->bonebase, 1);
totsel = count_bone_select(arm, &arm->bonebase, true);
if (totsel) {
/* use channels to get stats */
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {