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).
This commit is contained in:
Jeff Young 2021-08-08 00:02:07 +01:00
parent 56665b9ca7
commit 28b279cb2d
9 changed files with 47 additions and 121 deletions

View File

@ -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 ) );
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 ) );
}

View File

@ -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 );
}

View File

@ -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 <maciej.suminski@cern.ch>
*
* 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;

View File

@ -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;

View File

@ -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();

View File

@ -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;
}