Move some unit related util function to base_units.h

This commit is contained in:
John Beard 2017-02-09 18:16:28 +08:00 committed by Wayne Stambaugh
parent b47a6e415b
commit f723a5319c
4 changed files with 129 additions and 132 deletions

View File

@ -416,3 +416,101 @@ wxString AngleToStringDegrees( double aAngle )
return text; 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 );
}

View File

@ -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 ) void wxStringSplit( const wxString& aText, wxArrayString& aStrings, wxChar aSplitter )
{ {
wxString tmp; wxString tmp;

View File

@ -37,6 +37,12 @@
#include <common.h> #include <common.h>
#include <convert_to_biu.h> #include <convert_to_biu.h>
/// 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 /** Helper function Double2Str to print a float number without
* using scientific notation and no trailing 0 * using scientific notation and no trailing 0
* We want to avoid scientific notation in S-expr files (not easy to read) * 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 ); 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_ #endif // _BASE_UNITS_H_

View File

@ -141,14 +141,6 @@ static inline int kiRound_( double v, int line, const char* filename )
//-----</KiROUND KIT>----------------------------------------------------------- //-----</KiROUND KIT>-----------------------------------------------------------
/// 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 { enum EDA_UNITS_T {
INCHES = 0, INCHES = 0,
MILLIMETRES = 1, MILLIMETRES = 1,
@ -240,31 +232,6 @@ int GetCommandOptions( const int argc, const char** argv,
const char* stringtst, const char** optarg, const char* stringtst, const char** optarg,
int* optind ); 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. * Round to the nearest precision.
* *