|
Blender V4.3
|
#include <algorithm>#include <cctype>#include <cstdio>#include <cstdlib>#include <cstring>#include "BLI_math_base.h"#include "BLI_string.h"#include "BLI_string_utf8.h"#include "BLI_string_utf8_symbols.h"#include "BLI_sys_types.h"#include "DNA_scene_types.h"#include "BKE_unit.hh"Go to the source code of this file.
Classes | |
| struct | bUnitDef |
| struct | bUnitCollection |
| struct | PreferredUnits |
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 str_maxncpy, 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 str_maxncpy, 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, const PreferredUnits &units) |
| static size_t | unit_as_string_main (char *str, int str_maxncpy, double value, int prec, int type, bool split, bool pad, const PreferredUnits &units) |
| size_t | BKE_unit_value_as_string_adaptive (char *str, int str_maxncpy, double value, int prec, int system, int type, bool split, bool pad) |
| size_t | BKE_unit_value_as_string (char *str, int str_maxncpy, 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 bool | ch_is_op_unary (char op) |
| static const char * | find_next_negative (const char *str, const char *remaining_str) |
| static char * | find_next_op (const char *str, char *remaining_str, int remaining_str_maxncpy) |
| static char * | skip_unary_op (char *str) |
| static bool | unit_distribute_negatives (char *str, const int str_maxncpy) |
| 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 str_maxncpy, const int start_ofs) |
| static int | unit_scale_str (char *str, int str_maxncpy, char *str_tmp, double scale_pref, const bUnitDef *unit, const char *replace_str, bool case_sensitive) |
| static int | unit_replace (char *str, int str_maxncpy, char *str_tmp, double scale_pref, const bUnitDef *unit) |
| static bool | unit_find (const char *str, const bUnitDef *unit) |
| static const bUnitDef * | unit_find_in_collection (const bUnitCollection *usys, const char *str) |
| 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 UnitSettings *settings, int type, double value) |
| bool | BKE_unit_replace_string (char *str, int str_maxncpy, const char *str_prev, double scale_pref, int system, int type) |
| void | BKE_unit_name_to_alt (char *str, int str_maxncpy, 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 EPS 0.001 |
Definition at line 42 of file unit.cc.
Referenced by GHOST_DirectManipulationViewportEventHandler::OnContentUpdated(), and unit_best_fit().
| #define NULL_UNIT |
| #define SEP_CHR '#' |
Definition at line 38 of file unit.cc.
Referenced by BKE_unit_replace_string().
| #define SEP_STR "#" |
Definition at line 39 of file unit.cc.
Referenced by appdir_app_template_directories(), BKE_appdir_folder_caches(), blf_load_datafiles_dir(), blender::gpu::cache_dir_get(), blender::io::obj::OBJMTLParserTest::check(), blender::io::obj::OBJMTLParserTest::check_string(), blender::io::obj::OBJExportRegressionTest::compare_obj_export_to_golden(), blender::io::stl::STLExportTest::compare_to_golden(), blender::io::usd::export_endjob_usdz_cleanup(), blender::io::usd::export_texture(), filelist_readjob_list_lib_add_datablock(), filelist_readjob_main_assets_add_items(), fsmenu_insert_entry(), fsmenu_xdg_user_dirs_parse(), blender::compositor::get_operations_export_dir(), get_proxy_filepath(), blender::io::stl::STLExportTest::get_temp_filename(), blender::io::obj::ObjExporterWriterTest::get_temp_obj_filename(), blender::io::ply::PLYExportTest::get_temp_ply_filename(), get_thumb_dir(), blender::io::obj::OBJImportTest::import_and_check(), blender::io::ply::PLYImportTest::import_and_check(), blender::io::stl::stl_importer_test::import_and_check(), blender::ed::asset::index::AssetLibraryIndex::init_indices_base_path(), blender::bke::tests::ImageTest::load_image(), blender::asset_system::AssetLibraryService::normalize_asset_weak_reference_relative_asset_identifier(), path_normalize_impl(), blender::gpu::read_spirv_from_disk(), blender::asset_system::AssetLibraryService::resolve_asset_weak_reference_to_full_path(), blender::asset_system::AssetLibraryService::rfind_blendfile_extension(), blender::ed::geometry::run_node_group_get_name(), blender::asset_system::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), seq_proxy_get_filepath(), seq_sound_proxy_update_cb(), blender::asset_system::tests::AssetLibraryServiceTest::SetUp(), blender::asset_system::tests::AssetLibraryTestBase::SetUp(), blender::tests::FileOpsTest::SetUp(), blender::io::usd::temp_textures_dir(), blender::io::obj::TEST(), blender::io::obj::TEST(), blender::io::obj::TEST(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::asset_system::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::bke::tests::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::obj::TEST_F(), blender::io::stl::TEST_F(), blender::io::stl::TEST_F(), blender::io::stl::TEST_F(), blender::io::stl::TEST_F(), blender::io::TEST_F(), blender::io::TEST_F(), blender::io::TEST_F(), blender::tests::TEST_F(), TEST_F(), unit_scale_str(), blender::asset_system::tests::AssetLibraryServiceTest::use_temp_path(), blender::asset_system::tests::AssetLibraryTestBase::use_temp_path(), and blender::gpu::write_spirv_to_disk().
| #define TEMP_STR_SIZE 256 |
Definition at line 35 of file unit.cc.
Referenced by BKE_unit_replace_string(), and unit_scale_str().
| #define UNIT_COLLECTION_LENGTH | ( | def | ) | (ARRAY_SIZE(def) - 1) |
| #define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1) |
Definition at line 1519 of file unit.cc.
Referenced by BKE_unit_is_valid(), BKE_unit_replace_string(), BKE_unit_string_contains_unit(), and unit_get_system().
| anonymous enum |
| double BKE_unit_apply_preferred_unit | ( | const 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 2303 of file unit.cc.
References BKE_unit_base_scalar(), get_preferred_display_unit_if_used(), and preferred_units_from_UnitSettings().
Referenced by user_string_to_number().
| int BKE_unit_base_get | ( | const void * | usys_pt | ) |
Definition at line 2490 of file unit.cc.
Referenced by ED_scene_grid_scale(), and view3d_grid_steps_ex().
Definition at line 2495 of file unit.cc.
References bUnitCollection::base_unit, and unit_get_system().
Referenced by blo_do_versions_280(), and scene_init_data().
Base scale for these units.
Definition at line 2462 of file unit.cc.
References bUnitDef::scalar, 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 2446 of file unit.cc.
References 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 2506 of file unit.cc.
References BLI_assert, bUnitCollection::length, bUnitDef::name_display, and bUnitCollection::units.
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 2512 of file unit.cc.
References BLI_assert, BLI_assert_msg, bUnitCollection::length, and bUnitCollection::units.
| bool BKE_unit_is_suppressed | ( | const void * | usys_pt, |
| int | index ) |
Definition at line 2530 of file unit.cc.
References B_UNIT_DEF_SUPPRESS, BLI_assert, bUnitDef::flag, bUnitCollection::length, and bUnitCollection::units.
Definition at line 2472 of file unit.cc.
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 ) |
Definition at line 2500 of file unit.cc.
References BLI_assert, bUnitCollection::length, bUnitDef::name, and bUnitCollection::units.
| void BKE_unit_name_to_alt | ( | char * | str, |
| int | str_maxncpy, | ||
| const char * | orig_str, | ||
| int | system, | ||
| int | type ) |
Make string keyboard-friendly, e.g: 10µm -> 10um.
Definition at line 2405 of file unit.cc.
References B_UNIT_DEF_CASE_SENSITIVE, BLI_assert, BLI_strncpy(), BLI_strncpy_rlen(), int, str, 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 | str_maxncpy, | ||
| 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 2315 of file unit.cc.
References BLI_strncpy(), ch_is_op(), ELEM, is_valid_unit_collection(), bUnitDef::scalar, SEP_CHR, SNPRINTF, str, TEMP_STR_SIZE, 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 2523 of file unit.cc.
References BLI_assert, bUnitCollection::length, bUnitDef::scalar, and bUnitCollection::units.
Referenced by ED_scene_grid_scale(), and view3d_grid_steps_ex().
| bool BKE_unit_string_contains_unit | ( | const char * | str, |
| int | type ) |
Definition at line 2289 of file unit.cc.
References is_valid_unit_collection(), str, unit_find_in_collection(), unit_get_system(), and UNIT_SYSTEM_TOT.
Referenced by user_string_to_number().
Loop over scales, could add names later.
Definition at line 2477 of file unit.cc.
References bUnitCollection::length, and unit_get_system().
Referenced by ED_scene_grid_scale(), and view3d_grid_steps_ex().
| size_t BKE_unit_value_as_string | ( | char * | str, |
| int | str_maxncpy, | ||
| double | value, | ||
| int | prec, | ||
| int | type, | ||
| const UnitSettings * | settings, | ||
| bool | pad ) |
Representation of a value in units. Negative precision is used to disable stripping of zeroes. This reduces text jumping when changing values.
Definition at line 1876 of file unit.cc.
References pad, preferred_units_from_UnitSettings(), str, unit_as_string_main(), and USER_UNIT_OPT_SPLIT.
Referenced by applyShrinkFatten(), depthdropper_depth_sample_pt(), DRW_text_edit_mesh_measure_stats(), edbm_bevel_update_status_text(), edbm_inset_update_header(), knifetool_draw_angle(), knifetool_draw_visible_distances(), ruler_item_as_string(), translate_dist_to_str(), ui_get_but_string_unit(), and blender::ed::object::voxel_size_edit_draw().
| size_t BKE_unit_value_as_string_adaptive | ( | char * | str, |
| int | str_maxncpy, | ||
| 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 1863 of file unit.cc.
References pad, str, PreferredUnits::system, unit_as_string_main(), and USER_UNIT_ADAPTIVE.
Referenced by bpyunits_to_string(), outputNumInput(), and value_to_editstr().
|
static |
Definition at line 1947 of file unit.cc.
Referenced by BKE_unit_replace_string(), find_next_op(), and find_previous_non_value_char().
|
static |
Definition at line 1969 of file unit.cc.
Referenced by skip_unary_op().
|
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 2119 of file unit.cc.
References str.
Referenced by unit_scale_str().
|
static |
Helper function for unit_distribute_negatives to find the next negative to distribute.
Definition at line 1987 of file unit.cc.
References ELEM, find_next_negative(), and str.
Referenced by find_next_negative(), and unit_distribute_negatives().
|
static |
Helper function for unit_distribute_negatives to find the next operation, including "-".
Definition at line 2013 of file unit.cc.
References BLI_assert_msg, ch_is_op(), ELEM, and str.
Referenced by unit_distribute_negatives().
Helper for unit_scale_str for the process of correctly applying the order of operations for the unit's bias term.
Definition at line 2105 of file unit.cc.
References ch_is_op(), and str.
Referenced by unit_scale_str().
|
static |
Definition at line 1786 of file unit.cc.
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, 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 1781 of file unit.cc.
References bUnitDef::name, 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 1889 of file unit.cc.
Referenced by unit_find_str().
|
static |
Definition at line 1737 of file unit.cc.
References PreferredUnits::system.
Referenced by BKE_unit_apply_preferred_unit(), and BKE_unit_value_as_string().
|
static |
Skip over multiple successive unary operators (typically -), skipping spaces. This allows for --90d to be handled properly, see: #117783.
Definition at line 2053 of file unit.cc.
References ch_is_op_unary(), and str.
Referenced by unit_distribute_negatives().
|
static |
Definition at line 1641 of file unit.cc.
References B_UNIT_DEF_NO_SPACE, BLI_snprintf_rlen(), CLAMP, integer_digits_d(), len, pad, str, unit_best_fit(), and unit_default().
Referenced by unit_as_string_main(), and unit_as_string_split_pair().
|
static |
Definition at line 1833 of file unit.cc.
References buDummyCollection, get_preferred_display_unit_if_used(), is_valid_unit_collection(), length(), pad, str, 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 1749 of file unit.cc.
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 1593 of file unit.cc.
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 1588 of file unit.cc.
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 2270 of file unit.cc.
References str, unit_default(), and unit_find_in_collection().
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 2067 of file unit.cc.
References find_next_negative(), find_next_op(), int, skip_unary_op(), and str.
Referenced by BKE_unit_replace_string().
|
static |
Definition at line 1623 of file unit.cc.
References ceil(), floor(), and unit_best_fit().
Referenced by unit_as_string_split_pair().
|
static |
Definition at line 2235 of file unit.cc.
References B_UNIT_DEF_CASE_SENSITIVE, str, and unit_find_str().
Referenced by unit_find_in_collection().
|
static |
Definition at line 2254 of file unit.cc.
References str, unit_find(), and bUnitCollection::units.
Referenced by BKE_unit_string_contains_unit(), and unit_detect_from_str().
|
static |
Definition at line 1894 of file unit.cc.
References BLI_str_find_prev_char_utf8(), BLI_strcasestr(), isalpha_or_utf8(), and str.
Referenced by BKE_unit_name_to_alt(), unit_find(), and unit_scale_str().
|
static |
Definition at line 1581 of file unit.cc.
References B_UNIT_TYPE_TOT, BLI_assert, bUnitSystems, 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 2219 of file unit.cc.
References B_UNIT_DEF_CASE_SENSITIVE, str, and unit_scale_str().
Referenced by BKE_unit_replace_string().
|
static |
Definition at line 2130 of file unit.cc.
References BLI_snprintf_rlen(), find_end_of_value_chars(), find_previous_non_value_char(), int, len, SEP_STR, str, TEMP_STR_SIZE, and unit_find_str().
Referenced by unit_replace().
|
static |
Definition at line 1722 of file unit.cc.
References B_UNIT_CAMERA, B_UNIT_LENGTH, B_UNIT_MASS, B_UNIT_TIME, B_UNIT_WAVELENGTH, and ELEM.
Referenced by unit_as_string_main().
|
static |
|
static |
|
static |
|
static |
Definition at line 167 of file unit.cc.
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 |
Definition at line 1520 of file unit.cc.
Referenced by unit_get_system().
|
static |
|
static |