Commit: 22ddd573638582ad5213bb4a7ff23ccae50dd285
Author: Jacques Lucke
Date:   Wed Jan 9 10:39:31 2019 +0100
Branches: master
https://developer.blender.org/rB22ddd573638582ad5213bb4a7ff23ccae50dd285

Fix T60338: Allow user to input units of another system

===================================================================

M       source/blender/blenkernel/BKE_unit.h
M       source/blender/blenkernel/intern/unit.c
M       source/blender/editors/util/numinput.c

===================================================================

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;

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to