Blender
V3.3
|
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "BLI_math.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_sys_types.h"
#include "DNA_scene_types.h"
#include "BKE_unit.h"
Go to the source code of this file.
Classes | |
struct | bUnitDef |
struct | bUnitCollection |
struct | PreferredUnits |
Typedefs | |
typedef struct bUnitDef | bUnitDef |
typedef struct bUnitCollection | bUnitCollection |
Enumerations | |
enum | { B_UNIT_DEF_NONE = 0 , B_UNIT_DEF_SUPPRESS = 1 , B_UNIT_DEF_TENTH = 2 , B_UNIT_DEF_CASE_SENSITIVE = 4 , B_UNIT_DEF_NO_SPACE = 8 } |
Functions | |
static const bUnitCollection * | unit_get_system (int system, int type) |
static const bUnitDef * | unit_default (const bUnitCollection *usys) |
static const bUnitDef * | unit_best_fit (double value, const bUnitCollection *usys, const bUnitDef *unit_start, int suppress) |
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 size_t | unit_as_string (char *str, int len_max, double value, int prec, const bUnitCollection *usys, const bUnitDef *unit, char pad) |
static bool | unit_should_be_split (int type) |
static PreferredUnits | preferred_units_from_UnitSettings (const UnitSettings *settings) |
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 | is_valid_unit_collection (const bUnitCollection *usys) |
static const bUnitDef * | get_preferred_display_unit_if_used (int type, PreferredUnits units) |
static size_t | unit_as_string_main (char *str, int len_max, double value, int prec, int type, bool split, bool pad, PreferredUnits units) |
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) |
size_t | BKE_unit_value_as_string (char *str, int len_max, double value, int prec, int type, const UnitSettings *settings, bool pad) |
BLI_INLINE bool | isalpha_or_utf8 (const int ch) |
static const char * | unit_find_str (const char *str, const char *substr, bool case_sensitive) |
static bool | ch_is_op (char op) |
static char * | find_next_negative (const char *str, const char *remaining_str) |
static char * | find_next_op (const char *str, char *remaining_str, int len_max) |
static bool | unit_distribute_negatives (char *str, const int len_max) |
static int | find_previous_non_value_char (const char *str, const int start_ofs) |
static int | find_end_of_value_chars (const char *str, const int len_max, const int start_ofs) |
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 int | unit_replace (char *str, int len_max, char *str_tmp, double scale_pref, const bUnitDef *unit) |
static bool | unit_find (const char *str, const bUnitDef *unit) |
static const bUnitDef * | unit_detect_from_str (const bUnitCollection *usys, const char *str, const char *str_prev) |
bool | BKE_unit_string_contains_unit (const char *str, int type) |
double | BKE_unit_apply_preferred_unit (const struct UnitSettings *settings, int type, double value) |
bool | BKE_unit_replace_string (char *str, int len_max, const char *str_prev, double scale_pref, int system, int type) |
void | BKE_unit_name_to_alt (char *str, int len_max, const char *orig_str, int system, int type) |
double | BKE_unit_closest_scalar (double value, int system, int type) |
double | BKE_unit_base_scalar (int system, int type) |
bool | BKE_unit_is_valid (int system, int type) |
void | BKE_unit_system_get (int system, int type, void const **r_usys_pt, int *r_len) |
int | BKE_unit_base_get (const void *usys_pt) |
int | BKE_unit_base_of_type_get (int system, int type) |
const char * | BKE_unit_name_get (const void *usys_pt, int index) |
const char * | BKE_unit_display_name_get (const void *usys_pt, int index) |
const char * | BKE_unit_identifier_get (const void *usys_pt, int index) |
double | BKE_unit_scalar_get (const void *usys_pt, int index) |
bool | BKE_unit_is_suppressed (const void *usys_pt, int index) |
#define UNIT_COLLECTION_LENGTH | ( | def | ) | (ARRAY_SIZE(def) - 1) |
#define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1) |
typedef struct bUnitCollection bUnitCollection |
anonymous enum |
double BKE_unit_apply_preferred_unit | ( | const struct UnitSettings * | settings, |
int | type, | ||
double | value | ||
) |
If user does not specify a unit, this converts it to the unit from the settings.
Definition at line 1080 of file unit.c.
References bUnitDef::bias, BKE_unit_base_scalar(), get_preferred_display_unit_if_used(), NULL, preferred_units_from_UnitSettings(), bUnitDef::scalar, PreferredUnits::system, and type.
Referenced by user_string_to_number().
int BKE_unit_base_get | ( | const void * | usys_pt | ) |
Definition at line 1264 of file unit.c.
Referenced by ED_scene_grid_scale(), and ED_view3d_grid_steps().
int BKE_unit_base_of_type_get | ( | int | system, |
int | type | ||
) |
Definition at line 1269 of file unit.c.
References bUnitCollection::base_unit, type, and unit_get_system().
Referenced by blo_do_versions_280(), and scene_init_data().
double BKE_unit_base_scalar | ( | int | system, |
int | type | ||
) |
Base scale for these units.
Definition at line 1236 of file unit.c.
References bUnitDef::scalar, type, unit_default(), and unit_get_system().
Referenced by BKE_unit_apply_preferred_unit(), and ui_numedit_apply_snapf().
The size of the unit used for this value (used for calculating the click-step).
Definition at line 1220 of file unit.c.
References NULL, bUnitDef::scalar, type, unit_best_fit(), and unit_get_system().
Referenced by ui_get_but_step_unit().
const char* BKE_unit_display_name_get | ( | const void * | usys_pt, |
int | index | ||
) |
Definition at line 1278 of file unit.c.
Referenced by ED_scene_grid_scale(), and ED_view3d_grid_view_scale().
const char* BKE_unit_identifier_get | ( | const void * | usys_pt, |
int | index | ||
) |
Definition at line 1282 of file unit.c.
References BLI_assert_msg, bUnitDef::identifier, and NULL.
Definition at line 1296 of file unit.c.
References B_UNIT_DEF_SUPPRESS.
bool BKE_unit_is_valid | ( | int | system, |
int | type | ||
) |
Definition at line 1246 of file unit.c.
References B_UNIT_TYPE_TOT, and UNIT_SYSTEM_TOT.
Referenced by bpyunits_validate(), and ui_numedit_apply_snapf().
const char* BKE_unit_name_get | ( | const void * | usys_pt, |
int | index | ||
) |
void BKE_unit_name_to_alt | ( | char * | str, |
int | len_max, | ||
const char * | orig_str, | ||
int | system, | ||
int | type | ||
) |
Make string keyboard-friendly, e.g: 10µm -> 10um
.
Definition at line 1180 of file unit.c.
References B_UNIT_DEF_CASE_SENSITIVE, BLI_strncpy_rlen(), bUnitDef::name, offset, str, type, unit_find_str(), unit_get_system(), and bUnitCollection::units.
Referenced by bpyunits_to_string(), and ui_but_convert_to_unit_alt_name().
bool BKE_unit_replace_string | ( | char * | str, |
int | len_max, | ||
const char * | str_prev, | ||
double | scale_pref, | ||
int | system, | ||
int | type | ||
) |
Replace units with values, used before python button evaluation.
Make a copy of the string that replaces the units with numbers. This is only used when evaluating user input and can afford to be a bit slower
This is to be used before python evaluation so: 10.1km -> 10.1*1000.0
...will be resolved by Python.
Values will be split by an add sign: 5'2" -> 5*0.3048 + 2*0.0254
str_prev | is optional, when valid it is used to get a base unit when none is set. |
Definition at line 1091 of file unit.c.
References BLI_snprintf(), ch_is_op(), ELEM, is_valid_unit_collection(), bUnitDef::name, bUnitDef::scalar, SEP_CHR, str, TEMP_STR_SIZE, type, unit_detect_from_str(), unit_distribute_negatives(), unit_get_system(), unit_replace(), UNIT_SYSTEM_TOT, and bUnitCollection::units.
Referenced by bpyunits_to_value(), and user_string_to_number().
Definition at line 1291 of file unit.c.
Referenced by ED_scene_grid_scale(), and ED_view3d_grid_steps().
bool BKE_unit_string_contains_unit | ( | const char * | str, |
int | type | ||
) |
Definition at line 1063 of file unit.c.
References is_valid_unit_collection(), bUnitCollection::length, str, type, unit_find(), unit_get_system(), UNIT_SYSTEM_TOT, and bUnitCollection::units.
Referenced by user_string_to_number().
Loop over scales, could add names later.
Definition at line 1251 of file unit.c.
References bUnitCollection::length, NULL, type, and unit_get_system().
Referenced by ED_scene_grid_scale(), ED_view3d_grid_steps(), and ED_view3d_grid_view_scale().
size_t BKE_unit_value_as_string | ( | char * | str, |
int | len_max, | ||
double | value, | ||
int | prec, | ||
int | type, | ||
const UnitSettings * | settings, | ||
bool | pad | ||
) |
Definition at line 678 of file unit.c.
References UnitSettings::flag, pad, preferred_units_from_UnitSettings(), str, type, unit_as_string_main(), and USER_UNIT_OPT_SPLIT.
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 | ||
) |
Humanly readable representation of a value in units (used for button drawing).
Definition at line 665 of file unit.c.
References PreferredUnits::length, PreferredUnits::mass, pad, PreferredUnits::rotation, blender::io::alembic::split(), str, PreferredUnits::system, PreferredUnits::temperature, PreferredUnits::time, type, unit_as_string_main(), and USER_UNIT_ADAPTIVE.
Referenced by bpyunits_to_string(), outputNumInput(), and value_to_editstr().
|
static |
Definition at line 748 of file unit.c.
Referenced by BKE_unit_replace_string(), find_next_op(), and find_previous_non_value_char().
|
static |
Helper for unit_scale_str for the process of correctly applying the order of operations for the unit's bias term.
Definition at line 894 of file unit.c.
References str.
Referenced by unit_scale_str().
|
static |
Helper function for unit_distribute_negatives to find the next negative to distribute.
Definition at line 776 of file unit.c.
References ELEM, NULL, and str.
Referenced by unit_distribute_negatives().
|
static |
Helper function for unit_distribute_negatives to find the next operation, including "-".
Definition at line 802 of file unit.c.
References BLI_assert_msg, ch_is_op(), ELEM, and str.
Referenced by unit_distribute_negatives().
|
static |
Helper for unit_scale_str for the process of correctly applying the order of operations for the unit's bias term.
Definition at line 880 of file unit.c.
References ch_is_op(), and str.
Referenced by unit_scale_str().
|
static |
Definition at line 588 of file unit.c.
References B_UNIT_AREA, B_UNIT_LENGTH, B_UNIT_MASS, B_UNIT_ROTATION, B_UNIT_TEMPERATURE, B_UNIT_TIME, B_UNIT_VOLUME, is_valid_unit_collection(), bUnitCollection::length, PreferredUnits::length, PreferredUnits::mass, MIN2, NULL, PreferredUnits::rotation, PreferredUnits::system, PreferredUnits::temperature, PreferredUnits::time, type, unit_get_system(), bUnitCollection::units, USER_UNIT_ADAPTIVE, and USER_UNIT_ROT_RADIANS.
Referenced by BKE_unit_apply_preferred_unit(), and unit_as_string_main().
|
static |
Definition at line 583 of file unit.c.
References bUnitDef::name, NULL, and bUnitCollection::units.
Referenced by BKE_unit_replace_string(), BKE_unit_string_contains_unit(), get_preferred_display_unit_if_used(), and unit_as_string_main().
BLI_INLINE bool isalpha_or_utf8 | ( | const int | ch | ) |
Definition at line 691 of file unit.c.
Referenced by unit_find_str().
|
static |
Definition at line 539 of file unit.c.
References PreferredUnits::length, UnitSettings::length_unit, PreferredUnits::mass, UnitSettings::mass_unit, PreferredUnits::rotation, PreferredUnits::system, UnitSettings::system, UnitSettings::system_rotation, PreferredUnits::temperature, UnitSettings::temperature_unit, PreferredUnits::time, and UnitSettings::time_unit.
Referenced by BKE_unit_apply_preferred_unit(), and BKE_unit_value_as_string().
|
static |
Definition at line 443 of file unit.c.
References B_UNIT_DEF_NO_SPACE, bUnitDef::bias, BLI_snprintf_rlen(), CLAMP, bUnitDef::flag, if(), integer_digits_d(), len, bUnitDef::name_short, NULL, pad, bUnitDef::scalar, str, unit_best_fit(), and unit_default().
Referenced by unit_as_string_main(), and unit_as_string_split_pair().
|
static |
Definition at line 635 of file unit.c.
References buDummyCollection, get_preferred_display_unit_if_used(), is_valid_unit_collection(), blender::math::length(), NULL, pad, blender::io::alembic::split(), str, PreferredUnits::system, type, unit_as_string(), unit_as_string_split_pair(), unit_get_system(), and unit_should_be_split().
Referenced by BKE_unit_value_as_string(), and BKE_unit_value_as_string_adaptive().
|
static |
Definition at line 551 of file unit.c.
References integer_digits_d(), max_ii(), bUnitDef::scalar, str, unit_as_string(), and unit_dual_convert().
Referenced by unit_as_string_main().
|
static |
Definition at line 396 of file unit.c.
References B_UNIT_DEF_SUPPRESS, B_UNIT_DEF_TENTH, EPS, bUnitDef::name, unit_default(), bUnitCollection::units, and UNLIKELY.
Referenced by BKE_unit_closest_scalar(), unit_as_string(), and unit_dual_convert().
|
static |
Definition at line 391 of file unit.c.
References bUnitCollection::base_unit, and bUnitCollection::units.
Referenced by BKE_unit_base_scalar(), unit_as_string(), unit_best_fit(), and unit_detect_from_str().
|
static |
Try to find a default unit from current or previous string. This allows us to handle cases like 2 + 2mm, people would expect to get 4mm, not 2.002m!
Definition at line 1034 of file unit.c.
References bUnitDef::name, NULL, str, unit_default(), unit_find(), and bUnitCollection::units.
Referenced by BKE_unit_replace_string().
|
static |
Put parentheses around blocks of values after negative signs to get rid of an implied "+" between numbers without an operation between them. For example:
"-1m50cm + 1 - 2m50cm" -> "-(1m50cm) + 1 - (2m50cm)"
Definition at line 843 of file unit.c.
References find_next_negative(), find_next_op(), NULL, and str.
Referenced by BKE_unit_replace_string().
|
static |
Definition at line 426 of file unit.c.
References ceil(), blender::math::floor(), NULL, bUnitDef::scalar, and unit_best_fit().
Referenced by unit_as_string_split_pair().
Definition at line 1009 of file unit.c.
References B_UNIT_DEF_CASE_SENSITIVE, bUnitDef::flag, bUnitDef::name, bUnitDef::name_alt, bUnitDef::name_plural, bUnitDef::name_short, str, and unit_find_str().
Referenced by BKE_unit_string_contains_unit(), and unit_detect_from_str().
|
static |
Definition at line 696 of file unit.c.
References BLI_str_find_prev_char_utf8(), BLI_strcasestr(), isalpha_or_utf8(), NULL, and str.
Referenced by BKE_unit_name_to_alt(), unit_find(), and unit_scale_str().
|
static |
Definition at line 384 of file unit.c.
References B_UNIT_TYPE_TOT, BLI_assert, bUnitSystems, type, and UNIT_SYSTEM_TOT.
Referenced by BKE_unit_base_of_type_get(), BKE_unit_base_scalar(), BKE_unit_closest_scalar(), BKE_unit_name_to_alt(), BKE_unit_replace_string(), BKE_unit_string_contains_unit(), BKE_unit_system_get(), get_preferred_display_unit_if_used(), and unit_as_string_main().
|
static |
Definition at line 994 of file unit.c.
References B_UNIT_DEF_CASE_SENSITIVE, bUnitDef::flag, bUnitDef::name, bUnitDef::name_alt, bUnitDef::name_plural, bUnitDef::name_short, str, and unit_scale_str().
Referenced by BKE_unit_replace_string().
|
static |
Definition at line 905 of file unit.c.
References bUnitDef::bias, BLI_snprintf_rlen(), find_end_of_value_chars(), find_previous_non_value_char(), len, NULL, bUnitDef::scalar, SEP_STR, str, TEMP_STR_SIZE, and unit_find_str().
Referenced by unit_replace().
|
static |
Definition at line 524 of file unit.c.
References B_UNIT_CAMERA, B_UNIT_LENGTH, B_UNIT_MASS, B_UNIT_TIME, ELEM, and type.
Referenced by unit_as_string_main().
|
static |
|
static |
|
static |
Definition at line 1 of file unit.c.
Referenced by unit_as_string_main().
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Definition at line 338 of file unit.c.
Referenced by unit_get_system().
|
static |
|
static |