2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
user interface units, off by default.
- currently only distances work.
- user preferences, edit section to set the units and scale.
- option to display pairs (nicer for imperial display?)
- support for evaluating multiple comma separated values eg: 2',11" ..or.. 5ft, 4mil
- comma separated expressions/values accumulate 1+1,2**3,4cm/3
- attempted fast conversion from a value to a string so button drawing isn't too slow.
* imperial long/short *
- mile, mi
- yard, yd
- foot, '
- inch, "
- thou, mil
* metric long/short *
kilometer, km
meter, m
centimeter, cm
millimeter, mm
micrometer, um
nanometer, nm
picometer, pm
2009-08-11 20:53:01 +02:00
|
|
|
|
2012-02-17 19:59:41 +01:00
|
|
|
#pragma once
|
user interface units, off by default.
- currently only distances work.
- user preferences, edit section to set the units and scale.
- option to display pairs (nicer for imperial display?)
- support for evaluating multiple comma separated values eg: 2',11" ..or.. 5ft, 4mil
- comma separated expressions/values accumulate 1+1,2**3,4cm/3
- attempted fast conversion from a value to a string so button drawing isn't too slow.
* imperial long/short *
- mile, mi
- yard, yd
- foot, '
- inch, "
- thou, mil
* metric long/short *
kilometer, km
meter, m
centimeter, cm
millimeter, mm
micrometer, um
nanometer, nm
picometer, pm
2009-08-11 20:53:01 +02:00
|
|
|
|
2023-11-28 22:05:12 +01:00
|
|
|
#include "BLI_sys_types.h"
|
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-18 14:05:18 +01:00
|
|
|
*/
|
|
|
|
|
2018-10-03 10:20:16 +02:00
|
|
|
struct UnitSettings;
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/* In all cases the value is assumed to be scaled by the user-preference. */
|
user interface units, off by default.
- currently only distances work.
- user preferences, edit section to set the units and scale.
- option to display pairs (nicer for imperial display?)
- support for evaluating multiple comma separated values eg: 2',11" ..or.. 5ft, 4mil
- comma separated expressions/values accumulate 1+1,2**3,4cm/3
- attempted fast conversion from a value to a string so button drawing isn't too slow.
* imperial long/short *
- mile, mi
- yard, yd
- foot, '
- inch, "
- thou, mil
* metric long/short *
kilometer, km
meter, m
centimeter, cm
millimeter, mm
micrometer, um
nanometer, nm
picometer, pm
2009-08-11 20:53:01 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Humanly readable representation of a value in units (used for button drawing).
|
|
|
|
*/
|
2023-05-07 07:22:58 +02:00
|
|
|
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);
|
2022-06-10 11:15:47 +02:00
|
|
|
/**
|
|
|
|
* Representation of a value in units. Negative precision is used to disable stripping of zeroes.
|
|
|
|
* This reduces text jumping when changing values.
|
|
|
|
*/
|
2020-09-09 15:41:15 +02:00
|
|
|
size_t BKE_unit_value_as_string(char *str,
|
2023-05-07 07:22:58 +02:00
|
|
|
int str_maxncpy,
|
2020-09-09 15:41:15 +02:00
|
|
|
double value,
|
|
|
|
int prec,
|
|
|
|
int type,
|
2023-11-28 22:13:09 +01:00
|
|
|
const UnitSettings *settings,
|
2020-09-09 15:41:15 +02:00
|
|
|
bool pad);
|
user interface units, off by default.
- currently only distances work.
- user preferences, edit section to set the units and scale.
- option to display pairs (nicer for imperial display?)
- support for evaluating multiple comma separated values eg: 2',11" ..or.. 5ft, 4mil
- comma separated expressions/values accumulate 1+1,2**3,4cm/3
- attempted fast conversion from a value to a string so button drawing isn't too slow.
* imperial long/short *
- mile, mi
- yard, yd
- foot, '
- inch, "
- thou, mil
* metric long/short *
kilometer, km
meter, m
centimeter, cm
millimeter, mm
micrometer, um
nanometer, nm
picometer, pm
2009-08-11 20:53:01 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* 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`
|
|
|
|
*
|
|
|
|
* \param str_prev: is optional, when valid it is used to get a base unit when none is set.
|
|
|
|
*
|
|
|
|
* \return True of a change was made.
|
|
|
|
*/
|
2020-09-09 15:41:15 +02:00
|
|
|
bool BKE_unit_replace_string(
|
2023-05-07 07:22:58 +02:00
|
|
|
char *str, int str_maxncpy, const char *str_prev, double scale_pref, int system, int type);
|
user interface units, off by default.
- currently only distances work.
- user preferences, edit section to set the units and scale.
- option to display pairs (nicer for imperial display?)
- support for evaluating multiple comma separated values eg: 2',11" ..or.. 5ft, 4mil
- comma separated expressions/values accumulate 1+1,2**3,4cm/3
- attempted fast conversion from a value to a string so button drawing isn't too slow.
* imperial long/short *
- mile, mi
- yard, yd
- foot, '
- inch, "
- thou, mil
* metric long/short *
kilometer, km
meter, m
centimeter, cm
millimeter, mm
micrometer, um
nanometer, nm
picometer, pm
2009-08-11 20:53:01 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* \return true if the string contains any valid unit for the given type.
|
|
|
|
*/
|
2020-09-09 15:41:15 +02:00
|
|
|
bool BKE_unit_string_contains_unit(const char *str, int type);
|
2018-10-03 10:20:16 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* If user does not specify a unit, this converts it to the unit from the settings.
|
|
|
|
*/
|
2023-11-28 22:13:09 +01:00
|
|
|
double BKE_unit_apply_preferred_unit(const UnitSettings *settings, int type, double value);
|
2018-10-03 10:20:16 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Make string keyboard-friendly, e.g: `10µm -> 10um`.
|
|
|
|
*/
|
2023-05-07 07:22:58 +02:00
|
|
|
void BKE_unit_name_to_alt(char *str, int str_maxncpy, const char *orig_str, int system, int type);
|
patch [#23758] Better handling of UTF chars in UNITS fields (lengths, angles, etc.)
from Lorenzo Tozzi (oni_niubbo) with minor edits.
--- from the tracker
The present situation is this: due to bug#22274, during editing, UTF chars are stripped from buttons with a unit associated
(length, angles, etc.).
Example: if the button displays '90°' and you click on it with LMB, the editing string will become '90'.
The problem arises if you use microns: '34µm' becomes '34' that blender interprets as 34 meters. So clicking on a button
and hitting enter won't confirm the previous value, but will change it (very badly also).
Of course nobody is using microns in blender, but the problem will arise when we will implement areas and option 'Separate
Units' will be enabled. The value '2m² 3cm²' will become '2m' during editing.
This patch solves the problem rewriting the string in a smarter way than just stripping the UTF chars: the unit is translated
from unit->name_short ('µm') to unit->name_alt ('um'). So clicking on '34µm' the editing string will become
'34um'.
--- end
note: rather then allowing empty strings in name_alt field I made it so if the unit system was the default one a NULL name_alt will just strip the string, since its the default its not needed.
2010-09-15 19:37:00 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* The size of the unit used for this value (used for calculating the click-step).
|
|
|
|
*/
|
2020-09-09 15:41:15 +02:00
|
|
|
double BKE_unit_closest_scalar(double value, int system, int type);
|
2009-08-12 16:11:53 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Base scale for these units.
|
|
|
|
*/
|
2020-09-09 15:41:15 +02:00
|
|
|
double BKE_unit_base_scalar(int system, int type);
|
2009-08-12 19:02:03 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* \return true is the unit system exists.
|
|
|
|
*/
|
2020-09-09 15:41:15 +02:00
|
|
|
bool BKE_unit_is_valid(int system, int type);
|
2010-09-16 06:19:22 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Loop over scales, could add names later.
|
|
|
|
*/
|
2019-05-01 03:09:22 +02:00
|
|
|
// double bUnit_Iter(void **unit, char **name, int system, int type);
|
2009-08-12 16:11:53 +02:00
|
|
|
|
2020-09-09 15:41:15 +02:00
|
|
|
void BKE_unit_system_get(int system, int type, const void **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);
|
2009-08-12 16:11:53 +02:00
|
|
|
|
2023-07-31 03:50:54 +02:00
|
|
|
/** Aligned with #PropertyUnit and `bpyunits_ucategories_items` in `bpy_utils_units.cc`. */
|
2014-06-17 16:06:12 +02:00
|
|
|
enum {
|
|
|
|
B_UNIT_NONE = 0,
|
|
|
|
B_UNIT_LENGTH = 1,
|
|
|
|
B_UNIT_AREA = 2,
|
|
|
|
B_UNIT_VOLUME = 3,
|
|
|
|
B_UNIT_MASS = 4,
|
|
|
|
B_UNIT_ROTATION = 5,
|
|
|
|
B_UNIT_TIME = 6,
|
2021-06-08 11:50:19 +02:00
|
|
|
B_UNIT_TIME_ABSOLUTE = 7,
|
|
|
|
B_UNIT_VELOCITY = 8,
|
|
|
|
B_UNIT_ACCELERATION = 9,
|
|
|
|
B_UNIT_CAMERA = 10,
|
|
|
|
B_UNIT_POWER = 11,
|
|
|
|
B_UNIT_TEMPERATURE = 12,
|
|
|
|
B_UNIT_TYPE_TOT = 13,
|
2014-06-17 16:06:12 +02:00
|
|
|
};
|