From 1142eb259bedfabef777f4759146bf45781e4d07 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 5 Jun 2019 22:09:09 -0400 Subject: [PATCH] Eagle: properly translate group buses now that we support them --- eeschema/sch_eagle_plugin.cpp | 35 ++++++++++++++++++++++++++++++++++- eeschema/sch_eagle_plugin.h | 8 ++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index de8eb2a432..622db49e5a 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -39,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -700,7 +702,7 @@ void SCH_EAGLE_PLUGIN::loadSheet( wxXmlNode* aSheetNode, int aSheetIndex ) while( busNode ) { // Get the bus name - wxString busName = busNode->GetAttribute( "name" ); + wxString busName = translateEagleBusName( busNode->GetAttribute( "name" ) ); // Load segments of this bus loadSegments( busNode, busName, wxString() ); @@ -2643,3 +2645,34 @@ wxString SCH_EAGLE_PLUGIN::fixSymbolName( const wxString& aName ) return ret; } + + +wxString SCH_EAGLE_PLUGIN::translateEagleBusName( const wxString& aEagleName ) const +{ + if( SCH_CONNECTION::IsBusVectorLabel( aEagleName ) ) + return aEagleName; + + wxString ret = "{"; + + wxStringTokenizer tokenizer( aEagleName, "," ); + + while( tokenizer.HasMoreTokens() ) + { + wxString member = tokenizer.GetNextToken(); + + // In Eagle, overbar text is automatically stopped at the end of the net name, even when + // that net name is part of a bus definition. In KiCad, we don't (currently) do that, so + // if there is an odd number of overbar markers in this net name, we need to append one + // to close it out before appending the space. + + if( member.Freq( '!' ) % 2 > 0 ) + member << "!"; + + ret << member << " "; + } + + ret.Trim( true ); + ret << "}"; + + return ret; +} diff --git a/eeschema/sch_eagle_plugin.h b/eeschema/sch_eagle_plugin.h index 7bac73641d..9923217ce1 100644 --- a/eeschema/sch_eagle_plugin.h +++ b/eeschema/sch_eagle_plugin.h @@ -174,6 +174,14 @@ private: ///> Moves net labels that are detached from any wire to the nearest wire void adjustNetLabels(); + /** + * Translates an Eagle-style bus name into one that is KiCad-compatible. + * For vector buses such as A[7..0] this has no impact. + * For group buses, we translate from Eagle-style to KiCad-style. + * @param aEagleName is the name of the bus from the Eagle schematic + */ + wxString translateEagleBusName( const wxString& aEagleName ) const; + wxString getLibName(); wxFileName getLibFileName();