Blender V4.3
unit.cc File Reference
#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
 

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 /* Metric ton. */
 
#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 /* Imperial ton. */
 
#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)   (ARRAY_SIZE(def) - 1)
 
#define NULL_UNIT
 
#define UNIT_SYSTEM_TOT   (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / sizeof(void *)) - 1)
 

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 bUnitCollectionunit_get_system (int system, int type)
 
static const bUnitDefunit_default (const bUnitCollection *usys)
 
static const bUnitDefunit_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 bUnitDefget_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 bUnitDefunit_find_in_collection (const bUnitCollection *usys, const char *str)
 
static const bUnitDefunit_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)
 

Variables

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

Macro Definition Documentation

◆ EPS

#define EPS   0.001

◆ NULL_UNIT

#define NULL_UNIT
Value:
{ \
/*name*/ nullptr, \
/*name_plural*/ nullptr, \
/*name_short*/ nullptr, \
/*name_alt*/ nullptr, \
/*name_display*/ nullptr, \
/*identifier*/ nullptr, \
/*scalar*/ 0.0, \
/*bias*/ 0.0, \
/*flag*/ 0, \
}

Definition at line 138 of file unit.cc.

◆ SEP_CHR

#define SEP_CHR   '#'

Definition at line 38 of file unit.cc.

Referenced by BKE_unit_replace_string().

◆ SEP_STR

#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().

◆ TEMP_STR_SIZE

#define TEMP_STR_SIZE   256

Definition at line 35 of file unit.cc.

Referenced by BKE_unit_replace_string(), and unit_scale_str().

◆ UN_SC_CH

#define UN_SC_CH   20.1168f

Definition at line 57 of file unit.cc.

◆ UN_SC_CM

#define UN_SC_CM   0.01f

Definition at line 50 of file unit.cc.

◆ UN_SC_CWT

#define UN_SC_CWT   45.359237f

Definition at line 74 of file unit.cc.

◆ UN_SC_DAG

#define UN_SC_DAG   0.01f

Definition at line 68 of file unit.cc.

◆ UN_SC_DAM

#define UN_SC_DAM   10.0f

Definition at line 47 of file unit.cc.

◆ UN_SC_DM

#define UN_SC_DM   0.1f

Definition at line 49 of file unit.cc.

◆ UN_SC_FAH

#define UN_SC_FAH   0.555555555555f

Definition at line 80 of file unit.cc.

◆ UN_SC_FT

#define UN_SC_FT   0.3048f

Definition at line 59 of file unit.cc.

◆ UN_SC_FUR

#define UN_SC_FUR   201.168f

Definition at line 56 of file unit.cc.

◆ UN_SC_G

#define UN_SC_G   0.001f

Definition at line 69 of file unit.cc.

◆ UN_SC_HG

#define UN_SC_HG   0.1f

Definition at line 67 of file unit.cc.

◆ UN_SC_HM

#define UN_SC_HM   100.0f

Definition at line 46 of file unit.cc.

◆ UN_SC_IN

#define UN_SC_IN   0.0254f

Definition at line 60 of file unit.cc.

◆ UN_SC_ITON

#define UN_SC_ITON   907.18474f /* Imperial ton. */

Definition at line 73 of file unit.cc.

◆ UN_SC_KG

#define UN_SC_KG   1.0f

Definition at line 66 of file unit.cc.

◆ UN_SC_KM

#define UN_SC_KM   1000.0f

Definition at line 45 of file unit.cc.

◆ UN_SC_LB

#define UN_SC_LB   0.45359237f

Definition at line 76 of file unit.cc.

◆ UN_SC_M

#define UN_SC_M   1.0f

Definition at line 48 of file unit.cc.

◆ UN_SC_MG

#define UN_SC_MG   0.000001f

Definition at line 70 of file unit.cc.

◆ UN_SC_MI

#define UN_SC_MI   1609.344f

Definition at line 55 of file unit.cc.

◆ UN_SC_MIL

#define UN_SC_MIL   0.0000254f

Definition at line 61 of file unit.cc.

◆ UN_SC_MM

#define UN_SC_MM   0.001f

Definition at line 51 of file unit.cc.

◆ UN_SC_MTON

#define UN_SC_MTON   1000.0f /* Metric ton. */

Definition at line 64 of file unit.cc.

◆ UN_SC_OZ

#define UN_SC_OZ   0.028349523125f

Definition at line 77 of file unit.cc.

◆ UN_SC_QL

#define UN_SC_QL   100.0f

Definition at line 65 of file unit.cc.

◆ UN_SC_ST

#define UN_SC_ST   6.35029318f

Definition at line 75 of file unit.cc.

◆ UN_SC_UM

#define UN_SC_UM   0.000001f

Definition at line 52 of file unit.cc.

◆ UN_SC_YD

#define UN_SC_YD   0.9144f

Definition at line 58 of file unit.cc.

◆ UNIT_COLLECTION_LENGTH

#define UNIT_COLLECTION_LENGTH ( def)    (ARRAY_SIZE(def) - 1)

Definition at line 134 of file unit.cc.

◆ UNIT_SYSTEM_TOT

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

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
B_UNIT_DEF_NONE 
B_UNIT_DEF_SUPPRESS 

Use for units that are not used enough to be translated into for common use.

B_UNIT_DEF_TENTH 

Display a unit even if its value is 0.1, eg 0.1mm instead of 100um.

B_UNIT_DEF_CASE_SENSITIVE 

Short unit name is case sensitive, for example to distinguish mW and MW.

B_UNIT_DEF_NO_SPACE 

Short unit name does not have space between it and preceding number.

Definition at line 111 of file unit.cc.

Function Documentation

◆ BKE_unit_apply_preferred_unit()

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().

◆ BKE_unit_base_get()

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().

◆ BKE_unit_base_of_type_get()

int BKE_unit_base_of_type_get ( int system,
int type )

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().

◆ BKE_unit_base_scalar()

double BKE_unit_base_scalar ( int system,
int type )

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().

◆ BKE_unit_closest_scalar()

double BKE_unit_closest_scalar ( double value,
int system,
int type )

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().

◆ BKE_unit_display_name_get()

const char * BKE_unit_display_name_get ( const void * usys_pt,
int index )

◆ BKE_unit_identifier_get()

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.

◆ BKE_unit_is_suppressed()

bool BKE_unit_is_suppressed ( const void * usys_pt,
int index )

◆ BKE_unit_is_valid()

bool BKE_unit_is_valid ( int system,
int type )
Returns
true is the unit system exists.

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().

◆ BKE_unit_name_get()

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.

◆ BKE_unit_name_to_alt()

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().

◆ BKE_unit_replace_string()

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

Parameters
str_previs optional, when valid it is used to get a base unit when none is set.
Returns
True of a change was made.

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().

◆ BKE_unit_scalar_get()

double BKE_unit_scalar_get ( const void * usys_pt,
int index )

◆ BKE_unit_string_contains_unit()

bool BKE_unit_string_contains_unit ( const char * str,
int type )
Returns
true if the string contains any valid unit for the given 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().

◆ BKE_unit_system_get()

void BKE_unit_system_get ( int system,
int type,
const void ** r_usys_pt,
int * r_len )

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().

◆ BKE_unit_value_as_string()

size_t BKE_unit_value_as_string ( char * str,
int str_maxncpy,
double value,
int prec,
int type,
const UnitSettings * settings,
bool pad )

◆ BKE_unit_value_as_string_adaptive()

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().

◆ ch_is_op()

static bool ch_is_op ( char op)
static

Definition at line 1947 of file unit.cc.

Referenced by BKE_unit_replace_string(), find_next_op(), and find_previous_non_value_char().

◆ ch_is_op_unary()

static bool ch_is_op_unary ( char op)
static

Definition at line 1969 of file unit.cc.

Referenced by skip_unary_op().

◆ find_end_of_value_chars()

static int find_end_of_value_chars ( const char * str,
const int str_maxncpy,
const int start_ofs )
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().

◆ find_next_negative()

static const char * find_next_negative ( const char * str,
const char * remaining_str )
static

Helper function for unit_distribute_negatives to find the next negative to distribute.

Note
This unnecessarily skips the next space if it comes right after the "-" just to make a more predictable output.

Definition at line 1987 of file unit.cc.

References ELEM, find_next_negative(), and str.

Referenced by find_next_negative(), and unit_distribute_negatives().

◆ find_next_op()

static char * find_next_op ( const char * str,
char * remaining_str,
int remaining_str_maxncpy )
static

Helper function for unit_distribute_negatives to find the next operation, including "-".

Note
This unnecessarily skips the space before the operation character just to make a more predictable output.

Definition at line 2013 of file unit.cc.

References BLI_assert_msg, ch_is_op(), ELEM, and str.

Referenced by unit_distribute_negatives().

◆ find_previous_non_value_char()

static int find_previous_non_value_char ( const char * str,
const int start_ofs )
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 2105 of file unit.cc.

References ch_is_op(), and str.

Referenced by unit_scale_str().

◆ get_preferred_display_unit_if_used()

◆ is_valid_unit_collection()

static bool is_valid_unit_collection ( const bUnitCollection * usys)
static

◆ isalpha_or_utf8()

BLI_INLINE bool isalpha_or_utf8 ( const int ch)

Definition at line 1889 of file unit.cc.

Referenced by unit_find_str().

◆ preferred_units_from_UnitSettings()

static PreferredUnits preferred_units_from_UnitSettings ( const UnitSettings * settings)
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().

◆ skip_unary_op()

static char * skip_unary_op ( char * str)
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().

◆ unit_as_string()

static size_t unit_as_string ( char * str,
int str_maxncpy,
double value,
int prec,
const bUnitCollection * usys,
const bUnitDef * unit,
char pad )
static

◆ unit_as_string_main()

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 )
static

◆ unit_as_string_split_pair()

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

◆ unit_best_fit()

static const bUnitDef * unit_best_fit ( double value,
const bUnitCollection * usys,
const bUnitDef * unit_start,
int suppress )
static

◆ unit_default()

static const bUnitDef * unit_default ( const bUnitCollection * usys)
static

◆ unit_detect_from_str()

static const bUnitDef * unit_detect_from_str ( const bUnitCollection * usys,
const char * str,
const char * str_prev )
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!

Note
This does not handle corner cases like 2 + 2cm + 1 + 2.5mm... We can't support everything.

Definition at line 2270 of file unit.cc.

References str, unit_default(), and unit_find_in_collection().

Referenced by BKE_unit_replace_string().

◆ unit_distribute_negatives()

static bool unit_distribute_negatives ( char * str,
const int str_maxncpy )
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().

◆ unit_dual_convert()

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

Definition at line 1623 of file unit.cc.

References ceil(), floor(), and unit_best_fit().

Referenced by unit_as_string_split_pair().

◆ unit_find()

static bool unit_find ( const char * str,
const bUnitDef * unit )
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().

◆ unit_find_in_collection()

static const bUnitDef * unit_find_in_collection ( const bUnitCollection * usys,
const char * str )
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().

◆ unit_find_str()

static const char * unit_find_str ( const char * str,
const char * substr,
bool case_sensitive )
static

◆ unit_get_system()

◆ unit_replace()

static int unit_replace ( char * str,
int str_maxncpy,
char * str_tmp,
double scale_pref,
const bUnitDef * unit )
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().

◆ unit_scale_str()

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

◆ unit_should_be_split()

static bool unit_should_be_split ( int type)
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().

Variable Documentation

◆ buCameraLenCollection

bUnitCollection buCameraLenCollection
static
Initial value:
= {
3,
0,
}
static bUnitDef buCameraLenDef[]
Definition unit.cc:1240
#define UNIT_COLLECTION_LENGTH(def)
Definition unit.cc:134

Definition at line 1299 of file unit.cc.

◆ buCameraLenDef

bUnitDef buCameraLenDef[]
static

Definition at line 1240 of file unit.cc.

◆ buColorTempCollection

bUnitCollection buColorTempCollection
static
Initial value:
= {
0,
0,
}
static bUnitDef buColorTempDef[]
Definition unit.cc:1463

Definition at line 1478 of file unit.cc.

◆ buColorTempDef

bUnitDef buColorTempDef[]
static
Initial value:
= {
{
"kelvin",
"kelvin",
"K",
nullptr,
"Kelvin",
"KELVIN",
1.0f,
0.0,
},
}
#define NULL_UNIT
Definition unit.cc:138
@ B_UNIT_DEF_NONE
Definition unit.cc:112

Definition at line 1463 of file unit.cc.

◆ buDummyCollection

bUnitCollection buDummyCollection
static
Initial value:
= {
0,
0,
}
static bUnitDef buDummyDef[]
Definition unit.cc:152

Definition at line 167 of file unit.cc.

Referenced by unit_as_string_main().

◆ buDummyDef

bUnitDef buDummyDef[]
static
Initial value:
= {
{
"",
nullptr,
"",
nullptr,
nullptr,
nullptr,
1.0,
0.0,
0,
},
}

Definition at line 152 of file unit.cc.

◆ buFrequencyCollection

bUnitCollection buFrequencyCollection
static
Initial value:
= {
0,
0,
}
static bUnitDef buFrequencyDef[]
Definition unit.cc:1486

Definition at line 1512 of file unit.cc.

◆ buFrequencyDef

bUnitDef buFrequencyDef[]
static
Initial value:
= {
{
"hertz",
"hertz",
"Hz",
nullptr,
"Hertz",
"HERTZ",
1.0f,
0.0,
},
{
"kilohertz",
"kilohertz",
"kHz",
nullptr,
"Kilohertz",
"KILOHERTZ",
1e3f,
0.0,
},
}

Definition at line 1486 of file unit.cc.

◆ buImperialAclCollection

bUnitCollection buImperialAclCollection
static
Initial value:
= {
0,
0,
}
static bUnitDef buImperialAclDef[]
Definition unit.cc:1070

Definition at line 1085 of file unit.cc.

◆ buImperialAclDef

bUnitDef buImperialAclDef[]
static
Initial value:
= {
{
"foot per second squared",
"feet per second squared",
"ft/s2",
"Feet per second squared",
nullptr,
0.0,
},
}
#define BLI_STR_UTF8_SUPERSCRIPT_2
#define UN_SC_FT
Definition unit.cc:59

Definition at line 1070 of file unit.cc.

◆ buImperialAreaCollection

bUnitCollection buImperialAreaCollection
static
Initial value:
= {
4,
0,
}
static bUnitDef buImperialAreaDef[]
Definition unit.cc:546

Definition at line 627 of file unit.cc.

◆ buImperialAreaDef

bUnitDef buImperialAreaDef[]
static

Definition at line 546 of file unit.cc.

◆ buImperialLenCollection

bUnitCollection buImperialLenCollection
static
Initial value:
= {
4,
0,
}
static bUnitDef buImperialLenDef[]
Definition unit.cc:301

Definition at line 383 of file unit.cc.

◆ buImperialLenDef

bUnitDef buImperialLenDef[]
static

Definition at line 301 of file unit.cc.

◆ buImperialMassCollection

bUnitCollection buImperialMassCollection
static
Initial value:
= {
3,
0,
}
static bUnitDef buImperialMassDef[]
Definition unit.cc:911

Definition at line 970 of file unit.cc.

◆ buImperialMassDef

bUnitDef buImperialMassDef[]
static

Definition at line 911 of file unit.cc.

◆ buImperialTempCollection

bUnitCollection buImperialTempCollection
static
Initial value:
= {
1,
0,
}
static bUnitDef buImperialTempDef[]
Definition unit.cc:1429

Definition at line 1455 of file unit.cc.

◆ buImperialTempDef

bUnitDef buImperialTempDef[]
static
Initial value:
= {
{
"kelvin",
"kelvin",
"K",
nullptr,
"Kelvin",
"KELVIN",
1.0f,
0.0,
},
{
"fahrenheit",
"fahrenheit",
"F",
"Fahrenheit",
"FAHRENHEIT",
459.67,
},
}
#define BLI_STR_UTF8_DEGREE_SIGN
#define UN_SC_FAH
Definition unit.cc:80

Definition at line 1429 of file unit.cc.

◆ buImperialVelCollection

bUnitCollection buImperialVelCollection
static
Initial value:
= {
0,
0,
}
static bUnitDef buImperialVelDef[]
Definition unit.cc:1014

Definition at line 1040 of file unit.cc.

◆ buImperialVelDef

bUnitDef buImperialVelDef[]
static
Initial value:
= {
{
"foot per second",
"feet per second",
"ft/s",
"fps",
"Feet per second",
nullptr,
0.0,
},
{
"mile per hour",
"miles per hour",
"mph",
nullptr,
"Miles per hour",
nullptr,
UN_SC_MI / 3600.0f,
0.0,
},
}
@ B_UNIT_DEF_SUPPRESS
Definition unit.cc:114
#define UN_SC_MI
Definition unit.cc:55

Definition at line 1014 of file unit.cc.

◆ buImperialVolCollection

bUnitCollection buImperialVolCollection
static
Initial value:
= {
4,
0,
}
static bUnitDef buImperialVolDef[]
Definition unit.cc:734

Definition at line 815 of file unit.cc.

◆ buImperialVolDef

bUnitDef buImperialVolDef[]
static

Definition at line 734 of file unit.cc.

◆ buMetricAclCollection

bUnitCollection buMetricAclCollection
static
Initial value:
= {
0,
0,
}
static bUnitDef buMetricAclDef[]
Definition unit.cc:1048

Definition at line 1063 of file unit.cc.

◆ buMetricAclDef

bUnitDef buMetricAclDef[]
static
Initial value:
= {
{
"meter per second squared",
"meters per second squared",
"m/s2",
"Meters per second squared",
nullptr,
0.0,
},
}
#define UN_SC_M
Definition unit.cc:48

Definition at line 1048 of file unit.cc.

◆ buMetricAreaCollection

bUnitCollection buMetricAreaCollection
static
Initial value:
= {
3,
0,
}
static bUnitDef buMetricAreaDef[]
Definition unit.cc:447

Definition at line 539 of file unit.cc.

◆ buMetricAreaDef

bUnitDef buMetricAreaDef[]
static

Definition at line 447 of file unit.cc.

◆ buMetricLenCollection

const bUnitCollection buMetricLenCollection
static
Initial value:
= {
3,
0,
}
static bUnitDef buMetricLenDef[]
Definition unit.cc:175

Definition at line 294 of file unit.cc.

◆ buMetricLenDef

bUnitDef buMetricLenDef[]
static

Definition at line 175 of file unit.cc.

◆ buMetricMassCollection

bUnitCollection buMetricMassCollection
static
Initial value:
= {
2,
0,
}
static bUnitDef buMetricMassDef[]
Definition unit.cc:823

Definition at line 904 of file unit.cc.

◆ buMetricMassDef

bUnitDef buMetricMassDef[]
static

Definition at line 823 of file unit.cc.

◆ buMetricTempCollection

bUnitCollection buMetricTempCollection
static
Initial value:
= {
0,
0,
}
static bUnitDef buMetricTempDef[]
Definition unit.cc:1396

Definition at line 1422 of file unit.cc.

◆ buMetricTempDef

bUnitDef buMetricTempDef[]
static
Initial value:
= {
{
"kelvin",
"kelvin",
"K",
nullptr,
"Kelvin",
"KELVIN",
1.0f,
0.0,
},
{
"celsius",
"celsius",
"C",
"Celsius",
"CELSIUS",
1.0f,
273.15,
},
}

Definition at line 1396 of file unit.cc.

◆ buMetricVelCollection

bUnitCollection buMetricVelCollection
static
Initial value:
= {
0,
0,
}
static bUnitDef buMetricVelDef[]
Definition unit.cc:981

Definition at line 1007 of file unit.cc.

◆ buMetricVelDef

bUnitDef buMetricVelDef[]
static
Initial value:
= {
{
"meter per second",
"meters per second",
"m/s",
nullptr,
"Meters per second",
nullptr,
0.0,
},
{
"kilometer per hour",
"kilometers per hour",
"km/h",
"kph",
"Kilometers per hour",
nullptr,
UN_SC_KM / 3600.0f,
0.0,
},
}
#define UN_SC_KM
Definition unit.cc:45

Definition at line 981 of file unit.cc.

◆ buMetricVolCollection

bUnitCollection buMetricVolCollection
static
Initial value:
= {
3,
0,
}
static bUnitDef buMetricVolDef[]
Definition unit.cc:635

Definition at line 727 of file unit.cc.

◆ buMetricVolDef

bUnitDef buMetricVolDef[]
static

Definition at line 635 of file unit.cc.

◆ buNaturalRotCollection

bUnitCollection buNaturalRotCollection
static
Initial value:
= {
0,
0,
}
static bUnitDef buNaturalRotDef[]
Definition unit.cc:1171

Definition at line 1232 of file unit.cc.

◆ buNaturalRotDef

bUnitDef buNaturalRotDef[]
static

Definition at line 1171 of file unit.cc.

◆ buNaturalTimeCollection

bUnitCollection buNaturalTimeCollection
static
Initial value:
= {
3,
0,
}
static bUnitDef buNaturalTimeDef[]
Definition unit.cc:1093

Definition at line 1164 of file unit.cc.

◆ buNaturalTimeDef

bUnitDef buNaturalTimeDef[]
static

Definition at line 1093 of file unit.cc.

◆ bUnitSystems

const bUnitCollection* bUnitSystems[][B_UNIT_TYPE_TOT]
static

Definition at line 1520 of file unit.cc.

Referenced by unit_get_system().

◆ buPowerCollection

bUnitCollection buPowerCollection
static
Initial value:
= {
3,
0,
}
static bUnitDef buPowerDef[]
Definition unit.cc:1307

Definition at line 1388 of file unit.cc.

◆ buPowerDef

bUnitDef buPowerDef[]
static

Definition at line 1307 of file unit.cc.

◆ buWavelengthLenCollection

bUnitCollection buWavelengthLenCollection
static
Initial value:
= {
2,
0,
}
static bUnitDef buWavelengthLenDef[]
Definition unit.cc:391

Definition at line 439 of file unit.cc.

◆ buWavelengthLenDef

bUnitDef buWavelengthLenDef[]
static

Definition at line 391 of file unit.cc.