Schematic: don't require cursor on selected net to assign netclass

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/13199
This commit is contained in:
Mike Williams 2022-12-22 10:15:48 -05:00
parent bf5fd38bf7
commit 3037f2b444
1 changed files with 99 additions and 86 deletions

View File

@ -1187,123 +1187,136 @@ int SCH_EDITOR_CONTROL::AssignNetclass( const TOOL_EVENT& aEvent )
m_frame->RecalculateConnections( NO_CLEANUP ); m_frame->RecalculateConnections( NO_CLEANUP );
} }
const SCH_CONNECTION* conn = nullptr;
VECTOR2D connPos;
for( EDA_ITEM* item : selectionTool->GetSelection() )
{
conn = static_cast<SCH_ITEM*>( item )->Connection();
connPos = item->GetPosition();
if( conn )
break;
}
if( !conn )
{
m_frame->ShowInfoBarError( _( "No net selected." ) );
return 0;
}
// Remove selection in favor of highlighting so the whole net is highlighted // Remove selection in favor of highlighting so the whole net is highlighted
selectionTool->ClearSelection(); selectionTool->ClearSelection();
highlightNet( m_toolMgr, cursorPos ); highlightNet( m_toolMgr, connPos );
const SCH_CONNECTION* conn = m_frame->GetHighlightedConnection(); wxString netName = conn->Name();
if( conn ) if( conn->IsBus() )
{ {
wxString netName = conn->Name(); wxString prefix;
if( conn->IsBus() ) if( NET_SETTINGS::ParseBusVector( netName, &prefix, nullptr ) )
{ {
wxString prefix; netName = prefix + wxT( "*" );
if( NET_SETTINGS::ParseBusVector( netName, &prefix, nullptr ) )
{
netName = prefix + wxT( "*" );
}
else if( NET_SETTINGS::ParseBusGroup( netName, &prefix, nullptr ) )
{
netName = prefix + wxT( ".*" );
}
} }
else if( !conn->Driver() || CONNECTION_SUBGRAPH::GetDriverPriority( conn->Driver() ) else if( NET_SETTINGS::ParseBusGroup( netName, &prefix, nullptr ) )
< CONNECTION_SUBGRAPH::PRIORITY::SHEET_PIN )
{ {
m_frame->ShowInfoBarError( _( "Net must be labeled to assign a netclass." ) ); netName = prefix + wxT( ".*" );
highlightNet( m_toolMgr, CLEAR );
return 0;
} }
}
else if( !conn->Driver() || CONNECTION_SUBGRAPH::GetDriverPriority( conn->Driver() )
< CONNECTION_SUBGRAPH::PRIORITY::SHEET_PIN )
{
m_frame->ShowInfoBarError( _( "Net must be labeled to assign a netclass." ) );
highlightNet( m_toolMgr, CLEAR );
return 0;
}
DIALOG_ASSIGN_NETCLASS dlg( m_frame, netName, schematic.GetNetClassAssignmentCandidates(), DIALOG_ASSIGN_NETCLASS dlg( m_frame, netName, schematic.GetNetClassAssignmentCandidates(),
[&]( const std::vector<wxString>& aNetNames ) [&]( const std::vector<wxString>& aNetNames )
{
for( SCH_ITEM* item : screen->Items() )
{ {
for( SCH_ITEM* item : screen->Items() ) bool redraw = item->IsBrightened();
SCH_CONNECTION* itemConn = item->Connection();
if( itemConn && alg::contains( aNetNames, itemConn->Name() ) )
item->SetBrightened();
else
item->ClearBrightened();
redraw |= item->IsBrightened();
if( item->Type() == SCH_SYMBOL_T )
{ {
bool redraw = item->IsBrightened(); SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
SCH_CONNECTION* itemConn = item->Connection();
if( itemConn && alg::contains( aNetNames, itemConn->Name() ) ) redraw |= symbol->HasBrightenedPins();
item->SetBrightened();
else
item->ClearBrightened();
redraw |= item->IsBrightened(); symbol->ClearBrightenedPins();
if( item->Type() == SCH_SYMBOL_T ) for( SCH_PIN* pin : symbol->GetPins() )
{ {
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item ); SCH_CONNECTION* pin_conn = pin->Connection();
redraw |= symbol->HasBrightenedPins(); if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
symbol->ClearBrightenedPins();
for( SCH_PIN* pin : symbol->GetPins() )
{ {
SCH_CONNECTION* pin_conn = pin->Connection(); pin->SetBrightened();
redraw = true;
if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
{
pin->SetBrightened();
redraw = true;
}
} }
} }
else if( item->Type() == SCH_SHEET_T ) }
else if( item->Type() == SCH_SHEET_T )
{
for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
{ {
for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() ) SCH_CONNECTION* pin_conn = pin->Connection();
{
SCH_CONNECTION* pin_conn = pin->Connection();
redraw |= pin->IsBrightened(); redraw |= pin->IsBrightened();
if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) ) if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
pin->SetBrightened(); pin->SetBrightened();
else else
pin->ClearBrightened(); pin->ClearBrightened();
redraw |= pin->IsBrightened(); redraw |= pin->IsBrightened();
}
} }
if( redraw )
getView()->Update( item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT );
} }
m_frame->GetCanvas()->ForceRefresh(); if( redraw )
} ); getView()->Update( item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT );
}
if( dlg.ShowModal() ) m_frame->GetCanvas()->ForceRefresh();
{ } );
getView()->UpdateAllItemsConditionally(
[]( KIGFX::VIEW_ITEM* aItem ) -> int if( dlg.ShowModal() )
{
getView()->UpdateAllItemsConditionally(
[]( KIGFX::VIEW_ITEM* aItem ) -> int
{
// Netclass coloured items
//
if( dynamic_cast<SCH_LINE*>( aItem ) )
return KIGFX::REPAINT;
else if( dynamic_cast<SCH_JUNCTION*>( aItem ) )
return KIGFX::REPAINT;
else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem ) )
return KIGFX::REPAINT;
// Items that might reference an item's netclass name
//
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
if( text && text->HasTextVars() )
{ {
// Netclass coloured items text->ClearRenderCache();
// text->ClearBoundingBoxCache();
if( dynamic_cast<SCH_LINE*>( aItem ) ) return KIGFX::GEOMETRY | KIGFX::REPAINT;
return KIGFX::REPAINT; }
else if( dynamic_cast<SCH_JUNCTION*>( aItem ) )
return KIGFX::REPAINT;
else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem ) )
return KIGFX::REPAINT;
// Items that might reference an item's netclass name return 0;
// } );
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
if( text && text->HasTextVars() )
{
text->ClearRenderCache();
text->ClearBoundingBoxCache();
return KIGFX::GEOMETRY | KIGFX::REPAINT;
}
return 0;
} );
}
} }
highlightNet( m_toolMgr, CLEAR ); highlightNet( m_toolMgr, CLEAR );