Fix a few issues with bus unfolding

Bus submenus weren't sending events because tool wasn't set.
Net names need to be unescaped for display.
Unfolding wasn't drawing the new wire segments.
SCH_LINE_WIRE_BUS_TOOL could get caught in an infinite event handling loop.

Fixes https://gitlab.com/kicad/code/kicad/issues/3796
This commit is contained in:
Jon Evans 2020-01-21 22:02:07 -05:00
parent 752bc5b7ba
commit da222d96b1
2 changed files with 31 additions and 17 deletions

View File

@ -113,14 +113,18 @@ void SCH_CONNECTION::ConfigureFromLabel( wxString aLabel )
{
m_members.clear();
if( IsBusVectorLabel( aLabel ) )
m_name = aLabel;
m_local_name = aLabel;
wxString unescaped = UnescapeString( aLabel );
if( IsBusVectorLabel( unescaped ) )
{
m_name = aLabel;
m_type = CONNECTION_TYPE::BUS;
std::vector<wxString> members;
ParseBusVector( aLabel, &m_vector_prefix, members );
ParseBusVector( unescaped, &m_vector_prefix, members );
long i = 0;
for( const auto& vector_member : members )
@ -134,16 +138,14 @@ void SCH_CONNECTION::ConfigureFromLabel( wxString aLabel )
m_members.push_back( member );
}
}
else if( IsBusGroupLabel( aLabel ) )
else if( IsBusGroupLabel( unescaped ) )
{
m_type = CONNECTION_TYPE::BUS_GROUP;
m_name = aLabel;
m_local_name = aLabel;
m_type = CONNECTION_TYPE::BUS_GROUP;
std::vector<wxString> members;
wxString group_name;
if( ParseBusGroup( aLabel, &group_name, members ) )
if( ParseBusGroup( unescaped, &group_name, members ) )
{
// Named bus groups generate a net prefix, unnamed ones don't
wxString prefix = group_name != wxT( "" ) ? ( group_name + wxT( "." ) ) : wxT( "" );
@ -173,9 +175,7 @@ void SCH_CONNECTION::ConfigureFromLabel( wxString aLabel )
}
else
{
m_name = aLabel;
m_local_name = aLabel;
m_type = CONNECTION_TYPE::NET;
m_type = CONNECTION_TYPE::NET;
}
}
@ -317,7 +317,7 @@ void SCH_CONNECTION::AppendInfoToMsgPanel( MSG_PANEL_ITEMS& aList ) const
wxString msg, group_name;
std::vector<wxString> group_members;
aList.push_back( MSG_PANEL_ITEM( _( "Connection Name" ), Name(), BROWN ) );
aList.push_back( MSG_PANEL_ITEM( _( "Connection Name" ), UnescapeString( Name() ), BROWN ) );
if( !IsBus() )
{

View File

@ -123,9 +123,10 @@ private:
selection = selTool->RequestSelection( busType );
bus = (SCH_LINE*) selection.Front();
}
if( !bus )
{
Append( ID_POPUP_SCH_UNFOLD_BUS, _( "no bus selected" ), wxEmptyString );
Append( ID_POPUP_SCH_UNFOLD_BUS, _( "No bus selected" ), wxEmptyString );
Enable( ID_POPUP_SCH_UNFOLD_BUS, false );
return;
}
@ -134,7 +135,7 @@ private:
if( !connection || !connection->IsBus() || connection->Members().empty() )
{
Append( ID_POPUP_SCH_UNFOLD_BUS, _( "bus has no connections" ), wxEmptyString );
Append( ID_POPUP_SCH_UNFOLD_BUS, _( "Bus has no connections" ), wxEmptyString );
Enable( ID_POPUP_SCH_UNFOLD_BUS, false );
return;
}
@ -150,17 +151,18 @@ private:
for( const auto& member : connection->Members() )
{
int id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ );
wxString name = member->LocalName();
wxString name = UnescapeString( member->LocalName() );
if( member->Type() == CONNECTION_TYPE::BUS )
{
ACTION_MENU* submenu = new ACTION_MENU( true );
submenu->SetTool( m_tool );
AppendSubMenu( submenu, name );
for( const auto& sub_member : member->Members() )
{
id = ID_POPUP_SCH_UNFOLD_BUS + ( idx++ );
submenu->Append( id, sub_member->LocalName(), wxEmptyString );
submenu->Append( id, UnescapeString( sub_member->LocalName() ), wxEmptyString );
}
}
else
@ -335,6 +337,14 @@ int SCH_LINE_WIRE_BUS_TOOL::UnfoldBus( const TOOL_EVENT& aEvent )
break;
}
else if( evt->Action() == TA_CHOICE_MENU_CLOSED )
{
break;
}
else
{
evt->SetPassEvent();
}
}
}
@ -365,7 +375,7 @@ SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus( const wxString& aNet )
m_busUnfold.label = new SCH_LABEL( m_busUnfold.entry->m_End(), aNet );
m_busUnfold.label->SetTextSize( wxSize( GetDefaultTextSize(), GetDefaultTextSize() ) );
m_busUnfold.label->SetLabelSpinStyle( LABEL_SPIN_STYLE::LEFT );
m_busUnfold.label->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT );
m_busUnfold.label->SetParent( m_frame->GetScreen() );
m_busUnfold.label->SetFlags( IS_NEW | IS_MOVED );
@ -640,6 +650,10 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType
// Update the label "ghost" position
m_busUnfold.label->SetPosition( cursorPos );
m_view->AddToPreview( m_busUnfold.label->Clone() );
// Ensure segment is non-null at the start of bus unfold
if( !segment )
segment = m_wires.back();
}
if( segment )