diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index 8d168a3836..f0d4edfa19 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -142,7 +142,7 @@ void LENGTH_TUNER_TOOL::performTuning() frame()->SetActiveLayer( ToLAYER_ID ( m_startItem->Layers().Start() ) ); if( m_startItem->Net() >= 0 ) - highlightNet( true, m_startItem->Net() ); + highlightNets( true, { m_startItem->Net() } ); } controls()->ForceCursorPosition( false ); @@ -153,7 +153,7 @@ void LENGTH_TUNER_TOOL::performTuning() if( !m_router->StartRouting( m_startSnapPoint, m_startItem, layer ) ) { frame()->ShowInfoBarMsg( m_router->FailureReason() ); - highlightNet( false ); + highlightNets( false ); return; } @@ -259,7 +259,7 @@ void LENGTH_TUNER_TOOL::performTuning() controls()->SetAutoPan( false ); controls()->ForceCursorPosition( false ); frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); - highlightNet( false ); + highlightNets( false ); } diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index 4384315c64..e847970e65 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -49,7 +49,6 @@ TOOL_BASE::TOOL_BASE( const std::string& aToolName ) : m_cancelled = false; m_startItem = nullptr; - m_startHighlight = false; m_endItem = nullptr; m_gridHelper = nullptr; @@ -221,25 +220,37 @@ ITEM* TOOL_BASE::pickSingleItem( const VECTOR2I& aWhere, int aNet, int aLayer, b } -void TOOL_BASE::highlightNet( bool aEnabled, int aNetcode ) +void TOOL_BASE::highlightNets( bool aEnabled, std::set aNetcodes ) { RENDER_SETTINGS* rs = getView()->GetPainter()->GetSettings(); - if( aNetcode >= 0 && aEnabled ) + if( aNetcodes.size() > 0 && aEnabled ) { - // If the user has previously set the current net to be highlighted, - // we assume they want to keep it highlighted after routing - m_startHighlight = ( rs->IsHighlightEnabled() - && rs->GetHighlightNetCodes().count( aNetcode ) ); + // If the user has previously set some of the routed nets to be highlighted, + // we assume they want to keep them highlighted after routing - rs->SetHighlight( true, aNetcode ); + const std::set& currentNetCodes = rs->GetHighlightNetCodes(); + bool keep = false; + + for( const int& netcode : aNetcodes ) + { + if( currentNetCodes.find( netcode ) != currentNetCodes.end() ) + { + keep = true; + break; + } + } + + if( rs->IsHighlightEnabled() && keep ) + m_startHighlightNetcodes = currentNetCodes; + else + m_startHighlightNetcodes.clear(); + + rs->SetHighlight( aNetcodes, true ); } else { - if( !m_startHighlight ) - rs->SetHighlight( false ); - - m_startHighlight = false; + rs->SetHighlight( m_startHighlightNetcodes, m_startHighlightNetcodes.size() > 0 ); } // Do not remove this call. This is required to update the layers when we highlight a net. @@ -317,9 +328,9 @@ void TOOL_BASE::updateEndItem( const TOOL_EVENT& aEvent ) m_gridHelper->SetSnap( !aEvent.Modifier( MD_SHIFT ) ); controls()->ForceCursorPosition( false ); - + VECTOR2I mousePos = controls()->GetMousePosition(); - + if( m_router->GetState() == ROUTER::ROUTE_TRACK && aEvent.IsDrag() ) { // If the user is moving the mouse quickly while routing then clicks will come in as diff --git a/pcbnew/router/pns_tool_base.h b/pcbnew/router/pns_tool_base.h index 2233730321..760cd5e032 100644 --- a/pcbnew/router/pns_tool_base.h +++ b/pcbnew/router/pns_tool_base.h @@ -61,7 +61,7 @@ protected: bool aIgnorePads = false, const std::vector aAvoidItems = {} ); - virtual void highlightNet( bool aEnabled, int aNetcode = -1 ); + virtual void highlightNets( bool aEnabled, std::set aNetcodes = {} ); virtual void updateStartItem( const TOOL_EVENT& aEvent, bool aIgnorePads = false ); virtual void updateEndItem( const TOOL_EVENT& aEvent ); @@ -69,7 +69,7 @@ protected: SIZES_SETTINGS m_savedSizes; // Stores sizes settings between router invocations ITEM* m_startItem; VECTOR2I m_startSnapPoint; - bool m_startHighlight; // Was net highlighted before routing? + std::set m_startHighlightNetcodes; // The set of nets highlighted before routing ITEM* m_endItem; VECTOR2I m_endSnapPoint; diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index ca791f5d31..cd28133845 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -1184,11 +1184,6 @@ bool ROUTER_TOOL::prepareInteractive() editFrame->GetCanvas()->Refresh(); } - if( m_startItem && m_startItem->Net() > 0 ) - highlightNet( true, m_startItem->Net() ); - - controls()->SetAutoPan( true ); - PNS::SIZES_SETTINGS sizes( m_router->Sizes() ); m_iface->SetStartLayer( routingLayer ); @@ -1200,13 +1195,28 @@ bool ROUTER_TOOL::prepareInteractive() m_router->UpdateSizes( sizes ); + if( m_startItem && m_startItem->Net() > 0 ) + { + if( m_router->Mode() == PNS::PNS_MODE_ROUTE_DIFF_PAIR ) + { + if( int coupledNet = m_router->GetRuleResolver()->DpCoupledNet( m_startItem->Net() ) ) + highlightNets( true, { m_startItem->Net(), coupledNet } ); + } + else + { + highlightNets( true, { m_startItem->Net() } ); + } + } + + controls()->SetAutoPan( true ); + if( !m_router->StartRouting( m_startSnapPoint, m_startItem, routingLayer ) ) { // It would make more sense to leave the net highlighted as the higher-contrast mode // makes the router clearances more visible. However, since we just started routing // the conversion of the screen from low contrast to high contrast is a bit jarring and // makes the infobar coming up less noticeable. - highlightNet( false ); + highlightNets( false ); frame()->ShowInfoBarError( m_router->FailureReason(), true, [&]() @@ -1241,7 +1251,7 @@ bool ROUTER_TOOL::finishInteractive() controls()->SetAutoPan( false ); controls()->ForceCursorPosition( false ); frame()->UndoRedoBlock( false ); - highlightNet( false ); + highlightNets( false ); return true; } @@ -1819,7 +1829,7 @@ void ROUTER_TOOL::performDragging( int aMode ) m_gridHelper->SetAuxAxes( false ); ctls->ForceCursorPosition( false ); - highlightNet( false ); + highlightNets( false ); m_cancelled = true; @@ -1834,7 +1844,7 @@ void ROUTER_TOOL::performDragging( int aMode ) return; if( m_startItem && m_startItem->Net() > 0 ) - highlightNet( true, m_startItem->Net() ); + highlightNets( true, { m_startItem->Net() } ); ctls->SetAutoPan( true ); m_gridHelper->SetAuxAxes( true, m_startSnapPoint ); @@ -1916,7 +1926,7 @@ void ROUTER_TOOL::performDragging( int aMode ) frame()->UndoRedoBlock( false ); ctls->SetAutoPan( false ); ctls->ForceCursorPosition( false ); - highlightNet( false ); + highlightNets( false ); } @@ -2100,7 +2110,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) m_startItem = startItem; if( m_startItem && m_startItem->Net() > 0 ) - highlightNet( true, m_startItem->Net() ); + highlightNets( true, { m_startItem->Net() } ); } else if( footprint ) { @@ -2333,7 +2343,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) controls()->SetAutoPan( false ); controls()->ForceCursorPosition( false ); frame()->UndoRedoBlock( false ); - highlightNet( false ); + highlightNets( false ); return 0; }