From 3e53426b6c871edc8d6cdac13e0879d16f3905ca Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 16 Oct 2022 22:21:14 +0100 Subject: [PATCH] Use same ratsnest colours in the router as the rest of KiCad. --- pcbnew/router/pns_diff_pair_placer.cpp | 4 ++-- pcbnew/router/pns_kicad_iface.cpp | 30 ++++++++++++++++++++++++-- pcbnew/router/pns_kicad_iface.h | 4 ++-- pcbnew/router/pns_line_placer.cpp | 2 +- pcbnew/router/pns_router.h | 2 +- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/pcbnew/router/pns_diff_pair_placer.cpp b/pcbnew/router/pns_diff_pair_placer.cpp index f9d551cf4c..2aa209fe44 100644 --- a/pcbnew/router/pns_diff_pair_placer.cpp +++ b/pcbnew/router/pns_diff_pair_placer.cpp @@ -848,10 +848,10 @@ void DIFF_PAIR_PLACER::updateLeadingRatLine() TOPOLOGY topo( m_lastNode ); if( topo.LeadingRatLine( &m_currentTrace.PLine(), ratLineP ) ) - m_router->GetInterface()->DisplayRatline( ratLineP, 1 ); + m_router->GetInterface()->DisplayRatline( ratLineP, m_netP ); if( topo.LeadingRatLine ( &m_currentTrace.NLine(), ratLineN ) ) - m_router->GetInterface()->DisplayRatline( ratLineN, 3 ); + m_router->GetInterface()->DisplayRatline( ratLineN, m_netN ); } diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 912e651c14..9ac5118f49 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -47,6 +47,8 @@ #include #include +#include + #include #include @@ -1497,10 +1499,34 @@ void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aClearance, bool } -void PNS_KICAD_IFACE::DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aColor ) +void PNS_KICAD_IFACE::DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aNetCode ) { ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aRatline, m_view ); - pitem->SetColor( COLOR4D( static_cast( aColor ) ) ); + + KIGFX::RENDER_SETTINGS* renderSettings = m_view->GetPainter()->GetSettings(); + KIGFX::PCB_RENDER_SETTINGS* rs = static_cast( renderSettings ); + bool colorByNet = rs->GetNetColorMode() != NET_COLOR_MODE::OFF; + COLOR4D defaultColor = rs->GetColor( nullptr, LAYER_RATSNEST ); + COLOR4D color = defaultColor; + + std::shared_ptr connectivity = m_board->GetConnectivity(); + std::set highlightedNets = rs->GetHighlightNetCodes(); + std::map& netColors = rs->GetNetColorMap(); + std::map& ncColors = rs->GetNetclassColorMap(); + const std::map& ncMap = connectivity->GetNetclassMap(); + + if( colorByNet && netColors.count( aNetCode ) ) + color = netColors.at( aNetCode ); + else if( colorByNet && ncMap.count( aNetCode ) && ncColors.count( ncMap.at( aNetCode ) ) ) + color = ncColors.at( ncMap.at( aNetCode ) ); + else + color = defaultColor; + + if( color == COLOR4D::UNSPECIFIED ) + color = defaultColor; + + pitem->SetColor( color.Brightened( 0.5 ).WithAlpha( std::min( 1.0, color.a + 0.4 ) ) ); + m_previewItems->Add( pitem ); m_view->Update( m_previewItems ); } diff --git a/pcbnew/router/pns_kicad_iface.h b/pcbnew/router/pns_kicad_iface.h index c59db93f1a..18950bbe28 100644 --- a/pcbnew/router/pns_kicad_iface.h +++ b/pcbnew/router/pns_kicad_iface.h @@ -60,7 +60,7 @@ public: bool IsItemVisible( const PNS::ITEM* aItem ) const override { return true; }; void HideItem( PNS::ITEM* aItem ) override {} void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false ) override {} - void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aColor = -1 ) override {} + void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aNetCode ) override {} void AddItem( PNS::ITEM* aItem ) override; void UpdateItem( PNS::ITEM* aItem ) override; void RemoveItem( PNS::ITEM* aItem ) override; @@ -116,7 +116,7 @@ public: bool IsItemVisible( const PNS::ITEM* aItem ) const override; void HideItem( PNS::ITEM* aItem ) override; void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false ) override; - void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aColor = -1 ) override; + void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aNetCode ) override; void Commit() override; void AddItem( PNS::ITEM* aItem ) override; void UpdateItem( PNS::ITEM* aItem ) override; diff --git a/pcbnew/router/pns_line_placer.cpp b/pcbnew/router/pns_line_placer.cpp index ef7e14e8d2..62d3a6e39a 100644 --- a/pcbnew/router/pns_line_placer.cpp +++ b/pcbnew/router/pns_line_placer.cpp @@ -1726,7 +1726,7 @@ void LINE_PLACER::updateLeadingRatLine() TOPOLOGY topo( m_lastNode ); if( topo.LeadingRatLine( ¤t, ratLine ) ) - m_router->GetInterface()->DisplayRatline( ratLine, 5 ); + m_router->GetInterface()->DisplayRatline( ratLine, m_currentNet ); } diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h index 62fdd593f4..8dfa50be9a 100644 --- a/pcbnew/router/pns_router.h +++ b/pcbnew/router/pns_router.h @@ -97,7 +97,7 @@ enum DRAG_MODE virtual bool IsItemVisible( const PNS::ITEM* aItem ) const = 0; virtual bool IsFlashedOnLayer( const PNS::ITEM* aItem, int aLayer ) const = 0; virtual void DisplayItem( const ITEM* aItem, int aClearance, bool aEdit = false ) = 0; - virtual void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aColor = -1 ) = 0; + virtual void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aNetCode ) = 0; virtual void HideItem( ITEM* aItem ) = 0; virtual void Commit() = 0; virtual bool ImportSizes( SIZES_SETTINGS& aSizes, ITEM* aStartItem, int aNet ) = 0;