From 122bd7ca7c733076dd5a004fd8257d6c6d76d527 Mon Sep 17 00:00:00 2001 From: Ian McInerney <ian.s.mcinerney@ieee.org> Date: Sun, 4 Oct 2020 16:29:18 +0100 Subject: [PATCH] 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. --- common/base_units.cpp | 28 +++++++++++----- common/eda_draw_frame.cpp | 16 ++------- eeschema/sch_base_frame.cpp | 47 +++++---------------------- gerbview/gerbview_frame.cpp | 7 ++++ include/base_units.h | 12 ++++--- pagelayout_editor/pl_editor_frame.cpp | 1 + pcbnew/class_zone.cpp | 2 +- pcbnew/pcb_base_frame.cpp | 8 +++++ 8 files changed, 56 insertions(+), 65 deletions(-) diff --git a/common/base_units.cpp b/common/base_units.cpp index 0d31be3a5a..7f04d16c85 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -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 ) { diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index 9b45a54c8c..d1a50a81ae 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -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; } diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 28c3fca321..ba9b8dc8c9 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -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 diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index b0cb0a9bfc..7572ea19d9 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -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" ); diff --git a/include/base_units.h b/include/base_units.h index 33b880a3a0..2eaadc3211 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -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 ); /** diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index f048782358..cebf79b619 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -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; diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 79fe385be6..611e8e58b8 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -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; diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 8c49de675c..0e18d0f630 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -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";