diff --git a/common/string.cpp b/common/string.cpp index b37af0ba4a..99b8f30d08 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -41,6 +41,59 @@ static const char illegalFileNameChars[] = "\\/:\"<>|"; +wxString ConvertToNewOverbarNotation( const wxString& aOldStr ) +{ + wxString newStr; + bool inOverbar = false; + + for( wxString::const_iterator chIt = aOldStr.begin(); chIt != aOldStr.end(); ++chIt ) + { + if( *chIt == '~' ) + { + wxString::const_iterator lookahead = chIt; + + if( ++lookahead != aOldStr.end() && *lookahead == '~' ) + { + if( ++lookahead != aOldStr.end() && *lookahead == '{' ) + { + // This way the subseqent opening curly brace will not start an + // overbar. + newStr << "~~{}"; + continue; + } + + // Two subsequent tildes mean a tilde. + newStr << "~"; + continue; + } + else + { + if( inOverbar ) + { + newStr << "}"; + inOverbar = false; + } + else + { + newStr << "~{"; + inOverbar = true; + } + + continue; + } + } + + newStr << *chIt; + } + + // Explicitly end the overbar even if there was no terminating '~' in the aOldStr. + if( inOverbar ) + newStr << "}"; + + return newStr; +} + + bool ConvertSmartQuotesAndDashes( wxString* aString ) { bool retVal = false; diff --git a/eeschema/sch_file_versions.h b/eeschema/sch_file_versions.h index 1139a39562..21e9104222 100644 --- a/eeschema/sch_file_versions.h +++ b/eeschema/sch_file_versions.h @@ -60,4 +60,5 @@ //#define SEXPR_SCHEMATIC_FILE_VERSION 20210123 // Rename "unconnected" pintype to "no_connect". //#define SEXPR_SCHEMATIC_FILE_VERSION 20210125 // R/W uuids for pins, labels, wires, etc. //#define SEXPR_SCHEMATIC_FILE_VERSION 20210126 // Fix bug with writing pin uuids. -#define SEXPR_SCHEMATIC_FILE_VERSION 20210406 // Add schematic level uuids. +//#define SEXPR_SCHEMATIC_FILE_VERSION 20210406 // Add schematic level uuids. +#define SEXPR_SCHEMATIC_FILE_VERSION 20210606 // Change overbar syntax from `~...~` to `~{...}`. diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index d62f2898fb..02b76c7b6d 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -41,6 +41,7 @@ #include #include #include // KiROUND, Clamp +#include #include #include #include @@ -601,6 +602,11 @@ void SCH_SEXPR_PARSER::parseEDA_TEXT( EDA_TEXT* aText ) wxCHECK_RET( aText && CurTok() == T_effects, wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as EDA_TEXT." ) ); + // In version 20210606 the notation for overbars was changed from `~...~` to `~{...}`. We need to convert + // the old syntax to the new one. + if( m_requiredVersion < 20210606 ) + aText->SetText( ConvertToNewOverbarNotation( aText->GetText() ) ); + T token; for( token = NextTok(); token != T_RIGHT; token = NextTok() ) diff --git a/include/kicad_string.h b/include/kicad_string.h index 23d204aeed..75df0c39bd 100644 --- a/include/kicad_string.h +++ b/include/kicad_string.h @@ -38,6 +38,11 @@ #include +/** + * Convert the old `~...~` overbar notation to the new `~{...}` one. + */ +wxString ConvertToNewOverbarNotation( const wxString& aOldStr ); + /** * Convert curly quotes and em/en dashes to straight quotes and dashes. * diff --git a/pcbnew/plugins/kicad/kicad_plugin.h b/pcbnew/plugins/kicad/kicad_plugin.h index 8ace5199fd..63517dbce9 100644 --- a/pcbnew/plugins/kicad/kicad_plugin.h +++ b/pcbnew/plugins/kicad/kicad_plugin.h @@ -96,7 +96,8 @@ class PCB_TEXT; //#define SEXPR_BOARD_FILE_VERSION 20210108 // Pad locking moved from footprint to pads //#define SEXPR_BOARD_FILE_VERSION 20210126 // Store pintype alongside pinfunction (in pads). //#define SEXPR_BOARD_FILE_VERSION 20210228 // Move global margins back to board file -#define SEXPR_BOARD_FILE_VERSION 20210424 // Correct locked flag syntax (remove parens). +//#define SEXPR_BOARD_FILE_VERSION 20210424 // Correct locked flag syntax (remove parens). +#define SEXPR_BOARD_FILE_VERSION 20210606 // Change overbar syntax from `~...~` to `~{...}`. #define BOARD_FILE_HOST_VERSION 20200825 ///< Earlier files than this include the host tag diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index 3b9d73c3c3..20895ccd1e 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -56,6 +56,7 @@ #include // for RECT_CHAMFER_POSITIONS definition #include #include // KiROUND, Clamp +#include #include using namespace PCB_KEYS_T; @@ -294,6 +295,11 @@ void PCB_PARSER::parseEDA_TEXT( EDA_TEXT* aText ) wxCHECK_RET( CurTok() == T_effects, wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as EDA_TEXT." ) ); + // In version 20210606 the notation for overbars was changed from `~...~` to `~{...}`. We need to convert + // the old syntax to the new one. + if( m_requiredVersion < 20210606 ) + aText->SetText( ConvertToNewOverbarNotation( aText->GetText() ) ); + T token; // Prior to v5.0 text size was omitted from file format if equal to 60mils