Fix T40862: numinput transform did not take into account scale_length.

This commit is contained in:
Bastien Montagne 2014-06-30 10:57:39 +02:00
parent 61e1ea382b
commit cadf77d5ef
Notes: blender-bot 2023-02-14 10:24:50 +01:00
Referenced by issue #40888, Memory error when selecting Cycles render engine
Referenced by issue #40862, Imperial Units 2.71
7 changed files with 46 additions and 34 deletions

View File

@ -846,7 +846,7 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, const wmEvent *even
applyNumInput(&mm->num, &value);
if (hasNumInput(&mm->num)) {
outputNumInput(&mm->num, str_tx);
outputNumInput(&mm->num, str_tx, scene->unit.scale_length);
}
else {
BLI_snprintf(str_tx, sizeof(str_tx), "%d", (int)value);

View File

@ -76,7 +76,7 @@ enum {
*/
void initNumInput(NumInput *n);
void outputNumInput(NumInput *n, char *str);
void outputNumInput(NumInput *n, char *str, const float scale_length);
bool hasNumInput(const NumInput *n);
bool applyNumInput(NumInput *n, float *vec);
bool handleNumInput(struct bContext *C, NumInput *n, const struct wmEvent *event);

View File

@ -79,13 +79,14 @@ static void edbm_bevel_update_header(wmOperator *op, bContext *C)
char msg[HEADER_LENGTH];
ScrArea *sa = CTX_wm_area(C);
Scene *sce = CTX_data_scene(C);
if (sa) {
BevelData *opdata = op->customdata;
char offset_str[NUM_STR_REP_LEN];
if (hasNumInput(&opdata->num_input)) {
outputNumInput(&opdata->num_input, offset_str);
outputNumInput(&opdata->num_input, offset_str, sce->unit.scale_length);
}
else {
BLI_snprintf(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset"));

View File

@ -85,11 +85,12 @@ static void edbm_inset_update_header(wmOperator *op, bContext *C)
char msg[HEADER_LENGTH];
ScrArea *sa = CTX_wm_area(C);
Scene *sce = CTX_data_scene(C);
if (sa) {
char flts_str[NUM_STR_REP_LEN * 2];
if (hasNumInput(&opdata->num_input))
outputNumInput(&opdata->num_input, flts_str);
outputNumInput(&opdata->num_input, flts_str, sce->unit.scale_length);
else {
BLI_snprintf(flts_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "thickness"));
BLI_snprintf(flts_str + NUM_STR_REP_LEN, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "depth"));

View File

@ -696,10 +696,11 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
if (show_cuts) {
Scene *sce = CTX_data_scene(C);
char buf[64 + NUM_STR_REP_LEN * 2];
char str_rep[NUM_STR_REP_LEN * 2];
if (hasNumInput(&lcd->num)) {
outputNumInput(&lcd->num, str_rep);
outputNumInput(&lcd->num, str_rep, sce->unit.scale_length);
}
else {
BLI_snprintf(str_rep, NUM_STR_REP_LEN, "%d", cuts);

View File

@ -2841,7 +2841,7 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN * 2];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bend Angle: %s Radius: %s Alt, Clamp %s"),
&c[0], &c[NUM_STR_REP_LEN],
@ -3009,7 +3009,7 @@ static void applyShear(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shear: %s %s"), c, t->proptext);
}
@ -3108,7 +3108,7 @@ static void headerResize(TransInfo *t, float vec[3], char str[MAX_INFO_LEN])
char tvec[NUM_STR_REP_LEN * 3];
size_t ofs = 0;
if (hasNumInput(&t->num)) {
outputNumInput(&(t->num), tvec);
outputNumInput(&(t->num), tvec, t->scene->unit.scale_length);
}
else {
BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", vec[0]);
@ -3520,7 +3520,7 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("To Sphere: %s %s"), c, t->proptext);
}
@ -3877,7 +3877,7 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Rot: %s %s %s"), &c[0], t->con.text, t->proptext);
}
@ -3981,7 +3981,7 @@ static void applyTrackball(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN * 2];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Trackball: %s %s %s"),
&c[0], &c[NUM_STR_REP_LEN], t->proptext);
@ -4083,7 +4083,7 @@ static void headerTranslation(TransInfo *t, float vec[3], char str[MAX_INFO_LEN]
float dist;
if (hasNumInput(&t->num)) {
outputNumInput(&(t->num), tvec);
outputNumInput(&(t->num), tvec, t->scene->unit.scale_length);
dist = len_v3(t->num.val);
}
else {
@ -4331,7 +4331,7 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Shrink/Fatten:"), MAX_INFO_LEN - ofs);
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, " %s", c);
}
else {
@ -4426,7 +4426,7 @@ static void applyTilt(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Tilt: %s° %s"), &c[0], t->proptext);
@ -4502,7 +4502,7 @@ static void applyCurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shrink/Fatten: %s"), c);
}
else {
@ -4578,7 +4578,7 @@ static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Feather Shrink/Fatten: %s"), c);
}
else {
@ -4671,7 +4671,7 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Push/Pull: %s%s %s"), c, t->con.text, t->proptext);
}
@ -4764,7 +4764,7 @@ static void applyBevelWeight(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
if (weight >= 0.0f)
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bevel Weight: +%s %s"), c, t->proptext);
@ -4842,7 +4842,7 @@ static void applyCrease(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
if (crease >= 0.0f)
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Crease: +%s %s"), c, t->proptext);
@ -4912,7 +4912,7 @@ static void headerBoneSize(TransInfo *t, float vec[3], char str[MAX_INFO_LEN])
{
char tvec[NUM_STR_REP_LEN * 3];
if (hasNumInput(&t->num)) {
outputNumInput(&(t->num), tvec);
outputNumInput(&(t->num), tvec, t->scene->unit.scale_length);
}
else {
BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", vec[0]);
@ -5049,7 +5049,7 @@ static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Envelope: %s"), c);
}
else {
@ -6224,7 +6224,7 @@ static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
if (is_proportional) {
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Edge Slide: %s (E)ven: %s"),
@ -6747,7 +6747,7 @@ static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2]))
ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Vert Slide: "), MAX_INFO_LEN - ofs);
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
ofs += BLI_strncpy_rlen(str + ofs, &c[0], MAX_INFO_LEN - ofs);
}
else {
@ -6814,7 +6814,7 @@ static void applyBoneRoll(TransInfo *t, const int UNUSED(mval[2]))
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Roll: %s"), &c[0]);
}
@ -6888,7 +6888,7 @@ static void applyBakeTime(TransInfo *t, const int mval[2])
if (hasNumInput(&t->num)) {
char c[NUM_STR_REP_LEN];
outputNumInput(&(t->num), c);
outputNumInput(&(t->num), c, t->scene->unit.scale_length);
if (time >= 0.0f)
BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Time: +%s %s"), c, t->proptext);
@ -7099,7 +7099,7 @@ static void headerSeqSlide(TransInfo *t, float val[2], char str[MAX_INFO_LEN])
size_t ofs = 0;
if (hasNumInput(&t->num)) {
outputNumInput(&(t->num), tvec);
outputNumInput(&(t->num), tvec, t->scene->unit.scale_length);
}
else {
BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.0f, %.0f", val[0], val[1]);
@ -7325,7 +7325,7 @@ static void headerTimeTranslate(TransInfo *t, char str[MAX_INFO_LEN])
/* if numeric input is active, use results from that, otherwise apply snapping to result */
if (hasNumInput(&t->num)) {
outputNumInput(&(t->num), tvec);
outputNumInput(&(t->num), tvec, t->scene->unit.scale_length);
}
else {
const Scene *scene = t->scene;
@ -7489,7 +7489,7 @@ static void headerTimeSlide(TransInfo *t, float sval, char str[MAX_INFO_LEN])
char tvec[NUM_STR_REP_LEN * 3];
if (hasNumInput(&t->num)) {
outputNumInput(&(t->num), tvec);
outputNumInput(&(t->num), tvec, t->scene->unit.scale_length);
}
else {
float minx = *((float *)(t->customData));
@ -7637,7 +7637,7 @@ static void headerTimeScale(TransInfo *t, char str[MAX_INFO_LEN])
char tvec[NUM_STR_REP_LEN * 3];
if (hasNumInput(&t->num))
outputNumInput(&(t->num), tvec);
outputNumInput(&(t->num), tvec, t->scene->unit.scale_length);
else
BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", t->values[0]);

View File

@ -87,15 +87,18 @@ void initNumInput(NumInput *n)
}
/* str must be NUM_STR_REP_LEN * (idx_max + 1) length. */
void outputNumInput(NumInput *n, char *str)
void outputNumInput(NumInput *n, char *str, const float scale_length)
{
short i, j;
short j;
const int ln = NUM_STR_REP_LEN;
int prec = 2; /* draw-only, and avoids too much issues with radian->degrees conversion. */
for (j = 0; j <= n->idx_max; j++) {
/* if AFFECTALL and no number typed and cursor not on number, use first number */
i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? 0 : j;
const short i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? 0 : j;
/* Use scale_length if needed! */
const float fac = ELEM3(n->unit_type[j], B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME) ? scale_length : 1.0f;
if (n->val_flag[i] & NUM_EDITED) {
/* Get the best precision, allows us to draw '10.0001' as '10' instead! */
@ -118,7 +121,7 @@ void outputNumInput(NumInput *n, char *str)
BLI_strncpy(val, "Invalid", sizeof(val));
}
else {
bUnit_AsString(val, sizeof(val), (double)n->val[i], prec,
bUnit_AsString(val, sizeof(val), (double)(n->val[i] * fac), prec,
n->unit_sys, n->unit_type[i], true, false);
}
@ -466,7 +469,9 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
/* At this point, our value has changed, try to interpret it with python (if str is not empty!). */
if (n->str[0]) {
#ifdef WITH_PYTHON
Scene *sce = CTX_data_scene(C);
double val;
float fac = 1.0f;
char str_unit_convert[NUM_STR_REP_LEN * 6]; /* Should be more than enough! */
const char *default_unit = NULL;
@ -474,6 +479,10 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
if (n->unit_use_radians && n->unit_type[idx] == B_UNIT_ROTATION)
default_unit = "r";
/* Use scale_length if needed! */
if (ELEM3(n->unit_type[idx], B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME))
fac /= sce->unit.scale_length;
BLI_strncpy(str_unit_convert, n->str, sizeof(str_unit_convert));
bUnit_ReplaceString(str_unit_convert, sizeof(str_unit_convert), default_unit, 1.0,
@ -481,7 +490,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
/* Note: with angles, we always get values as radians here... */
if (BPY_button_exec(C, str_unit_convert, &val, false) != -1) {
n->val[idx] = (float)val;
n->val[idx] = (float)val * fac;
n->val_flag[idx] &= ~NUM_INVALID;
}
else {