1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License 4 * as published by the Free Software Foundation; either version 2 5 * of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software Foundation, 14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 */ 16 17 #pragma once 18 19 /** \file 20 * \ingroup bke 21 */ 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 struct UnitSettings; 28 29 /* in all cases the value is assumed to be scaled by the user preference */ 30 31 /* humanly readable representation of a value in units (used for button drawing) */ 32 size_t BKE_unit_value_as_string_adaptive( 33 char *str, int len_max, double value, int prec, int system, int type, bool split, bool pad); 34 size_t BKE_unit_value_as_string(char *str, 35 int len_max, 36 double value, 37 int prec, 38 int type, 39 const struct UnitSettings *settings, 40 bool pad); 41 42 /* replace units with values, used before python button evaluation */ 43 bool BKE_unit_replace_string( 44 char *str, int len_max, const char *str_prev, double scale_pref, int system, int type); 45 46 /* return true if the string contains any valid unit for the given type */ 47 bool BKE_unit_string_contains_unit(const char *str, int type); 48 49 /* If user does not specify a unit, this converts it to the unit from the settings. */ 50 double BKE_unit_apply_preferred_unit(const struct UnitSettings *settings, int type, double value); 51 52 /* make string keyboard-friendly: 10µm --> 10um */ 53 void BKE_unit_name_to_alt(char *str, int len_max, const char *orig_str, int system, int type); 54 55 /* the size of the unit used for this value (used for calculating the ckickstep) */ 56 double BKE_unit_closest_scalar(double value, int system, int type); 57 58 /* base scale for these units */ 59 double BKE_unit_base_scalar(int system, int type); 60 61 /* return true is the unit system exists */ 62 bool BKE_unit_is_valid(int system, int type); 63 64 /* loop over scales, could add names later */ 65 // double bUnit_Iter(void **unit, char **name, int system, int type); 66 67 void BKE_unit_system_get(int system, int type, const void **r_usys_pt, int *r_len); 68 int BKE_unit_base_get(const void *usys_pt); 69 int BKE_unit_base_of_type_get(int system, int type); 70 const char *BKE_unit_name_get(const void *usys_pt, int index); 71 const char *BKE_unit_display_name_get(const void *usys_pt, int index); 72 const char *BKE_unit_identifier_get(const void *usys_pt, int index); 73 double BKE_unit_scalar_get(const void *usys_pt, int index); 74 bool BKE_unit_is_suppressed(const void *usys_pt, int index); 75 76 /* aligned with PropertyUnit */ 77 enum { 78 B_UNIT_NONE = 0, 79 B_UNIT_LENGTH = 1, 80 B_UNIT_AREA = 2, 81 B_UNIT_VOLUME = 3, 82 B_UNIT_MASS = 4, 83 B_UNIT_ROTATION = 5, 84 B_UNIT_TIME = 6, 85 B_UNIT_VELOCITY = 7, 86 B_UNIT_ACCELERATION = 8, 87 B_UNIT_CAMERA = 9, 88 B_UNIT_POWER = 10, 89 B_UNIT_TEMPERATURE = 11, 90 B_UNIT_TYPE_TOT = 12, 91 }; 92 93 #ifdef __cplusplus 94 } 95 #endif 96