diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-01-09 12:39:31 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-01-09 12:40:05 +0300 |
commit | 22ddd573638582ad5213bb4a7ff23ccae50dd285 (patch) | |
tree | 45f521fa73ae8a4062113c297e3e0703a549c2ca | |
parent | 06d1c2f7373d3b506675dd671661be26bc50704f (diff) |
Fix T60338: Allow user to input units of another system
-rw-r--r-- | source/blender/blenkernel/BKE_unit.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/unit.c | 14 | ||||
-rw-r--r-- | source/blender/editors/util/numinput.c | 14 |
3 files changed, 16 insertions, 14 deletions
diff --git a/source/blender/blenkernel/BKE_unit.h b/source/blender/blenkernel/BKE_unit.h index b19cc340bbf..81da3bea3d6 100644 --- a/source/blender/blenkernel/BKE_unit.h +++ b/source/blender/blenkernel/BKE_unit.h @@ -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); diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index 7cac4c148ff..3fd47b515f6 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -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; diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c index e3c0f6ca685..817b12fbc4d 100644 --- a/source/blender/editors/util/numinput.c +++ b/source/blender/editors/util/numinput.c @@ -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; |