From a87550a2c6ae14c77b66fe393ad3674379c09b76 Mon Sep 17 00:00:00 2001 From: Johannes Pfister Date: Tue, 28 Feb 2023 11:59:47 +0000 Subject: [PATCH] When importing legacy PCB dimension: Use automatic dimension when Unit couldn't be determined --- common/eda_units.cpp | 5 ++++- include/eda_units.h | 3 ++- pcbnew/plugins/kicad/pcb_parser.cpp | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common/eda_units.cpp b/common/eda_units.cpp index 93c2bb0251..5315275c16 100644 --- a/common/eda_units.cpp +++ b/common/eda_units.cpp @@ -65,7 +65,7 @@ int EDA_UNIT_UTILS::Mils2mm( double aVal ) } -void EDA_UNIT_UTILS::FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits ) +bool EDA_UNIT_UTILS::FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits ) { wxString buf( aTextValue.Strip( wxString::both ) ); unsigned brk_point = 0; @@ -92,6 +92,9 @@ void EDA_UNIT_UTILS::FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS aUnits = EDA_UNITS::INCHES; else if( unit == wxT( "de" ) || unit == wxT( "ra" ) ) // "deg" or "rad" aUnits = EDA_UNITS::DEGREES; + else + return false; + return true; } diff --git a/include/eda_units.h b/include/eda_units.h index 89546f0911..0e0bcfcc73 100644 --- a/include/eda_units.h +++ b/include/eda_units.h @@ -67,8 +67,9 @@ namespace EDA_UNIT_UTILS /** * Writes any unit info found in the string to aUnits. + * @return true - when unit was found, false - when unit could not be determined */ - void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits ); + bool FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits ); /** * Get the units string for a given units type. diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index a6dd1d2b76..6e28b2e660 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -3226,8 +3226,11 @@ PCB_DIMENSION_BASE* PCB_PARSER::parseDIMENSION( BOARD_ITEM* aParent, bool aInFP if( isLegacyDimension ) { - EDA_UNITS units = EDA_UNITS::INCHES; - EDA_UNIT_UTILS::FetchUnitsFromString( text->GetText(), units ); + EDA_UNITS units = EDA_UNITS::MILLIMETRES; + + if( !EDA_UNIT_UTILS::FetchUnitsFromString( text->GetText(), units ) ) + dim->SetAutoUnits( true ); //Not determined => use automatic units + dim->SetUnits( units ); }