diff --git a/eeschema/sch_connection.cpp b/eeschema/sch_connection.cpp index 02542335fb..d98e824b37 100644 --- a/eeschema/sch_connection.cpp +++ b/eeschema/sch_connection.cpp @@ -631,6 +631,88 @@ bool SCH_CONNECTION::ParseBusGroup( wxString aGroup, wxString* aName, } +wxString SCH_CONNECTION::PrintBusForUI( const wxString& aGroup ) +{ + size_t groupLen = aGroup.length(); + size_t i = 0; + wxString ret; + int braceNesting = 0; + int tildeNesting = 0; + + // Parse prefix + // + for( ; i < groupLen; ++i ) + { + if( isSuperSub( aGroup[i] ) && i + 1 < groupLen && aGroup[i+1] == '{' ) + { + braceNesting++; + i++; + continue; + } + else if( aGroup[i] == '~' ) + { + if( tildeNesting ) + { + tildeNesting = 0; + continue; + } + else + { + tildeNesting++; + } + } + else if( aGroup[i] == '}' ) + { + braceNesting--; + continue; + } + + ret += aGroup[i]; + + if( aGroup[i] == '{' ) + break; + } + + // Parse members + // + i++; // '{' character + + for( ; i < groupLen; ++i ) + { + if( isSuperSub( aGroup[i] ) && i + 1 < groupLen && aGroup[i+1] == '{' ) + { + braceNesting++; + i++; + continue; + } + else if( aGroup[i] == '~' ) + { + if( tildeNesting ) + { + tildeNesting = 0; + continue; + } + else + { + tildeNesting++; + } + } + else if( aGroup[i] == '}' ) + { + braceNesting--; + continue; + } + + ret += aGroup[i]; + + if( aGroup[i] == '}' ) + break; + } + + return ret; +} + + bool SCH_CONNECTION::IsSubsetOf( SCH_CONNECTION* aOther ) const { if( aOther->IsNet() ) diff --git a/eeschema/sch_connection.h b/eeschema/sch_connection.h index 8007d58eb5..c929eb8b13 100644 --- a/eeschema/sch_connection.h +++ b/eeschema/sch_connection.h @@ -245,6 +245,8 @@ public: return m_members; } + static wxString PrintBusForUI( const wxString& aString ); + /** * Returns true if aOther is a subset of this connection or vice versa. * diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index 385c2028dd..ef0ced3eb1 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -151,7 +151,7 @@ private: for( const auto& member : connection->Members() ) { int id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ ); - wxString name = UnescapeString( member->LocalName() ); + wxString name = SCH_CONNECTION::PrintBusForUI( member->LocalName() ); if( member->Type() == CONNECTION_TYPE::BUS ) { @@ -162,7 +162,8 @@ private: for( const auto& sub_member : member->Members() ) { id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ ); - submenu->Append( id, UnescapeString( sub_member->LocalName() ), wxEmptyString ); + name = SCH_CONNECTION::PrintBusForUI( sub_member->LocalName() ); + submenu->Append( id, name, wxEmptyString ); } } else diff --git a/include/kicad_string.h b/include/kicad_string.h index 71bce02119..09cc1e5506 100644 --- a/include/kicad_string.h +++ b/include/kicad_string.h @@ -53,6 +53,11 @@ wxString EscapeString( const wxString& aSource, ESCAPE_CONTEXT aContext ); wxString UnescapeString( const wxString& aSource ); +/** + * Remove markup (such as overbar or subscript) that we can't render to menu items. + */ +wxString PrettyPrintForMenu( const wxString& aString ); + /** * Copy bytes from @a aSource delimited string segment to @a aDest buffer. *