diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 9614dcb75d..e33f983b3e 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -128,6 +128,7 @@ public: int ClearanceEpsilon() const { return m_clearanceEpsilon; } void ClearCacheForItem( const PNS::ITEM* aItem ) override; + void ClearCaches() override; private: int holeRadius( const PNS::ITEM* aItem ) const; @@ -377,6 +378,14 @@ void PNS_PCBNEW_RULE_RESOLVER::ClearCacheForItem( const PNS::ITEM* aItem ) } +void PNS_PCBNEW_RULE_RESOLVER::ClearCaches() +{ + m_clearanceCache.clear(); + m_holeClearanceCache.clear(); + m_holeToHoleClearanceCache.clear(); +} + + int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB, bool aUseClearanceEpsilon ) { diff --git a/pcbnew/router/pns_node.cpp b/pcbnew/router/pns_node.cpp index 60a591fd7f..a62c956ad8 100644 --- a/pcbnew/router/pns_node.cpp +++ b/pcbnew/router/pns_node.cpp @@ -307,6 +307,10 @@ NODE::OPT_OBSTACLE NODE::NearestObstacle( const LINE* aLine, int aKindMask, for( int i = 0; i < aLine->CLine().SegmentCount(); i++ ) { + // Note: Clearances between &s and other items are cached, + // which means they'll be the same for all segments in the line. + // Disabling the cache will lead to slowness. + const SEGMENT s( *aLine, aLine->CLine().CSegment( i ) ); QueryColliding( &s, obstacleList, aKindMask ); } @@ -479,6 +483,10 @@ NODE::OPT_OBSTACLE NODE::CheckColliding( const ITEM* aItemA, int aKindMask ) for( int i = 0; i < l.SegmentCount(); i++ ) { + // Note: Clearances between &s and other items are cached, + // which means they'll be the same for all segments in the line. + // Disabling the cache will lead to slowness. + const SEGMENT s( *line, l.CSegment( i ) ); n += QueryColliding( &s, obs, aKindMask, 1 ); @@ -489,7 +497,7 @@ NODE::OPT_OBSTACLE NODE::CheckColliding( const ITEM* aItemA, int aKindMask ) if( line->EndsWithVia() ) { n += QueryColliding( &line->Via(), obs, aKindMask, 1 ); - + if( n ) return OPT_OBSTACLE( obs[0] ); } diff --git a/pcbnew/router/pns_node.h b/pcbnew/router/pns_node.h index 27681fa3e5..fb197c2335 100644 --- a/pcbnew/router/pns_node.h +++ b/pcbnew/router/pns_node.h @@ -103,6 +103,7 @@ public: virtual wxString NetName( int aNet ) = 0; virtual void ClearCacheForItem( const ITEM* aItem ) {} + virtual void ClearCaches() {} }; /** diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index 1883858e7a..039b1a4632 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -166,6 +166,8 @@ bool ROUTER::StartDragging( const VECTOR2I& aP, ITEM_SET aStartItems, int aDragM m_world->SetCollisionQueryScope( NODE::CQS_IGNORE_HOLE_CLEARANCE ); } + GetRuleResolver()->ClearCaches(); + if( aStartItems.Count( ITEM::SOLID_T ) == aStartItems.Size() ) { m_dragger = std::make_unique( this ); @@ -396,6 +398,8 @@ bool ROUTER::StartRouting( const VECTOR2I& aP, ITEM* aStartItem, int aLayer ) m_world->SetCollisionQueryScope( NODE::CQS_IGNORE_HOLE_CLEARANCE ); } + GetRuleResolver()->ClearCaches(); + if( !isStartingPointRoutable( aP, aStartItem, aLayer ) ) return false; @@ -790,7 +794,7 @@ bool ROUTER::GetUpdatedItems( std::vector& aRemoved, std::vectorGetUpdatedItems( aRemoved, aAdded ); - + //printf("added %d removed %d\n", aRemoved.size(), aAdded.size() ); return true;