router: Clear rule resolver caches on routing/dragging start.

Fixes https://gitlab.com/kicad/code/kicad/issues/12907
This commit is contained in:
Alex 2022-11-17 02:05:12 +05:00
parent 3f790d9dae
commit 3dea146488
4 changed files with 24 additions and 2 deletions

View File

@ -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 )
{

View File

@ -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] );
}

View File

@ -103,6 +103,7 @@ public:
virtual wxString NetName( int aNet ) = 0;
virtual void ClearCacheForItem( const ITEM* aItem ) {}
virtual void ClearCaches() {}
};
/**

View File

@ -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<COMPONENT_DRAGGER>( 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<PNS::ITEM*>& aRemoved, std::vector<PNS
}
tmpNode->GetUpdatedItems( aRemoved, aAdded );
//printf("added %d removed %d\n", aRemoved.size(), aAdded.size() );
return true;