Make the statubar aware of mils units

Switch Eeschema to use the built-in printing routines
because its precisions are close to those and it is
cleaner.

Give mils a precision of 2 decimal places to match
the precision shown in inches.
This commit is contained in:
Ian McInerney 2020-10-04 16:29:18 +01:00
parent ad29a2f3b4
commit 122bd7ca7c
8 changed files with 56 additions and 65 deletions

View File

@ -119,21 +119,24 @@ double To_User_Unit( EDA_UNITS aUnit, double aValue )
*/
// A lower-precision (for readability) version of StringFromValue()
wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, EDA_DATA_TYPE aType )
wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, bool aAddUnitLabel,
EDA_DATA_TYPE aType )
{
return MessageTextFromValue( aUnits, double( aValue ), aType );
return MessageTextFromValue( aUnits, double( aValue ), aAddUnitLabel, aType );
}
// A lower-precision (for readability) version of StringFromValue()
wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, EDA_DATA_TYPE aType )
wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, bool aAddUnitLabel,
EDA_DATA_TYPE aType )
{
return MessageTextFromValue( aUnits, double( aValue ), aType );
return MessageTextFromValue( aUnits, double( aValue ), aAddUnitLabel, aType );
}
// A lower-precision (for readability) version of StringFromValue()
wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, EDA_DATA_TYPE aType )
wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLabel,
EDA_DATA_TYPE aType )
{
wxString text;
const wxChar* format;
@ -165,7 +168,7 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, EDA_DATA_TYPE aT
format = wxT( "%.3f" );
#endif
break;
case EDA_UNITS::MILS:
#if defined( EESCHEMA )
format = wxT( "%.0f" );
@ -181,12 +184,19 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, EDA_DATA_TYPE aT
format = wxT( "%.3f" );
#endif
break;
case EDA_UNITS::UNSCALED:
format = wxT( "%.0f" );
break;
}
text.Printf( format, value );
text += " ";
text += GetAbbreviatedUnitsLabel( aUnits, aType );
if( aAddUnitLabel )
{
text += " ";
text += GetAbbreviatedUnitsLabel( aUnits, aType );
}
return text;
}
@ -505,7 +515,7 @@ wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnit, EDA_DATA_TYPE aType )
case EDA_DATA_TYPE::VOLUME:
return _( "cu. mils" );
}
case EDA_UNITS::INCHES:
switch( aType )
{

View File

@ -469,23 +469,12 @@ void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
}
/*
* Display the grid status.
*/
void EDA_DRAW_FRAME::DisplayGridMsg()
{
wxString line;
wxString gridformatter;
switch( m_userUnits )
{
case EDA_UNITS::INCHES: gridformatter = "grid %.3f"; break;
case EDA_UNITS::MILLIMETRES: gridformatter = "grid %.4f"; break;
default: gridformatter = "grid %f"; break;
}
double grid = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x );
line.Printf( gridformatter, grid );
line.Printf( "grid %s",
MessageTextFromValue( GetUserUnits(), GetCanvas()->GetGAL()->GetGridSize().x, false ) );
SetStatusText( line, 4 );
}
@ -498,6 +487,7 @@ void EDA_DRAW_FRAME::DisplayUnitsMsg()
switch( m_userUnits )
{
case EDA_UNITS::INCHES: msg = _( "Inches" ); break;
case EDA_UNITS::MILS: msg = _( "mils" ); break;
case EDA_UNITS::MILLIMETRES: msg = _( "mm" ); break;
default: msg = _( "Units" ); break;
}

View File

@ -157,48 +157,19 @@ void SCH_BASE_FRAME::UpdateStatusBar()
EDA_DRAW_FRAME::UpdateStatusBar();
// Display absolute coordinates:
// Display absolute and relative coordinates
VECTOR2D cursorPos = GetCanvas()->GetViewControls()->GetCursorPosition();
double dXpos = To_User_Unit( GetUserUnits(), cursorPos.x );
double dYpos = To_User_Unit( GetUserUnits(), cursorPos.y );
VECTOR2D d = cursorPos - screen->m_LocalOrigin;
wxString absformatter;
wxString locformatter;
switch( GetUserUnits() )
{
case EDA_UNITS::INCHES:
absformatter = "X %.3f Y %.3f";
locformatter = "dx %.3f dy %.3f dist %.3f";
break;
case EDA_UNITS::MILLIMETRES:
absformatter = "X %.4f Y %.4f";
locformatter = "dx %.4f dy %.4f dist %.4f";
break;
case EDA_UNITS::UNSCALED:
absformatter = "X %f Y %f";
locformatter = "dx %f dy %f dist %f";
break;
default:
wxASSERT( false );
break;
}
line.Printf( absformatter, dXpos, dYpos );
line.Printf( "X %s Y %s",
MessageTextFromValue( GetUserUnits(), cursorPos.x, false ),
MessageTextFromValue( GetUserUnits(), cursorPos.y, false ) );
SetStatusText( line, 2 );
// Display relative coordinates:
double dx = cursorPos.x - screen->m_LocalOrigin.x;
double dy = cursorPos.y - screen->m_LocalOrigin.y;
dXpos = To_User_Unit( GetUserUnits(), dx );
dYpos = To_User_Unit( GetUserUnits(), dy );
// We already decided the formatter above
line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );
line.Printf( "dx %s dy %s dist %s",
MessageTextFromValue( GetUserUnits(), d.x, false ),
MessageTextFromValue( GetUserUnits(), d.y, false ),
MessageTextFromValue( GetUserUnits(), hypot( d.x, d.y ), false ) );
SetStatusText( line, 3 );
// refresh grid display

View File

@ -1014,6 +1014,7 @@ void GERBVIEW_FRAME::DisplayGridMsg()
switch( m_userUnits )
{
case EDA_UNITS::INCHES: gridformatter = "grid X %.6f Y %.6f"; break;
case EDA_UNITS::MILS: gridformatter = "grid X %.2f Y %.2f"; break;
case EDA_UNITS::MILLIMETRES: gridformatter = "grid X %.6f Y %.6f"; break;
default: gridformatter = "grid X %f Y %f"; break;
}
@ -1047,6 +1048,7 @@ void GERBVIEW_FRAME::UpdateStatusBar()
switch( GetUserUnits() )
{
case EDA_UNITS::INCHES: formatter = wxT( "r %.6f theta %.1f" ); break;
case EDA_UNITS::MILS: formatter = wxT( "r %.6f theta %.1f" ); break;
case EDA_UNITS::MILLIMETRES: formatter = wxT( "r %.5f theta %.1f" ); break;
case EDA_UNITS::UNSCALED: formatter = wxT( "r %f theta %f" ); break;
default: wxASSERT( false ); break;
@ -1071,6 +1073,11 @@ void GERBVIEW_FRAME::UpdateStatusBar()
relformatter = wxT( "dx %.6f dy %.6f dist %.4f" );
break;
case EDA_UNITS::MILS:
absformatter = wxT( "X %.2f Y %.2f" );
relformatter = wxT( "dx %.2f dy %.2f dist %.4f" );
break;
case EDA_UNITS::MILLIMETRES:
absformatter = wxT( "X %.5f Y %.5f" );
relformatter = wxT( "dx %.5f dy %.5f dist %.3f" );

View File

@ -115,14 +115,18 @@ wxString AngleToStringDegrees( double aAngle );
* @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 aAddUnitLabel If true, adds the unit label to the end of the string
* @param aType Type of the unit being used (e.g. distance, area, etc.)
* @return The converted string for display in user interface elements.
*/
wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLabel = true,
EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, bool aAddUnitLabel = true,
EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, bool aAddUnitLabel = true,
EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
/**
* Function StringFromValue
@ -162,7 +166,7 @@ double From_User_Unit( EDA_UNITS aUnit, double aValue );
* @param aTextValue A reference to a wxString object containing the string to convert.
* @return A double representing that value in internal units
*/
double DoubleValueFromString( EDA_UNITS aUnits, const wxString& aTextValue,
double DoubleValueFromString( EDA_UNITS aUnits, const wxString& aTextValue,
EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
/**

View File

@ -715,6 +715,7 @@ void PL_EDITOR_FRAME::UpdateStatusBar()
switch( GetUserUnits() )
{
case EDA_UNITS::INCHES: SetStatusText( _( "inches" ), 6 ); break;
case EDA_UNITS::MILS: SetStatusText( _( "mils" ), 6 ); break;
case EDA_UNITS::MILLIMETRES: SetStatusText( _( "mm" ), 6 ); break;
case EDA_UNITS::UNSCALED: SetStatusText( wxEmptyString, 6 ); break;
default: wxASSERT( false ); break;

View File

@ -618,7 +618,7 @@ void ZONE_CONTAINER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PA
aList.emplace_back( _( "Fill Mode" ), msg, BROWN );
msg = MessageTextFromValue( units, m_area, EDA_DATA_TYPE::AREA );
msg = MessageTextFromValue( units, m_area, true, EDA_DATA_TYPE::AREA );
aList.emplace_back( _( "Filled Area" ), msg, BLUE );
wxString source;

View File

@ -538,6 +538,9 @@ void PCB_BASE_FRAME::UpdateStatusBar()
case EDA_UNITS::MILLIMETRES:
formatter = wxT( "r %.6f theta %.1f" );
break;
case EDA_UNITS::MILS:
formatter = wxT( "r %.6f theta %.1f" );
break;
case EDA_UNITS::UNSCALED:
formatter = wxT( "r %f theta %f" );
break;
@ -568,6 +571,11 @@ void PCB_BASE_FRAME::UpdateStatusBar()
locformatter = "dx %.6f dy %.6f dist %.4f";
break;
case EDA_UNITS::MILS:
absformatter = "X %.2f Y %.2f";
locformatter = "dx %.2f dy %.2f dist %.4f";
break;
case EDA_UNITS::MILLIMETRES:
absformatter = "X %.6f Y %.6f";
locformatter = "dx %.6f dy %.6f dist %.3f";