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

View File

@ -105,20 +105,26 @@ wxString CoordinateToString( int aValue, bool aUseMils = false );
wxString AngleToStringDegrees( double aAngle ); wxString AngleToStringDegrees( double aAngle );
/** /**
* Function LengthDoubleToString * Function MessageTextFromValue
* is a helper to convert the \a double length \a aValue to a string in inches, * 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, * 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. * files, etc., because the mantissa of the number displayed has 4 digits max
* (i.e. the value shows the decimils or the microns ) * for readability. The actual internal value could need up to 8 digits to be
* However the actual internal value could need up to 8 digits to be printed * 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 aValue The double value to convert.
* @param aUseMils Convert inch values to mils if true. * @param aUseMils Convert inch values to mils if true.
* @return The converted string for display in user interface elements. * @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 * Function StringFromValue

View File

@ -857,28 +857,6 @@ public:
*/ */
virtual void PrintPage( wxDC* aDC, LSET aPrintMask, bool aPrintMirrorMode, void* aData = NULL ); 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 * Function UseGalCanvas
* used to switch between standard and GAL-based canvas. * 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" ), text.Printf( _( "Pcb Graphic %s, length %s on %s" ),
GetChars( ShowShape( m_Shape ) ), GetChars( ShowShape( m_Shape ) ),
GetChars( ::LengthDoubleToString( GetLength() ) ), GetChars( ::MessageTextFromValue( g_UserUnit, GetLength() ) ),
GetChars( GetLayerName() ) ); GetChars( GetLayerName() ) );
return text; return text;

View File

@ -1080,15 +1080,15 @@ void TRACK::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
track_buffer_start = track_buffer_start->Back(); track_buffer_start = track_buffer_start->Back();
board->MarkTrace( track_buffer_start, this, NULL, &trackLen, &lenPadToDie, false ); 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 ) ); aList.push_back( MSG_PANEL_ITEM( _( "Length" ), msg, DARKCYAN ) );
if( lenPadToDie != 0 ) if( lenPadToDie != 0 )
{ {
msg = ::LengthDoubleToString( trackLen + lenPadToDie ); msg = ::MessageTextFromValue( g_UserUnit, trackLen + lenPadToDie );
aList.push_back( MSG_PANEL_ITEM( _( "Full Length" ), msg, DARKCYAN ) ); 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 ) ); 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 ) ); aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, DARKCYAN ) );
// Display segment length // Display segment length
msg = ::LengthDoubleToString( GetLength() ); msg = ::MessageTextFromValue( g_UserUnit, GetLength() );
aList.push_back( MSG_PANEL_ITEM( _( "Segment Length" ), msg, DARKCYAN ) ); 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 ) ); aList.push_back( MSG_PANEL_ITEM( _( "Width" ), msg, DARKCYAN ) );
// Display segment length // Display segment length
msg = ::LengthDoubleToString( GetLength() ); msg = ::MessageTextFromValue( g_UserUnit, GetLength() );
aList.push_back( MSG_PANEL_ITEM( _( "Segment Length" ), msg, DARKCYAN ) ); aList.push_back( MSG_PANEL_ITEM( _( "Segment Length" ), msg, DARKCYAN ) );
} }
@ -1613,7 +1613,7 @@ wxString TRACK::GetSelectMenuText() const
GetChars( ShowWidth() ), GetChars( ShowWidth() ),
GetChars( GetNetnameMsg() ), GetChars( GetNetnameMsg() ),
GetChars( GetLayerName() ), GetChars( GetLayerName() ),
GetChars( ::LengthDoubleToString( GetLength() ) ) ); GetChars( ::MessageTextFromValue( g_UserUnit, GetLength() ) ) );
return text; 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 ) ); aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, BLUE ) );
// Displays the full net length (tracks on pcb + internal ICs connections ): // 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 ) ); aList.push_back( MSG_PANEL_ITEM( _( "Net Length" ), txt, RED ) );
// Displays the net length of tracks only: // 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 ) ); aList.push_back( MSG_PANEL_ITEM( _( "On Board" ), txt, RED ) );
// Displays the net length of internal ICs connections (wires inside ICs): // 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 ) ); aList.push_back( MSG_PANEL_ITEM( _( "In Package" ), txt, RED ) );
} }

View File

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

View File

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

View File

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