BKE_unit.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * ***** BEGIN GPL LICENSE BLOCK *****
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. *
  18. * Contributor(s): Campbell Barton
  19. *
  20. * ***** END GPL LICENSE BLOCK *****
  21. */
  22. #ifndef __BKE_UNIT_H__
  23. #define __BKE_UNIT_H__
  24. /** \file BKE_unit.h
  25. * \ingroup bke
  26. */
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* in all cases the value is assumed to be scaled by the user preference */
  31. /* humanly readable representation of a value in units (used for button drawing) */
  32. size_t bUnit_AsString(char *str, int len_max, double value, int prec, int system, int type, bool split, bool pad);
  33. /* replace units with values, used before python button evaluation */
  34. bool bUnit_ReplaceString(char *str, int len_max, const char *str_prev, double scale_pref, int system, int type);
  35. /* make string keyboard-friendly: 10µm --> 10um */
  36. void bUnit_ToUnitAltName(char *str, int len_max, const char *orig_str, int system, int type);
  37. /* the size of the unit used for this value (used for calculating the ckickstep) */
  38. double bUnit_ClosestScalar(double value, int system, int type);
  39. /* base scale for these units */
  40. double bUnit_BaseScalar(int system, int type);
  41. /* return true is the unit system exists */
  42. bool bUnit_IsValid(int system, int type);
  43. /* loop over scales, coudl add names later */
  44. //double bUnit_Iter(void **unit, char **name, int system, int type);
  45. void bUnit_GetSystem(int system, int type, void const **r_usys_pt, int *r_len);
  46. int bUnit_GetBaseUnit(const void *usys_pt);
  47. const char *bUnit_GetName(const void *usys_pt, int index);
  48. const char *bUnit_GetNameDisplay(const void *usys_pt, int index);
  49. double bUnit_GetScaler(const void *usys_pt, int index);
  50. /* aligned with PropertyUnit */
  51. enum {
  52. B_UNIT_NONE = 0,
  53. B_UNIT_LENGTH = 1,
  54. B_UNIT_AREA = 2,
  55. B_UNIT_VOLUME = 3,
  56. B_UNIT_MASS = 4,
  57. B_UNIT_ROTATION = 5,
  58. B_UNIT_TIME = 6,
  59. B_UNIT_VELOCITY = 7,
  60. B_UNIT_ACCELERATION = 8,
  61. B_UNIT_CAMERA = 9,
  62. B_UNIT_TYPE_TOT = 10,
  63. };
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif /* __BKE_UNIT_H__ */