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.

516 lines
12 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  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.cpp
  28. * @brief Code to handle objects that require both schematic and board internal units.
  29. * @note This file is an ugly hack to solve the problem of formatting the base units
  30. * for either schematics or boards in objects that are include in both domains.
  31. * At some point in the future. This code should be rolled back into the
  32. * appropriate object and build with the correct internal unit formatting
  33. * depending on the application.
  34. */
  35. #include <macros.h>
  36. #include <base_struct.h>
  37. #include <class_title_block.h>
  38. #include <common.h>
  39. #include <base_units.h>
  40. #if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) || defined( GERBVIEW ) || defined( PL_EDITOR )
  41. #define IU_TO_MM( x ) ( x / IU_PER_MM )
  42. #define IU_TO_IN( x ) ( x / IU_PER_MILS / 1000 )
  43. #define MM_TO_IU( x ) ( x * IU_PER_MM )
  44. #define IN_TO_IU( x ) ( x * IU_PER_MILS * 1000 )
  45. #else
  46. #error "Cannot resolve internal units due to no definition of EESCHEMA, CVPCB or PCBNEW."
  47. #endif
  48. // Helper function to print a float number without using scientific notation
  49. // and no trailing 0
  50. // So we cannot always just use the %g or the %f format to print a fp number
  51. // this helper function uses the %f format when needed, or %g when %f is
  52. // not well working and then removes trailing 0
  53. std::string Double2Str( double aValue )
  54. {
  55. char buf[50];
  56. int len;
  57. if( aValue != 0.0 && fabs( aValue ) <= 0.0001 )
  58. {
  59. // For these small values, %f works fine,
  60. // and %g gives an exponent
  61. len = sprintf( buf, "%.16f", aValue );
  62. while( --len > 0 && buf[len] == '0' )
  63. buf[len] = '\0';
  64. if( buf[len] == '.' )
  65. buf[len] = '\0';
  66. else
  67. ++len;
  68. }
  69. else
  70. {
  71. // For these values, %g works fine, and sometimes %f
  72. // gives a bad value (try aValue = 1.222222222222, with %.16f format!)
  73. len = sprintf( buf, "%.16g", aValue );
  74. }
  75. return std::string( buf, len );
  76. }
  77. double To_User_Unit( EDA_UNITS_T aUnit, double aValue )
  78. {
  79. switch( aUnit )
  80. {
  81. case MILLIMETRES:
  82. return IU_TO_MM( aValue );
  83. case INCHES:
  84. return IU_TO_IN( aValue );
  85. case DEGREES:
  86. return aValue / 10.0f;
  87. default:
  88. return aValue;
  89. }
  90. }
  91. /* Convert a value to a string using double notation.
  92. * For readability, the mantissa has 0, 1, 3 or 4 digits, depending on units
  93. * for unit = inch the mantissa has 3 digits (Eeschema) or 4 digits
  94. * for unit = mil the mantissa has 0 digits (Eeschema) or 1 digits
  95. * for unit = mm the mantissa has 3 digits (Eeschema) or 4 digits
  96. * Should be used only to display info in status,
  97. * but not in dialogs, because 4 digits only
  98. * could truncate the actual value
  99. */
  100. wxString CoordinateToString( int aValue, bool aConvertToMils )
  101. {
  102. return LengthDoubleToString( (double) aValue, aConvertToMils );
  103. }
  104. wxString LengthDoubleToString( double aValue, bool aConvertToMils )
  105. {
  106. wxString text;
  107. const wxChar* format;
  108. double value = To_User_Unit( g_UserUnit, aValue );
  109. if( g_UserUnit == INCHES )
  110. {
  111. if( aConvertToMils )
  112. {
  113. #if defined( EESCHEMA )
  114. format = wxT( "%.0f" );
  115. #else
  116. format = wxT( "%.1f" );
  117. #endif
  118. value *= 1000;
  119. }
  120. else
  121. {
  122. #if defined( EESCHEMA )
  123. format = wxT( "%.3f" );
  124. #else
  125. format = wxT( "%.4f" );
  126. #endif
  127. }
  128. }
  129. else
  130. {
  131. #if defined( EESCHEMA )
  132. format = wxT( "%.2f" );
  133. #else
  134. format = wxT( "%.3f" );
  135. #endif
  136. }
  137. text.Printf( format, value );
  138. if( g_UserUnit == INCHES )
  139. text += ( aConvertToMils ) ? _( " mils" ) : _( " in" );
  140. else
  141. text += _( " mm" );
  142. return text;
  143. }
  144. /* Remove trailing 0 from a string containing a converted float number.
  145. * the trailing 0 are removed if the mantissa has more
  146. * than aTrailingZeroAllowed digits and some trailing 0
  147. */
  148. void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed )
  149. {
  150. struct lconv * lc = localeconv();
  151. char sep = lc->decimal_point[0];
  152. unsigned sep_pos = aStringValue.Find( sep );
  153. if( sep_pos > 0 )
  154. {
  155. // We want to keep at least aTrailingZeroAllowed digits after the separator
  156. unsigned min_len = sep_pos + aTrailingZeroAllowed + 1;
  157. while( aStringValue.Len() > min_len )
  158. {
  159. if( aStringValue.Last() == '0' )
  160. aStringValue.RemoveLast();
  161. else
  162. break;
  163. }
  164. }
  165. }
  166. /* Convert a value to a string using double notation.
  167. * For readability, the mantissa has 3 or more digits,
  168. * the trailing 0 are removed if the mantissa has more than 3 digits
  169. * and some trailing 0
  170. * This function should be used to display values in dialogs because a value
  171. * entered in mm (for instance 2.0 mm) could need up to 8 digits mantissa
  172. * if displayed in inch to avoid truncation or rounding made just by the printf function.
  173. * otherwise the actual value is rounded when read from dialog and converted
  174. * in internal units, and therefore modified.
  175. */
  176. wxString StringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol )
  177. {
  178. double value_to_print = To_User_Unit( aUnit, aValue );
  179. #if defined( EESCHEMA )
  180. wxString stringValue = wxString::Format( wxT( "%.3f" ), value_to_print );
  181. // Strip trailing zeros. However, keep at least 3 digits in mantissa
  182. // For readability
  183. StripTrailingZeros( stringValue, 3 );
  184. #else
  185. char buf[50];
  186. int len;
  187. if( value_to_print != 0.0 && fabs( value_to_print ) <= 0.0001 )
  188. {
  189. len = sprintf( buf, "%.10f", value_to_print );
  190. while( --len > 0 && buf[len] == '0' )
  191. buf[len] = '\0';
  192. if( buf[len]=='.' || buf[len]==',' )
  193. buf[len] = '\0';
  194. else
  195. ++len;
  196. }
  197. else
  198. {
  199. len = sprintf( buf, "%.10g", value_to_print );
  200. }
  201. wxString stringValue( buf, wxConvUTF8 );
  202. #endif
  203. if( aAddUnitSymbol )
  204. {
  205. switch( aUnit )
  206. {
  207. case INCHES:
  208. stringValue += _( " \"" );
  209. break;
  210. case MILLIMETRES:
  211. stringValue += _( " mm" );
  212. break;
  213. case DEGREES:
  214. stringValue += _( " deg" );
  215. break;
  216. case UNSCALED_UNITS:
  217. break;
  218. }
  219. }
  220. return stringValue;
  221. }
  222. void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue )
  223. {
  224. wxString msg = StringFromValue( g_UserUnit, aValue );
  225. aTextCtr.SetValue( msg );
  226. }
  227. double From_User_Unit( EDA_UNITS_T aUnit, double aValue )
  228. {
  229. double value;
  230. switch( aUnit )
  231. {
  232. case MILLIMETRES:
  233. value = MM_TO_IU( aValue );
  234. break;
  235. case INCHES:
  236. value = IN_TO_IU( aValue );
  237. break;
  238. case DEGREES:
  239. // Convert to "decidegrees"
  240. value = aValue * 10;
  241. break;
  242. default:
  243. case UNSCALED_UNITS:
  244. value = aValue;
  245. }
  246. return value;
  247. }
  248. double DoubleValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue )
  249. {
  250. double value;
  251. double dtmp = 0;
  252. // Acquire the 'right' decimal point separator
  253. const struct lconv* lc = localeconv();
  254. wxChar decimal_point = lc->decimal_point[0];
  255. wxString buf( aTextValue.Strip( wxString::both ) );
  256. // Convert the period in decimal point
  257. buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
  258. // Find the end of the numeric part
  259. unsigned brk_point = 0;
  260. while( brk_point < buf.Len() )
  261. {
  262. wxChar ch = buf[brk_point];
  263. if( !( (ch >= '0' && ch <='9') || (ch == decimal_point) || (ch == '-') || (ch == '+') ) )
  264. {
  265. break;
  266. }
  267. ++brk_point;
  268. }
  269. // Extract the numeric part
  270. buf.Left( brk_point );
  271. buf.ToDouble( &dtmp );
  272. // Check the optional unit designator (2 ch significant)
  273. wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
  274. if( aUnits == INCHES || aUnits == MILLIMETRES )
  275. {
  276. if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
  277. {
  278. aUnits = INCHES;
  279. }
  280. else if( unit == wxT( "mm" ) )
  281. {
  282. aUnits = MILLIMETRES;
  283. }
  284. else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) // Mils or thous
  285. {
  286. aUnits = INCHES;
  287. dtmp /= 1000;
  288. }
  289. }
  290. else if( aUnits == DEGREES )
  291. {
  292. if( unit == wxT( "ra" ) ) // Radians
  293. {
  294. dtmp *= 180.0f / M_PI;
  295. }
  296. }
  297. value = From_User_Unit( aUnits, dtmp );
  298. return value;
  299. }
  300. int ValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue )
  301. {
  302. double value = DoubleValueFromString( aUnits, aTextValue );
  303. return KiROUND( value );
  304. }
  305. int ValueFromString( const wxString& aTextValue )
  306. {
  307. int value;
  308. value = ValueFromString( g_UserUnit, aTextValue);
  309. return value;
  310. }
  311. int ValueFromTextCtrl( const wxTextCtrl& aTextCtr )
  312. {
  313. int value;
  314. wxString msg = aTextCtr.GetValue();
  315. value = ValueFromString( g_UserUnit, msg );
  316. return value;
  317. }
  318. wxString& operator <<( wxString& aString, const wxPoint& aPos )
  319. {
  320. aString << wxT( "@ (" ) << CoordinateToString( aPos.x );
  321. aString << wxT( "," ) << CoordinateToString( aPos.y );
  322. aString << wxT( ")" );
  323. return aString;
  324. }
  325. /**
  326. * Function AngleToStringDegrees
  327. * is a helper to convert the \a double \a aAngle (in internal unit)
  328. * to a string in degrees
  329. */
  330. wxString AngleToStringDegrees( double aAngle )
  331. {
  332. wxString text;
  333. text.Printf( wxT( "%.3f" ), aAngle/10.0 );
  334. StripTrailingZeros( text, 1 );
  335. return text;
  336. }
  337. wxString ReturnUnitSymbol( EDA_UNITS_T aUnit, const wxString& formatString )
  338. {
  339. wxString tmp;
  340. wxString label;
  341. switch( aUnit )
  342. {
  343. case INCHES:
  344. tmp = _( "\"" );
  345. break;
  346. case MILLIMETRES:
  347. tmp = _( "mm" );
  348. break;
  349. case UNSCALED_UNITS:
  350. break;
  351. case DEGREES:
  352. wxASSERT( false );
  353. break;
  354. }
  355. if( formatString.IsEmpty() )
  356. return tmp;
  357. label.Printf( formatString, GetChars( tmp ) );
  358. return label;
  359. }
  360. wxString GetUnitsLabel( EDA_UNITS_T aUnit )
  361. {
  362. wxString label;
  363. switch( aUnit )
  364. {
  365. case INCHES:
  366. label = _( "inches" );
  367. break;
  368. case MILLIMETRES:
  369. label = _( "millimeters" );
  370. break;
  371. case UNSCALED_UNITS:
  372. label = _( "units" );
  373. break;
  374. case DEGREES:
  375. label = _( "degrees" );
  376. break;
  377. }
  378. return label;
  379. }
  380. wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit )
  381. {
  382. wxString label;
  383. switch( aUnit )
  384. {
  385. case INCHES:
  386. label = _( "in" );
  387. break;
  388. case MILLIMETRES:
  389. label = _( "mm" );
  390. break;
  391. case UNSCALED_UNITS:
  392. break;
  393. case DEGREES:
  394. label = _( "deg" );
  395. break;
  396. default:
  397. label = wxT( "??" );
  398. break;
  399. }
  400. return label;
  401. }
  402. void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit )
  403. {
  404. wxString msg = Stext.GetLabel();
  405. msg += ReturnUnitSymbol( aUnit );
  406. Stext.SetLabel( msg );
  407. }