From 28b279cb2d5e7aee475c356e4dbf6ce7ce1f5aba Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 8 Aug 2021 00:02:07 +0100 Subject: [PATCH] Units cleanup. It's 2021. Time to move beyond ASCII. This also makes spacing of units consistent (space before abbreviated units, no space before symbolic units). --- 3d-viewer/dialogs/panel_preview_3d_model.cpp | 4 +- common/base_units.cpp | 119 ++++-------------- common/preview_items/preview_utils.cpp | 2 +- common/widgets/unit_binder.cpp | 10 +- pcbnew/dialogs/dialog_plot.cpp | 10 +- .../dialogs/dialog_track_via_properties.cpp | 6 +- pcbnew/fp_text_grid_table.cpp | 12 +- pcbnew/pcb_dimension.cpp | 2 +- pcbnew/toolbars_pcb_editor.cpp | 3 - 9 files changed, 47 insertions(+), 121 deletions(-) diff --git a/3d-viewer/dialogs/panel_preview_3d_model.cpp b/3d-viewer/dialogs/panel_preview_3d_model.cpp index 20e37d5ba6..dcf87f846c 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model.cpp @@ -247,7 +247,7 @@ wxString PANEL_PREVIEW_3D_MODEL::formatScaleValue( double aValue ) wxString PANEL_PREVIEW_3D_MODEL::formatRotationValue( double aValue ) { - return wxString::Format( "%.2f %s", aValue, GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); + return wxString::Format( "%.2f%s", aValue, GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); } @@ -257,7 +257,7 @@ wxString PANEL_PREVIEW_3D_MODEL::formatOffsetValue( double aValue ) if( m_userUnits == EDA_UNITS::INCHES ) aValue /= 25.4f; - return wxString::Format( "%.4f %s", aValue, GetAbbreviatedUnitsLabel( m_userUnits ) ); + return wxString::Format( "%.4f%s", aValue, GetAbbreviatedUnitsLabel( m_userUnits ) ); } diff --git a/common/base_units.cpp b/common/base_units.cpp index 0d4553fd45..f2a55d7920 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -179,10 +179,7 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLab text.Printf( format, value ); if( aAddUnitLabel ) - { - text += " "; text += GetAbbreviatedUnitsLabel( aUnits, aType ); - } return text; } @@ -219,13 +216,11 @@ wxString StringFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, value_to_print = To_User_Unit( aUnits, value_to_print ); } - - char buf[50]; - int len; + char buf[50]; if( value_to_print != 0.0 && fabs( value_to_print ) <= 0.0001 ) { - len = sprintf( buf, "%.10f", value_to_print ); + int len = sprintf( buf, "%.10f", value_to_print ); while( --len > 0 && buf[len] == '0' ) buf[len] = '\0'; @@ -238,41 +233,15 @@ wxString StringFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, else { if( aUnits == EDA_UNITS::MILS ) - len = sprintf( buf, "%.7g", value_to_print ); + sprintf( buf, "%.7g", value_to_print ); else - len = sprintf( buf, "%.10g", value_to_print ); + sprintf( buf, "%.10g", value_to_print ); } - wxString stringValue( buf, wxConvUTF8 ); + wxString stringValue( buf, wxConvUTF8 ); if( aAddUnitSymbol ) - { - switch( aUnits ) - { - case EDA_UNITS::MILLIMETRES: - stringValue += wxT( " mm" ); - break; - - case EDA_UNITS::DEGREES: - stringValue += wxT( " deg" ); - break; - - case EDA_UNITS::MILS: - stringValue += wxT( " mils" ); - break; - - case EDA_UNITS::INCHES: - stringValue += wxT( " in" ); - break; - - case EDA_UNITS::PERCENT: - stringValue += wxT( "%" ); - break; - - case EDA_UNITS::UNSCALED: - break; - } - } + stringValue += GetAbbreviatedUnitsLabel( aUnits, aType ); return stringValue; } @@ -420,64 +389,30 @@ long long int ValueFromString( EDA_UNITS aUnits, const wxString& aTextValue, EDA } -wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnit, EDA_DATA_TYPE aType ) +wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnits, EDA_DATA_TYPE aType ) { - switch( aUnit ) + wxString label; + + switch( aUnits ) { - case EDA_UNITS::MILLIMETRES: - switch( aType ) - { - default: - wxASSERT( 0 ); - KI_FALLTHROUGH; - case EDA_DATA_TYPE::DISTANCE: - return _( "mm" ); - case EDA_DATA_TYPE::AREA: - return _( "sq. mm" ); - case EDA_DATA_TYPE::VOLUME: - return _( "cu. mm" ); - } - - case EDA_UNITS::MILS: - switch( aType ) - { - default: - wxASSERT( 0 ); - KI_FALLTHROUGH; - case EDA_DATA_TYPE::DISTANCE: - return _( "mils" ); - case EDA_DATA_TYPE::AREA: - return _( "sq. mils" ); - case EDA_DATA_TYPE::VOLUME: - return _( "cu. mils" ); - } - - case EDA_UNITS::INCHES: - switch( aType ) - { - default: - wxASSERT( 0 ); - KI_FALLTHROUGH; - case EDA_DATA_TYPE::DISTANCE: - return _( "in" ); - case EDA_DATA_TYPE::AREA: - return _( "sq. in" ); - case EDA_DATA_TYPE::VOLUME: - return _( "cu. in" ); - } - - case EDA_UNITS::PERCENT: - return _( "%" ); - - case EDA_UNITS::UNSCALED: - return wxEmptyString; - - case EDA_UNITS::DEGREES: - return _( "deg" ); - - default: - return wxT( "??" ); + case EDA_UNITS::MILLIMETRES: label = wxT( " mm" ); break; + case EDA_UNITS::DEGREES: label = wxT( "°" ); break; + case EDA_UNITS::MILS: label = wxT( " mils" ); break; + case EDA_UNITS::INCHES: label = wxT( " in" ); break; + case EDA_UNITS::PERCENT: label = wxT( "%" ); break; + case EDA_UNITS::UNSCALED: break; + default: UNIMPLEMENTED_FOR( "Unknown units" ); break; } + + switch( aType ) + { + case EDA_DATA_TYPE::VOLUME: label += wxT( "³" ); break; + case EDA_DATA_TYPE::AREA: label += wxT( "²" ); break; + case EDA_DATA_TYPE::DISTANCE: break; + default: UNIMPLEMENTED_FOR( "Unknown measurement" ); break; + } + + return label; } diff --git a/common/preview_items/preview_utils.cpp b/common/preview_items/preview_utils.cpp index 1889f155fb..995781adc7 100644 --- a/common/preview_items/preview_utils.cpp +++ b/common/preview_items/preview_utils.cpp @@ -55,7 +55,7 @@ wxString KIGFX::PREVIEW::DimensionLabel( const wxString& prefix, double aVal, ED str << wxString::Format( fmtStr, To_User_Unit( aUnits, aVal ) ); if( aIncludeUnits ) - str << " " << GetAbbreviatedUnitsLabel( aUnits ); + str << GetAbbreviatedUnitsLabel( aUnits ); return str; } diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index 03d5b23209..cd67b694e8 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -68,7 +68,7 @@ UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent, wxStaticText* aLabel, wxWindo } if( m_unitLabel ) - m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ) ); + m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) ); m_valueCtrl->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ), nullptr, this ); @@ -94,7 +94,7 @@ void UNIT_BINDER::SetUnits( EDA_UNITS aUnits ) m_units = aUnits; if( m_unitLabel ) - m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ) ); + m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) ); } @@ -109,7 +109,7 @@ void UNIT_BINDER::SetDataType( EDA_DATA_TYPE aDataType ) m_dataType = aDataType; if( m_unitLabel ) - m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ) ); + m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) ); } @@ -283,7 +283,7 @@ void UNIT_BINDER::SetValue( const wxString& aValue ) m_eval.Clear(); if( m_unitLabel ) - m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ) ); + m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) ); } @@ -325,7 +325,7 @@ void UNIT_BINDER::ChangeValue( const wxString& aValue ) m_eval.Clear(); if( m_unitLabel ) - m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ) ); + m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) ); } diff --git a/pcbnew/dialogs/dialog_plot.cpp b/pcbnew/dialogs/dialog_plot.cpp index b9c68c8fa5..348d62ca4e 100644 --- a/pcbnew/dialogs/dialog_plot.cpp +++ b/pcbnew/dialogs/dialog_plot.cpp @@ -720,12 +720,10 @@ void DIALOG_PLOT::applyPlotSettings() m_widthAdjustMaxValue ) ) { m_trackWidthCorrection.SetValue( m_PSWidthAdjust ); - msg.Printf( _( "Width correction constrained. " - "The reasonable width correction value must be in a range of " - " [%s; %s] (%s) for current design rules." ), - StringFromValue( GetUserUnits(), m_widthAdjustMinValue, false ), - StringFromValue( GetUserUnits(), m_widthAdjustMaxValue, false ), - GetAbbreviatedUnitsLabel( GetUserUnits() ) ); + msg.Printf( _( "Width correction constrained. The width correction value must be in the" + " range of [%s; %s] for the current design rules." ), + StringFromValue( GetUserUnits(), m_widthAdjustMinValue, true ), + StringFromValue( GetUserUnits(), m_widthAdjustMaxValue, true ) ); reporter.Report( msg, RPT_SEVERITY_WARNING ); } diff --git a/pcbnew/dialogs/dialog_track_via_properties.cpp b/pcbnew/dialogs/dialog_track_via_properties.cpp index bbad8fe4a0..afe0b0a9d2 100644 --- a/pcbnew/dialogs/dialog_track_via_properties.cpp +++ b/pcbnew/dialogs/dialog_track_via_properties.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 CERN - * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -298,7 +298,7 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen m_netSelector->Disable(); } - m_DesignRuleViasUnit->SetLabel( GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) ); + m_DesignRuleViasUnit->SetLabel( GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ).Trim( false ) ); int viaSelection = wxNOT_FOUND; @@ -341,7 +341,7 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen if( m_tracks ) { - m_DesignRuleWidthsUnits->SetLabel( GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) ); + m_DesignRuleWidthsUnits->SetLabel( GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ).Trim( false ) ); int widthSelection = wxNOT_FOUND; diff --git a/pcbnew/fp_text_grid_table.cpp b/pcbnew/fp_text_grid_table.cpp index 8797e13455..c59795e1aa 100644 --- a/pcbnew/fp_text_grid_table.cpp +++ b/pcbnew/fp_text_grid_table.cpp @@ -55,14 +55,10 @@ FP_TEXT_GRID_TABLE::FP_TEXT_GRID_TABLE( PCB_BASE_FRAME* aFrame ) : if( g_menuOrientations.IsEmpty() ) { - g_menuOrientations.push_back( - wxT( "0 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); - g_menuOrientations.push_back( - wxT( "90 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); - g_menuOrientations.push_back( - wxT( "-90 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); - g_menuOrientations.push_back( - wxT( "180 " ) + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); + g_menuOrientations.push_back( "0" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); + g_menuOrientations.push_back( "90" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); + g_menuOrientations.push_back( "-90" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); + g_menuOrientations.push_back( "180" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); } m_orientationColAttr = new wxGridCellAttr; diff --git a/pcbnew/pcb_dimension.cpp b/pcbnew/pcb_dimension.cpp index dedf6241b5..3f5512a5cc 100644 --- a/pcbnew/pcb_dimension.cpp +++ b/pcbnew/pcb_dimension.cpp @@ -319,7 +319,7 @@ void PCB_DIMENSION_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, EDA_UNITS units; GetUnits( units ); - aList.emplace_back( _( "Units" ), GetAbbreviatedUnitsLabel( units ) ); + aList.emplace_back( _( "Units" ), GetAbbreviatedUnitsLabel( units ).Trim( false ) ); ORIGIN_TRANSFORMS originTransforms = aFrame->GetOriginTransforms(); units = aFrame->GetUserUnits(); diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index e752258f09..41a75ec38d 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -622,10 +622,7 @@ static wxString ComboBoxUnits( EDA_UNITS aUnits, double aValue, bool aIncludeLab text.Printf( format, To_User_Unit( aUnits, aValue ) ); if( aIncludeLabel ) - { - text += " "; text += GetAbbreviatedUnitsLabel( aUnits, EDA_DATA_TYPE::DISTANCE ); - } return text; }