Improve SNR in status bar (and use common code).

This commit is contained in:
Jeff Young 2020-10-06 11:47:01 +01:00
parent 52794b3456
commit ee95d8fe2e
6 changed files with 44 additions and 167 deletions

View File

@ -163,7 +163,7 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLab
default: default:
case EDA_UNITS::MILLIMETRES: case EDA_UNITS::MILLIMETRES:
#if defined( EESCHEMA ) #if defined( EESCHEMA )
format = wxT( "%.4f" ); format = wxT( "%.2f" );
#else #else
format = wxT( "%.3f" ); format = wxT( "%.3f" );
#endif #endif
@ -179,12 +179,16 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLab
case EDA_UNITS::INCHES: case EDA_UNITS::INCHES:
#if defined( EESCHEMA ) #if defined( EESCHEMA )
format = wxT( "%.4f" );
#else
format = wxT( "%.3f" ); format = wxT( "%.3f" );
#else
format = wxT( "%.4f" );
#endif #endif
break; break;
case EDA_UNITS::DEGREES:
format = wxT( "%.1f" );
break;
case EDA_UNITS::UNSCALED: case EDA_UNITS::UNSCALED:
format = wxT( "%.0f" ); format = wxT( "%.0f" );
break; break;

View File

@ -490,7 +490,7 @@ void EDA_DRAW_FRAME::DisplayUnitsMsg()
switch( m_userUnits ) switch( m_userUnits )
{ {
case EDA_UNITS::INCHES: msg = _( "Inches" ); break; case EDA_UNITS::INCHES: msg = _( "inches" ); break;
case EDA_UNITS::MILS: msg = _( "mils" ); break; case EDA_UNITS::MILS: msg = _( "mils" ); break;
case EDA_UNITS::MILLIMETRES: msg = _( "mm" ); break; case EDA_UNITS::MILLIMETRES: msg = _( "mm" ); break;
default: msg = _( "Units" ); break; default: msg = _( "Units" ); break;

View File

@ -76,29 +76,6 @@ void GRID_MENU::update()
} }
} }
wxString GRID_MENU::GridMenuUnits( EDA_UNITS aUnits, double aValue )
{
wxString text;
const wxChar* format;
switch( aUnits )
{
default: wxASSERT_MSG( false, "Invalid unit" ); KI_FALLTHROUGH;
case EDA_UNITS::UNSCALED: format = wxT( "%.0f" ); break;
case EDA_UNITS::MILLIMETRES: format = wxT( "%.4f" ); break;
case EDA_UNITS::MILS: format = wxT( "%.2f" ); break;
case EDA_UNITS::INCHES: format = wxT( "%.4f" ); break;
}
text.Printf( format, To_User_Unit( aUnits, aValue ) );
text += " ";
text += GetAbbreviatedUnitsLabel( aUnits, EDA_DATA_TYPE::DISTANCE );
return text;
}
void GRID_MENU::BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* aCfg, void GRID_MENU::BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* aCfg,
EDA_DRAW_FRAME* aParent ) EDA_DRAW_FRAME* aParent )
{ {
@ -113,8 +90,9 @@ void GRID_MENU::BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* a
{ {
int val = (int) ValueFromString( EDA_UNITS::MILLIMETRES, gridSize ); int val = (int) ValueFromString( EDA_UNITS::MILLIMETRES, gridSize );
msg.Printf( _( "Grid: %s (%s)" ), GRID_MENU::GridMenuUnits( primaryUnit, val ), msg.Printf( _( "Grid: %s (%s)" ),
GRID_MENU::GridMenuUnits( secondaryUnit, val ) ); MessageTextFromValue( primaryUnit, val ),
MessageTextFromValue( secondaryUnit, val ) );
aGridsList->Add( msg ); aGridsList->Add( msg );
} }
@ -123,8 +101,9 @@ void GRID_MENU::BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* a
{ {
int val = (int) ValueFromString( EDA_UNITS::INCHES, aCfg->m_Window.grid.user_grid_x ); int val = (int) ValueFromString( EDA_UNITS::INCHES, aCfg->m_Window.grid.user_grid_x );
msg.Printf( _( "User grid: %s (%s)" ), GRID_MENU::GridMenuUnits( primaryUnit, val ), msg.Printf( _( "User grid: %s (%s)" ),
GRID_MENU::GridMenuUnits( secondaryUnit, val ) ); MessageTextFromValue( primaryUnit, val ),
MessageTextFromValue( secondaryUnit, val ) );
aGridsList->Add( msg ); aGridsList->Add( msg );
} }

View File

@ -1011,19 +1011,10 @@ void GERBVIEW_FRAME::SetGridColor( COLOR4D aColor )
void GERBVIEW_FRAME::DisplayGridMsg() void GERBVIEW_FRAME::DisplayGridMsg()
{ {
wxString line; wxString line;
wxString gridformatter;
switch( m_userUnits ) line.Printf( "grid X %s Y %s",
{ MessageTextFromValue( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x ),
case EDA_UNITS::INCHES: gridformatter = "grid X %.6f Y %.6f"; break; MessageTextFromValue( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().y ) );
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;
}
double grid_x = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x );
double grid_y = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().y );
line.Printf( gridformatter, grid_x, grid_y );
SetStatusText( line, 4 ); SetStatusText( line, 4 );
} }
@ -1045,67 +1036,30 @@ void GERBVIEW_FRAME::UpdateStatusBar()
double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y; double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y;
double theta = RAD2DEG( atan2( -dy, dx ) ); double theta = RAD2DEG( atan2( -dy, dx ) );
double ro = hypot( dx, dy ); double ro = hypot( dx, dy );
wxString formatter;
switch( GetUserUnits() ) line.Printf( wxT( "r %s theta %s" ),
{ MessageTextFromValue( GetUserUnits(), ro, false ),
case EDA_UNITS::INCHES: formatter = wxT( "r %.6f theta %.1f" ); break; MessageTextFromValue( EDA_UNITS::DEGREES, theta, false ) );
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;
}
line.Printf( formatter, To_User_Unit( GetUserUnits(), ro ), theta );
SetStatusText( line, 3 ); SetStatusText( line, 3 );
} }
// Display absolute coordinates: // Display absolute coordinates:
double dXpos = To_User_Unit( GetUserUnits(), cursorPos.x ); line.Printf( wxT( "X %s Y %s" ),
double dYpos = To_User_Unit( GetUserUnits(), cursorPos.y ); MessageTextFromValue( GetUserUnits(), cursorPos.x, false ),
MessageTextFromValue( GetUserUnits(), cursorPos.y, false ) );
wxString absformatter;
wxString relformatter;
switch( GetUserUnits() )
{
case EDA_UNITS::INCHES:
absformatter = wxT( "X %.6f Y %.6f" );
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" );
break;
case EDA_UNITS::UNSCALED:
absformatter = wxT( "X %f Y %f" );
relformatter = wxT( "dx %f dy %f dist %f" );
break;
default:
wxASSERT( false );
break;
}
line.Printf( absformatter, dXpos, dYpos );
SetStatusText( line, 2 ); SetStatusText( line, 2 );
if( !GetShowPolarCoords() ) // display relative cartesian coordinates if( !GetShowPolarCoords() )
{ {
// Display relative coordinates: // Display relative cartesian coordinates:
dXpos = To_User_Unit( GetUserUnits(), cursorPos.x - GetScreen()->m_LocalOrigin.x ); double dXpos = cursorPos.x - GetScreen()->m_LocalOrigin.x;
dYpos = To_User_Unit( GetUserUnits(), cursorPos.y - GetScreen()->m_LocalOrigin.y ); double dYpos = cursorPos.y - GetScreen()->m_LocalOrigin.y;
// We already decided the formatter above line.Printf( wxT( "dx %s dy %s dist %s" ),
line.Printf( relformatter, dXpos, dYpos, hypot( dXpos, dYpos ) ); MessageTextFromValue( GetUserUnits(), dXpos, false ),
MessageTextFromValue( GetUserUnits(), dYpos, false ),
MessageTextFromValue( GetUserUnits(), hypot( dXpos, dYpos ), false ) );
SetStatusText( line, 3 ); SetStatusText( line, 3 );
} }

View File

@ -39,8 +39,6 @@ public:
static void BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* aCfg, static void BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* aCfg,
EDA_DRAW_FRAME* aParent ); EDA_DRAW_FRAME* aParent );
static wxString GridMenuUnits( EDA_UNITS aUnits, double aValue );
private: private:
ACTION_MENU* create() const override ACTION_MENU* create() const override
{ {

View File

@ -489,18 +489,10 @@ GENERAL_COLLECTORS_GUIDE PCB_BASE_FRAME::GetCollectorsGuide()
void PCB_BASE_FRAME::DisplayGridMsg() void PCB_BASE_FRAME::DisplayGridMsg()
{ {
wxString line; wxString line;
wxString gridformatter;
switch( m_userUnits ) line.Printf( "grid X %s Y %s",
{ MessageTextFromValue( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x ),
case EDA_UNITS::INCHES: gridformatter = "grid X %.6f Y %.6f"; break; MessageTextFromValue( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().y ) );
case EDA_UNITS::MILLIMETRES: gridformatter = "grid X %.6f Y %.6f"; break;
default: gridformatter = "grid X %f Y %f"; break;
}
double grid_x = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x );
double grid_y = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().y );
line.Printf( gridformatter, grid_x, grid_y );
SetStatusText( line, 4 ); SetStatusText( line, 4 );
} }
@ -527,26 +519,10 @@ void PCB_BASE_FRAME::UpdateStatusBar()
double dy = cursorPos.y - screen->m_LocalOrigin.y; double dy = cursorPos.y - screen->m_LocalOrigin.y;
double theta = RAD2DEG( atan2( -dy, dx ) ); double theta = RAD2DEG( atan2( -dy, dx ) );
double ro = hypot( dx, dy ); double ro = hypot( dx, dy );
wxString formatter;
switch( GetUserUnits() ) line.Printf( wxT( "r %s theta %s" ),
{ MessageTextFromValue( GetUserUnits(), ro, false ),
case EDA_UNITS::INCHES: MessageTextFromValue( EDA_UNITS::DEGREES, theta, false ) );
formatter = wxT( "r %.6f theta %.1f" );
break;
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;
default: wxASSERT( false ); break;
}
line.Printf( formatter, To_User_Unit( GetUserUnits(), ro ), theta );
SetStatusText( line, 3 ); SetStatusText( line, 3 );
} }
@ -556,41 +532,9 @@ void PCB_BASE_FRAME::UpdateStatusBar()
double userYpos = m_originTransforms.ToDisplayAbsY( static_cast<double>( cursorPos.y ) ); double userYpos = m_originTransforms.ToDisplayAbsY( static_cast<double>( cursorPos.y ) );
// Display absolute coordinates: // Display absolute coordinates:
double dXpos = To_User_Unit( GetUserUnits(), userXpos ); line.Printf( wxT( "X %s Y %s" ),
double dYpos = To_User_Unit( GetUserUnits(), userYpos ); MessageTextFromValue( GetUserUnits(), userXpos, false ),
MessageTextFromValue( GetUserUnits(), userYpos, false ) );
// The following sadly is an if Eeschema/if Pcbnew
wxString absformatter;
wxString locformatter;
switch( GetUserUnits() )
{
case EDA_UNITS::INCHES:
absformatter = "X %.6f Y %.6f";
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";
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 );
SetStatusText( line, 2 ); SetStatusText( line, 2 );
if( !GetShowPolarCoords() ) // display relative cartesian coordinates if( !GetShowPolarCoords() ) // display relative cartesian coordinates
@ -603,12 +547,10 @@ void PCB_BASE_FRAME::UpdateStatusBar()
userXpos = m_originTransforms.ToDisplayRelX( relXpos ); userXpos = m_originTransforms.ToDisplayRelX( relXpos );
userYpos = m_originTransforms.ToDisplayRelY( relYpos ); userYpos = m_originTransforms.ToDisplayRelY( relYpos );
// Display relative coordinates: line.Printf( wxT( "dx %s dy %s dist %s" ),
dXpos = To_User_Unit( GetUserUnits(), userXpos ); MessageTextFromValue( GetUserUnits(), userXpos, false ),
dYpos = To_User_Unit( GetUserUnits(), userYpos ); MessageTextFromValue( GetUserUnits(), userYpos, false ),
MessageTextFromValue( GetUserUnits(), hypot( userXpos, userYpos ), false ) );
// We already decided the formatter above
line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );
SetStatusText( line, 3 ); SetStatusText( line, 3 );
} }