You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
6.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 CERN
  5. * Copyright (C) 1992-2011 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @author Wayne Stambaugh <stambaughw@verizon.net>
  27. * @file base_units.h
  28. * @brief Implementation of conversion functions that require both schematic and board
  29. * internal units.
  30. */
  31. #ifndef _BASE_UNITS_H_
  32. #define _BASE_UNITS_H_
  33. #include <common.h>
  34. #include <convert_to_biu.h>
  35. /**
  36. * Function To_User_Unit
  37. * convert \a aValue in internal units to the appropriate user units defined by \a aUnit.
  38. *
  39. * @return The converted value, in double
  40. * @param aUnit The units to convert \a aValue to.
  41. * @param aValue The value in internal units to convert.
  42. */
  43. double To_User_Unit( EDA_UNITS_T aUnit, double aValue );
  44. /**
  45. * Function CoordinateToString
  46. * is a helper to convert the \a integer coordinate \a aValue to a string in inches,
  47. * millimeters, or unscaled units according to the current user units setting.
  48. *
  49. * Should be used only to display a coordinate in status, but not in dialogs,
  50. * because the mantissa of the number displayed has 4 digits max for readability.
  51. * (i.e. the value shows the decimils or the microns )
  52. * However the actual internal value could need up to 8 digits to be printed
  53. *
  54. * @param aValue The integer coordinate to convert.
  55. * @param aConvertToMils Convert inch values to mils if true. This setting has no effect if
  56. * the current user unit is millimeters.
  57. * @return The converted string for display in user interface elements.
  58. */
  59. wxString CoordinateToString( int aValue, bool aConvertToMils = false );
  60. /**
  61. * Function LenghtDoubleToString
  62. * is a helper to convert the \a double length \a aValue to a string in inches,
  63. * millimeters, or unscaled units according to the current user units setting.
  64. *
  65. * Should be used only to display a coordinate in status, but not in dialogs,
  66. * because the mantissa of the number displayed has 4 digits max for readability.
  67. * (i.e. the value shows the decimils or the microns )
  68. * However the actual internal value could need up to 8 digits to be printed
  69. *
  70. * @param aValue The double value to convert.
  71. * @param aConvertToMils Convert inch values to mils if true. This setting has no effect if
  72. * the current user unit is millimeters.
  73. * @return The converted string for display in user interface elements.
  74. */
  75. wxString LengthDoubleToString( double aValue, bool aConvertToMils = false );
  76. /**
  77. * Function ReturnStringFromValue
  78. * returns the string from \a aValue according to units (inch, mm ...) for display,
  79. * and the initial unit for value.
  80. *
  81. * For readability, the mantissa has 3 or more digits (max 8 digits),
  82. * the trailing 0 are removed if the mantissa has more than 3 digits
  83. * and some trailing 0
  84. * This function should be used to display values in dialogs because a value
  85. * entered in mm (for instance 2.0 mm) could need up to 8 digits mantissa
  86. * if displayed in inch to avoid truncation or rounding made just by the printf function.
  87. * otherwise the actual value is rounded when read from dialog and converted
  88. * in internal units, and therefore modified.
  89. *
  90. * @param aUnit = display units (INCHES, MILLIMETRE ..)
  91. * @param aValue = value in Internal_Unit
  92. * @param aAddUnitSymbol = true to add symbol unit to the string value
  93. * @return A wxString object containing value and optionally the symbol unit (like 2.000 mm)
  94. */
  95. wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol = false );
  96. /**
  97. * Operator << overload
  98. * outputs a point to the argument string in a format resembling
  99. * "@ (x,y)
  100. * @param aString Where to put the text describing the point value
  101. * @param aPoint The point to output.
  102. * @return wxString& - the input string
  103. */
  104. wxString& operator <<( wxString& aString, const wxPoint& aPoint );
  105. /**
  106. * Function PutValueInLocalUnits
  107. * converts \a aValue from internal units to user units and append the units notation
  108. * (mm or ")then inserts the string an \a aTextCtrl.
  109. *
  110. * This function is used in dialog boxes for entering values depending on selected units.
  111. */
  112. void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue );
  113. /**
  114. * Return in internal units the value "val" given in inch or mm
  115. */
  116. double From_User_Unit( EDA_UNITS_T aUnit, double aValue );
  117. /**
  118. * Function ReturnValueFromString
  119. * converts \a aTextValue in \a aUnits to internal units used by the application.
  120. *
  121. * @param aUnits The units of \a aTextValue.
  122. * @param aTextValue A reference to a wxString object containing the string to convert.
  123. * @return The string from Value, according to units (inch, mm ...) for display,
  124. */
  125. int ReturnValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue );
  126. /**
  127. * Function ReturnValueFromString
  128. * converts \a aTextValue in \a aUnits to internal units used by the application,
  129. * unit type will be obtained from g_UserUnit.
  130. *
  131. * @param aTextValue A reference to a wxString object containing the string to convert.
  132. * @return The string from Value, according to units (inch, mm ...) for display,
  133. */
  134. int ReturnValueFromString( const wxString& aTextValue );
  135. /**
  136. * Convert the number Value in a string according to the internal units
  137. * and the selected unit (g_UserUnit) and put it in the wxTextCtrl TextCtrl
  138. */
  139. int ReturnValueFromTextCtrl( const wxTextCtrl& aTextCtr );
  140. #endif // _BASE_UNITS_H_