7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-07 18:35:32 +00:00

connectivity: TOPO_MATCH now prioritizes component candidates by the ratio of matching pad nets.

This improves cloning of circuits with numerous of matching component mappings (e.g. LED matrices) by
taking preference for mappings with same order of net connections.
This commit is contained in:
Tomasz Wlostowski 2025-03-06 23:03:22 +01:00
parent a468c486eb
commit 91ee987cfe
2 changed files with 22 additions and 6 deletions
pcbnew/connectivity

View File

@ -118,7 +118,7 @@ bool PIN::IsIsomorphic( const PIN& b ) const
}
// fixme: terrible performance, but computers are fast these days, ain't they? :D
bool checkIfPadNetsMatch( BACKTRACK_STAGE& aMatches, CONNECTION_GRAPH* aRefGraph, COMPONENT* aRef, COMPONENT* aTgt )
bool checkIfPadNetsMatch( const BACKTRACK_STAGE& aMatches, CONNECTION_GRAPH* aRefGraph, COMPONENT* aRef, COMPONENT* aTgt )
{
std::map<PIN*, PIN*> pairs;
std::vector<PIN*> pref, ptgt;
@ -197,7 +197,7 @@ bool checkIfPadNetsMatch( BACKTRACK_STAGE& aMatches, CONNECTION_GRAPH* aRefGraph
std::vector<COMPONENT*>
CONNECTION_GRAPH::findMatchingComponents( CONNECTION_GRAPH* aRefGraph, COMPONENT* aRef, BACKTRACK_STAGE& partialMatches )
CONNECTION_GRAPH::findMatchingComponents( CONNECTION_GRAPH* aRefGraph, COMPONENT* aRef, const BACKTRACK_STAGE& partialMatches )
{
std::vector<COMPONENT*> matches;
for( auto cmpTarget : m_components )
@ -228,11 +228,27 @@ CONNECTION_GRAPH::findMatchingComponents( CONNECTION_GRAPH* aRefGraph, COMPONENT
{
wxLogTrace( traceTopoMatch, wxT("reject\n") );
}
}
auto padSimilarity=[]( COMPONENT*a, COMPONENT*b ) -> double {
int n=0;
for(int i=0;i<a->m_pins.size();i++)
{
PIN* pa = a->m_pins[i];
PIN* pb = b->m_pins[i];
if( pa->GetNetCode() == pb->GetNetCode() )
n++;
}
return (double)n / (double) a->m_pins.size();
};
std::sort(matches.begin(), matches.end(), [&] ( COMPONENT*a, COMPONENT*b ) -> int
{
return padSimilarity( aRef,a ) > padSimilarity( aRef, b );
}
);
return matches;
}

View File

@ -184,7 +184,7 @@ private:
std::vector<COMPONENT*> findMatchingComponents( CONNECTION_GRAPH* aRefGraph,
COMPONENT* ref,
BACKTRACK_STAGE& partialMatches );
const BACKTRACK_STAGE& partialMatches );
std::vector<COMPONENT*> m_components;