KiCad PCB EDA Suite
LIB_TREE_NODE_LIB Class Reference

Node type: library. More...

#include <lib_tree_model.h>

Inheritance diagram for LIB_TREE_NODE_LIB:
LIB_TREE_NODE

Public Types

enum  TYPE {
  ROOT , LIB , LIBID , UNIT ,
  INVALID
}
 
typedef std::vector< std::unique_ptr< LIB_TREE_NODE > > PTR_VECTOR
 

Public Member Functions

 LIB_TREE_NODE_LIB (LIB_TREE_NODE_LIB const &_)=delete
 The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be copied around. More...
 
void operator= (LIB_TREE_NODE_LIB const &_)=delete
 
 LIB_TREE_NODE_LIB (LIB_TREE_NODE *aParent, const wxString &aName, const wxString &aDesc)
 Construct an empty library node. More...
 
LIB_TREE_NODE_LIB_IDAddItem (LIB_TREE_ITEM *aItem)
 Construct a new alias node, add it to this library, and return it. More...
 
virtual void UpdateScore (EDA_COMBINED_MATCHER &aMatcher, const wxString &aLib) override
 Update the score for this part. More...
 
void ResetScore ()
 Initialize score to kLowestDefaultScore, recursively. More...
 
void AssignIntrinsicRanks (bool presorted=false)
 Store intrinsic ranks on all children of this node. More...
 
void SortNodes ()
 Sort child nodes quickly and recursively (IntrinsicRanks must have been set). More...
 

Static Public Member Functions

static int Compare (LIB_TREE_NODE const &aNode1, LIB_TREE_NODE const &aNode2)
 Compare two nodes. More...
 

Public Attributes

LIB_TREE_NODEm_Parent
 
PTR_VECTOR m_Children
 
enum TYPE m_Type
 
int m_IntrinsicRank
 The rank of the item before any search terms are applied. More...
 
int m_Score
 
bool m_Pinned
 
wxString m_Name
 
wxString m_Desc
 
wxString m_Footprint
 
wxString m_MatchName
 
wxString m_SearchText
 
bool m_Normalized
 
std::map< wxString, wxString > m_Fields
 
LIB_ID m_LibId
 
int m_Unit
 
bool m_IsRoot
 

Detailed Description

Node type: library.

Definition at line 231 of file lib_tree_model.h.

Member Typedef Documentation

◆ PTR_VECTOR

typedef std::vector<std::unique_ptr<LIB_TREE_NODE> > LIB_TREE_NODE::PTR_VECTOR
inherited

Definition at line 116 of file lib_tree_model.h.

Member Enumeration Documentation

◆ TYPE

enum LIB_TREE_NODE::TYPE
inherited
Enumerator
ROOT 
LIB 
LIBID 
UNIT 
INVALID 

Definition at line 112 of file lib_tree_model.h.

Constructor & Destructor Documentation

◆ LIB_TREE_NODE_LIB() [1/2]

LIB_TREE_NODE_LIB::LIB_TREE_NODE_LIB ( LIB_TREE_NODE_LIB const &  _)
delete

The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be copied around.

◆ LIB_TREE_NODE_LIB() [2/2]

LIB_TREE_NODE_LIB::LIB_TREE_NODE_LIB ( LIB_TREE_NODE aParent,
const wxString &  aName,
const wxString &  aDesc 
)

Construct an empty library node.

Parameters
aParentparent node, should be a CMP_TREE_NODE_ROOT
aNamedisplay name of the library
aDesca description of the library

Definition at line 294 of file lib_tree_model.cpp.

296{
297 m_Type = LIB;
298 m_Name = aName;
299 m_MatchName = aName.Lower();
300 m_Desc = aDesc;
301 m_Parent = aParent;
302 m_LibId.SetLibNickname( aName );
303}
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:98
enum TYPE m_Type
LIB_TREE_NODE * m_Parent
wxString m_MatchName

References LIB_TREE_NODE::LIB, LIB_TREE_NODE::m_Desc, LIB_TREE_NODE::m_LibId, LIB_TREE_NODE::m_MatchName, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Parent, LIB_TREE_NODE::m_Type, and LIB_ID::SetLibNickname().

Member Function Documentation

◆ AddItem()

LIB_TREE_NODE_LIB_ID & LIB_TREE_NODE_LIB::AddItem ( LIB_TREE_ITEM aItem)

Construct a new alias node, add it to this library, and return it.

Parameters
aItemLIB_COMPONENT to provide data

Definition at line 306 of file lib_tree_model.cpp.

307{
308 LIB_TREE_NODE_LIB_ID* item = new LIB_TREE_NODE_LIB_ID( this, aItem );
309 m_Children.push_back( std::unique_ptr<LIB_TREE_NODE>( item ) );
310 return *item;
311}
Node type: LIB_ID.
PTR_VECTOR m_Children

References LIB_TREE_NODE::m_Children.

Referenced by LIB_TREE_MODEL_ADAPTER::DoAddLibrary(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary(), and FP_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

◆ AssignIntrinsicRanks()

void LIB_TREE_NODE::AssignIntrinsicRanks ( bool  presorted = false)
inherited

Store intrinsic ranks on all children of this node.

See m_IntrinsicRank member doc for more information.

Definition at line 62 of file lib_tree_model.cpp.

63{
64 std::vector<LIB_TREE_NODE*> sort_buf;
65
66 if( presorted )
67 {
68 int max = m_Children.size() - 1;
69
70 for( int i = 0; i <= max; ++i )
71 m_Children[i]->m_IntrinsicRank = max - i;
72 }
73 else
74 {
75 for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
76 sort_buf.push_back( child.get() );
77
78 std::sort( sort_buf.begin(), sort_buf.end(),
79 []( LIB_TREE_NODE* a, LIB_TREE_NODE* b ) -> bool
80 {
81 return StrNumCmp( a->m_Name, b->m_Name, true ) > 0;
82 } );
83
84 for( int i = 0; i < (int) sort_buf.size(); ++i )
85 sort_buf[i]->m_IntrinsicRank = i;
86 }
87}
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
int m_IntrinsicRank
The rank of the item before any search terms are applied.

References LIB_TREE_NODE::m_Children, and LIB_TREE_NODE::m_IntrinsicRank.

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), FP_TREE_MODEL_ADAPTER::AddLibraries(), LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks(), LIB_TREE_MODEL_ADAPTER::DoAddLibrary(), FP_TREE_SYNCHRONIZING_ADAPTER::Sync(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary(), and FP_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

◆ Compare()

int LIB_TREE_NODE::Compare ( LIB_TREE_NODE const &  aNode1,
LIB_TREE_NODE const &  aNode2 
)
staticinherited

Compare two nodes.

Returns negative if aNode1 < aNode2, zero if aNode1 == aNode2, or positive if aNode1 > aNode2.

Definition at line 103 of file lib_tree_model.cpp.

104{
105 if( aNode1.m_Type != aNode2.m_Type )
106 return 0;
107
108 // Recently used sorts at top
109 if( aNode1.m_Name.StartsWith( wxT( "-- " ) ) )
110 return 1;
111 else if( aNode2.m_Name.StartsWith( wxT( "-- " ) ) )
112 return 0;
113
114 // Pinned nodes go next
115 if( aNode1.m_Pinned && !aNode2.m_Pinned )
116 return 1;
117 else if( aNode2.m_Pinned && !aNode1.m_Pinned )
118 return -1;
119
120 if( aNode1.m_Parent != aNode2.m_Parent )
121 return 0;
122
123 return aNode1.m_IntrinsicRank - aNode2.m_IntrinsicRank;
124}

References LIB_TREE_NODE::m_IntrinsicRank, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Parent, LIB_TREE_NODE::m_Pinned, and LIB_TREE_NODE::m_Type.

◆ operator=()

void LIB_TREE_NODE_LIB::operator= ( LIB_TREE_NODE_LIB const &  _)
delete

◆ ResetScore()

void LIB_TREE_NODE::ResetScore ( )
inherited

Initialize score to kLowestDefaultScore, recursively.

Definition at line 53 of file lib_tree_model.cpp.

54{
55 for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
56 child->ResetScore();
57
59}
static const unsigned kLowestDefaultScore

References kLowestDefaultScore, LIB_TREE_NODE::m_Children, and LIB_TREE_NODE::m_Score.

Referenced by LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

◆ SortNodes()

void LIB_TREE_NODE::SortNodes ( )
inherited

Sort child nodes quickly and recursively (IntrinsicRanks must have been set).

Definition at line 90 of file lib_tree_model.cpp.

91{
92 std::sort( m_Children.begin(), m_Children.end(),
93 []( std::unique_ptr<LIB_TREE_NODE>& a, std::unique_ptr<LIB_TREE_NODE>& b )
94 {
95 return Compare( *a, *b ) > 0;
96 } );
97
98 for( std::unique_ptr<LIB_TREE_NODE>& node: m_Children )
99 node->SortNodes();
100}

References LIB_TREE_NODE::m_Children.

Referenced by LIB_TREE_MODEL_ADAPTER::resortTree(), and LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

◆ UpdateScore()

void LIB_TREE_NODE_LIB::UpdateScore ( EDA_COMBINED_MATCHER aMatcher,
const wxString &  aLib 
)
overridevirtual

Update the score for this part.

This is accumulative - it will be called once per search term.

Parameters
aMatcheran EDA_COMBINED_MATCHER initialized with the search term

Implements LIB_TREE_NODE.

Definition at line 314 of file lib_tree_model.cpp.

315{
316 m_Score = 0;
317
318 // We need to score leaf nodes, which are usually (but not always) children.
319
320 if( m_Children.size() )
321 {
322 for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
323 {
324 child->UpdateScore( aMatcher, aLib );
325 m_Score = std::max( m_Score, child->m_Score );
326 }
327 }
328 else
329 {
330 // No children; we are a leaf.
331
332 if( !aLib.IsEmpty() )
333 {
334 m_Score = m_MatchName == aLib ? 1000 : 0;
335 return;
336 }
337
338 int found_pos = EDA_PATTERN_NOT_FOUND;
339 int matchers_fired = 0;
340
341 if( aMatcher.GetPattern() == m_MatchName )
342 {
343 m_Score += 1000; // exact match. High score :)
344 }
345 else if( aMatcher.Find( m_MatchName, matchers_fired, found_pos ) )
346 {
347 // Substring match. The earlier in the string the better.
348 m_Score += matchPosScore( found_pos, 20 ) + 20;
349 }
350
351 // More matchers = better match
352 m_Score += 2 * matchers_fired;
353 }
354}
bool Find(const wxString &aTerm, int &aMatchersTriggered, int &aPosition)
const wxString & GetPattern() const
static const int EDA_PATTERN_NOT_FOUND
static int matchPosScore(int aPosition, int aMaximum)

References EDA_PATTERN_NOT_FOUND, EDA_COMBINED_MATCHER::Find(), EDA_COMBINED_MATCHER::GetPattern(), LIB_TREE_NODE::m_Children, LIB_TREE_NODE::m_MatchName, LIB_TREE_NODE::m_Score, and matchPosScore().

Member Data Documentation

◆ m_Children

◆ m_Desc

◆ m_Fields

std::map<wxString, wxString> LIB_TREE_NODE::m_Fields
inherited
See also
LIB_TREE_ITEMS::GetChooserFields

Definition at line 140 of file lib_tree_model.h.

Referenced by LIB_TREE_MODEL_ADAPTER::GetValue(), LIB_TREE_NODE_LIB_ID::LIB_TREE_NODE_LIB_ID(), and LIB_TREE_NODE_LIB_ID::Update().

◆ m_Footprint

wxString LIB_TREE_NODE::m_Footprint
inherited

◆ m_IntrinsicRank

int LIB_TREE_NODE::m_IntrinsicRank
inherited

The rank of the item before any search terms are applied.

This is a fairly expensive sort (involving string compares) so it helps to store the result of that sort.

Definition at line 127 of file lib_tree_model.h.

Referenced by LIB_TREE_NODE::AssignIntrinsicRanks(), LIB_TREE_NODE::Compare(), and LIB_TREE_NODE_UNIT::LIB_TREE_NODE_UNIT().

◆ m_IsRoot

◆ m_LibId

◆ m_MatchName

◆ m_Name

◆ m_Normalized

bool LIB_TREE_NODE::m_Normalized
inherited

◆ m_Parent

◆ m_Pinned

◆ m_Score

int LIB_TREE_NODE::m_Score
inherited

◆ m_SearchText

wxString LIB_TREE_NODE::m_SearchText
inherited

◆ m_Type

◆ m_Unit


The documentation for this class was generated from the following files: