Cleanup: Rename public "bUnit" functions

This commit renames the functions in "BKE_unit.h` to be consistent
with the naming in the rest of blenkernel.

bUnit_AsString -> BKE_unit_value_as_string_adaptive
bUnit_AsString2 -> BKE_unit_value_as_string
bUnit_ReplaceString -> BKE_unit_replace_string
bUnit_ApplyPreferredUnit -> BKE_unit_apply_preferred_unit
bUnit_ToUnitAltName -> BKE_unit_name_to_alt
bUnit_ClosestScalar -> BKE_unit_closest_scalar
bUnit_BaseScalar -> BKE_unit_base_scalar
bUnit_IsValid -> BKE_unit_is_valid
bUnit_GetSystem -> BKE_unit_system_get
bUnit_GetBaseUnit -> BKE_unit_base_get
bUnit_GetBaseUnitOfType -> BKE_unit_base_of_type_get
bUnit_GetName -> BKE_unit_name_get
bUnit_GetNameDisplay -> BKE_unit_display_name_get
bUnit_GetIdentifier -> BKE_unit_identifier_get
bUnit_GetScaler -> BKE_unit_scalar_get
bUnit_IsSuppressed -> BKE_unit_is_suppressed

Differential Revision: https://developer.blender.org/D8828
This commit is contained in:
2020-09-09 08:41:15 -05:00
parent 6dc7266cf1
commit 842f52d418
15 changed files with 160 additions and 157 deletions

View File

@@ -29,49 +29,49 @@ struct UnitSettings;
/* in all cases the value is assumed to be scaled by the user preference */ /* in all cases the value is assumed to be scaled by the user preference */
/* humanly readable representation of a value in units (used for button drawing) */ /* humanly readable representation of a value in units (used for button drawing) */
size_t bUnit_AsString( 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); char *str, int len_max, double value, int prec, int system, int type, bool split, bool pad);
size_t bUnit_AsString2(char *str, size_t BKE_unit_value_as_string(char *str,
int len_max, int len_max,
double value, double value,
int prec, int prec,
int type, int type,
const struct UnitSettings *settings, const struct UnitSettings *settings,
bool pad); bool pad);
/* replace units with values, used before python button evaluation */ /* replace units with values, used before python button evaluation */
bool bUnit_ReplaceString( bool BKE_unit_replace_string(
char *str, int len_max, const char *str_prev, double scale_pref, int system, int type); char *str, int len_max, const char *str_prev, double scale_pref, int system, int type);
/* return true if the string contains any valid unit for the given type */ /* return true if the string contains any valid unit for the given type */
bool bUnit_ContainsUnit(const char *str, int type); bool BKE_unit_string_contains_unit(const char *str, int type);
/* If user does not specify a unit, this converts it to the unit from the settings. */ /* If user does not specify a unit, this converts it to the unit from the settings. */
double bUnit_ApplyPreferredUnit(const struct UnitSettings *settings, int type, double value); double BKE_unit_apply_preferred_unit(const struct UnitSettings *settings, int type, double value);
/* make string keyboard-friendly: 10µm --> 10um */ /* make string keyboard-friendly: 10µm --> 10um */
void bUnit_ToUnitAltName(char *str, int len_max, const char *orig_str, int system, int type); void BKE_unit_name_to_alt(char *str, int len_max, const char *orig_str, int system, int type);
/* the size of the unit used for this value (used for calculating the ckickstep) */ /* the size of the unit used for this value (used for calculating the ckickstep) */
double bUnit_ClosestScalar(double value, int system, int type); double BKE_unit_closest_scalar(double value, int system, int type);
/* base scale for these units */ /* base scale for these units */
double bUnit_BaseScalar(int system, int type); double BKE_unit_base_scalar(int system, int type);
/* return true is the unit system exists */ /* return true is the unit system exists */
bool bUnit_IsValid(int system, int type); bool BKE_unit_is_valid(int system, int type);
/* loop over scales, could add names later */ /* loop over scales, could add names later */
// double bUnit_Iter(void **unit, char **name, int system, int type); // double bUnit_Iter(void **unit, char **name, int system, int type);
void bUnit_GetSystem(int system, int type, void const **r_usys_pt, int *r_len); void BKE_unit_system_get(int system, int type, const void **r_usys_pt, int *r_len);
int bUnit_GetBaseUnit(const void *usys_pt); int BKE_unit_base_get(const void *usys_pt);
int bUnit_GetBaseUnitOfType(int system, int type); int BKE_unit_base_of_type_get(int system, int type);
const char *bUnit_GetName(const void *usys_pt, int index); const char *BKE_unit_name_get(const void *usys_pt, int index);
const char *bUnit_GetNameDisplay(const void *usys_pt, int index); const char *BKE_unit_display_name_get(const void *usys_pt, int index);
const char *bUnit_GetIdentifier(const void *usys_pt, int index); const char *BKE_unit_identifier_get(const void *usys_pt, int index);
double bUnit_GetScaler(const void *usys_pt, int index); double BKE_unit_scalar_get(const void *usys_pt, int index);
bool bUnit_IsSuppressed(const void *usys_pt, int index); bool BKE_unit_is_suppressed(const void *usys_pt, int index);
/* aligned with PropertyUnit */ /* aligned with PropertyUnit */
enum { enum {

View File

@@ -154,11 +154,11 @@ static void scene_init_data(ID *id)
scene->unit.system = USER_UNIT_METRIC; scene->unit.system = USER_UNIT_METRIC;
scene->unit.scale_length = 1.0f; scene->unit.scale_length = 1.0f;
scene->unit.length_unit = (uchar)bUnit_GetBaseUnitOfType(USER_UNIT_METRIC, B_UNIT_LENGTH); scene->unit.length_unit = (uchar)BKE_unit_base_of_type_get(USER_UNIT_METRIC, B_UNIT_LENGTH);
scene->unit.mass_unit = (uchar)bUnit_GetBaseUnitOfType(USER_UNIT_METRIC, B_UNIT_MASS); scene->unit.mass_unit = (uchar)BKE_unit_base_of_type_get(USER_UNIT_METRIC, B_UNIT_MASS);
scene->unit.time_unit = (uchar)bUnit_GetBaseUnitOfType(USER_UNIT_METRIC, B_UNIT_TIME); scene->unit.time_unit = (uchar)BKE_unit_base_of_type_get(USER_UNIT_METRIC, B_UNIT_TIME);
scene->unit.temperature_unit = (uchar)bUnit_GetBaseUnitOfType(USER_UNIT_METRIC, scene->unit.temperature_unit = (uchar)BKE_unit_base_of_type_get(USER_UNIT_METRIC,
B_UNIT_TEMPERATURE); B_UNIT_TEMPERATURE);
/* Anti-Aliasing threshold. */ /* Anti-Aliasing threshold. */
scene->grease_pencil_settings.smaa_threshold = 1.0f; scene->grease_pencil_settings.smaa_threshold = 1.0f;

View File

@@ -662,7 +662,7 @@ static size_t unit_as_string_main(char *str,
return unit_as_string(str, len_max, value, prec, usys, main_unit, pad ? ' ' : '\0'); return unit_as_string(str, len_max, value, prec, usys, main_unit, pad ? ' ' : '\0');
} }
size_t bUnit_AsString( 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) char *str, int len_max, double value, int prec, int system, int type, bool split, bool pad)
{ {
PreferredUnits units; PreferredUnits units;
@@ -675,13 +675,13 @@ size_t bUnit_AsString(
return unit_as_string_main(str, len_max, value, prec, type, split, pad, units); return unit_as_string_main(str, len_max, value, prec, type, split, pad, units);
} }
size_t bUnit_AsString2(char *str, size_t BKE_unit_value_as_string(char *str,
int len_max, int len_max,
double value, double value,
int prec, int prec,
int type, int type,
const UnitSettings *settings, const UnitSettings *settings,
bool pad) bool pad)
{ {
bool do_split = (settings->flag & USER_UNIT_OPT_SPLIT) != 0; bool do_split = (settings->flag & USER_UNIT_OPT_SPLIT) != 0;
PreferredUnits units = preferred_units_from_UnitSettings(settings); PreferredUnits units = preferred_units_from_UnitSettings(settings);
@@ -1059,7 +1059,7 @@ static const bUnitDef *unit_detect_from_str(const bUnitCollection *usys,
return unit; return unit;
} }
bool bUnit_ContainsUnit(const char *str, int type) bool BKE_unit_string_contains_unit(const char *str, int type)
{ {
for (int system = 0; system < UNIT_SYSTEM_TOT; system++) { for (int system = 0; system < UNIT_SYSTEM_TOT; system++) {
const bUnitCollection *usys = unit_get_system(system, type); const bUnitCollection *usys = unit_get_system(system, type);
@@ -1076,12 +1076,12 @@ bool bUnit_ContainsUnit(const char *str, int type)
return false; return false;
} }
double bUnit_ApplyPreferredUnit(const struct UnitSettings *settings, int type, double value) double BKE_unit_apply_preferred_unit(const struct UnitSettings *settings, int type, double value)
{ {
PreferredUnits units = preferred_units_from_UnitSettings(settings); PreferredUnits units = preferred_units_from_UnitSettings(settings);
const bUnitDef *unit = get_preferred_display_unit_if_used(type, units); const bUnitDef *unit = get_preferred_display_unit_if_used(type, units);
const double scalar = (unit == NULL) ? bUnit_BaseScalar(units.system, type) : unit->scalar; const double scalar = (unit == NULL) ? BKE_unit_base_scalar(units.system, type) : unit->scalar;
const double bias = (unit == NULL) ? 0.0 : unit->bias; /* Base unit shouldn't have a bias. */ const double bias = (unit == NULL) ? 0.0 : unit->bias; /* Base unit shouldn't have a bias. */
return value * scalar + bias; return value * scalar + bias;
@@ -1103,7 +1103,7 @@ double bUnit_ApplyPreferredUnit(const struct UnitSettings *settings, int type, d
* *
* \return True of a change was made. * \return True of a change was made.
*/ */
bool bUnit_ReplaceString( bool BKE_unit_replace_string(
char *str, int len_max, const char *str_prev, double scale_pref, int system, int type) char *str, int len_max, const char *str_prev, double scale_pref, int system, int type)
{ {
const bUnitCollection *usys = unit_get_system(system, type); const bUnitCollection *usys = unit_get_system(system, type);
@@ -1133,7 +1133,7 @@ bool bUnit_ReplaceString(
} }
else { else {
/* BLI_snprintf would not fit into str_tmp, cant do much in this case. /* BLI_snprintf would not fit into str_tmp, cant do much in this case.
* Check for this because otherwise bUnit_ReplaceString could call its self forever. */ * Check for this because otherwise BKE_unit_replace_string could call its self forever. */
return changed; return changed;
} }
@@ -1194,7 +1194,7 @@ bool bUnit_ReplaceString(
} }
/* 45µm --> 45um */ /* 45µm --> 45um */
void bUnit_ToUnitAltName(char *str, int len_max, const char *orig_str, int system, int type) void BKE_unit_name_to_alt(char *str, int len_max, const char *orig_str, int system, int type)
{ {
const bUnitCollection *usys = unit_get_system(system, type); const bUnitCollection *usys = unit_get_system(system, type);
@@ -1234,7 +1234,7 @@ void bUnit_ToUnitAltName(char *str, int len_max, const char *orig_str, int syste
strncpy(str, orig_str, len_max); strncpy(str, orig_str, len_max);
} }
double bUnit_ClosestScalar(double value, int system, int type) double BKE_unit_closest_scalar(double value, int system, int type)
{ {
const bUnitCollection *usys = unit_get_system(system, type); const bUnitCollection *usys = unit_get_system(system, type);
@@ -1250,7 +1250,7 @@ double bUnit_ClosestScalar(double value, int system, int type)
return unit->scalar; return unit->scalar;
} }
double bUnit_BaseScalar(int system, int type) double BKE_unit_base_scalar(int system, int type)
{ {
const bUnitCollection *usys = unit_get_system(system, type); const bUnitCollection *usys = unit_get_system(system, type);
if (usys) { if (usys) {
@@ -1260,12 +1260,12 @@ double bUnit_BaseScalar(int system, int type)
return 1.0; return 1.0;
} }
bool bUnit_IsValid(int system, int type) bool BKE_unit_is_valid(int system, int type)
{ {
return !(system < 0 || system > UNIT_SYSTEM_TOT || type < 0 || type > B_UNIT_TYPE_TOT); return !(system < 0 || system > UNIT_SYSTEM_TOT || type < 0 || type > B_UNIT_TYPE_TOT);
} }
void bUnit_GetSystem(int system, int type, void const **r_usys_pt, int *r_len) void BKE_unit_system_get(int system, int type, void const **r_usys_pt, int *r_len)
{ {
const bUnitCollection *usys = unit_get_system(system, type); const bUnitCollection *usys = unit_get_system(system, type);
*r_usys_pt = usys; *r_usys_pt = usys;
@@ -1278,25 +1278,25 @@ void bUnit_GetSystem(int system, int type, void const **r_usys_pt, int *r_len)
*r_len = usys->length; *r_len = usys->length;
} }
int bUnit_GetBaseUnit(const void *usys_pt) int BKE_unit_base_get(const void *usys_pt)
{ {
return ((bUnitCollection *)usys_pt)->base_unit; return ((bUnitCollection *)usys_pt)->base_unit;
} }
int bUnit_GetBaseUnitOfType(int system, int type) int BKE_unit_base_of_type_get(int system, int type)
{ {
return unit_get_system(system, type)->base_unit; return unit_get_system(system, type)->base_unit;
} }
const char *bUnit_GetName(const void *usys_pt, int index) const char *BKE_unit_name_get(const void *usys_pt, int index)
{ {
return ((bUnitCollection *)usys_pt)->units[index].name; return ((bUnitCollection *)usys_pt)->units[index].name;
} }
const char *bUnit_GetNameDisplay(const void *usys_pt, int index) const char *BKE_unit_display_name_get(const void *usys_pt, int index)
{ {
return ((bUnitCollection *)usys_pt)->units[index].name_display; return ((bUnitCollection *)usys_pt)->units[index].name_display;
} }
const char *bUnit_GetIdentifier(const void *usys_pt, int index) const char *BKE_unit_identifier_get(const void *usys_pt, int index)
{ {
const bUnitDef *unit = ((const bUnitCollection *)usys_pt)->units + index; const bUnitDef *unit = ((const bUnitCollection *)usys_pt)->units + index;
if (unit->identifier == NULL) { if (unit->identifier == NULL) {
@@ -1305,12 +1305,12 @@ const char *bUnit_GetIdentifier(const void *usys_pt, int index)
return unit->identifier; return unit->identifier;
} }
double bUnit_GetScaler(const void *usys_pt, int index) double BKE_unit_scalar_get(const void *usys_pt, int index)
{ {
return ((bUnitCollection *)usys_pt)->units[index].scalar; return ((bUnitCollection *)usys_pt)->units[index].scalar;
} }
bool bUnit_IsSuppressed(const void *usys_pt, int index) bool BKE_unit_is_suppressed(const void *usys_pt, int index)
{ {
return (((bUnitCollection *)usys_pt)->units[index].flag & B_UNIT_DEF_SUPPRESS) != 0; return (((bUnitCollection *)usys_pt)->units[index].flag & B_UNIT_DEF_SUPPRESS) != 0;
} }

View File

@@ -2975,10 +2975,10 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
UnitSettings *unit = &scene->unit; UnitSettings *unit = &scene->unit;
if (unit->system != USER_UNIT_NONE) { if (unit->system != USER_UNIT_NONE) {
unit->length_unit = bUnit_GetBaseUnitOfType(scene->unit.system, B_UNIT_LENGTH); unit->length_unit = BKE_unit_base_of_type_get(scene->unit.system, B_UNIT_LENGTH);
unit->mass_unit = bUnit_GetBaseUnitOfType(scene->unit.system, B_UNIT_MASS); unit->mass_unit = BKE_unit_base_of_type_get(scene->unit.system, B_UNIT_MASS);
} }
unit->time_unit = bUnit_GetBaseUnitOfType(USER_UNIT_NONE, B_UNIT_TIME); unit->time_unit = BKE_unit_base_of_type_get(USER_UNIT_NONE, B_UNIT_TIME);
} }
/* gpencil grid settings */ /* gpencil grid settings */

View File

@@ -298,13 +298,13 @@ void DRW_text_edit_mesh_measure_stats(ARegion *region,
} }
if (unit->system) { if (unit->system) {
numstr_len = bUnit_AsString2(numstr, numstr_len = BKE_unit_value_as_string(numstr,
sizeof(numstr), sizeof(numstr),
len_v3v3(v1, v2) * unit->scale_length, len_v3v3(v1, v2) * unit->scale_length,
3, 3,
B_UNIT_LENGTH, B_UNIT_LENGTH,
unit, unit,
false); false);
} }
else { else {
numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), conv_float, len_v3v3(v1, v2)); numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), conv_float, len_v3v3(v1, v2));
@@ -440,13 +440,14 @@ void DRW_text_edit_mesh_measure_stats(ARegion *region,
mul_m4_v3(ob->obmat, vmid); mul_m4_v3(ob->obmat, vmid);
if (unit->system) { if (unit->system) {
numstr_len = bUnit_AsString2(numstr, numstr_len = BKE_unit_value_as_string(
sizeof(numstr), numstr,
(double)(area * unit->scale_length * unit->scale_length), sizeof(numstr),
3, (double)(area * unit->scale_length * unit->scale_length),
B_UNIT_AREA, 3,
unit, B_UNIT_AREA,
false); unit,
false);
} }
else { else {
numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), conv_float, area); numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), conv_float, area);

View File

@@ -2571,7 +2571,7 @@ void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t maxlen)
orig_str = BLI_strdup(str); orig_str = BLI_strdup(str);
bUnit_ToUnitAltName(str, maxlen, orig_str, unit->system, RNA_SUBTYPE_UNIT_VALUE(unit_type)); BKE_unit_name_to_alt(str, maxlen, orig_str, unit->system, RNA_SUBTYPE_UNIT_VALUE(unit_type));
MEM_freeN(orig_str); MEM_freeN(orig_str);
} }
@@ -2606,13 +2606,13 @@ static void ui_get_but_string_unit(
precision = float_precision; precision = float_precision;
} }
bUnit_AsString2(str, BKE_unit_value_as_string(str,
len_max, len_max,
ui_get_but_scale_unit(but, value), ui_get_but_scale_unit(but, value),
precision, precision,
RNA_SUBTYPE_UNIT_VALUE(unit_type), RNA_SUBTYPE_UNIT_VALUE(unit_type),
unit, unit,
pad); pad);
} }
static float ui_get_but_step_unit(uiBut *but, float step_default) static float ui_get_but_step_unit(uiBut *but, float step_default)
@@ -2622,12 +2622,13 @@ static float ui_get_but_step_unit(uiBut *but, float step_default)
/* Scaling up 'step_origg ' here is a bit arbitrary, /* Scaling up 'step_origg ' here is a bit arbitrary,
* its just giving better scales from user POV */ * its just giving better scales from user POV */
const double scale_step = ui_get_but_scale_unit(but, step_orig * 10); const double scale_step = ui_get_but_scale_unit(but, step_orig * 10);
const double step = bUnit_ClosestScalar(scale_step, but->block->unit->system, unit_type); const double step = BKE_unit_closest_scalar(scale_step, but->block->unit->system, unit_type);
/* -1 is an error value */ /* -1 is an error value */
if (step != -1.0) { if (step != -1.0) {
const double scale_unit = ui_get_but_scale_unit(but, 1.0); const double scale_unit = ui_get_but_scale_unit(but, 1.0);
const double step_unit = bUnit_ClosestScalar(scale_unit, but->block->unit->system, unit_type); const double step_unit = BKE_unit_closest_scalar(
scale_unit, but->block->unit->system, unit_type);
double step_final; double step_final;
BLI_assert(step > 0.0); BLI_assert(step > 0.0);

View File

@@ -193,13 +193,13 @@ static void depthdropper_depth_sample_pt(
*r_depth = len_v3v3(view_co, co_align); *r_depth = len_v3v3(view_co, co_align);
bUnit_AsString2(ddr->name, BKE_unit_value_as_string(ddr->name,
sizeof(ddr->name), sizeof(ddr->name),
(double)*r_depth, (double)*r_depth,
4, 4,
B_UNIT_LENGTH, B_UNIT_LENGTH,
&scene->unit, &scene->unit,
false); false);
} }
else { else {
BLI_strncpy(ddr->name, "Nothing under cursor", sizeof(ddr->name)); BLI_strncpy(ddr->name, "Nothing under cursor", sizeof(ddr->name));

View File

@@ -4614,8 +4614,8 @@ static float ui_numedit_apply_snapf(
UnitSettings *unit = but->block->unit; UnitSettings *unit = but->block->unit;
const int unit_type = RNA_SUBTYPE_UNIT_VALUE(UI_but_unit_type_get(but)); const int unit_type = RNA_SUBTYPE_UNIT_VALUE(UI_but_unit_type_get(but));
if (bUnit_IsValid(unit->system, unit_type)) { if (BKE_unit_is_valid(unit->system, unit_type)) {
fac = (float)bUnit_BaseScalar(unit->system, unit_type); fac = (float)BKE_unit_base_scalar(unit->system, unit_type);
if (ELEM(unit_type, B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME)) { if (ELEM(unit_type, B_UNIT_LENGTH, B_UNIT_AREA, B_UNIT_VOLUME)) {
fac /= unit->scale_length; fac /= unit->scale_length;
} }

View File

@@ -158,13 +158,13 @@ static void edbm_bevel_update_status_text(bContext *C, wmOperator *op)
} }
else { else {
double offset_val = (double)RNA_float_get(op->ptr, "offset"); double offset_val = (double)RNA_float_get(op->ptr, "offset");
bUnit_AsString2(offset_str, BKE_unit_value_as_string(offset_str,
NUM_STR_REP_LEN, NUM_STR_REP_LEN,
offset_val * sce->unit.scale_length, offset_val * sce->unit.scale_length,
3, 3,
B_UNIT_LENGTH, B_UNIT_LENGTH,
&sce->unit, &sce->unit,
true); true);
} }
prop = RNA_struct_find_property(op->ptr, "offset_type"); prop = RNA_struct_find_property(op->ptr, "offset_type");

View File

@@ -879,14 +879,14 @@ float ED_scene_grid_scale(const Scene *scene, const char **r_grid_unit)
const void *usys; const void *usys;
int len; int len;
bUnit_GetSystem(scene->unit.system, B_UNIT_LENGTH, &usys, &len); BKE_unit_system_get(scene->unit.system, B_UNIT_LENGTH, &usys, &len);
if (usys) { if (usys) {
int i = bUnit_GetBaseUnit(usys); int i = BKE_unit_base_get(usys);
if (r_grid_unit) { if (r_grid_unit) {
*r_grid_unit = bUnit_GetNameDisplay(usys, i); *r_grid_unit = BKE_unit_display_name_get(usys, i);
} }
return (float)bUnit_GetScaler(usys, i) / scene->unit.scale_length; return (float)BKE_unit_scalar_get(usys, i) / scene->unit.scale_length;
} }
} }
@@ -906,20 +906,20 @@ void ED_view3d_grid_steps(const Scene *scene,
{ {
const void *usys; const void *usys;
int i, len; int i, len;
bUnit_GetSystem(scene->unit.system, B_UNIT_LENGTH, &usys, &len); BKE_unit_system_get(scene->unit.system, B_UNIT_LENGTH, &usys, &len);
float grid_scale = v3d->grid; float grid_scale = v3d->grid;
BLI_assert(STEPS_LEN >= len); BLI_assert(STEPS_LEN >= len);
if (usys) { if (usys) {
if (rv3d->view == RV3D_VIEW_USER) { if (rv3d->view == RV3D_VIEW_USER) {
/* Skip steps */ /* Skip steps */
len = bUnit_GetBaseUnit(usys) + 1; len = BKE_unit_base_get(usys) + 1;
} }
grid_scale /= scene->unit.scale_length; grid_scale /= scene->unit.scale_length;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
r_grid_steps[i] = (float)bUnit_GetScaler(usys, len - 1 - i) * grid_scale; r_grid_steps[i] = (float)BKE_unit_scalar_get(usys, len - 1 - i) * grid_scale;
} }
for (; i < STEPS_LEN; i++) { for (; i < STEPS_LEN; i++) {
/* Fill last slots */ /* Fill last slots */
@@ -971,10 +971,10 @@ float ED_view3d_grid_view_scale(Scene *scene,
if (r_grid_unit) { if (r_grid_unit) {
const void *usys; const void *usys;
int len; int len;
bUnit_GetSystem(scene->unit.system, B_UNIT_LENGTH, &usys, &len); BKE_unit_system_get(scene->unit.system, B_UNIT_LENGTH, &usys, &len);
if (usys) { if (usys) {
*r_grid_unit = bUnit_GetNameDisplay(usys, len - i - 1); *r_grid_unit = BKE_unit_display_name_get(usys, len - i - 1);
} }
} }
} }

View File

@@ -179,7 +179,7 @@ static void ruler_item_as_string(
BLI_snprintf(numstr, numstr_size, "%.*f°", prec, RAD2DEGF(ruler_angle)); BLI_snprintf(numstr, numstr_size, "%.*f°", prec, RAD2DEGF(ruler_angle));
} }
else { else {
bUnit_AsString2( BKE_unit_value_as_string(
numstr, numstr_size, (double)ruler_angle, prec, B_UNIT_ROTATION, unit, false); numstr, numstr_size, (double)ruler_angle, prec, B_UNIT_ROTATION, unit, false);
} }
} }
@@ -190,13 +190,13 @@ static void ruler_item_as_string(
BLI_snprintf(numstr, numstr_size, "%.*f", prec, ruler_len); BLI_snprintf(numstr, numstr_size, "%.*f", prec, ruler_len);
} }
else { else {
bUnit_AsString2(numstr, BKE_unit_value_as_string(numstr,
numstr_size, numstr_size,
(double)(ruler_len * unit->scale_length), (double)(ruler_len * unit->scale_length),
prec, prec,
B_UNIT_LENGTH, B_UNIT_LENGTH,
unit, unit,
false); false);
} }
} }
} }

View File

@@ -89,13 +89,13 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_
dist = len_v3(vec); dist = len_v3(vec);
if (!(t->flag & T_2D_EDIT) && t->scene->unit.system) { if (!(t->flag & T_2D_EDIT) && t->scene->unit.system) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
bUnit_AsString2(&tvec[NUM_STR_REP_LEN * i], BKE_unit_value_as_string(&tvec[NUM_STR_REP_LEN * i],
NUM_STR_REP_LEN, NUM_STR_REP_LEN,
dvec[i] * t->scene->unit.scale_length, dvec[i] * t->scene->unit.scale_length,
4, 4,
B_UNIT_LENGTH, B_UNIT_LENGTH,
&t->scene->unit, &t->scene->unit,
true); true);
} }
} }
else { else {
@@ -106,13 +106,13 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_
} }
if (!(t->flag & T_2D_EDIT) && t->scene->unit.system) { if (!(t->flag & T_2D_EDIT) && t->scene->unit.system) {
bUnit_AsString2(distvec, BKE_unit_value_as_string(distvec,
sizeof(distvec), sizeof(distvec),
dist * t->scene->unit.scale_length, dist * t->scene->unit.scale_length,
4, 4,
B_UNIT_LENGTH, B_UNIT_LENGTH,
&t->scene->unit, &t->scene->unit,
false); false);
} }
else if (dist > 1e10f || dist < -1e10f) { else if (dist > 1e10f || dist < -1e10f) {
/* prevent string buffer overflow */ /* prevent string buffer overflow */

View File

@@ -136,14 +136,14 @@ void outputNumInput(NumInput *n, char *str, UnitSettings *unit_settings)
BLI_strncpy(val, "Invalid", sizeof(val)); BLI_strncpy(val, "Invalid", sizeof(val));
} }
else { else {
bUnit_AsString(val, BKE_unit_value_as_string_adaptive(val,
sizeof(val), sizeof(val),
(double)(n->val[i] * fac), (double)(n->val[i] * fac),
prec, prec,
n->unit_sys, n->unit_sys,
n->unit_type[i], n->unit_type[i],
true, true,
false); false);
} }
/* +1 because of trailing '\0' */ /* +1 because of trailing '\0' */
@@ -165,7 +165,7 @@ void outputNumInput(NumInput *n, char *str, UnitSettings *unit_settings)
} }
else { else {
char tstr[NUM_STR_REP_LEN]; char tstr[NUM_STR_REP_LEN];
bUnit_AsString( BKE_unit_value_as_string_adaptive(
tstr, ln, (double)n->val[i], prec, n->unit_sys, n->unit_type[i], true, false); tstr, ln, (double)n->val[i], prec, n->unit_sys, n->unit_type[i], true, false);
BLI_snprintf(&str[j * ln], ln, "%s%s%s", cur, tstr, cur); BLI_snprintf(&str[j * ln], ln, "%s%s%s", cur, tstr, cur);
} }
@@ -252,14 +252,14 @@ bool applyNumInput(NumInput *n, float *vec)
static void value_to_editstr(NumInput *n, int idx) static void value_to_editstr(NumInput *n, int idx)
{ {
const int prec = 6; /* editing, higher precision needed. */ const int prec = 6; /* editing, higher precision needed. */
n->str_cur = bUnit_AsString(n->str, n->str_cur = BKE_unit_value_as_string_adaptive(n->str,
NUM_STR_REP_LEN, NUM_STR_REP_LEN,
(double)n->val[idx], (double)n->val[idx],
prec, prec,
n->unit_sys, n->unit_sys,
n->unit_type[idx], n->unit_type[idx],
true, true,
false); false);
} }
static bool editstr_insert_at_cursor(NumInput *n, const char *buf, const int buf_len) static bool editstr_insert_at_cursor(NumInput *n, const char *buf, const int buf_len)
@@ -288,17 +288,17 @@ bool user_string_to_number(bContext *C,
{ {
#ifdef WITH_PYTHON #ifdef WITH_PYTHON
double unit_scale = BKE_scene_unit_scale(unit, type, 1.0); double unit_scale = BKE_scene_unit_scale(unit, type, 1.0);
if (bUnit_ContainsUnit(str, type)) { if (BKE_unit_string_contains_unit(str, type)) {
char str_unit_convert[256]; char str_unit_convert[256];
BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert)); BLI_strncpy(str_unit_convert, str, sizeof(str_unit_convert));
bUnit_ReplaceString( BKE_unit_replace_string(
str_unit_convert, sizeof(str_unit_convert), str, unit_scale, unit->system, type); str_unit_convert, sizeof(str_unit_convert), str, unit_scale, unit->system, type);
return BPY_run_string_as_number(C, NULL, str_unit_convert, error_prefix, r_value); return BPY_run_string_as_number(C, NULL, str_unit_convert, error_prefix, r_value);
} }
int success = BPY_run_string_as_number(C, NULL, str, error_prefix, r_value); int success = BPY_run_string_as_number(C, NULL, str, error_prefix, r_value);
*r_value = bUnit_ApplyPreferredUnit(unit, type, *r_value); *r_value = BKE_unit_apply_preferred_unit(unit, type, *r_value);
*r_value /= unit_scale; *r_value /= unit_scale;
return success; return success;

View File

@@ -2514,7 +2514,7 @@ static const EnumPropertyItem *rna_UnitSettings_itemf_wrapper(const int system,
{ {
const void *usys; const void *usys;
int len; int len;
bUnit_GetSystem(system, type, &usys, &len); BKE_unit_system_get(system, type, &usys, &len);
EnumPropertyItem *items = NULL; EnumPropertyItem *items = NULL;
int totitem = 0; int totitem = 0;
@@ -2526,10 +2526,10 @@ static const EnumPropertyItem *rna_UnitSettings_itemf_wrapper(const int system,
RNA_enum_item_add(&items, &totitem, &adaptive); RNA_enum_item_add(&items, &totitem, &adaptive);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
if (!bUnit_IsSuppressed(usys, i)) { if (!BKE_unit_is_suppressed(usys, i)) {
EnumPropertyItem tmp = {0}; EnumPropertyItem tmp = {0};
tmp.identifier = bUnit_GetIdentifier(usys, i); tmp.identifier = BKE_unit_identifier_get(usys, i);
tmp.name = bUnit_GetNameDisplay(usys, i); tmp.name = BKE_unit_display_name_get(usys, i);
tmp.value = i; tmp.value = i;
RNA_enum_item_add(&items, &totitem, &tmp); RNA_enum_item_add(&items, &totitem, &tmp);
} }
@@ -2587,8 +2587,8 @@ static void rna_UnitSettings_system_update(Main *UNUSED(bmain),
unit->mass_unit = USER_UNIT_ADAPTIVE; unit->mass_unit = USER_UNIT_ADAPTIVE;
} }
else { else {
unit->length_unit = bUnit_GetBaseUnitOfType(unit->system, B_UNIT_LENGTH); unit->length_unit = BKE_unit_base_of_type_get(unit->system, B_UNIT_LENGTH);
unit->mass_unit = bUnit_GetBaseUnitOfType(unit->system, B_UNIT_MASS); unit->mass_unit = BKE_unit_base_of_type_get(unit->system, B_UNIT_MASS);
} }
} }

View File

@@ -134,7 +134,7 @@ static bool bpyunits_validate(const char *usys_str, const char *ucat_str, int *r
return false; return false;
} }
if (!bUnit_IsValid(*r_usys, *r_ucat)) { if (!BKE_unit_is_valid(*r_usys, *r_ucat)) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"%.200s / %.200s unit system/category combination is not valid.", "%.200s / %.200s unit system/category combination is not valid.",
usys_str, usys_str,
@@ -197,7 +197,7 @@ static PyObject *bpyunits_to_value(PyObject *UNUSED(self), PyObject *args, PyObj
str = PyMem_MALLOC(sizeof(*str) * (size_t)str_len); str = PyMem_MALLOC(sizeof(*str) * (size_t)str_len);
BLI_strncpy(str, inpt, (size_t)str_len); BLI_strncpy(str, inpt, (size_t)str_len);
bUnit_ReplaceString(str, (int)str_len, uref, scale, usys, ucat); BKE_unit_replace_string(str, (int)str_len, uref, scale, usys, ucat);
if (!PyC_RunString_AsNumber(NULL, str, "<bpy_units_api>", &result)) { if (!PyC_RunString_AsNumber(NULL, str, "<bpy_units_api>", &result)) {
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
@@ -291,10 +291,11 @@ static PyObject *bpyunits_to_string(PyObject *UNUSED(self), PyObject *args, PyOb
char buf1[64], buf2[64], *str; char buf1[64], buf2[64], *str;
PyObject *result; PyObject *result;
bUnit_AsString(buf1, sizeof(buf1), value, precision, usys, ucat, (bool)split_unit, false); BKE_unit_value_as_string_adaptive(
buf1, sizeof(buf1), value, precision, usys, ucat, (bool)split_unit, false);
if (compatible_unit) { if (compatible_unit) {
bUnit_ToUnitAltName(buf2, sizeof(buf2), buf1, usys, ucat); BKE_unit_name_to_alt(buf2, sizeof(buf2), buf1, usys, ucat);
str = buf2; str = buf2;
} }
else { else {