Use more self-documenting names for conversion routines.

In particular, make sure no one thinks the low-precision ones are
OK for dialogs and/or files.

(cherry picked from commit bc1fcfa)
This commit is contained in:
Jeff Young 2018-03-06 12:06:46 +00:00
parent f5d70644f2
commit f7861c90ec
10 changed files with 49 additions and 71 deletions

View File

@ -120,20 +120,29 @@ double To_User_Unit( EDA_UNITS_T aUnit, double aValue, bool aUseMils )
* but not in dialogs, because 4 digits only
* could truncate the actual value
*/
// JEY TODO: retire this in favour of MessageTextFromValue()....
wxString CoordinateToString( int aValue, bool aUseMils )
{
return LengthDoubleToString( (double) aValue, aUseMils );
return MessageTextFromValue( g_UserUnit, aValue, aUseMils );
}
// JEY TODO: remove; use StringFromValue() instead
wxString LengthDoubleToString( double aValue, bool aUseMils )
// A lower-precision (for readability) version of StringFromValue()
wxString MessageTextFromValue( EDA_UNITS_T aUnits, int aValue, bool aUseMils )
{
return MessageTextFromValue( aUnits, (double) aValue, aUseMils );
}
// A lower-precision (for readability) version of StringFromValue()
wxString MessageTextFromValue( EDA_UNITS_T aUnits, double aValue, bool aUseMils )
{
wxString text;
const wxChar* format;
double value = To_User_Unit( g_UserUnit, aValue );
double value = To_User_Unit( aUnits, aValue, aUseMils );
if( g_UserUnit == INCHES )
if( aUnits == INCHES )
{
if( aUseMils )
{
@ -142,7 +151,6 @@ wxString LengthDoubleToString( double aValue, bool aUseMils )
#else
format = wxT( "%.1f" );
#endif
value *= 1000;
}
else
{
@ -165,10 +173,7 @@ wxString LengthDoubleToString( double aValue, bool aUseMils )
text.Printf( format, value );
text += " ";
if( g_UserUnit == INCHES )
text += ( aUseMils ) ? _( " mils" ) : _( " in" );
else
text += _( "mm" );
text += GetAbbreviatedUnitsLabel( aUnits );
return text;
}
@ -209,9 +214,9 @@ void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed )
* otherwise the actual value is rounded when read from dialog and converted
* in internal units, and therefore modified.
*/
wxString StringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol, bool aUseMils )
wxString StringFromValue( EDA_UNITS_T aUnits, int aValue, bool aAddUnitSymbol, bool aUseMils )
{
double value_to_print = To_User_Unit( aUnit, aValue, aUseMils );
double value_to_print = To_User_Unit( aUnits, aValue, aUseMils );
#if defined( EESCHEMA )
wxString stringValue = wxString::Format( wxT( "%.3f" ), value_to_print );
@ -248,7 +253,7 @@ wxString StringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol, bo
if( aAddUnitSymbol )
{
switch( aUnit )
switch( aUnits )
{
case INCHES:
if( aUseMils )
@ -283,9 +288,9 @@ void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue )
}
double From_User_Unit( EDA_UNITS_T aUnit, double aValue, bool aUseMils )
double From_User_Unit( EDA_UNITS_T aUnits, double aValue, bool aUseMils )
{
switch( aUnit )
switch( aUnits )
{
case MILLIMETRES:
return MM_TO_IU( aValue );

View File

@ -884,17 +884,6 @@ void EDA_DRAW_FRAME::PushPreferences( const EDA_DRAW_PANEL* aParentCanvas )
m_canvas->SetEnableAutoPan( aParentCanvas->GetEnableAutoPan() );
}
wxString EDA_DRAW_FRAME::CoordinateToString( int aValue, bool aConvertToMils ) const
{
return ::CoordinateToString( aValue, aConvertToMils );
}
wxString EDA_DRAW_FRAME::LengthDoubleToString( double aValue, bool aConvertToMils ) const
{
return ::LengthDoubleToString( aValue, aConvertToMils );
}
bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, EDA_KEY aKey, const wxPoint& aPosition,
int aExplicitCommand )
{

View File

@ -105,20 +105,26 @@ wxString CoordinateToString( int aValue, bool aUseMils = false );
wxString AngleToStringDegrees( double aAngle );
/**
* Function LengthDoubleToString
* Function MessageTextFromValue
* is a helper to convert the \a double length \a aValue to a string in inches,
* millimeters, or unscaled units according to the current user units setting.
* millimeters, or unscaled units.
*
* Should be used only to display a coordinate in status, but not in dialogs,
* because the mantissa of the number displayed has 4 digits max for readability.
* (i.e. the value shows the decimils or the microns )
* However the actual internal value could need up to 8 digits to be printed
* files, etc., because the mantissa of the number displayed has 4 digits max
* for readability. The actual internal value could need up to 8 digits to be
* printed.
*
* Use StringFromValue() instead where precision matters.
*
* @param aUnits The units to show the value in. The unit string is added to the
* message text.
* @param aValue The double value to convert.
* @param aUseMils Convert inch values to mils if true.
* @return The converted string for display in user interface elements.
*/
wxString LengthDoubleToString( double aValue, bool aUseMils = false );
wxString MessageTextFromValue( EDA_UNITS_T aUnits, double aValue, bool aUseMils = false );
wxString MessageTextFromValue( EDA_UNITS_T aUnits, int aValue, bool aUseMils = false );
/**
* Function StringFromValue

View File

@ -857,28 +857,6 @@ public:
*/
virtual void PrintPage( wxDC* aDC, LSET aPrintMask, bool aPrintMirrorMode, void* aData = NULL );
/**
* Function CoordinateToString
* is a helper to convert the \a integer coordinate \a aValue to a string in inches or mm
* according to the current user units setting.
* @param aValue The coordinate to convert.
* @param aConvertToMils Convert inch values to mils if true. This setting has no effect if
* the current user unit is millimeters.
* @return The converted string for display in user interface elements.
*/
wxString CoordinateToString( int aValue, bool aConvertToMils = false ) const;
/**
* Function LengthDoubleToString
* is a helper to convert the \a double value \a aValue to a string in inches or mm
* according to the current user units setting.
* @param aValue The coordinate to convert.
* @param aConvertToMils Convert inch values to mils if true. This setting has no effect if
* the current user unit is millimeters.
* @return The converted string for display in user interface elements.
*/
wxString LengthDoubleToString( double aValue, bool aConvertToMils = false ) const;
/**
* Function UseGalCanvas
* used to switch between standard and GAL-based canvas.

View File

@ -727,7 +727,7 @@ wxString DRAWSEGMENT::GetSelectMenuText() const
text.Printf( _( "Pcb Graphic %s, length %s on %s" ),
GetChars( ShowShape( m_Shape ) ),
GetChars( ::LengthDoubleToString( GetLength() ) ),
GetChars( ::MessageTextFromValue( g_UserUnit, GetLength() ) ),
GetChars( GetLayerName() ) );
return text;

View File

@ -1080,15 +1080,15 @@ void TRACK::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
track_buffer_start = track_buffer_start->Back();
board->MarkTrace( track_buffer_start, this, NULL, &trackLen, &lenPadToDie, false );
msg = ::LengthDoubleToString( trackLen );
msg = ::MessageTextFromValue( g_UserUnit, trackLen );
aList.push_back( MSG_PANEL_ITEM( _( "Length" ), msg, DARKCYAN ) );
if( lenPadToDie != 0 )
{
msg = ::LengthDoubleToString( trackLen + lenPadToDie );
msg = ::MessageTextFromValue( g_UserUnit, trackLen + lenPadToDie );
aList.push_back( MSG_PANEL_ITEM( _( "Full Length" ), msg, DARKCYAN ) );
msg = ::LengthDoubleToString( lenPadToDie );
msg = ::MessageTextFromValue( g_UserUnit, lenPadToDie );
aList.push_back( MSG_PANEL_ITEM( _( "Pad To Die Length" ), msg, DARKCYAN ) );
}
}
@ -1196,7 +1196,7 @@ void TRACK::GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList )
aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, DARKCYAN ) );
// Display segment length
msg = ::LengthDoubleToString( GetLength() );
msg = ::MessageTextFromValue( g_UserUnit, GetLength() );
aList.push_back( MSG_PANEL_ITEM( _( "Segment Length" ), msg, DARKCYAN ) );
}
@ -1223,7 +1223,7 @@ void SEGZONE::GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList )
aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, DARKCYAN ) );
// Display segment length
msg = ::LengthDoubleToString( GetLength() );
msg = ::MessageTextFromValue( g_UserUnit, GetLength() );
aList.push_back( MSG_PANEL_ITEM( _( "Segment Length" ), msg, DARKCYAN ) );
}
@ -1613,7 +1613,7 @@ wxString TRACK::GetSelectMenuText() const
GetChars( ShowWidth() ),
GetChars( GetNetnameMsg() ),
GetChars( GetLayerName() ),
GetChars( ::LengthDoubleToString( GetLength() ) ) );
GetChars( ::MessageTextFromValue( g_UserUnit, GetLength() ) ) );
return text;
}

View File

@ -140,14 +140,14 @@ void NETINFO_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, BLUE ) );
// Displays the full net length (tracks on pcb + internal ICs connections ):
txt = ::LengthDoubleToString( lengthnet + lengthPadToDie );
txt = ::MessageTextFromValue( g_UserUnit, lengthnet + lengthPadToDie );
aList.push_back( MSG_PANEL_ITEM( _( "Net Length" ), txt, RED ) );
// Displays the net length of tracks only:
txt = ::LengthDoubleToString( lengthnet );
txt = ::MessageTextFromValue( g_UserUnit, lengthnet );
aList.push_back( MSG_PANEL_ITEM( _( "On Board" ), txt, RED ) );
// Displays the net length of internal ICs connections (wires inside ICs):
txt = ::LengthDoubleToString( lengthPadToDie );
txt = ::MessageTextFromValue( g_UserUnit, lengthPadToDie );
aList.push_back( MSG_PANEL_ITEM( _( "In Package" ), txt, RED ) );
}

View File

@ -377,11 +377,11 @@ const wxString DP_MEANDER_PLACER::TuningInfo() const
return _( "?" );
}
status += LengthDoubleToString( (double) m_lastLength, false );
status += ::MessageTextFromValue( g_UserUnit, m_lastLength, false );
status += "/";
status += LengthDoubleToString( (double) m_settings.m_targetLength, false );
status += ::MessageTextFromValue( g_UserUnit, m_settings.m_targetLength, false );
status += " (gap: ";
status += LengthDoubleToString( (double) m_originPair.Gap(), false );
status += ::MessageTextFromValue( g_UserUnit, m_originPair.Gap(), false );
status += ")";
return status;

View File

@ -252,9 +252,9 @@ const wxString MEANDER_PLACER::TuningInfo() const
return _( "?" );
}
status += LengthDoubleToString( (double) m_lastLength, false );
status += ::MessageTextFromValue( g_UserUnit, m_lastLength, false );
status += "/";
status += LengthDoubleToString( (double) m_settings.m_targetLength, false );
status += ::MessageTextFromValue( g_UserUnit, m_settings.m_targetLength, false );
return status;
}

View File

@ -163,9 +163,9 @@ const wxString MEANDER_SKEW_PLACER::TuningInfo() const
return _( "?" );
}
status += LengthDoubleToString( (double) m_lastLength - m_coupledLength, false );
status += ::MessageTextFromValue( g_UserUnit, m_lastLength - m_coupledLength, false );
status += "/";
status += LengthDoubleToString( (double) m_settings.m_targetSkew, false );
status += ::MessageTextFromValue( g_UserUnit, m_settings.m_targetSkew, false );
return status;
}