35 for( std::unique_ptr<LIB_TREE_NODE>& child:
m_Children )
44 std::vector<LIB_TREE_NODE*> sort_buf;
50 for(
int i = 0; i <= max; ++i )
55 for( std::unique_ptr<LIB_TREE_NODE>& child:
m_Children )
56 sort_buf.push_back( child.get() );
58 std::sort( sort_buf.begin(), sort_buf.end(),
61 return StrNumCmp( a->m_Name, b->m_Name, true ) > 0;
64 for(
int i = 0; i < (int) sort_buf.size(); ++i )
73 [&]( std::unique_ptr<LIB_TREE_NODE>& a, std::unique_ptr<LIB_TREE_NODE>& b )
75 return Compare( *a, *b, aUseScores );
78 for( std::unique_ptr<LIB_TREE_NODE>& node:
m_Children )
79 node->SortNodes( aUseScores );
90 if( aNode1.
m_Name.StartsWith( wxT(
"-- " ) ) )
92 if( aNode2.
m_Name.StartsWith( wxT(
"-- " ) ) )
98 if( aNode2.
m_Name.StartsWith( wxT(
"-- Recently Used" ) ) )
100 else if( aNode1.
m_Name.StartsWith( wxT(
"-- Recently Used" ) ) )
110 else if( aNode2.
m_Name.StartsWith( wxT(
"-- " ) ) )
127 return reinterpret_cast<const void*
>( &aNode1 ) <
reinterpret_cast<const void*
>( &aNode2 );
132 : m_Parent( nullptr ),
134 m_IntrinsicRank( 0 ),
145 static void* locale =
nullptr;
146 static wxString namePrefix;
150 if(
Pgm().GetLocale() != locale )
152 namePrefix =
_(
"Unit" );
181 if( aFilter && !(*aFilter)(*
this) )
185 if( !aMatcher && aLib.IsEmpty() && ( !aFilter || (*aFilter)(*
this) ) )
220 m_Children.push_back( std::unique_ptr<LIB_TREE_NODE>( unit ) );
258 if( (
m_Score >= 0 || !aLib.IsEmpty() ) && currentScore > 0 )
265 if( aFilter && !(*aFilter)(*
this) )
269 if( !aMatcher && aLib.IsEmpty() && ( !aFilter || (*aFilter)(*
this) ) )
272 for( std::unique_ptr<LIB_TREE_NODE>& child:
m_Children )
273 child->UpdateScore( aMatcher, aLib, aFilter );
278 wxString
const& aDesc )
293 m_Children.push_back( std::unique_ptr<LIB_TREE_NODE>( item ) );
301 int maxChildScore = 0;
306 for( std::unique_ptr<LIB_TREE_NODE>& child:
m_Children )
308 child->UpdateScore( aMatcher, aLib, aFilter );
309 maxChildScore = std::max( maxChildScore, child->m_Score );
316 if( !aLib.IsEmpty() &&
m_Name.Lower().Matches( aLib ) )
326 if( maxChildScore <= 0 && ownScore > 0 )
328 for( std::unique_ptr<LIB_TREE_NODE>& child:
m_Children )
330 if( !aFilter || (*aFilter)( *
this ) )
331 child->ForceScore( 1 );
333 maxChildScore = std::max( maxChildScore, child->m_Score );
339 if( !
m_Children.empty() && maxChildScore <= 0 )
343 if(
m_Children.empty() && !aMatcher && aLib.IsEmpty() && ( !aFilter || (*aFilter)(*
this) ) )
357 m_Children.push_back( std::unique_ptr<LIB_TREE_NODE>( lib ) );
365 [&]( std::unique_ptr<LIB_TREE_NODE>& aNode )
367 return aNode->m_Name == aName;
382 for( std::unique_ptr<LIB_TREE_NODE>& child:
m_Children )
383 child->UpdateScore( aMatcher, aLib, aFilter );
int ScoreTerms(std::vector< SEARCH_TERM > &aWeightedTerms)
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
virtual wxString GetUnitReference(int aUnit)
For items with units, return an identifier for unit x.
virtual wxString GetLibNickname() const =0
virtual int GetSubUnitCount() const
For items with units, return the number of units.
virtual std::vector< SEARCH_TERM > GetSearchTerms()
virtual bool HasUnitDisplayName(int aUnit)
For items with units, return true if a display name is set for x.
virtual wxString GetFootprint()
For items with footprint fields.
virtual LIB_ID GetLIB_ID() const =0
virtual wxString GetDesc()=0
virtual bool IsRoot() const
For items having aliases, IsRoot() indicates the principal item.
virtual wxString GetName() const =0
virtual int GetPinCount()
The pin count for symbols or the unique pad count for footprints.
virtual wxString GetUnitDisplayName(int aUnit)
For items with units, return a display name for unit x.
virtual void GetChooserFields(std::map< wxString, wxString > &aColumnMap)
Retrieves a key/value map of the fields on this item that should be exposed to the library browser/ch...
void UpdateScore(EDA_COMBINED_MATCHER *aMatcher, const wxString &aLib, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) override
Perform the actual search.
LIB_TREE_NODE_ITEM(LIB_TREE_NODE_ITEM const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
LIB_TREE_NODE_UNIT & AddUnit(LIB_TREE_ITEM *aItem, int aUnit)
Add a new unit to the component and return it.
void Update(LIB_TREE_ITEM *aItem)
Update the node using data from a LIB_ALIAS object.
LIB_TREE_NODE_LIBRARY(LIB_TREE_NODE_LIBRARY const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
LIB_TREE_NODE_ITEM & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
void UpdateScore(EDA_COMBINED_MATCHER *aMatcher, const wxString &aLib, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) override
Update the score for this part.
LIB_TREE_NODE_LIBRARY & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
void RemoveLib(wxString const &aName)
Remove a library node from the root.
void UpdateScore(EDA_COMBINED_MATCHER *aMatcher, const wxString &aLib, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) override
Update the score for this part.
LIB_TREE_NODE_ROOT()
Construct the root node.
void Clear()
Clear the tree.
Node type: unit of component.
LIB_TREE_NODE_UNIT(LIB_TREE_NODE_UNIT const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
void UpdateScore(EDA_COMBINED_MATCHER *aMatcher, const wxString &aLib, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) override
Update the score for this part.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
void SortNodes(bool aUseScores)
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
static bool Compare(LIB_TREE_NODE const &aNode1, LIB_TREE_NODE const &aNode2, bool aUseScores)
Compare two nodes.
std::vector< SEARCH_TERM > m_SearchTerms
std::map< wxString, wxString > m_Fields
List of weighted search terms.
virtual void ResetScore()
Initialize scores recursively.
int m_IntrinsicRank
The rank of the item before any search terms are applied.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
virtual wxLocale * GetLocale()
Abstract pattern-matching tool and implementations.
PGM_BASE & Pgm()
The global Program "get" accessor.