Pretty print bus definitions to the menus.

This commit is contained in:
Jeff Young 2020-05-13 16:26:53 +01:00
parent 050191460f
commit 4a1ee40058
4 changed files with 92 additions and 2 deletions

View File

@ -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 bool SCH_CONNECTION::IsSubsetOf( SCH_CONNECTION* aOther ) const
{ {
if( aOther->IsNet() ) if( aOther->IsNet() )

View File

@ -245,6 +245,8 @@ public:
return m_members; return m_members;
} }
static wxString PrintBusForUI( const wxString& aString );
/** /**
* Returns true if aOther is a subset of this connection or vice versa. * Returns true if aOther is a subset of this connection or vice versa.
* *

View File

@ -151,7 +151,7 @@ private:
for( const auto& member : connection->Members() ) for( const auto& member : connection->Members() )
{ {
int id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ ); 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 ) if( member->Type() == CONNECTION_TYPE::BUS )
{ {
@ -162,7 +162,8 @@ private:
for( const auto& sub_member : member->Members() ) for( const auto& sub_member : member->Members() )
{ {
id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ ); 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 else

View File

@ -53,6 +53,11 @@ wxString EscapeString( const wxString& aSource, ESCAPE_CONTEXT aContext );
wxString UnescapeString( const wxString& aSource ); 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. * Copy bytes from @a aSource delimited string segment to @a aDest buffer.
* *