From 4d180efa5f0e2e4f9cff4417f273c41fc57312dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= Date: Tue, 18 Oct 2016 17:40:22 +0200 Subject: [PATCH] router: correct handling of per-pad/per-module clearance --- pcbnew/router/pns_kicad_iface.cpp | 47 +++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 67340d0100..5cf4151387 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -87,7 +88,8 @@ private: PNS::ROUTER* m_router; BOARD* m_board; - std::vector m_clearanceCache; + std::vector m_netClearanceCache; + std::unordered_map m_localClearanceCache; int m_defaultClearance; bool m_overrideEnabled; int m_overrideNetA, m_overrideNetB; @@ -103,7 +105,7 @@ PNS_PCBNEW_RULE_RESOLVER::PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER* PNS::NODE* world = m_router->GetWorld(); PNS::TOPOLOGY topo( world ); - m_clearanceCache.resize( m_board->GetNetCount() ); + m_netClearanceCache.resize( m_board->GetNetCount() ); for( unsigned int i = 0; i < m_board->GetNetCount(); i++ ) { @@ -120,11 +122,29 @@ PNS_PCBNEW_RULE_RESOLVER::PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER* int clearance = nc->GetClearance(); ent.clearance = clearance; - m_clearanceCache[i] = ent; + m_netClearanceCache[i] = ent; wxLogTrace( "PNS", "Add net %u netclass %s clearance %d", i, netClassName.mb_str(), clearance ); } + for( MODULE* mod = m_board->m_Modules; mod ; mod = mod->Next() ) + { + auto moduleClearance = mod->GetLocalClearance(); + + for( D_PAD* pad = mod->Pads(); pad; pad = pad->Next() ) + { + int padClearance = pad->GetLocalClearance(); + + if( padClearance > 0 ) + m_localClearanceCache[ pad ] = padClearance; + + else if( moduleClearance > 0 ) + m_localClearanceCache[ pad ] = moduleClearance; + } + } + + //printf("DefaultCL : %d\n", m_board->GetDesignSettings().m_NetClasses.Find ("Default clearance")->GetClearance()); + m_overrideEnabled = false; m_defaultClearance = Millimeter2iu( 0.254 ); // m_board->m_NetClasses.Find ("Default clearance")->GetClearance(); m_overrideNetA = 0; @@ -144,21 +164,27 @@ int PNS_PCBNEW_RULE_RESOLVER::localPadClearance( const PNS::ITEM* aItem ) const return 0; const D_PAD* pad = static_cast( aItem->Parent() ); - return pad->GetLocalClearance(); + + auto i = m_localClearanceCache.find( pad ); + + if( i == m_localClearanceCache.end() ) + return 0; + + return i->second; } int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) { int net_a = aA->Net(); - int cl_a = ( net_a >= 0 ? m_clearanceCache[net_a].clearance : m_defaultClearance ); + int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance ); int net_b = aB->Net(); - int cl_b = ( net_b >= 0 ? m_clearanceCache[net_b].clearance : m_defaultClearance ); + int cl_b = ( net_b >= 0 ? m_netClearanceCache[net_b].clearance : m_defaultClearance ); bool linesOnly = aA->OfKind( PNS::ITEM::SEGMENT_T | PNS::ITEM::LINE_T ) && aB->OfKind( PNS::ITEM::SEGMENT_T | PNS::ITEM::LINE_T ); - if( linesOnly && net_a >= 0 && net_b >= 0 && m_clearanceCache[net_a].coupledNet == net_b ) + if( linesOnly && net_a >= 0 && net_b >= 0 && m_netClearanceCache[net_a].coupledNet == net_b ) { cl_a = cl_b = m_router->Sizes().DiffPairGap() - 2 * PNS_HULL_MARGIN; } @@ -166,8 +192,11 @@ int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* a int pad_a = localPadClearance( aA ); int pad_b = localPadClearance( aB ); - cl_a = std::max( cl_a, pad_a ); - cl_b = std::max( cl_b, pad_b ); + if( pad_a > 0 ) + cl_a = pad_a; + + if( pad_b > 0 ) + cl_b = pad_b; return std::max( cl_a, cl_b ); }