2017-03-06 14:50:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2023-11-08 12:29:14 +00:00
|
|
|
*
|
2017-03-06 14:50:48 +00:00
|
|
|
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
|
|
|
|
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
|
2023-11-08 12:29:14 +00:00
|
|
|
* Copyright (C) 2023 CERN
|
2023-04-14 22:34:14 +00:00
|
|
|
* Copyright (C) 2014-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-03-06 14:50:48 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
#include <lib_tree_model.h>
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2020-05-11 16:23:04 +00:00
|
|
|
#include <algorithm>
|
2017-03-06 14:50:48 +00:00
|
|
|
#include <eda_pattern_match.h>
|
2018-07-27 20:47:51 +00:00
|
|
|
#include <lib_tree_item.h>
|
2018-01-25 23:49:04 +00:00
|
|
|
#include <pgm_base.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2017-03-06 14:50:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-08 12:29:14 +00:00
|
|
|
void LIB_TREE_NODE::ResetScore()
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2020-12-24 19:42:41 +00:00
|
|
|
for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
|
2023-11-08 12:29:14 +00:00
|
|
|
child->ResetScore();
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2023-10-31 14:48:12 +00:00
|
|
|
m_Score = 0;
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
void LIB_TREE_NODE::AssignIntrinsicRanks( bool presorted )
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
std::vector<LIB_TREE_NODE*> sort_buf;
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
if( presorted )
|
|
|
|
{
|
2020-02-07 17:06:24 +00:00
|
|
|
int max = m_Children.size() - 1;
|
2018-08-05 11:56:02 +00:00
|
|
|
|
|
|
|
for( int i = 0; i <= max; ++i )
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Children[i]->m_IntrinsicRank = max - i;
|
2018-08-05 11:56:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-24 19:42:41 +00:00
|
|
|
for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
|
|
|
|
sort_buf.push_back( child.get() );
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
std::sort( sort_buf.begin(), sort_buf.end(),
|
|
|
|
[]( LIB_TREE_NODE* a, LIB_TREE_NODE* b ) -> bool
|
2020-02-07 17:06:24 +00:00
|
|
|
{
|
|
|
|
return StrNumCmp( a->m_Name, b->m_Name, true ) > 0;
|
|
|
|
} );
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2018-08-05 11:56:02 +00:00
|
|
|
for( int i = 0; i < (int) sort_buf.size(); ++i )
|
2020-02-07 17:06:24 +00:00
|
|
|
sort_buf[i]->m_IntrinsicRank = i;
|
2018-08-05 11:56:02 +00:00
|
|
|
}
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-01 20:26:29 +00:00
|
|
|
void LIB_TREE_NODE::SortNodes( bool aUseScores )
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2020-02-07 17:06:24 +00:00
|
|
|
std::sort( m_Children.begin(), m_Children.end(),
|
2023-05-01 20:26:29 +00:00
|
|
|
[&]( std::unique_ptr<LIB_TREE_NODE>& a, std::unique_ptr<LIB_TREE_NODE>& b )
|
|
|
|
{
|
|
|
|
return Compare( *a, *b, aUseScores );
|
|
|
|
} );
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
for( std::unique_ptr<LIB_TREE_NODE>& node: m_Children )
|
2023-05-01 20:26:29 +00:00
|
|
|
node->SortNodes( aUseScores );
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-01 20:26:29 +00:00
|
|
|
bool LIB_TREE_NODE::Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2,
|
|
|
|
bool aUseScores )
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2020-02-07 17:06:24 +00:00
|
|
|
if( aNode1.m_Type != aNode2.m_Type )
|
2023-02-16 20:56:19 +00:00
|
|
|
return aNode1.m_Type < aNode2.m_Type;
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2022-07-09 18:19:58 +00:00
|
|
|
// Recently used sorts at top
|
|
|
|
if( aNode1.m_Name.StartsWith( wxT( "-- " ) ) )
|
2023-02-16 20:56:19 +00:00
|
|
|
{
|
|
|
|
if( aNode2.m_Name.StartsWith( wxT( "-- " ) ) )
|
|
|
|
{
|
2023-12-13 14:40:28 +00:00
|
|
|
// Make sure -- Recently Used is always at the top
|
2024-05-05 14:32:34 +00:00
|
|
|
// Start by checking the name of aNode2, because we
|
|
|
|
// want to satisfy the irreflexive property of the
|
|
|
|
// strict weak ordering.
|
|
|
|
if( aNode2.m_Name.StartsWith( wxT( "-- Recently Used" ) ) )
|
2023-12-13 14:40:28 +00:00
|
|
|
return false;
|
2024-05-05 14:32:34 +00:00
|
|
|
else if( aNode1.m_Name.StartsWith( wxT( "-- Recently Used" ) ) )
|
|
|
|
return true;
|
2023-12-13 14:40:28 +00:00
|
|
|
|
2023-02-16 20:56:19 +00:00
|
|
|
return aNode1.m_IntrinsicRank > aNode2.m_IntrinsicRank;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2022-07-09 18:19:58 +00:00
|
|
|
else if( aNode2.m_Name.StartsWith( wxT( "-- " ) ) )
|
2023-02-16 20:56:19 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2022-07-09 18:19:58 +00:00
|
|
|
|
|
|
|
// Pinned nodes go next
|
|
|
|
if( aNode1.m_Pinned && !aNode2.m_Pinned )
|
2023-02-16 20:56:19 +00:00
|
|
|
return true;
|
2022-07-09 18:19:58 +00:00
|
|
|
else if( aNode2.m_Pinned && !aNode1.m_Pinned )
|
2023-02-16 20:56:19 +00:00
|
|
|
return false;
|
2022-07-09 18:19:58 +00:00
|
|
|
|
2023-05-01 20:26:29 +00:00
|
|
|
if( aUseScores && aNode1.m_Score != aNode2.m_Score )
|
|
|
|
return aNode1.m_Score > aNode2.m_Score;
|
|
|
|
|
2023-02-16 20:56:19 +00:00
|
|
|
if( aNode1.m_IntrinsicRank != aNode2.m_IntrinsicRank )
|
|
|
|
return aNode1.m_IntrinsicRank > aNode2.m_IntrinsicRank;
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2023-02-16 20:56:19 +00:00
|
|
|
return reinterpret_cast<const void*>( &aNode1 ) < reinterpret_cast<const void*>( &aNode2 );
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
LIB_TREE_NODE::LIB_TREE_NODE()
|
2020-02-07 17:06:24 +00:00
|
|
|
: m_Parent( nullptr ),
|
2024-06-21 13:16:03 +00:00
|
|
|
m_Type( TYPE::INVALID ),
|
2020-02-07 17:06:24 +00:00
|
|
|
m_IntrinsicRank( 0 ),
|
2023-10-31 14:48:12 +00:00
|
|
|
m_Score( 0 ),
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Pinned( false ),
|
2023-12-18 21:09:13 +00:00
|
|
|
m_PinCount( 0 ),
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Unit( 0 ),
|
|
|
|
m_IsRoot( false )
|
2017-03-06 14:50:48 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
LIB_TREE_NODE_UNIT::LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem, int aUnit )
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2018-01-25 23:49:04 +00:00
|
|
|
static void* locale = nullptr;
|
|
|
|
static wxString namePrefix;
|
|
|
|
|
|
|
|
// Fetching translations can take a surprising amount of time when loading libraries,
|
|
|
|
// so only do it when necessary.
|
|
|
|
if( Pgm().GetLocale() != locale )
|
|
|
|
{
|
|
|
|
namePrefix = _( "Unit" );
|
|
|
|
locale = Pgm().GetLocale();
|
|
|
|
}
|
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Parent = aParent;
|
2024-06-21 13:16:03 +00:00
|
|
|
m_Type = TYPE::UNIT;
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Unit = aUnit;
|
|
|
|
m_LibId = aParent->m_LibId;
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Name = namePrefix + " " + aItem->GetUnitReference( aUnit );
|
2022-09-14 22:11:37 +00:00
|
|
|
|
|
|
|
if( aItem->HasUnitDisplayName( aUnit ) )
|
|
|
|
m_Desc = aItem->GetUnitDisplayName( aUnit );
|
|
|
|
else
|
|
|
|
m_Desc = wxEmptyString;
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
m_IntrinsicRank = -aUnit;
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-17 18:13:14 +00:00
|
|
|
void LIB_TREE_NODE_UNIT::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
|
|
|
|
std::function<bool( LIB_TREE_NODE& aNode )>* aFilter )
|
|
|
|
{
|
|
|
|
// aMatcher test results are inherited from parent
|
|
|
|
if( aMatcher )
|
|
|
|
m_Score = m_Parent->m_Score;
|
|
|
|
|
|
|
|
// aFilter test is subtractive
|
|
|
|
if( aFilter && !(*aFilter)(*this) )
|
|
|
|
m_Score = 0;
|
|
|
|
|
|
|
|
// show all nodes if no search/filter/etc. criteria are given
|
|
|
|
if( !aMatcher && aLib.IsEmpty() && ( !aFilter || (*aFilter)(*this) ) )
|
|
|
|
m_Score = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-17 18:17:50 +00:00
|
|
|
LIB_TREE_NODE_ITEM::LIB_TREE_NODE_ITEM( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem )
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2024-06-21 13:16:03 +00:00
|
|
|
m_Type = TYPE::ITEM;
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Parent = aParent;
|
2018-07-30 13:18:37 +00:00
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
m_LibId.SetLibNickname( aItem->GetLibNickname() );
|
2021-06-30 11:00:06 +00:00
|
|
|
m_LibId.SetLibItemName( aItem->GetName() );
|
2018-07-30 13:18:37 +00:00
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Name = aItem->GetName();
|
2024-04-02 16:10:23 +00:00
|
|
|
m_Desc = aItem->GetDesc();
|
2022-06-05 17:58:27 +00:00
|
|
|
m_Footprint = aItem->GetFootprint();
|
2023-09-29 16:02:57 +00:00
|
|
|
m_PinCount = aItem->GetPinCount();
|
2018-07-30 13:18:37 +00:00
|
|
|
|
2022-08-28 23:02:12 +00:00
|
|
|
aItem->GetChooserFields( m_Fields );
|
|
|
|
|
2023-05-01 20:26:29 +00:00
|
|
|
m_SearchTerms = aItem->GetSearchTerms();
|
2018-07-30 13:18:37 +00:00
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
m_IsRoot = aItem->IsRoot();
|
2018-07-30 13:18:37 +00:00
|
|
|
|
2024-04-02 17:28:17 +00:00
|
|
|
if( aItem->GetSubUnitCount() > 1 )
|
2018-08-05 13:03:23 +00:00
|
|
|
{
|
2024-04-02 17:28:17 +00:00
|
|
|
for( int u = 1; u <= aItem->GetSubUnitCount(); ++u )
|
2018-08-05 13:03:23 +00:00
|
|
|
AddUnit( aItem, u );
|
|
|
|
}
|
2018-01-10 11:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-17 18:17:50 +00:00
|
|
|
LIB_TREE_NODE_UNIT& LIB_TREE_NODE_ITEM::AddUnit( LIB_TREE_ITEM* aItem, int aUnit )
|
2018-01-10 11:04:34 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
LIB_TREE_NODE_UNIT* unit = new LIB_TREE_NODE_UNIT( this, aItem, aUnit );
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Children.push_back( std::unique_ptr<LIB_TREE_NODE>( unit ) );
|
2018-01-10 11:04:34 +00:00
|
|
|
return *unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-17 18:17:50 +00:00
|
|
|
void LIB_TREE_NODE_ITEM::Update( LIB_TREE_ITEM* aItem )
|
2018-01-10 11:04:34 +00:00
|
|
|
{
|
2024-04-02 16:10:23 +00:00
|
|
|
m_LibId.SetLibNickname( aItem->GetLIB_ID().GetLibNickname() );
|
2022-04-21 10:57:15 +00:00
|
|
|
m_LibId.SetLibItemName( aItem->GetName() );
|
2017-09-15 14:17:44 +00:00
|
|
|
|
2022-04-21 10:57:15 +00:00
|
|
|
m_Name = aItem->GetName();
|
2024-04-02 16:10:23 +00:00
|
|
|
m_Desc = aItem->GetDesc();
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2022-08-28 23:02:12 +00:00
|
|
|
aItem->GetChooserFields( m_Fields );
|
|
|
|
|
2023-05-01 20:26:29 +00:00
|
|
|
m_SearchTerms = aItem->GetSearchTerms();
|
2017-07-09 13:08:33 +00:00
|
|
|
|
2020-02-07 17:06:24 +00:00
|
|
|
m_IsRoot = aItem->IsRoot();
|
|
|
|
m_Children.clear();
|
2018-01-10 11:04:34 +00:00
|
|
|
|
2024-04-02 17:28:17 +00:00
|
|
|
for( int u = 1; u <= aItem->GetSubUnitCount(); ++u )
|
2018-07-27 20:47:51 +00:00
|
|
|
AddUnit( aItem, u );
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-17 18:17:50 +00:00
|
|
|
void LIB_TREE_NODE_ITEM::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
|
|
|
|
std::function<bool( LIB_TREE_NODE& aNode )>* aFilter )
|
2023-09-29 16:02:57 +00:00
|
|
|
{
|
2024-02-21 02:21:06 +00:00
|
|
|
// aMatcher test is additive, but if we don't match the given term at all, it nulls out
|
2023-11-08 12:29:14 +00:00
|
|
|
if( aMatcher )
|
2024-02-21 02:21:06 +00:00
|
|
|
{
|
|
|
|
int currentScore = aMatcher->ScoreTerms( m_SearchTerms );
|
2023-09-29 16:02:57 +00:00
|
|
|
|
2024-03-05 23:54:04 +00:00
|
|
|
// This is a hack: the second phase of search in the adapter will look for a tokenized
|
|
|
|
// LIB_ID and send the lib part down here. While we generally want to prune ourselves
|
|
|
|
// out here (by setting score to -1) the first time we fail to match a search term,
|
|
|
|
// we want to give the same search term a second chance if it has been split from a library
|
|
|
|
// name.
|
|
|
|
if( ( m_Score >= 0 || !aLib.IsEmpty() ) && currentScore > 0 )
|
2024-02-21 02:21:06 +00:00
|
|
|
m_Score += currentScore;
|
|
|
|
else
|
|
|
|
m_Score = -1; // Item has failed to match this term, rule it out
|
|
|
|
}
|
2023-09-29 16:02:57 +00:00
|
|
|
|
2023-11-08 12:29:14 +00:00
|
|
|
// aFilter test is subtractive
|
|
|
|
if( aFilter && !(*aFilter)(*this) )
|
|
|
|
m_Score = 0;
|
2023-09-29 16:02:57 +00:00
|
|
|
|
2023-11-08 12:29:14 +00:00
|
|
|
// show all nodes if no search/filter/etc. criteria are given
|
|
|
|
if( !aMatcher && aLib.IsEmpty() && ( !aFilter || (*aFilter)(*this) ) )
|
|
|
|
m_Score = 1;
|
2023-11-17 18:13:14 +00:00
|
|
|
|
|
|
|
for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
|
|
|
|
child->UpdateScore( aMatcher, aLib, aFilter );
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-08 17:34:14 +00:00
|
|
|
LIB_TREE_NODE_LIBRARY::LIB_TREE_NODE_LIBRARY( LIB_TREE_NODE* aParent, wxString const& aName,
|
|
|
|
wxString const& aDesc )
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2024-06-21 13:16:03 +00:00
|
|
|
m_Type = TYPE::LIBRARY;
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Name = aName;
|
|
|
|
m_Desc = aDesc;
|
|
|
|
m_Parent = aParent;
|
|
|
|
m_LibId.SetLibNickname( aName );
|
2023-10-23 17:23:24 +00:00
|
|
|
|
|
|
|
m_SearchTerms.emplace_back( SEARCH_TERM( aName, 8 ) );
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-17 18:17:50 +00:00
|
|
|
LIB_TREE_NODE_ITEM& LIB_TREE_NODE_LIBRARY::AddItem( LIB_TREE_ITEM* aItem )
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2023-11-17 18:17:50 +00:00
|
|
|
LIB_TREE_NODE_ITEM* item = new LIB_TREE_NODE_ITEM( this, aItem );
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Children.push_back( std::unique_ptr<LIB_TREE_NODE>( item ) );
|
2018-07-30 13:18:37 +00:00
|
|
|
return *item;
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-08 17:34:14 +00:00
|
|
|
void LIB_TREE_NODE_LIBRARY::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
|
|
|
|
std::function<bool( LIB_TREE_NODE& aNode )>* aFilter )
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2024-04-02 22:51:19 +00:00
|
|
|
int maxChildScore = 0;
|
2024-02-21 02:21:06 +00:00
|
|
|
|
2023-11-17 18:13:14 +00:00
|
|
|
for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2023-11-17 18:13:14 +00:00
|
|
|
child->UpdateScore( aMatcher, aLib, aFilter );
|
2024-04-02 22:51:19 +00:00
|
|
|
maxChildScore = std::max( maxChildScore, child->m_Score );
|
2018-08-01 00:21:50 +00:00
|
|
|
}
|
2023-10-31 14:48:12 +00:00
|
|
|
|
2024-02-21 02:21:06 +00:00
|
|
|
// Each time UpdateScore is called for a library, child (item) scores may go up or down.
|
|
|
|
// If the all go down to zero, we need to make sure to drop the library from the list.
|
2024-04-02 22:51:19 +00:00
|
|
|
if( maxChildScore > 0 )
|
|
|
|
m_Score = std::max( m_Score, maxChildScore );
|
2024-02-21 02:21:06 +00:00
|
|
|
else
|
|
|
|
m_Score = 0;
|
|
|
|
|
|
|
|
// aLib test is additive, but only when we've already accumulated some score from children
|
2024-03-05 23:54:04 +00:00
|
|
|
if( !aLib.IsEmpty()
|
|
|
|
&& m_Name.Lower().Matches( aLib )
|
|
|
|
&& ( m_Score > 0 || m_Children.empty() ) )
|
|
|
|
{
|
2023-11-08 12:29:14 +00:00
|
|
|
m_Score += 1;
|
2024-03-05 23:54:04 +00:00
|
|
|
}
|
2023-11-08 12:29:14 +00:00
|
|
|
|
2024-03-05 23:54:04 +00:00
|
|
|
// aMatcher test is additive
|
|
|
|
if( aMatcher )
|
2024-04-02 22:51:19 +00:00
|
|
|
{
|
|
|
|
int ownScore = aMatcher->ScoreTerms( m_SearchTerms );
|
|
|
|
m_Score += ownScore;
|
|
|
|
|
|
|
|
// If we have a hit on a library, show all children in that library
|
|
|
|
if( maxChildScore <= 0 && ownScore > 0 )
|
|
|
|
{
|
|
|
|
for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
|
|
|
|
child->ForceScore( 1 );
|
|
|
|
}
|
|
|
|
}
|
2023-11-08 12:29:14 +00:00
|
|
|
|
|
|
|
// show all nodes if no search/filter/etc. criteria are given
|
|
|
|
if( m_Children.empty() && !aMatcher && aLib.IsEmpty() && ( !aFilter || (*aFilter)(*this) ) )
|
|
|
|
m_Score = 1;
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
LIB_TREE_NODE_ROOT::LIB_TREE_NODE_ROOT()
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2024-06-21 13:16:03 +00:00
|
|
|
m_Type = TYPE::ROOT;
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-08 17:34:14 +00:00
|
|
|
LIB_TREE_NODE_LIBRARY& LIB_TREE_NODE_ROOT::AddLib( wxString const& aName, wxString const& aDesc )
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2023-11-08 17:34:14 +00:00
|
|
|
LIB_TREE_NODE_LIBRARY* lib = new LIB_TREE_NODE_LIBRARY( this, aName, aDesc );
|
2020-02-07 17:06:24 +00:00
|
|
|
m_Children.push_back( std::unique_ptr<LIB_TREE_NODE>( lib ) );
|
2017-03-06 14:50:48 +00:00
|
|
|
return *lib;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-08 12:29:14 +00:00
|
|
|
void LIB_TREE_NODE_ROOT::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
|
|
|
|
std::function<bool( LIB_TREE_NODE& aNode )>* aFilter )
|
2017-03-06 14:50:48 +00:00
|
|
|
{
|
2020-12-24 19:42:41 +00:00
|
|
|
for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
|
2023-11-08 12:29:14 +00:00
|
|
|
child->UpdateScore( aMatcher, aLib, aFilter );
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
|
|
|
|