From f723a5319cb51498f6ad823aa296e203d66f1fb0 Mon Sep 17 00:00:00 2001 From: John Beard Date: Thu, 9 Feb 2017 18:16:28 +0800 Subject: [PATCH] Move some unit related util function to base_units.h --- common/base_units.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++ common/common.cpp | 99 ------------------------------------------- include/base_units.h | 31 ++++++++++++++ include/common.h | 33 --------------- 4 files changed, 129 insertions(+), 132 deletions(-) diff --git a/common/base_units.cpp b/common/base_units.cpp index bd03bcf3a6..4611b182df 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -416,3 +416,101 @@ wxString AngleToStringDegrees( double aAngle ) return text; } + +wxString ReturnUnitSymbol( EDA_UNITS_T aUnit, const wxString& formatString ) +{ + wxString tmp; + wxString label; + + switch( aUnit ) + { + case INCHES: + tmp = _( "\"" ); + break; + + case MILLIMETRES: + tmp = _( "mm" ); + break; + + case UNSCALED_UNITS: + break; + + case DEGREES: + wxASSERT( false ); + break; + } + + if( formatString.IsEmpty() ) + return tmp; + + label.Printf( formatString, GetChars( tmp ) ); + + return label; +} + + +wxString GetUnitsLabel( EDA_UNITS_T aUnit ) +{ + wxString label; + + switch( aUnit ) + { + case INCHES: + label = _( "inches" ); + break; + + case MILLIMETRES: + label = _( "millimeters" ); + break; + + case UNSCALED_UNITS: + label = _( "units" ); + break; + + case DEGREES: + label = _( "degrees" ); + break; + } + + return label; +} + + +wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit ) +{ + wxString label; + + switch( aUnit ) + { + case INCHES: + label = _( "in" ); + break; + + case MILLIMETRES: + label = _( "mm" ); + break; + + case UNSCALED_UNITS: + break; + + case DEGREES: + label = _( "deg" ); + break; + + default: + label = wxT( "??" ); + break; + } + + return label; +} + + +void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit ) +{ + wxString msg = Stext.GetLabel(); + + msg += ReturnUnitSymbol( aUnit ); + + Stext.SetLabel( msg ); +} diff --git a/common/common.cpp b/common/common.cpp index faa2b71b41..8dd7a2a52f 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -135,105 +135,6 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString ) } -wxString ReturnUnitSymbol( EDA_UNITS_T aUnit, const wxString& formatString ) -{ - wxString tmp; - wxString label; - - switch( aUnit ) - { - case INCHES: - tmp = _( "\"" ); - break; - - case MILLIMETRES: - tmp = _( "mm" ); - break; - - case UNSCALED_UNITS: - break; - - case DEGREES: - wxASSERT( false ); - break; - } - - if( formatString.IsEmpty() ) - return tmp; - - label.Printf( formatString, GetChars( tmp ) ); - - return label; -} - - -wxString GetUnitsLabel( EDA_UNITS_T aUnit ) -{ - wxString label; - - switch( aUnit ) - { - case INCHES: - label = _( "inches" ); - break; - - case MILLIMETRES: - label = _( "millimeters" ); - break; - - case UNSCALED_UNITS: - label = _( "units" ); - break; - - case DEGREES: - label = _( "degrees" ); - break; - } - - return label; -} - - -wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit ) -{ - wxString label; - - switch( aUnit ) - { - case INCHES: - label = _( "in" ); - break; - - case MILLIMETRES: - label = _( "mm" ); - break; - - case UNSCALED_UNITS: - break; - - case DEGREES: - label = _( "deg" ); - break; - - default: - label = wxT( "??" ); - break; - } - - return label; -} - - -void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit ) -{ - wxString msg = Stext.GetLabel(); - - msg += ReturnUnitSymbol( aUnit ); - - Stext.SetLabel( msg ); -} - - void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSplitter ) { wxString tmp; diff --git a/include/base_units.h b/include/base_units.h index 6d37d99f93..5cbb0b6d62 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -37,6 +37,12 @@ #include #include +/// Convert mm to mils. +inline int Mm2mils( double x ) { return KiROUND( x * 1000./25.4 ); } + +/// Convert mils to mm. +inline int Mils2mm( double x ) { return KiROUND( x * 25.4 / 1000. ); } + /** Helper function Double2Str to print a float number without * using scientific notation and no trailing 0 * We want to avoid scientific notation in S-expr files (not easy to read) @@ -191,4 +197,29 @@ int ValueFromString( const wxString& aTextValue ); */ int ValueFromTextCtrl( const wxTextCtrl& aTextCtr ); +/** + * Returns the units symbol. + * + * @param aUnits - Units type, default is current units setting. + * @param aFormatString - A formatting string to embed the units symbol into. Note: + * the format string must contain the %s format specifier. + * @return The formatted units symbol. + */ +wxString ReturnUnitSymbol( EDA_UNITS_T aUnits = g_UserUnit, + const wxString& aFormatString = _( " (%s):" ) ); + +/** + * Get a human readable units string. + * + * The strings returned are full text name and not abbreviations or symbolic + * representations of the units. Use ReturnUnitSymbol() for that. + * + * @param aUnits - The units text to return. + * @return The human readable units string. + */ +wxString GetUnitsLabel( EDA_UNITS_T aUnits ); +wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit = g_UserUnit ); + +void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit = g_UserUnit ); + #endif // _BASE_UNITS_H_ diff --git a/include/common.h b/include/common.h index 8f6d1a1dca..d0337d5621 100644 --- a/include/common.h +++ b/include/common.h @@ -141,14 +141,6 @@ static inline int kiRound_( double v, int line, const char* filename ) //---------------------------------------------------------------- - -/// Convert mm to mils. -inline int Mm2mils( double x ) { return KiROUND( x * 1000./25.4 ); } - -/// Convert mils to mm. -inline int Mils2mm( double x ) { return KiROUND( x * 25.4 / 1000. ); } - - enum EDA_UNITS_T { INCHES = 0, MILLIMETRES = 1, @@ -240,31 +232,6 @@ int GetCommandOptions( const int argc, const char** argv, const char* stringtst, const char** optarg, int* optind ); -/** - * Returns the units symbol. - * - * @param aUnits - Units type, default is current units setting. - * @param aFormatString - A formatting string to embed the units symbol into. Note: - * the format string must contain the %s format specifier. - * @return The formatted units symbol. - */ -wxString ReturnUnitSymbol( EDA_UNITS_T aUnits = g_UserUnit, - const wxString& aFormatString = _( " (%s):" ) ); - -/** - * Get a human readable units string. - * - * The strings returned are full text name and not abbreviations or symbolic - * representations of the units. Use ReturnUnitSymbol() for that. - * - * @param aUnits - The units text to return. - * @return The human readable units string. - */ -wxString GetUnitsLabel( EDA_UNITS_T aUnits ); -wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit = g_UserUnit ); - -void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit = g_UserUnit ); - /** * Round to the nearest precision. *