diff --git a/pcbnew/connectivity/topo_match.cpp b/pcbnew/connectivity/topo_match.cpp index 1cbadd2db3..a6a8d07449 100644 --- a/pcbnew/connectivity/topo_match.cpp +++ b/pcbnew/connectivity/topo_match.cpp @@ -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; } diff --git a/pcbnew/connectivity/topo_match.h b/pcbnew/connectivity/topo_match.h index 08b222f89b..d91fb9a69e 100644 --- a/pcbnew/connectivity/topo_match.h +++ b/pcbnew/connectivity/topo_match.h @@ -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;