Fix T60338: Allow user to input units of another system
This commit is contained in:
parent
06d1c2f737
commit
22ddd57363
Notes:
blender-bot
2023-02-14 08:24:03 +01:00
Referenced by issue #60338, Error when typing in measurment in different unit system then scene is set to
|
@ -43,7 +43,7 @@ size_t bUnit_AsString2(char *str, int len_max, double value, int prec, int type,
|
|||
bool bUnit_ReplaceString(char *str, int len_max, const char *str_prev, double scale_pref, int system, int type);
|
||||
|
||||
/* return true if the string contains any valid unit for the given type */
|
||||
bool bUnit_ContainsUnit(const char *str, int system, int type);
|
||||
bool bUnit_ContainsUnit(const char *str, int type);
|
||||
|
||||
/* if user does not specify a unit, multiply with this value */
|
||||
double bUnit_PreferredInputUnitScalar(const struct UnitSettings *settings, int type);
|
||||
|
|
|
@ -721,14 +721,16 @@ static const bUnitDef *unit_detect_from_str(const bUnitCollection *usys, const c
|
|||
return unit;
|
||||
}
|
||||
|
||||
bool bUnit_ContainsUnit(const char *str, int system, int type)
|
||||
bool bUnit_ContainsUnit(const char *str, int type)
|
||||
{
|
||||
const bUnitCollection *usys = unit_get_system(system, type);
|
||||
if (!is_valid_unit_collection(usys)) return false;
|
||||
for (int system = 0; system < UNIT_SYSTEM_TOT; system++) {
|
||||
const bUnitCollection *usys = unit_get_system(system, type);
|
||||
if (!is_valid_unit_collection(usys)) continue;
|
||||
|
||||
for (int i = 0; i < usys->length; i++) {
|
||||
if (unit_find(str, usys->units + i)) {
|
||||
return true;
|
||||
for (int i = 0; i < usys->length; i++) {
|
||||
if (unit_find(str, usys->units + i)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -258,13 +258,7 @@ bool user_string_to_number(bContext *C, const char *str, const UnitSettings *uni
|
|||
{
|
||||
#ifdef WITH_PYTHON
|
||||
double unit_scale = BKE_scene_unit_scale(unit, type, 1.0);
|
||||
if (!bUnit_ContainsUnit(str, unit->system, type)) {
|
||||
int success = BPY_execute_string_as_number(C, NULL, str, true, r_value);
|
||||
*r_value *= bUnit_PreferredInputUnitScalar(unit, type);
|
||||
*r_value /= unit_scale;
|
||||
return success;
|
||||
}
|
||||
else {
|
||||
if (bUnit_ContainsUnit(str, type)) {
|
||||
char str_unit_convert[256];
|
||||
BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert));
|
||||
bUnit_ReplaceString(
|
||||
|
@ -273,6 +267,12 @@ bool user_string_to_number(bContext *C, const char *str, const UnitSettings *uni
|
|||
|
||||
return BPY_execute_string_as_number(C, NULL, str_unit_convert, true, r_value);
|
||||
}
|
||||
else {
|
||||
int success = BPY_execute_string_as_number(C, NULL, str, true, r_value);
|
||||
*r_value *= bUnit_PreferredInputUnitScalar(unit, type);
|
||||
*r_value /= unit_scale;
|
||||
return success;
|
||||
}
|
||||
#else
|
||||
*r_value = atof(str);
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue