Blender V5.3
unit.cc File Reference
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "BLI_math_base_c.hh"
#include "BLI_string.hh"
#include "BLI_string_utf8.hh"
#include "BLI_string_utf8_symbols.hh"
#include "BLI_sys_types.hh"
#include "DNA_scene_types.h"
#include "BKE_unit.hh"

Go to the source code of this file.

Classes

struct  blender::bUnitDef
struct  blender::bUnitCollection
struct  blender::PreferredUnits

Namespaces

namespace  blender
 BMesh Iterators.

Macros

#define TEMP_STR_SIZE   256
#define SEP_CHR   '#'
#define SEP_STR   "#"
#define EPS   0.001
#define UN_SC_KM   1000.0f
#define UN_SC_HM   100.0f
#define UN_SC_DAM   10.0f
#define UN_SC_M   1.0f
#define UN_SC_DM   0.1f
#define UN_SC_CM   0.01f
#define UN_SC_MM   0.001f
#define UN_SC_UM   0.000001f
#define UN_SC_MI   1609.344f
#define UN_SC_FUR   201.168f
#define UN_SC_CH   20.1168f
#define UN_SC_YD   0.9144f
#define UN_SC_FT   0.3048f
#define UN_SC_IN   0.0254f
#define UN_SC_MIL   0.0000254f
#define UN_SC_MTON   1000.0f
#define UN_SC_QL   100.0f
#define UN_SC_KG   1.0f
#define UN_SC_HG   0.1f
#define UN_SC_DAG   0.01f
#define UN_SC_G   0.001f
#define UN_SC_MG   0.000001f
#define UN_SC_ITON   907.18474f
#define UN_SC_CWT   45.359237f
#define UN_SC_ST   6.35029318f
#define UN_SC_LB   0.45359237f
#define UN_SC_OZ   0.028349523125f
#define UN_SC_FAH   0.555555555555f
#define UNIT_COLLECTION_LENGTH(def)
#define NULL_UNIT
#define UNIT_SYSTEM_TOT   (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1)

Enumerations

enum  {
  blender::B_UNIT_DEF_NONE = 0 , blender::B_UNIT_DEF_SUPPRESS = 1 , blender::B_UNIT_DEF_TENTH = 2 , blender::B_UNIT_DEF_CASE_SENSITIVE = 4 ,
  blender::B_UNIT_DEF_NO_SPACE = 8
}

Functions

static const bUnitCollection * blender::unit_get_system (int system, int type)
static const bUnitDef * blender::unit_default (const bUnitCollection *usys)
static const bUnitDef * blender::unit_best_fit (double value, const bUnitCollection *usys, const bUnitDef *unit_start, int suppress)
static void blender::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 blender::unit_as_string (char *str, int str_maxncpy, double value, int prec, const bool variable_width, const bUnitCollection *usys, const bUnitDef *unit, char pad, bool do_unit_suffix)
static bool blender::unit_should_be_split (int type)
static PreferredUnits blender::preferred_units_from_UnitSettings (const UnitSettings &settings)
static size_t blender::unit_as_string_split_pair (char *str, int str_maxncpy, double value, int prec, const bool variable_width, const bUnitCollection *usys, const bUnitDef *main_unit)
static bool blender::is_valid_unit_collection (const bUnitCollection *usys)
static bool blender::is_unit_adaptive (const int type, const PreferredUnits &units)
static int blender::get_preferred_display_unit_index_if_used (int type, const PreferredUnits &units)
static const bUnitDef * blender::get_preferred_display_unit_if_used (int type, const PreferredUnits &units)
static size_t blender::unit_as_string_main (char *str, int str_maxncpy, double value, int prec, int type, bool split, bool pad, bool do_unit_suffix, const PreferredUnits &units)
size_t blender::BKE_unit_value_as_string_adaptive (char *str, int str_maxncpy, double value, int prec, int system, int type, bool split, bool pad, bool do_unit_suffix)
size_t blender::BKE_unit_value_as_string (char *str, int str_maxncpy, double value, int prec, int type, const UnitSettings &settings, bool pad, bool do_unit_suffix)
size_t blender::BKE_unit_value_as_string_scaled (char *str, int str_maxncpy, double value, int prec, int type, const UnitSettings &settings, bool pad, bool do_unit_suffix)
double blender::BKE_unit_value_scale (const UnitSettings &settings, int unit_type, double value)
BLI_INLINE bool blender::isalpha_or_utf8 (const int ch)
static const char * blender::unit_find_str (const char *str, const char *substr, bool case_sensitive)
static bool blender::ch_is_op (char op)
static bool blender::ch_is_op_unary (char op)
static const char * blender::find_next_negative (const char *str, const char *remaining_str)
static char * blender::find_next_op (const char *str, char *remaining_str, int remaining_str_maxncpy)
static char * blender::skip_unary_op (char *str)
static bool blender::unit_distribute_negatives (char *str, const int str_maxncpy)
static int blender::find_previous_non_value_char (const char *str, const int start_ofs)
static int blender::find_end_of_value_chars (const char *str, const int str_maxncpy, const int start_ofs)
static int blender::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 blender::unit_replace (char *str, int str_maxncpy, char *str_tmp, double scale_pref, const bUnitDef *unit)
static bool blender::unit_find (const char *str, const bUnitDef *unit)
static const bUnitDef * blender::unit_find_in_collection (const bUnitCollection *usys, const char *str)
static const bUnitDef * blender::unit_detect_from_str (const bUnitCollection *usys, const char *str, const char *str_prev)
bool blender::BKE_unit_string_contains_unit (const char *str, int type)
double blender::BKE_unit_apply_preferred_unit (const UnitSettings &settings, int type, double value)
bool blender::BKE_unit_replace_string (char *str, int str_maxncpy, const char *str_prev, double scale_pref, int system, int type)
void blender::BKE_unit_name_to_alt (char *str, int str_maxncpy, const char *orig_str, int system, int type)
double blender::BKE_unit_closest_scalar (double value, int system, int type)
double blender::BKE_unit_base_scalar (int system, int type)
bool blender::BKE_unit_is_valid (int system, int type)
void blender::BKE_unit_system_get (int system, int type, const void **r_usys_pt, int *r_len)
int blender::BKE_unit_base_get (const void *usys_pt)
int blender::BKE_unit_base_of_type_get (int system, int type)
int blender::BKE_preffered_unit_of_type_or_base_get (const UnitSettings &settings, int type)
const char * blender::BKE_unit_name_get (const void *usys_pt, int index)
const char * blender::BKE_unit_display_name_get (const void *usys_pt, int index)
const char * blender::BKE_unit_display_name_short_get (const void *usys_pt, int index)
const char * blender::BKE_unit_identifier_get (const void *usys_pt, int index)
double blender::BKE_unit_scalar_get (const void *usys_pt, int index)
bool blender::BKE_unit_is_suppressed (const void *usys_pt, int index)
bool blender::BKE_unit_is_adaptive (const UnitSettings &settings, int type)
UnitConversion blender::BKE_unit_preferred_conversion_get (const UnitSettings &settings, int unit_type)

Variables

static bUnitDef blender::buDummyDef []
static bUnitCollection blender::buDummyCollection
static bUnitDef blender::buMetricLenDef []
static const bUnitCollection blender::buMetricLenCollection
static bUnitDef blender::buImperialLenDef []
static bUnitCollection blender::buImperialLenCollection
static bUnitDef blender::buWavelengthLenDef []
static bUnitCollection blender::buWavelengthLenCollection
static bUnitDef blender::buMetricAreaDef []
static bUnitCollection blender::buMetricAreaCollection
static bUnitDef blender::buImperialAreaDef []
static bUnitCollection blender::buImperialAreaCollection
static bUnitDef blender::buMetricVolDef []
static bUnitCollection blender::buMetricVolCollection
static bUnitDef blender::buImperialVolDef []
static bUnitCollection blender::buImperialVolCollection
static bUnitDef blender::buMetricMassDef []
static bUnitCollection blender::buMetricMassCollection
static bUnitDef blender::buImperialMassDef []
static bUnitCollection blender::buImperialMassCollection
static bUnitDef blender::buMetricVelDef []
static bUnitCollection blender::buMetricVelCollection
static bUnitDef blender::buImperialVelDef []
static bUnitCollection blender::buImperialVelCollection
static bUnitDef blender::buMetricAclDef []
static bUnitCollection blender::buMetricAclCollection
static bUnitDef blender::buImperialAclDef []
static bUnitCollection blender::buImperialAclCollection
static bUnitDef blender::buNaturalTimeDef []
static bUnitCollection blender::buNaturalTimeCollection
static bUnitDef blender::buNaturalRotDef []
static bUnitCollection blender::buNaturalRotCollection
static bUnitDef blender::buCameraLenDef []
static bUnitCollection blender::buCameraLenCollection
static bUnitDef blender::buPowerDef []
static bUnitCollection blender::buPowerCollection
static bUnitDef blender::buMetricTempDef []
static bUnitCollection blender::buMetricTempCollection
static bUnitDef blender::buImperialTempDef []
static bUnitCollection blender::buImperialTempCollection
static bUnitDef blender::buColorTempDef []
static bUnitCollection blender::buColorTempCollection
static bUnitDef blender::buFrequencyDef []
static bUnitCollection blender::buFrequencyCollection
static const bUnitCollection * blender::bUnitSystems [][B_UNIT_TYPE_TOT]

Macro Definition Documentation

◆ EPS

#define EPS   0.001

◆ NULL_UNIT

#define NULL_UNIT
Value:
{ \
nullptr, \
nullptr, \
nullptr, \
nullptr, \
nullptr, \
nullptr, \
0.0, \
0.0, \
0, \
}

Definition at line 140 of file unit.cc.

◆ SEP_CHR

#define SEP_CHR   '#'

Definition at line 40 of file unit.cc.

Referenced by blender::BKE_unit_replace_string().

◆ SEP_STR

#define SEP_STR   "#"

Definition at line 41 of file unit.cc.

Referenced by blender::appdir_app_template_directories(), blender::BKE_appdir_folder_caches(), blender::BKE_blender_project_config_file_write(), blender::BKE_blender_project_dir_is_project(), blender::BKE_blender_project_init_from_root_path(), blender::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::otio::OTIOTest::copy_image(), blender::io::usd::export_endjob_usdz_cleanup(), blender::filelist_readjob_list_lib_add_datablock(), blender::filelist_readjob_main_assets_add_items(), blender::filelist_readjob_recursive_dir_add_items(), blender::filelist_readjob_remote_asset_library_index_read(), blender::fsmenu_insert_entry(), blender::fsmenu_xdg_user_dirs_parse(), blender::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(), blender::get_thumb_dir(), blender::ed::asset::index::AssetLibraryIndex::init_indices_base_path(), blender::asset_system::is_online_essentials_dirpath(), blender::asset_system::AssetRepresentation::library_relative_identifier(), blender::bke::tests::ImageTest::load_image(), blender::asset_system::AssetLibraryService::normalize_asset_weak_reference_relative_asset_identifier(), blender::path_normalize_impl(), blender::gpu::read_spirv_from_disk(), blender::recents::recents_file_path(), blender::asset_system::AssetLibraryService::resolve_asset_weak_reference_to_full_path(), blender::asset_system::AssetLibraryService::rfind_blendfile_extension(), blender::asset_system::tests::AssetCatalogTest::save_from_memory_into_existing_asset_lib(), blender::seq::seq_proxy_get_filepath_for_elem(), blender::asset_system::tests::AssetLibraryServiceTest::SetUp(), blender::asset_system::tests::AssetLibraryTestBase::SetUp(), blender::io::otio::OTIOTest::SetUp(), blender::tests::FileOpsTest::SetUp(), blender::strip_sound_proxy_update_cb(), blender::io::usd::temp_textures_dir(), blender::ui::template_filepath_split_name_buttons(), blender::io::obj::TEST(), blender::io::obj::TEST(), blender::io::obj::TEST(), blender::io::ply::TEST(), blender::TEST(), blender::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::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::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::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::TEST_F(), blender::tests::TEST_F(), blender::tests::TEST_F(), blender::tests::TEST_F(), blender::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().

◆ TEMP_STR_SIZE

#define TEMP_STR_SIZE   256

Definition at line 37 of file unit.cc.

Referenced by blender::BKE_unit_replace_string(), and blender::unit_scale_str().

◆ UN_SC_CH

#define UN_SC_CH   20.1168f

Definition at line 59 of file unit.cc.

◆ UN_SC_CM

#define UN_SC_CM   0.01f

Definition at line 52 of file unit.cc.

◆ UN_SC_CWT

#define UN_SC_CWT   45.359237f

Definition at line 76 of file unit.cc.

◆ UN_SC_DAG

#define UN_SC_DAG   0.01f

Definition at line 70 of file unit.cc.

◆ UN_SC_DAM

#define UN_SC_DAM   10.0f

Definition at line 49 of file unit.cc.

◆ UN_SC_DM

#define UN_SC_DM   0.1f

Definition at line 51 of file unit.cc.

◆ UN_SC_FAH

#define UN_SC_FAH   0.555555555555f

Definition at line 82 of file unit.cc.

◆ UN_SC_FT

#define UN_SC_FT   0.3048f

Definition at line 61 of file unit.cc.

◆ UN_SC_FUR

#define UN_SC_FUR   201.168f

Definition at line 58 of file unit.cc.

◆ UN_SC_G

#define UN_SC_G   0.001f

Definition at line 71 of file unit.cc.

◆ UN_SC_HG

#define UN_SC_HG   0.1f

Definition at line 69 of file unit.cc.

◆ UN_SC_HM

#define UN_SC_HM   100.0f

Definition at line 48 of file unit.cc.

◆ UN_SC_IN

#define UN_SC_IN   0.0254f

Definition at line 62 of file unit.cc.

◆ UN_SC_ITON

#define UN_SC_ITON   907.18474f

Definition at line 75 of file unit.cc.

◆ UN_SC_KG

#define UN_SC_KG   1.0f

Definition at line 68 of file unit.cc.

◆ UN_SC_KM

#define UN_SC_KM   1000.0f

Definition at line 47 of file unit.cc.

◆ UN_SC_LB

#define UN_SC_LB   0.45359237f

Definition at line 78 of file unit.cc.

◆ UN_SC_M

#define UN_SC_M   1.0f

Definition at line 50 of file unit.cc.

◆ UN_SC_MG

#define UN_SC_MG   0.000001f

Definition at line 72 of file unit.cc.

◆ UN_SC_MI

#define UN_SC_MI   1609.344f

Definition at line 57 of file unit.cc.

◆ UN_SC_MIL

#define UN_SC_MIL   0.0000254f

Definition at line 63 of file unit.cc.

◆ UN_SC_MM

#define UN_SC_MM   0.001f

Definition at line 53 of file unit.cc.

◆ UN_SC_MTON

#define UN_SC_MTON   1000.0f

Definition at line 66 of file unit.cc.

◆ UN_SC_OZ

#define UN_SC_OZ   0.028349523125f

Definition at line 79 of file unit.cc.

◆ UN_SC_QL

#define UN_SC_QL   100.0f

Definition at line 67 of file unit.cc.

◆ UN_SC_ST

#define UN_SC_ST   6.35029318f

Definition at line 77 of file unit.cc.

◆ UN_SC_UM

#define UN_SC_UM   0.000001f

Definition at line 54 of file unit.cc.

◆ UN_SC_YD

#define UN_SC_YD   0.9144f

Definition at line 60 of file unit.cc.

◆ UNIT_COLLECTION_LENGTH

#define UNIT_COLLECTION_LENGTH ( def)
Value:
(ARRAY_SIZE(def) - 1)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept

Definition at line 136 of file unit.cc.

◆ UNIT_SYSTEM_TOT

#define UNIT_SYSTEM_TOT   (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1)