2011-02-18 13:05:18 +00:00
|
|
|
/*
|
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 18:53:01 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
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 18:53:01 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __BKE_UNIT_H__
|
|
|
|
#define __BKE_UNIT_H__
|
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 18:53:01 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-18 13:05:18 +00:00
|
|
|
*/
|
|
|
|
|
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 18:53:01 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-10-03 10:20:16 +02:00
|
|
|
struct UnitSettings;
|
|
|
|
|
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 18:53:01 +00:00
|
|
|
/* 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) */
|
2018-10-03 10:20:16 +02:00
|
|
|
size_t bUnit_AsString(char *str, int len_max, double value, int prec, int system, int type, bool split, bool pad);
|
|
|
|
size_t bUnit_AsString2(char *str, int len_max, double value, int prec, int type, const struct UnitSettings *settings, 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 18:53:01 +00:00
|
|
|
|
|
|
|
/* replace units with values, used before python button evaluation */
|
2014-08-20 12:31:15 +02:00
|
|
|
bool bUnit_ReplaceString(char *str, int len_max, 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 18:53:01 +00:00
|
|
|
|
2018-10-03 10:20:16 +02:00
|
|
|
/* return true if the string contains any valid unit for the given type */
|
2019-01-09 10:39:31 +01:00
|
|
|
bool bUnit_ContainsUnit(const char *str, int type);
|
2018-10-03 10:20:16 +02:00
|
|
|
|
|
|
|
/* if user does not specify a unit, multiply with this value */
|
2019-01-08 19:20:22 +01:00
|
|
|
double bUnit_PreferredInputUnitScalar(const struct UnitSettings *settings, int type);
|
2018-10-03 10:20:16 +02:00
|
|
|
|
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 17:37:00 +00:00
|
|
|
/* make string keyboard-friendly: 10µm --> 10um */
|
2011-11-05 11:04:28 +00:00
|
|
|
void bUnit_ToUnitAltName(char *str, int len_max, 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 17:37:00 +00:00
|
|
|
|
2009-08-12 08:16:10 +00:00
|
|
|
/* the size of the unit used for this value (used for calculating the ckickstep) */
|
2009-08-12 14:11:53 +00:00
|
|
|
double bUnit_ClosestScalar(double value, int system, int type);
|
|
|
|
|
2009-08-12 17:02:03 +00:00
|
|
|
/* base scale for these units */
|
|
|
|
double bUnit_BaseScalar(int system, int type);
|
|
|
|
|
2010-09-16 04:19:22 +00:00
|
|
|
/* return true is the unit system exists */
|
2014-08-20 12:31:15 +02:00
|
|
|
bool bUnit_IsValid(int system, int type);
|
2010-09-16 04:19:22 +00:00
|
|
|
|
2018-09-24 17:27:41 +02:00
|
|
|
/* loop over scales, could add names later */
|
2009-08-12 14:11:53 +00:00
|
|
|
//double bUnit_Iter(void **unit, char **name, int system, int type);
|
|
|
|
|
2016-05-03 13:52:07 +10:00
|
|
|
void bUnit_GetSystem(int system, int type, void const **r_usys_pt, int *r_len);
|
|
|
|
int bUnit_GetBaseUnit(const void *usys_pt);
|
2018-10-03 10:20:16 +02:00
|
|
|
int bUnit_GetBaseUnitOfType(int system, int type);
|
2016-05-03 13:52:07 +10:00
|
|
|
const char *bUnit_GetName(const void *usys_pt, int index);
|
|
|
|
const char *bUnit_GetNameDisplay(const void *usys_pt, int index);
|
2018-11-15 14:39:52 +01:00
|
|
|
const char *bUnit_GetIdentifier(const void *usys_pt, int index);
|
2016-05-03 13:52:07 +10:00
|
|
|
double bUnit_GetScaler(const void *usys_pt, int index);
|
2018-10-03 10:20:16 +02:00
|
|
|
bool bUnit_IsSuppressed(const void *usys_pt, int index);
|
2009-08-12 14:11:53 +00:00
|
|
|
|
|
|
|
/* aligned with PropertyUnit */
|
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,
|
|
|
|
B_UNIT_VELOCITY = 7,
|
|
|
|
B_UNIT_ACCELERATION = 8,
|
|
|
|
B_UNIT_CAMERA = 9,
|
2019-02-08 12:31:28 +01:00
|
|
|
B_UNIT_POWER = 10,
|
|
|
|
B_UNIT_TYPE_TOT = 11,
|
2014-06-17 16:06:12 +02:00
|
|
|
};
|
2009-08-12 08:16:10 +00:00
|
|
|
|
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 18:53:01 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#endif /* __BKE_UNIT_H__ */
|