Fix T60327: Value input with adaptive imperial units not working properly
This commit is contained in:
@@ -46,7 +46,7 @@ bool bUnit_ReplaceString(char *str, int len_max, const char *str_prev, double sc
|
|||||||
bool bUnit_ContainsUnit(const char *str, int system, int type);
|
bool bUnit_ContainsUnit(const char *str, int system, int type);
|
||||||
|
|
||||||
/* if user does not specify a unit, multiply with this value */
|
/* if user does not specify a unit, multiply with this value */
|
||||||
double bUnit_PreferredUnitScalar(const struct UnitSettings *settings, int type);
|
double bUnit_PreferredInputUnitScalar(const struct UnitSettings *settings, int type);
|
||||||
|
|
||||||
/* make string keyboard-friendly: 10µm --> 10um */
|
/* make string keyboard-friendly: 10µm --> 10um */
|
||||||
void bUnit_ToUnitAltName(char *str, int len_max, const char *orig_str, int system, int type);
|
void bUnit_ToUnitAltName(char *str, int len_max, const char *orig_str, int system, int type);
|
||||||
|
@@ -484,7 +484,7 @@ static bool is_valid_unit_collection(const bUnitCollection *usys)
|
|||||||
return usys != NULL && usys->units[0].name != NULL;
|
return usys != NULL && usys->units[0].name != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const bUnitDef *get_preferred_unit_if_used(int type, PreferredUnits units)
|
static const bUnitDef *get_preferred_display_unit_if_used(int type, PreferredUnits units)
|
||||||
{
|
{
|
||||||
const bUnitCollection *usys = unit_get_system(units.system, type);
|
const bUnitCollection *usys = unit_get_system(units.system, type);
|
||||||
if (!is_valid_unit_collection(usys)) return NULL;
|
if (!is_valid_unit_collection(usys)) return NULL;
|
||||||
@@ -525,7 +525,7 @@ static size_t unit_as_string_main(
|
|||||||
usys = &buDummyCollection;
|
usys = &buDummyCollection;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
main_unit = get_preferred_unit_if_used(type, units);
|
main_unit = get_preferred_display_unit_if_used(type, units);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (split && unit_should_be_split(type)) {
|
if (split && unit_should_be_split(type)) {
|
||||||
@@ -734,12 +734,12 @@ bool bUnit_ContainsUnit(const char *str, int system, int type)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
double bUnit_PreferredUnitScalar(const struct UnitSettings *settings, int type)
|
double bUnit_PreferredInputUnitScalar(const struct UnitSettings *settings, int type)
|
||||||
{
|
{
|
||||||
PreferredUnits units = preferred_units_from_UnitSettings(settings);
|
PreferredUnits units = preferred_units_from_UnitSettings(settings);
|
||||||
const bUnitDef *unit = get_preferred_unit_if_used(type, units);
|
const bUnitDef *unit = get_preferred_display_unit_if_used(type, units);
|
||||||
if (unit == NULL) return 1.0;
|
if (unit) return unit->scalar;
|
||||||
else return unit->scalar;
|
else return bUnit_BaseScalar(units.system, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make a copy of the string that replaces the units with numbers
|
/* make a copy of the string that replaces the units with numbers
|
||||||
@@ -905,7 +905,8 @@ double bUnit_ClosestScalar(double value, int system, int type)
|
|||||||
double bUnit_BaseScalar(int system, int type)
|
double bUnit_BaseScalar(int system, int type)
|
||||||
{
|
{
|
||||||
const bUnitCollection *usys = unit_get_system(system, type);
|
const bUnitCollection *usys = unit_get_system(system, type);
|
||||||
return unit_default(usys)->scalar;
|
if (usys) return unit_default(usys)->scalar;
|
||||||
|
else return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* external access */
|
/* external access */
|
||||||
|
@@ -260,7 +260,7 @@ bool user_string_to_number(bContext *C, const char *str, const UnitSettings *uni
|
|||||||
double unit_scale = BKE_scene_unit_scale(unit, type, 1.0);
|
double unit_scale = BKE_scene_unit_scale(unit, type, 1.0);
|
||||||
if (!bUnit_ContainsUnit(str, unit->system, type)) {
|
if (!bUnit_ContainsUnit(str, unit->system, type)) {
|
||||||
int success = BPY_execute_string_as_number(C, NULL, str, true, r_value);
|
int success = BPY_execute_string_as_number(C, NULL, str, true, r_value);
|
||||||
*r_value *= bUnit_PreferredUnitScalar(unit, type);
|
*r_value *= bUnit_PreferredInputUnitScalar(unit, type);
|
||||||
*r_value /= unit_scale;
|
*r_value /= unit_scale;
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user