30 #define TEMP_STR_SIZE 256
37 #define UN_SC_KM 1000.0f
38 #define UN_SC_HM 100.0f
39 #define UN_SC_DAM 10.0f
42 #define UN_SC_CM 0.01f
43 #define UN_SC_MM 0.001f
44 #define UN_SC_UM 0.000001f
46 #define UN_SC_MI 1609.344f
47 #define UN_SC_FUR 201.168f
48 #define UN_SC_CH 20.1168f
49 #define UN_SC_YD 0.9144f
50 #define UN_SC_FT 0.3048f
51 #define UN_SC_IN 0.0254f
52 #define UN_SC_MIL 0.0000254f
54 #define UN_SC_MTON 1000.0f
55 #define UN_SC_QL 100.0f
58 #define UN_SC_DAG 0.01f
59 #define UN_SC_G 0.001f
60 #define UN_SC_MG 0.000001f
62 #define UN_SC_ITON 907.18474f
63 #define UN_SC_CWT 45.359237f
64 #define UN_SC_ST 6.35029318f
65 #define UN_SC_LB 0.45359237f
66 #define UN_SC_OZ 0.028349523125f
68 #define UN_SC_FAH 0.555555555555f
122 #define UNIT_COLLECTION_LENGTH(def) (ARRAY_SIZE(def) - 1)
123 #define NULL_UNIT {NULL, NULL, NULL, NULL, NULL, NULL, 0.0, 0.0}
257 {
"meter per second squared",
"meters per second squared",
"m/s²",
"m/s2",
"Meters per second squared",
NULL,
UN_SC_M, 0.0,
B_UNIT_DEF_NONE},
263 {
"foot per second squared",
"feet per second squared",
"ft/s²",
"ft/s2",
"Feet per second squared",
NULL,
UN_SC_FT, 0.0,
B_UNIT_DEF_NONE},
272 {
"hour",
"hours",
"hr",
"h",
"Hours",
"HOURS", 3600.0, 0.0,
B_UNIT_DEF_NONE},
273 {
"minute",
"minutes",
"min",
"m",
"Minutes",
"MINUTES", 60.0, 0.0,
B_UNIT_DEF_NONE},
274 {
"second",
"seconds",
"sec",
"s",
"Seconds",
"SECONDS", 1.0, 0.0,
B_UNIT_DEF_NONE},
275 {
"millisecond",
"milliseconds",
"ms",
NULL,
"Milliseconds",
"MILLISECONDS", 0.001, 0.0,
B_UNIT_DEF_NONE},
276 {
"microsecond",
"microseconds",
"µs",
"us",
"Microseconds",
"MICROSECONDS", 0.000001, 0.0,
B_UNIT_DEF_NONE},
322 {
"celsius",
"celsius",
"°C",
"C",
"Celsius",
"CELSIUS", 1.0f, 273.15,
B_UNIT_DEF_NONE},
337 #define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1)
381 {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL},
401 double value_abs = value > 0.0 ? value : -value;
403 for (
const bUnitDef *unit = unit_start ? unit_start : usys->
units; unit->
name; unit++) {
411 if (value_abs >= unit->scalar * (0.1 -
EPS)) {
416 if (value_abs >= unit->scalar * (1.0 -
EPS)) {
437 *r_value_b = value - (*r_value_a);
462 double value_conv = (value / unit->
scalar) - unit->
bias;
463 bool strip_skip =
false;
491 while (i > 0 &&
str[i] ==
'0') {
495 if (i > 0 &&
str[i] ==
'.') {
510 while (unit->
name_short[j] && (i < len_max)) {
559 double value_a, value_b;
563 if (unit_b > unit_a) {
571 if (i + 2 < len_max) {
595 int max_offset = usys->
length - 1;
617 return usys->
units + 0;
620 return usys->
units + 3;
666 char *
str,
int len_max,
double value,
int prec,
int system,
int type,
bool split,
bool pad)
693 return (ch >= 128 || isalpha(ch));
698 if (substr ==
NULL || substr[0] ==
'\0') {
704 const char *str_found;
705 if (case_sensitive) {
706 str_found = strstr(
str, substr);
714 if (str_found ==
str ||
719 int len_name = strlen(substr);
778 char *str_found = strstr(remaining_str,
"-");
780 if (str_found ==
NULL) {
785 if ((str_found !=
str) &&
ELEM(*(str_found - 1),
'e',
'E')) {
789 if (*(str_found + 1) ==
' ') {
793 return str_found + 1;
805 for (i = 0; i < len_max; i++) {
806 if (remaining_str[i] ==
'\0') {
807 return remaining_str + i;
812 if (remaining_str !=
str && i != 0) {
814 if ((remaining_str[i] ==
'/') &&
ELEM(remaining_str[i - 1],
't',
'T',
'm',
'M') &&
815 ELEM(remaining_str[i + 1],
's',
'S')) {
820 if (
ELEM(remaining_str[i - 1],
'e',
'E')) {
825 if (remaining_str[i - 1] ==
' ') {
830 return remaining_str + i;
834 return remaining_str + i;
845 bool changed =
false;
847 char *remaining_str =
str;
848 int remaining_str_len = len_max;
851 remaining_str_len = len_max - (int)(remaining_str -
str);
852 if (remaining_str_len <= 2) {
859 memmove(remaining_str + 1, remaining_str, remaining_str_len - 2);
860 *remaining_str =
'(';
863 remaining_str =
find_next_op(
str, remaining_str + 1, remaining_str_len);
864 remaining_str_len = len_max - (int)(remaining_str -
str);
865 memmove(remaining_str + 1, remaining_str, remaining_str_len - 2);
866 *remaining_str =
')';
882 for (
int i = start_ofs; i > 0; i--) {
897 for (i = start_ofs; i < len_max; i++) {
898 if (!strchr(
"0123456789eE.",
str[i])) {
910 const char *replace_str,
920 if (str_found ==
NULL) {
924 int found_ofs = (int)(str_found -
str);
933 if (unit->
bias != 0.0) {
936 if (
len + 1 < len_max) {
937 memmove(
str + prev_op_ofs + 1,
str + prev_op_ofs,
len - prev_op_ofs + 1);
938 str[prev_op_ofs] =
'(';
947 if (value_end_ofs + len_bias_num < len_max) {
948 memmove(
str + value_end_ofs + len_bias_num,
str + value_end_ofs,
len - value_end_ofs + 1);
949 memcpy(
str + value_end_ofs, str_tmp, len_bias_num);
951 found_ofs += len_bias_num;
952 str_found += len_bias_num;
956 int len_name = strlen(replace_str);
957 int len_move = (
len - (found_ofs + len_name)) + 1;
963 if (len_num > len_max) {
967 if (found_ofs + len_num + len_move > len_max) {
969 len_move -= (found_ofs + len_num + len_move) - len_max;
975 memmove(str_found + len_num, str_found + len_name, len_move);
978 if (found_ofs + len_num > len_max) {
980 len_num -= (found_ofs + len_num) - len_max;
985 memcpy(str_found, str_tmp, len_num);
990 str[len_max - 1] =
'\0';
991 return found_ofs + len_num;
995 char *
str,
int len_max,
char *str_tmp,
double scale_pref,
const bUnitDef *unit)
1000 str + ofs, len_max - ofs, str_tmp, scale_pref, unit, unit->
name_short, case_sensitive);
1002 str + ofs, len_max - ofs, str_tmp, scale_pref, unit, unit->
name_plural,
false);
1004 str + ofs, len_max - ofs, str_tmp, scale_pref, unit, unit->
name_alt, case_sensitive);
1036 const char *str_prev)
1041 for (unit = usys->
units; unit->
name; unit++) {
1047 if (str_prev && (unit ==
NULL || unit->
name ==
NULL)) {
1049 for (unit = usys->
units; unit->
name; unit++) {
1071 for (
int i = 0; i < usys->
length; i++) {
1086 const double bias = (unit ==
NULL) ? 0.0 : unit->
bias;
1088 return value * scalar + bias;
1092 char *
str,
int len_max,
const char *str_prev,
double scale_pref,
int system,
int type)
1099 double scale_pref_base = scale_pref;
1101 bool changed =
false;
1111 scale_pref_base *= default_unit->
scalar;
1117 strncpy(
str, str_tmp, len_max);
1137 for (
int system_iter = 0; system_iter <
UNIT_SYSTEM_TOT; system_iter++) {
1138 if (system_iter != system) {
1144 while ((ofs =
unit_replace(
str + ofs, len_max - ofs, str_tmp, scale_pref_base, unit))) {
1157 char *str_found =
str;
1158 const char *ch =
str;
1160 while ((str_found = strchr(str_found,
SEP_CHR))) {
1161 bool op_found =
false;
1164 for (ch = str_found + 1; *ch !=
'\0'; ch++) {
1165 if (
ELEM(*ch,
' ',
'\t')) {
1173 *str_found++ = op_found ?
' ' :
'+';
1186 if (len_max > 0 && unit->name_alt) {
1188 const char *found =
unit_find_str(orig_str, unit->name_short, case_sensitive);
1190 int offset = (int)(found - orig_str);
1198 orig_str +=
offset + strlen(unit->name_short);
1202 if (unit->name_alt) {
1209 len_name = (len_name < len_max ? len_name : len_max);
1211 len_max -= len_name;
1217 strncpy(
str, orig_str, len_max);
1286 BLI_assert_msg(0,
"identifier for this unit is not specified yet");
#define BLI_assert_msg(a, msg)
MINLINE int integer_digits_d(double d)
MINLINE int max_ii(int a, int b)
size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
char * BLI_strcasestr(const char *s, const char *find) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
size_t BLI_snprintf_rlen(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
const char * BLI_str_find_prev_char_utf8(const char *p, const char *str_start) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1
Compatibility-like things for windows.
#define USER_UNIT_OPT_SPLIT
#define USER_UNIT_ROT_RADIANS
#define USER_UNIT_ADAPTIVE
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
int pad[32 - sizeof(int)]
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_device_inline float3 ceil(const float3 &a)
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
T length(const vec_base< T, Size > &a)
const struct bUnitDef * units
const char * name_display
static struct bUnitCollection buMetricTempCollection
static int find_end_of_value_chars(const char *str, const int len_max, const int start_ofs)
static struct bUnitDef buImperialLenDef[]
int BKE_unit_base_of_type_get(int system, int type)
static struct bUnitCollection buNaturalTimeCollection
@ B_UNIT_DEF_CASE_SENSITIVE
static const struct bUnitCollection * bUnitSystems[][B_UNIT_TYPE_TOT]
static PreferredUnits preferred_units_from_UnitSettings(const UnitSettings *settings)
static char * find_next_op(const char *str, char *remaining_str, int len_max)
static struct bUnitDef buMetricAreaDef[]
static struct bUnitCollection buCameraLenCollection
static struct bUnitDef buCameraLenDef[]
static struct bUnitDef buMetricAclDef[]
static struct bUnitCollection buImperialLenCollection
static struct bUnitDef buMetricVelDef[]
static char * find_next_negative(const char *str, const char *remaining_str)
static struct bUnitCollection buImperialVelCollection
bool BKE_unit_is_valid(int system, int type)
static struct bUnitCollection buMetricVolCollection
static struct bUnitDef buMetricMassDef[]
static const bUnitCollection * unit_get_system(int system, int type)
static struct bUnitCollection buDummyCollection
size_t BKE_unit_value_as_string_adaptive(char *str, int len_max, double value, int prec, int system, int type, bool split, bool pad)
static struct bUnitCollection buMetricAclCollection
static struct bUnitCollection buPowerCollection
static void unit_dual_convert(double value, const bUnitCollection *usys, bUnitDef const **r_unit_a, bUnitDef const **r_unit_b, double *r_value_a, double *r_value_b, const bUnitDef *main_unit)
static bool is_valid_unit_collection(const bUnitCollection *usys)
const char * BKE_unit_display_name_get(const void *usys_pt, int index)
static const struct bUnitCollection buMetricLenCollection
bool BKE_unit_is_suppressed(const void *usys_pt, int index)
#define UNIT_COLLECTION_LENGTH(def)
void BKE_unit_system_get(int system, int type, void const **r_usys_pt, int *r_len)
static struct bUnitCollection buImperialVolCollection
static const bUnitDef * unit_best_fit(double value, const bUnitCollection *usys, const bUnitDef *unit_start, int suppress)
static int unit_replace(char *str, int len_max, char *str_tmp, double scale_pref, const bUnitDef *unit)
static struct bUnitDef buMetricTempDef[]
void BKE_unit_name_to_alt(char *str, int len_max, const char *orig_str, int system, int type)
static struct bUnitCollection buMetricMassCollection
static struct bUnitDef buNaturalTimeDef[]
static struct bUnitDef buImperialAclDef[]
static const bUnitDef * unit_detect_from_str(const bUnitCollection *usys, const char *str, const char *str_prev)
const char * BKE_unit_identifier_get(const void *usys_pt, int index)
static size_t unit_as_string_split_pair(char *str, int len_max, double value, int prec, const bUnitCollection *usys, const bUnitDef *main_unit)
static bool unit_find(const char *str, const bUnitDef *unit)
int BKE_unit_base_get(const void *usys_pt)
static struct bUnitCollection buImperialAreaCollection
static struct bUnitDef buImperialMassDef[]
static size_t unit_as_string(char *str, int len_max, double value, int prec, const bUnitCollection *usys, const bUnitDef *unit, char pad)
double BKE_unit_scalar_get(const void *usys_pt, int index)
static struct bUnitDef buPowerDef[]
static struct bUnitDef buImperialTempDef[]
static bool ch_is_op(char op)
double BKE_unit_closest_scalar(double value, int system, int type)
static struct bUnitDef buImperialVolDef[]
static struct bUnitCollection buImperialMassCollection
static size_t unit_as_string_main(char *str, int len_max, double value, int prec, int type, bool split, bool pad, PreferredUnits units)
static struct bUnitCollection buImperialTempCollection
size_t BKE_unit_value_as_string(char *str, int len_max, double value, int prec, int type, const UnitSettings *settings, bool pad)
static struct bUnitDef buMetricLenDef[]
bool BKE_unit_replace_string(char *str, int len_max, const char *str_prev, double scale_pref, int system, int type)
double BKE_unit_apply_preferred_unit(const struct UnitSettings *settings, int type, double value)
static int find_previous_non_value_char(const char *str, const int start_ofs)
static struct bUnitCollection buImperialAclCollection
double BKE_unit_base_scalar(int system, int type)
struct bUnitCollection bUnitCollection
static int unit_scale_str(char *str, int len_max, char *str_tmp, double scale_pref, const bUnitDef *unit, const char *replace_str, bool case_sensitive)
static struct bUnitDef buMetricVolDef[]
static const bUnitDef * unit_default(const bUnitCollection *usys)
static const char * unit_find_str(const char *str, const char *substr, bool case_sensitive)
bool BKE_unit_string_contains_unit(const char *str, int type)
static struct bUnitCollection buMetricAreaCollection
static struct bUnitCollection buMetricVelCollection
static struct bUnitDef buImperialVelDef[]
const char * BKE_unit_name_get(const void *usys_pt, int index)
static struct bUnitCollection buNaturalRotCollection
static bool unit_distribute_negatives(char *str, const int len_max)
static struct bUnitDef buImperialAreaDef[]
static const bUnitDef * get_preferred_display_unit_if_used(int type, PreferredUnits units)
static struct bUnitDef buDummyDef[]
static struct bUnitDef buNaturalRotDef[]
BLI_INLINE bool isalpha_or_utf8(const int ch)
static bool unit_should_be_split(int type)