KiCad PCB EDA Suite
LIB_TREE_NODE Class Referenceabstract

Model class in the component selector Model-View-Adapter (mediated MVC) architecture. More...

#include <lib_tree_model.h>

Inheritance diagram for LIB_TREE_NODE:
LIB_TREE_NODE_LIB LIB_TREE_NODE_LIB_ID LIB_TREE_NODE_ROOT LIB_TREE_NODE_UNIT

Public Types

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

Public Member Functions

virtual void UpdateScore (EDA_COMBINED_MATCHER &aMatcher)=0
 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...
 
 LIB_TREE_NODE ()
 
virtual ~LIB_TREE_NODE ()
 

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_MatchName
 
wxString m_SearchText
 
bool m_Normalized
 
LIB_ID m_LibId
 
int m_Unit
 
bool m_IsRoot
 

Detailed Description

Model class in the component selector Model-View-Adapter (mediated MVC) architecture.

The other pieces are in:

This model is populated from LIB_ALIASes; helper methods in the adapter can accept entire libraries.

Quick summary of methods used to populate this class:

  • CMP_TREE_NODE_ROOT::AddLib() - add a new, empty library to the root
  • CMP_TREE_NODE_LIB::AddAlias() - add an alias and its units from a given LIB_ALIAS*

Quick summary of methods used to drive this class:

The data in the model is meant to be accessed directly. Quick summary of data members:

  • Parent - parent node, or nullptr if root
  • Children - vector of unique_ptrs to children
  • Type - ROOT, LIB, ALIAS, or UNIT
  • m_IntrinsicRank - cached initial sort order
  • m_Score - score taking into account search terms. Zero means irrelevant and should be hidden.
  • Name - name of the library/alias/unit, to be displayed
  • Desc - description of the alias, to be displayed
  • m_MatchName - Name, normalized to lowercase for matching
  • m_SearchText - normalized composite of keywords and description
  • LibId - the LIB_ID this alias or unit is from, or not valid
  • Unit - the unit number, or zero for non-units

Definition at line 75 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

Definition at line 82 of file lib_tree_model.h.

Member Enumeration Documentation

◆ TYPE

Enumerator
ROOT 
LIB 
LIBID 
UNIT 
INVALID 

Definition at line 78 of file lib_tree_model.h.

Constructor & Destructor Documentation

◆ LIB_TREE_NODE()

LIB_TREE_NODE::LIB_TREE_NODE ( )

Definition at line 118 of file lib_tree_model.cpp.

119  : m_Parent( nullptr ),
120  m_Type( INVALID ),
121  m_IntrinsicRank( 0 ),
123  m_Pinned( false ),
124  m_Normalized( false ),
125  m_Unit( 0 ),
126  m_IsRoot( false )
127 {}
int m_IntrinsicRank
The rank of the item before any search terms are applied.
LIB_TREE_NODE * m_Parent
static const unsigned kLowestDefaultScore
enum TYPE m_Type

◆ ~LIB_TREE_NODE()

virtual LIB_TREE_NODE::~LIB_TREE_NODE ( )
inlinevirtual

Definition at line 140 of file lib_tree_model.h.

140 {}

Member Function Documentation

◆ AssignIntrinsicRanks()

void LIB_TREE_NODE::AssignIntrinsicRanks ( bool  presorted = false)

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( auto const& node: m_Children )
76  sort_buf.push_back( &*node );
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 }
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Definition: string.cpp:388
int m_IntrinsicRank
The rank of the item before any search terms are applied.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
wxString m_Name
PTR_VECTOR m_Children

References m_Children, m_IntrinsicRank, m_Name, and StrNumCmp().

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

◆ Compare()

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

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  if( aNode1.m_Score != aNode2.m_Score )
109  return aNode1.m_Score - aNode2.m_Score;
110 
111  if( aNode1.m_Parent != aNode2.m_Parent )
112  return 0;
113 
114  return aNode1.m_IntrinsicRank - aNode2.m_IntrinsicRank;
115 }

References m_IntrinsicRank, m_Parent, m_Score, and m_Type.

Referenced by SortNodes().

◆ ResetScore()

void LIB_TREE_NODE::ResetScore ( )

Initialize score to kLowestDefaultScore, recursively.

Definition at line 53 of file lib_tree_model.cpp.

54 {
55  for( auto& child: m_Children )
56  child->ResetScore();
57 
59 }
static const unsigned kLowestDefaultScore
PTR_VECTOR m_Children

References kLowestDefaultScore, m_Children, and m_Score.

Referenced by LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

◆ SortNodes()

void LIB_TREE_NODE::SortNodes ( )

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 }
static int Compare(LIB_TREE_NODE const &aNode1, LIB_TREE_NODE const &aNode2)
Compare two nodes.
PTR_VECTOR m_Children

References Compare(), and m_Children.

Referenced by LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

◆ UpdateScore()

virtual void LIB_TREE_NODE::UpdateScore ( EDA_COMBINED_MATCHER aMatcher)
pure virtual

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

Implemented in LIB_TREE_NODE_ROOT, LIB_TREE_NODE_LIB, LIB_TREE_NODE_LIB_ID, and LIB_TREE_NODE_UNIT.

Member Data Documentation

◆ m_Children

◆ m_Desc

◆ m_IntrinsicRank

int LIB_TREE_NODE::m_IntrinsicRank

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 93 of file lib_tree_model.h.

Referenced by AssignIntrinsicRanks(), 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

◆ m_Parent

◆ m_Pinned

◆ m_Score

◆ m_SearchText

wxString LIB_TREE_NODE::m_SearchText

◆ m_Type

◆ m_Unit


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