From ee95d8fe2e796c8cc61fd0d7d9a76ee6e07e37e6 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 6 Oct 2020 11:47:01 +0100 Subject: [PATCH] Improve SNR in status bar (and use common code). --- common/base_units.cpp | 10 +++-- common/eda_draw_frame.cpp | 2 +- common/tool/grid_menu.cpp | 33 +++------------ gerbview/gerbview_frame.cpp | 80 ++++++++--------------------------- include/tool/grid_menu.h | 2 - pcbnew/pcb_base_frame.cpp | 84 ++++++------------------------------- 6 files changed, 44 insertions(+), 167 deletions(-) diff --git a/common/base_units.cpp b/common/base_units.cpp index 7f04d16c85..5134e60d4a 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -163,7 +163,7 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLab default: case EDA_UNITS::MILLIMETRES: #if defined( EESCHEMA ) - format = wxT( "%.4f" ); + format = wxT( "%.2f" ); #else format = wxT( "%.3f" ); #endif @@ -179,12 +179,16 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLab case EDA_UNITS::INCHES: #if defined( EESCHEMA ) - format = wxT( "%.4f" ); -#else format = wxT( "%.3f" ); +#else + format = wxT( "%.4f" ); #endif break; + case EDA_UNITS::DEGREES: + format = wxT( "%.1f" ); + break; + case EDA_UNITS::UNSCALED: format = wxT( "%.0f" ); break; diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index ac1135b710..1f937bf7d8 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -490,7 +490,7 @@ void EDA_DRAW_FRAME::DisplayUnitsMsg() 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::MILLIMETRES: msg = _( "mm" ); break; default: msg = _( "Units" ); break; diff --git a/common/tool/grid_menu.cpp b/common/tool/grid_menu.cpp index aa1c04b778..16d1e23f18 100644 --- a/common/tool/grid_menu.cpp +++ b/common/tool/grid_menu.cpp @@ -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, 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 ); - msg.Printf( _( "Grid: %s (%s)" ), GRID_MENU::GridMenuUnits( primaryUnit, val ), - GRID_MENU::GridMenuUnits( secondaryUnit, val ) ); + msg.Printf( _( "Grid: %s (%s)" ), + MessageTextFromValue( primaryUnit, val ), + MessageTextFromValue( secondaryUnit, val ) ); 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 ); - msg.Printf( _( "User grid: %s (%s)" ), GRID_MENU::GridMenuUnits( primaryUnit, val ), - GRID_MENU::GridMenuUnits( secondaryUnit, val ) ); + msg.Printf( _( "User grid: %s (%s)" ), + MessageTextFromValue( primaryUnit, val ), + MessageTextFromValue( secondaryUnit, val ) ); aGridsList->Add( msg ); } diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 6577c0337d..8122bf428e 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -1011,19 +1011,10 @@ void GERBVIEW_FRAME::SetGridColor( COLOR4D aColor ) void GERBVIEW_FRAME::DisplayGridMsg() { wxString line; - wxString gridformatter; - 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; - } - - 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 ); + line.Printf( "grid X %s Y %s", + MessageTextFromValue( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x ), + MessageTextFromValue( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().y ) ); SetStatusText( line, 4 ); } @@ -1045,67 +1036,30 @@ void GERBVIEW_FRAME::UpdateStatusBar() double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y; double theta = RAD2DEG( atan2( -dy, dx ) ); double ro = hypot( dx, dy ); - wxString formatter; - 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; - } - - line.Printf( formatter, To_User_Unit( GetUserUnits(), ro ), theta ); + line.Printf( wxT( "r %s theta %s" ), + MessageTextFromValue( GetUserUnits(), ro, false ), + MessageTextFromValue( EDA_UNITS::DEGREES, theta, false ) ); SetStatusText( line, 3 ); } // Display absolute coordinates: - double dXpos = To_User_Unit( GetUserUnits(), cursorPos.x ); - double dYpos = To_User_Unit( GetUserUnits(), cursorPos.y ); - - 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 ); + line.Printf( wxT( "X %s Y %s" ), + MessageTextFromValue( GetUserUnits(), cursorPos.x, false ), + MessageTextFromValue( GetUserUnits(), cursorPos.y, false ) ); SetStatusText( line, 2 ); - if( !GetShowPolarCoords() ) // display relative cartesian coordinates + if( !GetShowPolarCoords() ) { - // Display relative coordinates: - dXpos = To_User_Unit( GetUserUnits(), cursorPos.x - GetScreen()->m_LocalOrigin.x ); - dYpos = To_User_Unit( GetUserUnits(), cursorPos.y - GetScreen()->m_LocalOrigin.y ); + // Display relative cartesian coordinates: + double dXpos = cursorPos.x - GetScreen()->m_LocalOrigin.x; + double dYpos = cursorPos.y - GetScreen()->m_LocalOrigin.y; - // We already decided the formatter above - line.Printf( relformatter, dXpos, dYpos, hypot( dXpos, dYpos ) ); + line.Printf( wxT( "dx %s dy %s dist %s" ), + MessageTextFromValue( GetUserUnits(), dXpos, false ), + MessageTextFromValue( GetUserUnits(), dYpos, false ), + MessageTextFromValue( GetUserUnits(), hypot( dXpos, dYpos ), false ) ); SetStatusText( line, 3 ); } diff --git a/include/tool/grid_menu.h b/include/tool/grid_menu.h index 2f92657cc7..5a140e3bbf 100644 --- a/include/tool/grid_menu.h +++ b/include/tool/grid_menu.h @@ -39,8 +39,6 @@ public: static void BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* aCfg, EDA_DRAW_FRAME* aParent ); - static wxString GridMenuUnits( EDA_UNITS aUnits, double aValue ); - private: ACTION_MENU* create() const override { diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 186160888d..114c476d2c 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -489,18 +489,10 @@ GENERAL_COLLECTORS_GUIDE PCB_BASE_FRAME::GetCollectorsGuide() void PCB_BASE_FRAME::DisplayGridMsg() { wxString line; - wxString gridformatter; - switch( m_userUnits ) - { - case EDA_UNITS::INCHES: gridformatter = "grid X %.6f Y %.6f"; 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 ); + line.Printf( "grid X %s Y %s", + MessageTextFromValue( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x ), + MessageTextFromValue( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().y ) ); SetStatusText( line, 4 ); } @@ -527,26 +519,10 @@ void PCB_BASE_FRAME::UpdateStatusBar() double dy = cursorPos.y - screen->m_LocalOrigin.y; double theta = RAD2DEG( atan2( -dy, dx ) ); double ro = hypot( dx, dy ); - wxString formatter; - switch( GetUserUnits() ) - { - case EDA_UNITS::INCHES: - 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 ); + line.Printf( wxT( "r %s theta %s" ), + MessageTextFromValue( GetUserUnits(), ro, false ), + MessageTextFromValue( EDA_UNITS::DEGREES, theta, false ) ); SetStatusText( line, 3 ); } @@ -556,41 +532,9 @@ void PCB_BASE_FRAME::UpdateStatusBar() double userYpos = m_originTransforms.ToDisplayAbsY( static_cast( cursorPos.y ) ); // Display absolute coordinates: - double dXpos = To_User_Unit( GetUserUnits(), userXpos ); - double dYpos = To_User_Unit( GetUserUnits(), userYpos ); - - // 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 ); + line.Printf( wxT( "X %s Y %s" ), + MessageTextFromValue( GetUserUnits(), userXpos, false ), + MessageTextFromValue( GetUserUnits(), userYpos, false ) ); SetStatusText( line, 2 ); if( !GetShowPolarCoords() ) // display relative cartesian coordinates @@ -603,12 +547,10 @@ void PCB_BASE_FRAME::UpdateStatusBar() userXpos = m_originTransforms.ToDisplayRelX( relXpos ); userYpos = m_originTransforms.ToDisplayRelY( relYpos ); - // Display relative coordinates: - dXpos = To_User_Unit( GetUserUnits(), userXpos ); - dYpos = To_User_Unit( GetUserUnits(), userYpos ); - - // We already decided the formatter above - line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) ); + line.Printf( wxT( "dx %s dy %s dist %s" ), + MessageTextFromValue( GetUserUnits(), userXpos, false ), + MessageTextFromValue( GetUserUnits(), userYpos, false ), + MessageTextFromValue( GetUserUnits(), hypot( userXpos, userYpos ), false ) ); SetStatusText( line, 3 ); }