Move 5 helpers to EDA_UNIT_UTILS since they aren't iu specific

This commit is contained in:
Marek Roszko 2022-08-29 19:30:25 -04:00
parent df8b7a8fef
commit 03aa63bd50
22 changed files with 191 additions and 174 deletions

View File

@ -250,7 +250,7 @@ wxString PANEL_PREVIEW_3D_MODEL::formatRotationValue( double aValue )
{ {
return wxString::Format( wxT( "%.2f%s" ), return wxString::Format( wxT( "%.2f%s" ),
aValue, aValue,
GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
} }
@ -264,7 +264,7 @@ wxString PANEL_PREVIEW_3D_MODEL::formatOffsetValue( double aValue )
return wxString::Format( wxT( "%.6f%s" ), return wxString::Format( wxT( "%.6f%s" ),
aValue, aValue,
GetAbbreviatedUnitsLabel( m_userUnits ) ); EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_userUnits ) );
} }

View File

@ -52,18 +52,6 @@
#endif #endif
int Mm2mils( double x )
{
return KiROUND( x * 1000. / 25.4 );
}
int Mils2mm( double x )
{
return KiROUND( x * 25.4 / 1000. );
}
double To_User_Unit( EDA_UNITS aUnit, double aValue ) double To_User_Unit( EDA_UNITS aUnit, double aValue )
{ {
switch( aUnit ) switch( aUnit )
@ -188,7 +176,7 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLab
text.Printf( format, value ); text.Printf( format, value );
if( aAddUnitLabel ) if( aAddUnitLabel )
text += GetAbbreviatedUnitsLabel( aUnits, aType ); text += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits, aType );
return text; return text;
} }
@ -245,7 +233,7 @@ wxString StringFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol,
wxString stringValue( buf, wxConvUTF8 ); wxString stringValue( buf, wxConvUTF8 );
if( aAddUnitSymbol ) if( aAddUnitSymbol )
stringValue += GetAbbreviatedUnitsLabel( aUnits, aType ); stringValue += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits, aType );
return stringValue; return stringValue;
} }
@ -351,35 +339,6 @@ double DoubleValueFromString( EDA_UNITS aUnits, const wxString& aTextValue, EDA_
} }
void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits )
{
wxString buf( aTextValue.Strip( wxString::both ) );
unsigned brk_point = 0;
while( brk_point < buf.Len() )
{
wxChar c = buf[brk_point];
if( !( (c >= '0' && c <='9') || (c == '.') || (c == ',') || (c == '-') || (c == '+') ) )
break;
++brk_point;
}
// Check the unit designator (2 ch significant)
wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
if( unit == wxT( "mm" ) )
aUnits = EDA_UNITS::MILLIMETRES;
else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) // "mils" or "thou"
aUnits = EDA_UNITS::MILS;
else if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
aUnits = EDA_UNITS::INCHES;
else if( unit == wxT( "de" ) || unit == wxT( "ra" ) ) // "deg" or "rad"
aUnits = EDA_UNITS::DEGREES;
}
long long int ValueFromString( EDA_UNITS aUnits, const wxString& aTextValue, EDA_DATA_TYPE aType ) long long int ValueFromString( EDA_UNITS aUnits, const wxString& aTextValue, EDA_DATA_TYPE aType )
{ {
double value = DoubleValueFromString( aUnits, aTextValue, aType ); double value = DoubleValueFromString( aUnits, aTextValue, aType );
@ -388,33 +347,6 @@ long long int ValueFromString( EDA_UNITS aUnits, const wxString& aTextValue, EDA
} }
wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnits, EDA_DATA_TYPE aType )
{
wxString label;
switch( aUnits )
{
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;
}
std::string FormatInternalUnits( int aValue ) std::string FormatInternalUnits( int aValue )
{ {
char buf[50]; char buf[50];
@ -450,17 +382,6 @@ std::string FormatInternalUnits( int aValue )
} }
std::string FormatAngle( const EDA_ANGLE& aAngle )
{
char temp[50];
int len;
len = snprintf( temp, sizeof(temp), "%.10g", aAngle.AsDegrees() );
return std::string( temp, len );
}
std::string FormatInternalUnits( const wxPoint& aPoint ) std::string FormatInternalUnits( const wxPoint& aPoint )
{ {
return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y ); return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y );

View File

@ -310,11 +310,11 @@ void DIALOG_PRINT_GENERIC::initPrintData()
if( pageInfo.IsCustom() ) if( pageInfo.IsCustom() )
{ {
if( pageInfo.IsPortrait() ) if( pageInfo.IsPortrait() )
s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetWidthMils() ), s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ),
Mils2mm( pageInfo.GetHeightMils() ) ) ); EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) );
else else
s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetHeightMils() ), s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ),
Mils2mm( pageInfo.GetWidthMils() ) ) ); EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) );
} }
*s_PrintData = s_pageSetupData->GetPrintData(); *s_PrintData = s_pageSetupData->GetPrintData();

View File

@ -22,6 +22,8 @@
*/ */
#include <eda_units.h> #include <eda_units.h>
#include <math/util.h> // for KiROUND
#include <macros.h>
bool EDA_UNIT_UTILS::IsImperialUnit( EDA_UNITS aUnit ) bool EDA_UNIT_UTILS::IsImperialUnit( EDA_UNITS aUnit )
{ {
@ -52,3 +54,83 @@ bool EDA_UNIT_UTILS::IsMetricUnit( EDA_UNITS aUnit )
return false; return false;
} }
int EDA_UNIT_UTILS::Mm2mils( double aVal )
{
return KiROUND( aVal * 1000. / 25.4 );
}
int EDA_UNIT_UTILS::Mils2mm( double aVal )
{
return KiROUND( aVal * 25.4 / 1000. );
}
void EDA_UNIT_UTILS::FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits )
{
wxString buf( aTextValue.Strip( wxString::both ) );
unsigned brk_point = 0;
while( brk_point < buf.Len() )
{
wxChar c = buf[brk_point];
if( !( ( c >= '0' && c <= '9' ) || ( c == '.' ) || ( c == ',' ) || ( c == '-' )
|| ( c == '+' ) ) )
break;
++brk_point;
}
// Check the unit designator (2 ch significant)
wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
if( unit == wxT( "mm" ) )
aUnits = EDA_UNITS::MILLIMETRES;
else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) // "mils" or "thou"
aUnits = EDA_UNITS::MILS;
else if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
aUnits = EDA_UNITS::INCHES;
else if( unit == wxT( "de" ) || unit == wxT( "ra" ) ) // "deg" or "rad"
aUnits = EDA_UNITS::DEGREES;
}
wxString EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( EDA_UNITS aUnits, EDA_DATA_TYPE aType )
{
wxString label;
switch( aUnits )
{
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;
}
std::string EDA_UNIT_UTILS::FormatAngle( const EDA_ANGLE& aAngle )
{
char temp[50];
int len;
len = snprintf( temp, sizeof( temp ), "%.10g", aAngle.AsDegrees() );
return std::string( temp, len );
}

View File

@ -26,7 +26,7 @@
#include <common.h> #include <common.h>
#include <page_info.h> #include <page_info.h>
#include <macros.h> #include <macros.h>
#include <base_units.h> // for Mm2mils #include <eda_units.h>
// late arriving wxPAPER_A0, wxPAPER_A1 // late arriving wxPAPER_A0, wxPAPER_A1
@ -64,7 +64,7 @@ const wxChar PAGE_INFO::Custom[] = wxT( "User" );
// also see: wx/defs.h // also see: wx/defs.h
// local readability macro for millimeter wxSize // local readability macro for millimeter wxSize
#define MMsize( x, y ) wxSize( Mm2mils( x ), Mm2mils( y ) ) #define MMsize( x, y ) wxSize( EDA_UNIT_UTILS::Mm2mils( x ), EDA_UNIT_UTILS::Mm2mils( y ) )
// All MUST be defined as landscape. // All MUST be defined as landscape.
const PAGE_INFO PAGE_INFO::pageA5( MMsize( 210, 148 ), wxT( "A5" ), wxPAPER_A5 ); const PAGE_INFO PAGE_INFO::pageA5( MMsize( 210, 148 ), wxT( "A5" ), wxPAPER_A5 );

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 ) ); str << wxString::Format( fmtStr, To_User_Unit( aUnits, aVal ) );
if( aIncludeUnits ) if( aIncludeUnits )
str << GetAbbreviatedUnitsLabel( aUnits ); str << EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits );
return str; return str;
} }

View File

@ -68,7 +68,8 @@ UNIT_BINDER::UNIT_BINDER( EDA_BASE_FRAME* aParent, wxStaticText* aLabel, wxWindo
} }
if( m_unitLabel ) if( m_unitLabel )
m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) ); m_unitLabel->SetLabel(
EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) );
m_valueCtrl->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ), m_valueCtrl->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( UNIT_BINDER::onSetFocus ),
nullptr, this ); nullptr, this );
@ -96,7 +97,8 @@ void UNIT_BINDER::SetUnits( EDA_UNITS aUnits )
m_units = aUnits; m_units = aUnits;
if( m_unitLabel ) if( m_unitLabel )
m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) ); m_unitLabel->SetLabel(
EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) );
} }
@ -111,7 +113,8 @@ void UNIT_BINDER::SetDataType( EDA_DATA_TYPE aDataType )
m_dataType = aDataType; m_dataType = aDataType;
if( m_unitLabel ) if( m_unitLabel )
m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) ); m_unitLabel->SetLabel(
EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) );
} }
@ -321,7 +324,8 @@ void UNIT_BINDER::SetValue( const wxString& aValue )
m_eval.Clear(); m_eval.Clear();
if( m_unitLabel ) if( m_unitLabel )
m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) ); m_unitLabel->SetLabel(
EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) );
} }
@ -369,7 +373,8 @@ void UNIT_BINDER::ChangeValue( const wxString& aValue )
m_eval.Clear(); m_eval.Clear();
if( m_unitLabel ) if( m_unitLabel )
m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) ); m_unitLabel->SetLabel(
EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_units, m_dataType ).Trim( false ) );
} }

View File

@ -209,11 +209,11 @@ bool DIALOG_PRINT_USING_PRINTER::TransferDataToWindow()
if( pageInfo.IsCustom() ) if( pageInfo.IsCustom() )
{ {
if( pageInfo.IsPortrait() ) if( pageInfo.IsPortrait() )
pageSetupDialogData.SetPaperSize( wxSize( Mils2mm( pageInfo.GetWidthMils() ), pageSetupDialogData.SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ),
Mils2mm( pageInfo.GetHeightMils() ) ) ); EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) );
else else
pageSetupDialogData.SetPaperSize( wxSize( Mils2mm( pageInfo.GetHeightMils() ), pageSetupDialogData.SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ),
Mils2mm( pageInfo.GetWidthMils() ) ) ); EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) );
} }
pageSetupDialogData.GetPrintData().SetOrientation( pageInfo.GetWxOrientation() ); pageSetupDialogData.GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );

View File

@ -415,7 +415,7 @@ void SCH_SEXPR_PLUGIN_CACHE::savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter
getPinShapeToken( aPin->GetShape() ), getPinShapeToken( aPin->GetShape() ),
FormatInternalUnits( aPin->GetPosition().x ).c_str(), FormatInternalUnits( aPin->GetPosition().x ).c_str(),
FormatInternalUnits( aPin->GetPosition().y ).c_str(), FormatInternalUnits( aPin->GetPosition().y ).c_str(),
FormatAngle( getPinAngle( aPin->GetOrientation() ) ).c_str(), EDA_UNIT_UTILS::FormatAngle( getPinAngle( aPin->GetOrientation() ) ).c_str(),
FormatInternalUnits( aPin->GetLength() ).c_str() ); FormatInternalUnits( aPin->GetLength() ).c_str() );
if( !aPin->IsVisible() ) if( !aPin->IsVisible() )
@ -479,7 +479,7 @@ void SCH_SEXPR_PLUGIN_CACHE::saveTextBox( LIB_TEXTBOX* aTextBox, OUTPUTFORMATTER
aFormatter.Print( aNestLevel + 1, "(at %s %s %s) (size %s %s)\n", aFormatter.Print( aNestLevel + 1, "(at %s %s %s) (size %s %s)\n",
FormatInternalUnits( pos.x ).c_str(), FormatInternalUnits( pos.x ).c_str(),
FormatInternalUnits( pos.y ).c_str(), FormatInternalUnits( pos.y ).c_str(),
FormatAngle( aTextBox->GetTextAngle() ).c_str(), EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
FormatInternalUnits( size.x ).c_str(), FormatInternalUnits( size.x ).c_str(),
FormatInternalUnits( size.y ).c_str() ); FormatInternalUnits( size.y ).c_str() );

View File

@ -1703,7 +1703,7 @@ void SCH_SEXPR_PARSER::parsePAGE_INFO( PAGE_INFO& aPageInfo )
if( pageType == PAGE_INFO::Custom ) if( pageType == PAGE_INFO::Custom )
{ {
int width = Mm2mils( parseDouble( "width" ) ); // width stored in mm so we convert to mils int width = EDA_UNIT_UTILS::Mm2mils( parseDouble( "width" ) ); // width stored in mm so we convert to mils
// Perform some controls to avoid crashes if the size is edited by hands // Perform some controls to avoid crashes if the size is edited by hands
if( width < MIN_PAGE_SIZE_MILS ) if( width < MIN_PAGE_SIZE_MILS )
@ -1711,7 +1711,7 @@ void SCH_SEXPR_PARSER::parsePAGE_INFO( PAGE_INFO& aPageInfo )
else if( width > MAX_PAGE_SIZE_EESCHEMA_MILS ) else if( width > MAX_PAGE_SIZE_EESCHEMA_MILS )
width = MAX_PAGE_SIZE_EESCHEMA_MILS; width = MAX_PAGE_SIZE_EESCHEMA_MILS;
int height = Mm2mils( parseDouble( "height" ) ); // height stored in mm so we convert to mils int height = EDA_UNIT_UTILS::Mm2mils( parseDouble( "height" ) ); // height stored in mm so we convert to mils
if( height < MIN_PAGE_SIZE_MILS ) if( height < MIN_PAGE_SIZE_MILS )
height = MIN_PAGE_SIZE_MILS; height = MIN_PAGE_SIZE_MILS;

View File

@ -664,7 +664,7 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa
m_out->Quotew( aSymbol->GetLibId().Format().wx_str() ).c_str(), m_out->Quotew( aSymbol->GetLibId().Format().wx_str() ).c_str(),
FormatInternalUnits( aSymbol->GetPosition().x ).c_str(), FormatInternalUnits( aSymbol->GetPosition().x ).c_str(),
FormatInternalUnits( aSymbol->GetPosition().y ).c_str(), FormatInternalUnits( aSymbol->GetPosition().y ).c_str(),
FormatAngle( angle ).c_str() ); EDA_UNIT_UTILS::FormatAngle( angle ).c_str() );
bool mirrorX = aSymbol->GetOrientation() & SYM_MIRROR_X; bool mirrorX = aSymbol->GetOrientation() & SYM_MIRROR_X;
bool mirrorY = aSymbol->GetOrientation() & SYM_MIRROR_Y; bool mirrorY = aSymbol->GetOrientation() & SYM_MIRROR_Y;
@ -811,7 +811,7 @@ void SCH_SEXPR_PLUGIN::saveField( SCH_FIELD* aField, int aNestLevel )
aField->GetId(), aField->GetId(),
FormatInternalUnits( aField->GetPosition().x ).c_str(), FormatInternalUnits( aField->GetPosition().x ).c_str(),
FormatInternalUnits( aField->GetPosition().y ).c_str(), FormatInternalUnits( aField->GetPosition().y ).c_str(),
FormatAngle( aField->GetTextAngle() ).c_str() ); EDA_UNIT_UTILS::FormatAngle( aField->GetTextAngle() ).c_str() );
if( !aField->IsDefaultFormatting() if( !aField->IsDefaultFormatting()
|| ( aField->GetTextHeight() != Mils2iu( DEFAULT_SIZE_TEXT ) ) ) || ( aField->GetTextHeight() != Mils2iu( DEFAULT_SIZE_TEXT ) ) )
@ -920,7 +920,7 @@ void SCH_SEXPR_PLUGIN::saveSheet( SCH_SHEET* aSheet, int aNestLevel )
getSheetPinShapeToken( pin->GetShape() ), getSheetPinShapeToken( pin->GetShape() ),
FormatInternalUnits( pin->GetPosition().x ).c_str(), FormatInternalUnits( pin->GetPosition().x ).c_str(),
FormatInternalUnits( pin->GetPosition().y ).c_str(), FormatInternalUnits( pin->GetPosition().y ).c_str(),
FormatAngle( getSheetPinAngle( pin->GetSide() ) ).c_str() ); EDA_UNIT_UTILS::FormatAngle( getSheetPinAngle( pin->GetSide() ) ).c_str() );
pin->Format( m_out, aNestLevel + 1, 0 ); pin->Format( m_out, aNestLevel + 1, 0 );
@ -1111,7 +1111,7 @@ void SCH_SEXPR_PLUGIN::saveText( SCH_TEXT* aText, int aNestLevel )
m_out->Print( 0, " (at %s %s %s)", m_out->Print( 0, " (at %s %s %s)",
FormatInternalUnits( aText->GetPosition().x ).c_str(), FormatInternalUnits( aText->GetPosition().x ).c_str(),
FormatInternalUnits( aText->GetPosition().y ).c_str(), FormatInternalUnits( aText->GetPosition().y ).c_str(),
FormatAngle( angle ).c_str() ); EDA_UNIT_UTILS::FormatAngle( angle ).c_str() );
} }
else else
{ {
@ -1119,7 +1119,7 @@ void SCH_SEXPR_PLUGIN::saveText( SCH_TEXT* aText, int aNestLevel )
m_out->Print( aNestLevel + 1, "(at %s %s %s)", m_out->Print( aNestLevel + 1, "(at %s %s %s)",
FormatInternalUnits( aText->GetPosition().x ).c_str(), FormatInternalUnits( aText->GetPosition().x ).c_str(),
FormatInternalUnits( aText->GetPosition().y ).c_str(), FormatInternalUnits( aText->GetPosition().y ).c_str(),
FormatAngle( angle ).c_str() ); EDA_UNIT_UTILS::FormatAngle( angle ).c_str() );
} }
if( aText->GetFieldsAutoplaced() != FIELDS_AUTOPLACED_NO ) if( aText->GetFieldsAutoplaced() != FIELDS_AUTOPLACED_NO )
@ -1153,7 +1153,7 @@ void SCH_SEXPR_PLUGIN::saveTextBox( SCH_TEXTBOX* aTextBox, int aNestLevel )
m_out->Print( aNestLevel + 1, "(at %s %s %s) (size %s %s)\n", m_out->Print( aNestLevel + 1, "(at %s %s %s) (size %s %s)\n",
FormatInternalUnits( pos.x ).c_str(), FormatInternalUnits( pos.x ).c_str(),
FormatInternalUnits( pos.y ).c_str(), FormatInternalUnits( pos.y ).c_str(),
FormatAngle( aTextBox->GetTextAngle() ).c_str(), EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
FormatInternalUnits( size.x ).c_str(), FormatInternalUnits( size.x ).c_str(),
FormatInternalUnits( size.y ).c_str() ); FormatInternalUnits( size.y ).c_str() );

View File

@ -48,16 +48,6 @@
#define INDETERMINATE_STATE _( "-- mixed values --" ) #define INDETERMINATE_STATE _( "-- mixed values --" )
#define INDETERMINATE_ACTION _( "-- leave unchanged --" ) #define INDETERMINATE_ACTION _( "-- leave unchanged --" )
/**
* Convert mm to mils.
*/
int Mm2mils( double x );
/**
* Convert mils to mm.
*/
int Mils2mm( double x );
/** /**
* Function To_User_Unit * Function To_User_Unit
* convert \a aValue in internal units to the appropriate user units defined by \a aUnit. * convert \a aValue in internal units to the appropriate user units defined by \a aUnit.
@ -151,21 +141,6 @@ double DoubleValueFromString( EDA_UNITS aUnits, const wxString& aTextValue,
long long int ValueFromString( EDA_UNITS aUnits, const wxString& aTextValue, long long int ValueFromString( EDA_UNITS aUnits, const wxString& aTextValue,
EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE ); EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
/**
* Function FetchUnitsFromString
* writes any unit info found in the string to aUnits.
*/
void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits );
/**
* Get the units string for a given units type.
*
* @param aUnits - The units requested.
* @param aType - The data type of the unit (e.g. distance, area, etc.)
* @return The human readable units string.
*/
wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnit, EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
/** /**
* Function FormatInternalUnits * Function FormatInternalUnits
* converts \a aValue from internal units to a string appropriate for writing * converts \a aValue from internal units to a string appropriate for writing
@ -179,17 +154,6 @@ wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnit, EDA_DATA_TYPE aType = EDA_DA
*/ */
std::string FormatInternalUnits( int aValue ); std::string FormatInternalUnits( int aValue );
/**
* Function FormatAngle
* converts \a aAngle from board units to a string appropriate for writing to file.
*
* @note Internal angles for board items can be either degrees or tenths of degree
* on how KiCad is built.
* @param aAngle A angle value to convert.
* @return A std::string object containing the converted angle.
*/
std::string FormatAngle( const EDA_ANGLE& aAngle );
std::string FormatInternalUnits( const wxPoint& aPoint ); std::string FormatInternalUnits( const wxPoint& aPoint );
std::string FormatInternalUnits( const wxSize& aSize ); std::string FormatInternalUnits( const wxSize& aSize );

View File

@ -25,6 +25,9 @@
#ifndef EDA_UNITS_H #ifndef EDA_UNITS_H
#define EDA_UNITS_H #define EDA_UNITS_H
#include <wx/string.h>
#include <geometry/eda_angle.h>
/** /**
* The type of unit. * The type of unit.
*/ */
@ -50,6 +53,40 @@ namespace EDA_UNIT_UTILS
bool IsImperialUnit( EDA_UNITS aUnit ); bool IsImperialUnit( EDA_UNITS aUnit );
bool IsMetricUnit( EDA_UNITS aUnit ); bool IsMetricUnit( EDA_UNITS aUnit );
/**
* Convert mm to mils.
*/
int Mm2mils( double aVal );
/**
* Convert mils to mm.
*/
int Mils2mm( double aVal );
/**
* Writes any unit info found in the string to aUnits.
*/
void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits );
/**
* Get the units string for a given units type.
*
* @param aUnits - The units requested.
* @param aType - The data type of the unit (e.g. distance, area, etc.)
* @return The human readable units string.
*/
wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnit, EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
/**
* Converts \a aAngle from board units to a string appropriate for writing to file.
*
* @note Internal angles for board items can be either degrees or tenths of degree
* on how KiCad is built.
* @param aAngle A angle value to convert.
* @return std::string object containing the converted angle.
*/
std::string FormatAngle( const EDA_ANGLE& aAngle );
} }
#endif #endif

View File

@ -449,11 +449,11 @@ void PL_EDITOR_FRAME::ToPrinter( bool doPreview )
if( pageInfo.IsCustom() ) if( pageInfo.IsCustom() )
{ {
if( pageInfo.IsPortrait() ) if( pageInfo.IsPortrait() )
s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetWidthMils() ), s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ),
Mils2mm( pageInfo.GetHeightMils() ) ) ); EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) );
else else
s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetHeightMils() ), s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ),
Mils2mm( pageInfo.GetWidthMils() ) ) ); EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) );
} }
*s_PrintData = s_pageSetupData->GetPrintData(); *s_PrintData = s_pageSetupData->GetPrintData();

View File

@ -175,7 +175,7 @@ void PANEL_SETUP_BOARD_STACKUP::onAdjustDielectricThickness( wxCommandEvent& eve
if( min_thickness == 0 ) if( min_thickness == 0 )
{ {
title.Printf( _( "Enter board thickness in %s:" ), title.Printf( _( "Enter board thickness in %s:" ),
GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ).Trim( false ) ); EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ).Trim( false ) );
} }
else else
{ {

View File

@ -720,7 +720,7 @@ void DIALOG_PAD_PROPERTIES::displayPrimitivesList()
bs_info[0] = _( "Arc" ); bs_info[0] = _( "Arc" );
bs_info[1] = _( "center" ) + wxS( " " )+ formatCoord( m_units, primitive->GetCenter() ); bs_info[1] = _( "center" ) + wxS( " " )+ formatCoord( m_units, primitive->GetCenter() );
bs_info[2] = _( "start" ) + wxS( " " )+ formatCoord( m_units, primitive->GetStart() ); bs_info[2] = _( "start" ) + wxS( " " )+ formatCoord( m_units, primitive->GetStart() );
bs_info[3] = _( "angle" ) + wxS( " " )+ FormatAngle( primitive->GetArcAngle() ); bs_info[3] = _( "angle" ) + wxS( " " )+ EDA_UNIT_UTILS::FormatAngle( primitive->GetArcAngle() );
break; break;
case SHAPE_T::CIRCLE: case SHAPE_T::CIRCLE:

View File

@ -298,7 +298,8 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen
m_netSelector->Disable(); m_netSelector->Disable();
} }
m_DesignRuleViasUnit->SetLabel( GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ).Trim( false ) ); m_DesignRuleViasUnit->SetLabel(
EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ).Trim( false ) );
int viaSelection = wxNOT_FOUND; int viaSelection = wxNOT_FOUND;
@ -342,7 +343,8 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen
if( m_tracks ) if( m_tracks )
{ {
m_DesignRuleWidthsUnits->SetLabel( GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ).Trim( false ) ); m_DesignRuleWidthsUnits->SetLabel(
EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ).Trim( false ) );
int widthSelection = wxNOT_FOUND; int widthSelection = wxNOT_FOUND;
@ -412,7 +414,8 @@ void DIALOG_TRACK_VIA_PROPERTIES::onUnitsChanged( wxCommandEvent& aEvent )
} }
m_DesignRuleViasCtrl->SetSelection( viaSel ); m_DesignRuleViasCtrl->SetSelection( viaSel );
m_DesignRuleViasUnit->SetLabel( GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) ); m_DesignRuleViasUnit->SetLabel(
EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) );
} }
if( m_tracks ) if( m_tracks )
@ -430,7 +433,8 @@ void DIALOG_TRACK_VIA_PROPERTIES::onUnitsChanged( wxCommandEvent& aEvent )
} }
m_DesignRuleWidthsCtrl->SetSelection( trackSel ); m_DesignRuleWidthsCtrl->SetSelection( trackSel );
m_DesignRuleWidthsUnits->SetLabel( GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) ); m_DesignRuleWidthsUnits->SetLabel(
EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) );
} }
aEvent.Skip(); aEvent.Skip();

View File

@ -54,10 +54,14 @@ FP_TEXT_GRID_TABLE::FP_TEXT_GRID_TABLE( PCB_BASE_FRAME* aFrame ) :
if( g_menuOrientations.IsEmpty() ) if( g_menuOrientations.IsEmpty() )
{ {
g_menuOrientations.push_back( "0" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); g_menuOrientations.push_back(
g_menuOrientations.push_back( "90" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); "0" + EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
g_menuOrientations.push_back( "-90" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); g_menuOrientations.push_back(
g_menuOrientations.push_back( "180" + GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); "90" + EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
g_menuOrientations.push_back(
"-90" + EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
g_menuOrientations.push_back(
"180" + EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) );
} }
m_orientationColAttr = new wxGridCellAttr; m_orientationColAttr = new wxGridCellAttr;

View File

@ -78,12 +78,12 @@ void PCB_DIMENSION_BASE::updateText()
break; break;
case DIM_UNITS_FORMAT::BARE_SUFFIX: // normal case DIM_UNITS_FORMAT::BARE_SUFFIX: // normal
text += GetAbbreviatedUnitsLabel( m_units ); text += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_units );
break; break;
case DIM_UNITS_FORMAT::PAREN_SUFFIX: // parenthetical case DIM_UNITS_FORMAT::PAREN_SUFFIX: // parenthetical
text += wxT( " (" ); text += wxT( " (" );
text += GetAbbreviatedUnitsLabel( m_units ).Trim( false ); text += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_units ).Trim( false );
text += wxT( ")" ); text += wxT( ")" );
break; break;
} }
@ -332,7 +332,7 @@ void PCB_DIMENSION_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
EDA_UNITS units; EDA_UNITS units;
GetUnits( units ); GetUnits( units );
aList.emplace_back( _( "Units" ), GetAbbreviatedUnitsLabel( units ).Trim( false ) ); aList.emplace_back( _( "Units" ), EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( units ).Trim( false ) );
aList.emplace_back( _( "Font" ), m_text.GetDrawFont()->GetName() ); aList.emplace_back( _( "Font" ), m_text.GetDrawFont()->GetName() );
aList.emplace_back( _( "Text Thickness" ), aList.emplace_back( _( "Text Thickness" ),

View File

@ -1195,8 +1195,8 @@ void PCB_PARSER::parsePAGE_INFO()
else if( height > MAX_PAGE_SIZE_PCBNEW_MILS*Mils2mm ) else if( height > MAX_PAGE_SIZE_PCBNEW_MILS*Mils2mm )
height = MAX_PAGE_SIZE_PCBNEW_MILS*Mils2mm; height = MAX_PAGE_SIZE_PCBNEW_MILS*Mils2mm;
pageInfo.SetWidthMils( Mm2mils( width ) ); pageInfo.SetWidthMils( EDA_UNIT_UTILS::Mm2mils( width ) );
pageInfo.SetHeightMils( Mm2mils( height ) ); pageInfo.SetHeightMils( EDA_UNIT_UTILS::Mm2mils( height ) );
} }
token = NextTok(); token = NextTok();
@ -3220,7 +3220,7 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP
if( isLegacyDimension ) if( isLegacyDimension )
{ {
EDA_UNITS units = EDA_UNITS::INCHES; EDA_UNITS units = EDA_UNITS::INCHES;
FetchUnitsFromString( text->GetText(), units ); EDA_UNIT_UTILS::FetchUnitsFromString( text->GetText(), units );
dim->SetUnits( units ); dim->SetUnits( units );
} }

View File

@ -551,7 +551,7 @@ void PCB_PLUGIN::formatRenderCache( const EDA_TEXT* aText, int aNestLevel ) cons
m_out->Print( aNestLevel, "(render_cache %s %s\n", m_out->Print( aNestLevel, "(render_cache %s %s\n",
m_out->Quotew( shownText ).c_str(), m_out->Quotew( shownText ).c_str(),
FormatAngle( aText->GetDrawRotation() ).c_str() ); EDA_UNIT_UTILS::FormatAngle( aText->GetDrawRotation() ).c_str() );
for( const std::unique_ptr<KIFONT::GLYPH>& baseGlyph : *cache ) for( const std::unique_ptr<KIFONT::GLYPH>& baseGlyph : *cache )
{ {
@ -1221,7 +1221,7 @@ void PCB_PLUGIN::format( const FOOTPRINT* aFootprint, int aNestLevel ) const
FormatInternalUnits( aFootprint->GetPosition() ).c_str() ); FormatInternalUnits( aFootprint->GetPosition() ).c_str() );
if( !aFootprint->GetOrientation().IsZero() ) if( !aFootprint->GetOrientation().IsZero() )
m_out->Print( 0, " %s", FormatAngle( aFootprint->GetOrientation() ).c_str() ); m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aFootprint->GetOrientation() ).c_str() );
m_out->Print( 0, ")\n" ); m_out->Print( 0, ")\n" );
} }
@ -1554,7 +1554,7 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const
m_out->Print( 0, " (at %s", FormatInternalUnits( aPad->GetPos0() ).c_str() ); m_out->Print( 0, " (at %s", FormatInternalUnits( aPad->GetPos0() ).c_str() );
if( !aPad->GetOrientation().IsZero() ) if( !aPad->GetOrientation().IsZero() )
m_out->Print( 0, " %s", FormatAngle( aPad->GetOrientation() ).c_str() ); m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aPad->GetOrientation() ).c_str() );
m_out->Print( 0, ")" ); m_out->Print( 0, ")" );
@ -1707,7 +1707,7 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const
|| ( aPad->GetShape() != PAD_SHAPE::CIRCLE && aPad->GetThermalSpokeAngle() != ANGLE_90 ) ) || ( aPad->GetShape() != PAD_SHAPE::CIRCLE && aPad->GetThermalSpokeAngle() != ANGLE_90 ) )
{ {
StrPrintf( &output, " (thermal_bridge_angle %s)", StrPrintf( &output, " (thermal_bridge_angle %s)",
FormatAngle( aPad->GetThermalSpokeAngle() ).c_str() ); EDA_UNIT_UTILS::FormatAngle( aPad->GetThermalSpokeAngle() ).c_str() );
} }
if( aPad->GetThermalGap() != 0 ) if( aPad->GetThermalGap() != 0 )
@ -1847,7 +1847,7 @@ void PCB_PLUGIN::format( const PCB_TEXT* aText, int aNestLevel ) const
if( !aText->GetTextAngle().IsZero() ) if( !aText->GetTextAngle().IsZero() )
m_out->Print( 0, " %s", FormatAngle( aText->GetTextAngle() ).c_str() ); m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( aText->GetTextAngle() ).c_str() );
m_out->Print( 0, ")" ); m_out->Print( 0, ")" );
@ -1894,7 +1894,7 @@ void PCB_PLUGIN::format( const PCB_TEXTBOX* aTextBox, int aNestLevel ) const
} }
if( !aTextBox->GetTextAngle().IsZero() ) if( !aTextBox->GetTextAngle().IsZero() )
m_out->Print( 0, " (angle %s)", FormatAngle( aTextBox->GetTextAngle() ).c_str() ); m_out->Print( 0, " (angle %s)", EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str() );
formatLayer( aTextBox->GetLayer() ); formatLayer( aTextBox->GetLayer() );
@ -1987,7 +1987,7 @@ void PCB_PLUGIN::format( const FP_TEXT* aText, int aNestLevel ) const
} }
if( !orient.IsZero() ) if( !orient.IsZero() )
m_out->Print( 0, " %s", FormatAngle( orient ).c_str() ); m_out->Print( 0, " %s", EDA_UNIT_UTILS::FormatAngle( orient ).c_str() );
if( !aText->IsKeepUpright() ) if( !aText->IsKeepUpright() )
m_out->Print( 0, " unlocked" ); m_out->Print( 0, " unlocked" );
@ -2038,7 +2038,7 @@ void PCB_PLUGIN::format( const FP_TEXTBOX* aTextBox, int aNestLevel ) const
} }
if( !aTextBox->GetTextAngle().IsZero() ) if( !aTextBox->GetTextAngle().IsZero() )
m_out->Print( 0, " (angle %s)", FormatAngle( aTextBox->GetTextAngle() ).c_str() ); m_out->Print( 0, " (angle %s)", EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str() );
formatLayer( aTextBox->GetLayer() ); formatLayer( aTextBox->GetLayer() );

View File

@ -634,7 +634,7 @@ static wxString ComboBoxUnits( EDA_UNITS aUnits, double aValue, bool aIncludeLab
text.Printf( format, To_User_Unit( aUnits, aValue ) ); text.Printf( format, To_User_Unit( aUnits, aValue ) );
if( aIncludeLabel ) if( aIncludeLabel )
text += GetAbbreviatedUnitsLabel( aUnits, EDA_DATA_TYPE::DISTANCE ); text += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits, EDA_DATA_TYPE::DISTANCE );
return text; return text;
} }