From 03aa63bd50c845dfbaa457b9d70c3fd878f0feca Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Mon, 29 Aug 2022 19:30:25 -0400 Subject: [PATCH] Move 5 helpers to EDA_UNIT_UTILS since they aren't iu specific --- 3d-viewer/dialogs/panel_preview_3d_model.cpp | 4 +- common/base_units.cpp | 83 +------------------ common/dialogs/dialog_print_generic.cpp | 8 +- common/eda_units.cpp | 82 ++++++++++++++++++ common/page_info.cpp | 4 +- common/preview_items/preview_utils.cpp | 2 +- common/widgets/unit_binder.cpp | 15 ++-- .../dialogs/dialog_print_using_printer.cpp | 8 +- .../kicad/sch_sexpr_lib_plugin_cache.cpp | 4 +- .../sch_plugins/kicad/sch_sexpr_parser.cpp | 4 +- .../sch_plugins/kicad/sch_sexpr_plugin.cpp | 12 +-- include/base_units.h | 36 -------- include/eda_units.h | 37 +++++++++ pagelayout_editor/pl_editor_frame.cpp | 8 +- .../panel_board_stackup.cpp | 2 +- pcbnew/dialogs/dialog_pad_properties.cpp | 2 +- .../dialogs/dialog_track_via_properties.cpp | 12 ++- pcbnew/fp_text_grid_table.cpp | 12 ++- pcbnew/pcb_dimension.cpp | 6 +- pcbnew/plugins/kicad/pcb_parser.cpp | 6 +- pcbnew/plugins/kicad/pcb_plugin.cpp | 16 ++-- pcbnew/toolbars_pcb_editor.cpp | 2 +- 22 files changed, 191 insertions(+), 174 deletions(-) diff --git a/3d-viewer/dialogs/panel_preview_3d_model.cpp b/3d-viewer/dialogs/panel_preview_3d_model.cpp index fb5c1f8608..1ff6144347 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model.cpp @@ -250,7 +250,7 @@ wxString PANEL_PREVIEW_3D_MODEL::formatRotationValue( double aValue ) { return wxString::Format( wxT( "%.2f%s" ), 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" ), aValue, - GetAbbreviatedUnitsLabel( m_userUnits ) ); + EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_userUnits ) ); } diff --git a/common/base_units.cpp b/common/base_units.cpp index 35dde725b9..7ef28337bf 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -52,18 +52,6 @@ #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 ) { switch( aUnit ) @@ -188,7 +176,7 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLab text.Printf( format, value ); if( aAddUnitLabel ) - text += GetAbbreviatedUnitsLabel( aUnits, aType ); + text += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits, aType ); return text; } @@ -245,7 +233,7 @@ wxString StringFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, wxString stringValue( buf, wxConvUTF8 ); if( aAddUnitSymbol ) - stringValue += GetAbbreviatedUnitsLabel( aUnits, aType ); + stringValue += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits, aType ); 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 ) { 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 ) { 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 ) { return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y ); diff --git a/common/dialogs/dialog_print_generic.cpp b/common/dialogs/dialog_print_generic.cpp index 982e0bdc45..eab55ad648 100644 --- a/common/dialogs/dialog_print_generic.cpp +++ b/common/dialogs/dialog_print_generic.cpp @@ -310,11 +310,11 @@ void DIALOG_PRINT_GENERIC::initPrintData() if( pageInfo.IsCustom() ) { if( pageInfo.IsPortrait() ) - s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetWidthMils() ), - Mils2mm( pageInfo.GetHeightMils() ) ) ); + s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ), + EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) ); else - s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetHeightMils() ), - Mils2mm( pageInfo.GetWidthMils() ) ) ); + s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ), + EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) ); } *s_PrintData = s_pageSetupData->GetPrintData(); diff --git a/common/eda_units.cpp b/common/eda_units.cpp index b0cb1042b4..ee028df11f 100644 --- a/common/eda_units.cpp +++ b/common/eda_units.cpp @@ -22,6 +22,8 @@ */ #include +#include // for KiROUND +#include bool EDA_UNIT_UTILS::IsImperialUnit( EDA_UNITS aUnit ) { @@ -52,3 +54,83 @@ bool EDA_UNIT_UTILS::IsMetricUnit( EDA_UNITS aUnit ) 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 ); +} \ No newline at end of file diff --git a/common/page_info.cpp b/common/page_info.cpp index 5f1b9624f9..c9bca156ad 100644 --- a/common/page_info.cpp +++ b/common/page_info.cpp @@ -26,7 +26,7 @@ #include #include #include -#include // for Mm2mils +#include // late arriving wxPAPER_A0, wxPAPER_A1 @@ -64,7 +64,7 @@ const wxChar PAGE_INFO::Custom[] = wxT( "User" ); // also see: wx/defs.h // 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. const PAGE_INFO PAGE_INFO::pageA5( MMsize( 210, 148 ), wxT( "A5" ), wxPAPER_A5 ); diff --git a/common/preview_items/preview_utils.cpp b/common/preview_items/preview_utils.cpp index 97ee8aeaef..9c39621bb9 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 << EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits ); return str; } diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index 19fda7ecbc..5726649460 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -68,7 +68,8 @@ UNIT_BINDER::UNIT_BINDER( EDA_BASE_FRAME* aParent, wxStaticText* aLabel, wxWindo } 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 ), nullptr, this ); @@ -96,7 +97,8 @@ void UNIT_BINDER::SetUnits( EDA_UNITS aUnits ) m_units = aUnits; 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; 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(); 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(); 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 ) ); } diff --git a/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp index 717d1ac539..d2aaf326e1 100644 --- a/eeschema/dialogs/dialog_print_using_printer.cpp +++ b/eeschema/dialogs/dialog_print_using_printer.cpp @@ -209,11 +209,11 @@ bool DIALOG_PRINT_USING_PRINTER::TransferDataToWindow() if( pageInfo.IsCustom() ) { if( pageInfo.IsPortrait() ) - pageSetupDialogData.SetPaperSize( wxSize( Mils2mm( pageInfo.GetWidthMils() ), - Mils2mm( pageInfo.GetHeightMils() ) ) ); + pageSetupDialogData.SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ), + EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) ); else - pageSetupDialogData.SetPaperSize( wxSize( Mils2mm( pageInfo.GetHeightMils() ), - Mils2mm( pageInfo.GetWidthMils() ) ) ); + pageSetupDialogData.SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ), + EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) ); } pageSetupDialogData.GetPrintData().SetOrientation( pageInfo.GetWxOrientation() ); diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp index 002d7021ab..a5378e9335 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp @@ -415,7 +415,7 @@ void SCH_SEXPR_PLUGIN_CACHE::savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter getPinShapeToken( aPin->GetShape() ), FormatInternalUnits( aPin->GetPosition().x ).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() ); 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", FormatInternalUnits( pos.x ).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.y ).c_str() ); diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index c0af921bf7..8f8176100b 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -1703,7 +1703,7 @@ void SCH_SEXPR_PARSER::parsePAGE_INFO( PAGE_INFO& aPageInfo ) 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 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 ) 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 ) height = MIN_PAGE_SIZE_MILS; diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index 6ee136ef43..6152109312 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -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(), FormatInternalUnits( aSymbol->GetPosition().x ).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 mirrorY = aSymbol->GetOrientation() & SYM_MIRROR_Y; @@ -811,7 +811,7 @@ void SCH_SEXPR_PLUGIN::saveField( SCH_FIELD* aField, int aNestLevel ) aField->GetId(), FormatInternalUnits( aField->GetPosition().x ).c_str(), FormatInternalUnits( aField->GetPosition().y ).c_str(), - FormatAngle( aField->GetTextAngle() ).c_str() ); + EDA_UNIT_UTILS::FormatAngle( aField->GetTextAngle() ).c_str() ); if( !aField->IsDefaultFormatting() || ( aField->GetTextHeight() != Mils2iu( DEFAULT_SIZE_TEXT ) ) ) @@ -920,7 +920,7 @@ void SCH_SEXPR_PLUGIN::saveSheet( SCH_SHEET* aSheet, int aNestLevel ) getSheetPinShapeToken( pin->GetShape() ), FormatInternalUnits( pin->GetPosition().x ).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 ); @@ -1111,7 +1111,7 @@ void SCH_SEXPR_PLUGIN::saveText( SCH_TEXT* aText, int aNestLevel ) m_out->Print( 0, " (at %s %s %s)", FormatInternalUnits( aText->GetPosition().x ).c_str(), FormatInternalUnits( aText->GetPosition().y ).c_str(), - FormatAngle( angle ).c_str() ); + EDA_UNIT_UTILS::FormatAngle( angle ).c_str() ); } else { @@ -1119,7 +1119,7 @@ void SCH_SEXPR_PLUGIN::saveText( SCH_TEXT* aText, int aNestLevel ) m_out->Print( aNestLevel + 1, "(at %s %s %s)", FormatInternalUnits( aText->GetPosition().x ).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 ) @@ -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", FormatInternalUnits( pos.x ).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.y ).c_str() ); diff --git a/include/base_units.h b/include/base_units.h index ee9f182d0e..d30dff9506 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -48,16 +48,6 @@ #define INDETERMINATE_STATE _( "-- mixed values --" ) #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 * 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, 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 * 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 ); -/** - * 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 wxSize& aSize ); diff --git a/include/eda_units.h b/include/eda_units.h index c0422f8b34..b8d6a520e0 100644 --- a/include/eda_units.h +++ b/include/eda_units.h @@ -25,6 +25,9 @@ #ifndef EDA_UNITS_H #define EDA_UNITS_H +#include +#include + /** * The type of unit. */ @@ -50,6 +53,40 @@ namespace EDA_UNIT_UTILS bool IsImperialUnit( 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 \ No newline at end of file diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 4f805ee4ab..858179f956 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -449,11 +449,11 @@ void PL_EDITOR_FRAME::ToPrinter( bool doPreview ) if( pageInfo.IsCustom() ) { if( pageInfo.IsPortrait() ) - s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetWidthMils() ), - Mils2mm( pageInfo.GetHeightMils() ) ) ); + s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ), + EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) ); else - s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetHeightMils() ), - Mils2mm( pageInfo.GetWidthMils() ) ) ); + s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ), + EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) ); } *s_PrintData = s_pageSetupData->GetPrintData(); diff --git a/pcbnew/board_stackup_manager/panel_board_stackup.cpp b/pcbnew/board_stackup_manager/panel_board_stackup.cpp index d8a55ee4ed..ca93dc1004 100644 --- a/pcbnew/board_stackup_manager/panel_board_stackup.cpp +++ b/pcbnew/board_stackup_manager/panel_board_stackup.cpp @@ -175,7 +175,7 @@ void PANEL_SETUP_BOARD_STACKUP::onAdjustDielectricThickness( wxCommandEvent& eve if( min_thickness == 0 ) { title.Printf( _( "Enter board thickness in %s:" ), - GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ).Trim( false ) ); + EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ).Trim( false ) ); } else { diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index 6b2b82519d..86902c9e59 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -720,7 +720,7 @@ void DIALOG_PAD_PROPERTIES::displayPrimitivesList() bs_info[0] = _( "Arc" ); bs_info[1] = _( "center" ) + wxS( " " )+ formatCoord( m_units, primitive->GetCenter() ); 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; case SHAPE_T::CIRCLE: diff --git a/pcbnew/dialogs/dialog_track_via_properties.cpp b/pcbnew/dialogs/dialog_track_via_properties.cpp index f1cf3f841b..4f6b557837 100644 --- a/pcbnew/dialogs/dialog_track_via_properties.cpp +++ b/pcbnew/dialogs/dialog_track_via_properties.cpp @@ -298,7 +298,8 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen 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; @@ -342,7 +343,8 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen 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; @@ -412,7 +414,8 @@ void DIALOG_TRACK_VIA_PROPERTIES::onUnitsChanged( wxCommandEvent& aEvent ) } m_DesignRuleViasCtrl->SetSelection( viaSel ); - m_DesignRuleViasUnit->SetLabel( GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) ); + m_DesignRuleViasUnit->SetLabel( + EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) ); } if( m_tracks ) @@ -430,7 +433,8 @@ void DIALOG_TRACK_VIA_PROPERTIES::onUnitsChanged( wxCommandEvent& aEvent ) } m_DesignRuleWidthsCtrl->SetSelection( trackSel ); - m_DesignRuleWidthsUnits->SetLabel( GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) ); + m_DesignRuleWidthsUnits->SetLabel( + EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_frame->GetUserUnits() ) ); } aEvent.Skip(); diff --git a/pcbnew/fp_text_grid_table.cpp b/pcbnew/fp_text_grid_table.cpp index 61e174eb2c..4a6689cbac 100644 --- a/pcbnew/fp_text_grid_table.cpp +++ b/pcbnew/fp_text_grid_table.cpp @@ -54,10 +54,14 @@ FP_TEXT_GRID_TABLE::FP_TEXT_GRID_TABLE( PCB_BASE_FRAME* aFrame ) : if( g_menuOrientations.IsEmpty() ) { - 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 ) ); + g_menuOrientations.push_back( + "0" + EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( EDA_UNITS::DEGREES ) ); + g_menuOrientations.push_back( + "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; diff --git a/pcbnew/pcb_dimension.cpp b/pcbnew/pcb_dimension.cpp index 049ae1742c..c071a9051b 100644 --- a/pcbnew/pcb_dimension.cpp +++ b/pcbnew/pcb_dimension.cpp @@ -78,12 +78,12 @@ void PCB_DIMENSION_BASE::updateText() break; case DIM_UNITS_FORMAT::BARE_SUFFIX: // normal - text += GetAbbreviatedUnitsLabel( m_units ); + text += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_units ); break; case DIM_UNITS_FORMAT::PAREN_SUFFIX: // parenthetical text += wxT( " (" ); - text += GetAbbreviatedUnitsLabel( m_units ).Trim( false ); + text += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( m_units ).Trim( false ); text += wxT( ")" ); break; } @@ -332,7 +332,7 @@ void PCB_DIMENSION_BASE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, EDA_UNITS 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( _( "Text Thickness" ), diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index aedb9f4c65..d9cf30e78e 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -1195,8 +1195,8 @@ void PCB_PARSER::parsePAGE_INFO() else if( height > MAX_PAGE_SIZE_PCBNEW_MILS*Mils2mm ) height = MAX_PAGE_SIZE_PCBNEW_MILS*Mils2mm; - pageInfo.SetWidthMils( Mm2mils( width ) ); - pageInfo.SetHeightMils( Mm2mils( height ) ); + pageInfo.SetWidthMils( EDA_UNIT_UTILS::Mm2mils( width ) ); + pageInfo.SetHeightMils( EDA_UNIT_UTILS::Mm2mils( height ) ); } token = NextTok(); @@ -3220,7 +3220,7 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP if( isLegacyDimension ) { EDA_UNITS units = EDA_UNITS::INCHES; - FetchUnitsFromString( text->GetText(), units ); + EDA_UNIT_UTILS::FetchUnitsFromString( text->GetText(), units ); dim->SetUnits( units ); } diff --git a/pcbnew/plugins/kicad/pcb_plugin.cpp b/pcbnew/plugins/kicad/pcb_plugin.cpp index d229ea549f..5df9b2ceae 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.cpp +++ b/pcbnew/plugins/kicad/pcb_plugin.cpp @@ -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->Quotew( shownText ).c_str(), - FormatAngle( aText->GetDrawRotation() ).c_str() ); + EDA_UNIT_UTILS::FormatAngle( aText->GetDrawRotation() ).c_str() ); for( const std::unique_ptr& baseGlyph : *cache ) { @@ -1221,7 +1221,7 @@ void PCB_PLUGIN::format( const FOOTPRINT* aFootprint, int aNestLevel ) const FormatInternalUnits( aFootprint->GetPosition() ).c_str() ); 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" ); } @@ -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() ); 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, ")" ); @@ -1707,7 +1707,7 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const || ( aPad->GetShape() != PAD_SHAPE::CIRCLE && aPad->GetThermalSpokeAngle() != ANGLE_90 ) ) { StrPrintf( &output, " (thermal_bridge_angle %s)", - FormatAngle( aPad->GetThermalSpokeAngle() ).c_str() ); + EDA_UNIT_UTILS::FormatAngle( aPad->GetThermalSpokeAngle() ).c_str() ); } if( aPad->GetThermalGap() != 0 ) @@ -1847,7 +1847,7 @@ void PCB_PLUGIN::format( const PCB_TEXT* aText, int aNestLevel ) const 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, ")" ); @@ -1894,7 +1894,7 @@ void PCB_PLUGIN::format( const PCB_TEXTBOX* aTextBox, int aNestLevel ) const } 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() ); @@ -1987,7 +1987,7 @@ void PCB_PLUGIN::format( const FP_TEXT* aText, int aNestLevel ) const } 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() ) m_out->Print( 0, " unlocked" ); @@ -2038,7 +2038,7 @@ void PCB_PLUGIN::format( const FP_TEXTBOX* aTextBox, int aNestLevel ) const } 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() ); diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index c56cfa3ad0..408c543aa6 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -634,7 +634,7 @@ static wxString ComboBoxUnits( EDA_UNITS aUnits, double aValue, bool aIncludeLab text.Printf( format, To_User_Unit( aUnits, aValue ) ); if( aIncludeLabel ) - text += GetAbbreviatedUnitsLabel( aUnits, EDA_DATA_TYPE::DISTANCE ); + text += EDA_UNIT_UTILS::GetAbbreviatedUnitsLabel( aUnits, EDA_DATA_TYPE::DISTANCE ); return text; }