Score leaf nodes in LIB_TREEs, not just symbols & footprints.

Fixes: lp:1783251
* https://bugs.launchpad.net/kicad/+bug/1783251
This commit is contained in:
Jeff Young 2018-08-01 01:21:50 +01:00
parent 9175a48c90
commit 4e3c84e733
2 changed files with 30 additions and 8 deletions

View File

@ -267,11 +267,35 @@ void LIB_TREE_NODE_LIB::UpdateScore( EDA_COMBINED_MATCHER& aMatcher )
{
Score = 0;
// We need to score leaf nodes, which are usually (but not always) children.
if( Children.size() )
{
for( auto& child: Children )
{
child->UpdateScore( aMatcher );
Score = std::max( Score, child->Score );
}
}
else
{
// No children; we are a leaf.
int found_pos = EDA_PATTERN_NOT_FOUND;
int matchers_fired = 0;
if( aMatcher.GetPattern() == MatchName )
{
Score += 1000; // exact match. High score :)
}
else if( aMatcher.Find( MatchName, matchers_fired, found_pos ) )
{
// Substring match. The earlier in the string the better.
Score += matchPosScore( found_pos, 20 ) + 20;
}
// More matchers = better match
Score += 2 * matchers_fired;
}
}

View File

@ -369,11 +369,9 @@ void LIB_TREE_MODEL_ADAPTER::FindAndExpand( LIB_TREE_NODE& aNode,
if( !(*aHighScore) || node->Score > (*aHighScore)->Score )
(*aHighScore) = &*node;
}
else
{
FindAndExpand( *node, aFunc, aHighScore );
}
}
}
@ -384,7 +382,7 @@ LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ShowResults()
FindAndExpand( m_tree,
[]( LIB_TREE_NODE const* n )
{
return n->Type == LIB_TREE_NODE::TYPE::LIBID && n->Score > 1;
return /*n->Type == LIB_TREE_NODE::TYPE::LIBID &&*/ n->Score > 1;
},
&highScore );