From 91494fc5611f2bd1a57961a8bd70eaef6149cfc8 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Wed, 6 May 2020 09:27:01 -0400 Subject: [PATCH] Eeschema: add missing bus alias support to new schematic file format. Fixes https://gitlab.com/kicad/code/kicad/issues/4335 --- eeschema/sch_sexpr_parser.cpp | 43 +++++++++++++++++++++++++++++++++-- eeschema/sch_sexpr_parser.h | 1 + eeschema/sch_sexpr_plugin.cpp | 14 +++++++++++- eeschema/schematic.keywords | 2 ++ 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/eeschema/sch_sexpr_parser.cpp b/eeschema/sch_sexpr_parser.cpp index 2872129106..5e71ad6c7a 100644 --- a/eeschema/sch_sexpr_parser.cpp +++ b/eeschema/sch_sexpr_parser.cpp @@ -1981,9 +1981,14 @@ void SCH_SEXPR_PARSER::ParseSchematic( SCH_SHEET* aSheet ) parseSchSymbolInstances( screen ); break; + case T_bus_alias: + parseBusAlias( screen ); + break; + default: - Expecting( "symbol, bitmap, sheet, junction, no_connect, bus_entry, line, bus" - "text, label, global_label, hierarchical_label, or symbol_instances" ); + Expecting( "symbol, page, title_block, bitmap, sheet, junction, no_connect, " + "bus_entry, line, bus, text, label, global_label, hierarchical_label, " + "symbol_instances, or bus_alias" ); } } @@ -2546,3 +2551,37 @@ SCH_TEXT* SCH_SEXPR_PARSER::parseSchText() return text.release(); } + + +void SCH_SEXPR_PARSER::parseBusAlias( SCH_SCREEN* aScreen ) +{ + wxCHECK_RET( CurTok() == T_bus_alias, + wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a bus alias." ) ); + wxCHECK( aScreen, /* void */ ); + + T token; + auto busAlias = std::make_shared< BUS_ALIAS >( aScreen ); + + NeedSYMBOL(); + busAlias->SetName( FromUTF8() ); + NeedLEFT(); + token = NextTok(); + + if( token != T_members ) + Expecting( "members" ); + + token = NextTok(); + + while( token != T_RIGHT ) + { + if( !IsSymbol( token ) ) + Expecting( "quoted string" ); + + busAlias->AddMember( FromUTF8() ); + token = NextTok(); + } + + NeedRIGHT(); + + aScreen->AddBusAlias( busAlias ); +} diff --git a/eeschema/sch_sexpr_parser.h b/eeschema/sch_sexpr_parser.h index 85bef18ab4..588d00cd1b 100644 --- a/eeschema/sch_sexpr_parser.h +++ b/eeschema/sch_sexpr_parser.h @@ -215,6 +215,7 @@ class SCH_SEXPR_PARSER : public SCHEMATIC_LEXER SCH_BUS_WIRE_ENTRY* parseBusEntry(); SCH_LINE* parseLine(); SCH_TEXT* parseSchText(); + void parseBusAlias( SCH_SCREEN* aScreen ); public: SCH_SEXPR_PARSER( LINE_READER* aLineReader = nullptr ); diff --git a/eeschema/sch_sexpr_plugin.cpp b/eeschema/sch_sexpr_plugin.cpp index 11d29a51b1..1108797562 100644 --- a/eeschema/sch_sexpr_plugin.cpp +++ b/eeschema/sch_sexpr_plugin.cpp @@ -1178,7 +1178,19 @@ void SCH_SEXPR_PLUGIN::saveBusAlias( std::shared_ptr aAlias, int aNes { wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" ); - wxString members = boost::algorithm::join( aAlias->Members(), " " ); + wxString members; + + for( auto member : aAlias->Members() ) + { + if( members.IsEmpty() ) + members = m_out->Quotew( member ); + else + members += " " + m_out->Quotew( member ); + } + + m_out->Print( aNestLevel, "(bus_alias %s (members %s))\n", + m_out->Quotew( aAlias->GetName() ).c_str(), + TO_UTF8( members ) ); } diff --git a/eeschema/schematic.keywords b/eeschema/schematic.keywords index 1bc9d2ac44..f2e4139ba1 100644 --- a/eeschema/schematic.keywords +++ b/eeschema/schematic.keywords @@ -11,6 +11,7 @@ bitmap bold bottom bus +bus_alias bus_entry center circle @@ -54,6 +55,7 @@ lib_id lib_name lib_symbols line +members mid mirror name