KiCad PCB EDA Suite
CMP_TREE_NODE Class Referenceabstract

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

#include <cmp_tree_model.h>

Inheritance diagram for CMP_TREE_NODE:
CMP_TREE_NODE_LIB CMP_TREE_NODE_LIB_ID CMP_TREE_NODE_ROOT CMP_TREE_NODE_UNIT

Public Types

enum  TYPE {
  ROOT, LIB, LIBID, UNIT,
  INVALID
}
 
typedef std::vector< std::unique_ptr< CMP_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 ()
 Store intrinsic ranks on all children of this node. More...
 
void SortNodes ()
 Sort child nodes quickly and recursively (IntrinsicRanks must have been set). More...
 
 CMP_TREE_NODE ()
 
virtual ~CMP_TREE_NODE ()
 

Static Public Member Functions

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

Public Attributes

CMP_TREE_NODEParent
 Parent node or null. More...
 
PTR_VECTOR Children
 List of child nodes. More...
 
enum TYPE Type
 Node type. More...
 
int IntrinsicRank
 The rank of the item before any search terms are applied. More...
 
int Score
 The score of an item resulting from the search algorithm. More...
 
wxString Name
 Actual name of the part. More...
 
wxString Desc
 Description to be displayed. More...
 
wxString MatchName
 Normalized name for matching. More...
 
wxString SearchText
 Descriptive text to search. More...
 
bool SearchTextNormalized
 Support for lazy normalization. More...
 
LIB_ID LibId
 LIB_ID determined by the parent library nickname and alias name. More...
 
int Unit
 Actual unit, or zero. More...
 
bool IsRoot
 Indicates if the symbol is a root symbol instead of an alias. More...
 

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:

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
  • IntrinsicRank - cached initial sort order
  • 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
  • MatchName - Name, normalized to lowercase for matching
  • 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 77 of file cmp_tree_model.h.

Member Typedef Documentation

typedef std::vector<std::unique_ptr<CMP_TREE_NODE> > CMP_TREE_NODE::PTR_VECTOR

Definition at line 83 of file cmp_tree_model.h.

Member Enumeration Documentation

Enumerator
ROOT 
LIB 
LIBID 
UNIT 
INVALID 

Definition at line 79 of file cmp_tree_model.h.

Constructor & Destructor Documentation

CMP_TREE_NODE::CMP_TREE_NODE ( )

Definition at line 106 of file cmp_tree_model.cpp.

107  : Parent( nullptr ),
108  Type( INVALID ),
109  IntrinsicRank( 0 ),
111  SearchTextNormalized( false ),
112  Unit( 0 ),
113  IsRoot( false )
114 {}
bool SearchTextNormalized
Support for lazy normalization.
enum TYPE Type
Node type.
bool IsRoot
Indicates if the symbol is a root symbol instead of an alias.
CMP_TREE_NODE * Parent
Parent node or null.
int IntrinsicRank
The rank of the item before any search terms are applied.
static const unsigned kLowestDefaultScore
int Unit
Actual unit, or zero.
int Score
The score of an item resulting from the search algorithm.
virtual CMP_TREE_NODE::~CMP_TREE_NODE ( )
inlinevirtual

Definition at line 141 of file cmp_tree_model.h.

141 {}

Member Function Documentation

void CMP_TREE_NODE::AssignIntrinsicRanks ( )

Store intrinsic ranks on all children of this node.

See IntrinsicRank member doc for more information.

Definition at line 62 of file cmp_tree_model.cpp.

References Children, i, IntrinsicRank, and MatchName.

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::AddAliasList(), CMP_TREE_MODEL_ADAPTER::AddLibrary(), LIB_MANAGER_ADAPTER::Sync(), and LIB_MANAGER_ADAPTER::updateLibrary().

63 {
64  std::vector<CMP_TREE_NODE*> sort_buf;
65 
66  for( auto const& node: Children )
67  sort_buf.push_back( &*node );
68 
69  std::sort( sort_buf.begin(), sort_buf.end(),
70  []( CMP_TREE_NODE* a, CMP_TREE_NODE* b ) -> bool
71  { return a->MatchName > b->MatchName; } );
72 
73  for( int i = 0; i < (int) sort_buf.size(); ++i )
74  sort_buf[i]->IntrinsicRank = i;
75 }
wxString MatchName
Normalized name for matching.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
PTR_VECTOR Children
List of child nodes.
size_t i
Definition: json11.cpp:597
int IntrinsicRank
The rank of the item before any search terms are applied.
int CMP_TREE_NODE::Compare ( CMP_TREE_NODE const &  aNode1,
CMP_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 91 of file cmp_tree_model.cpp.

References IntrinsicRank, Parent, Score, and Type.

Referenced by SortNodes().

92 {
93  if( aNode1.Type != aNode2.Type )
94  return 0;
95 
96  if( aNode1.Score != aNode2.Score )
97  return aNode1.Score - aNode2.Score;
98 
99  if( aNode1.Parent != aNode2.Parent )
100  return 0;
101 
102  return aNode1.IntrinsicRank - aNode2.IntrinsicRank;
103 }
void CMP_TREE_NODE::ResetScore ( )

Initialize score to kLowestDefaultScore, recursively.

Definition at line 53 of file cmp_tree_model.cpp.

References Children, kLowestDefaultScore, and Score.

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::UpdateSearchString().

54 {
55  for( auto& child: Children )
56  child->ResetScore();
57 
59 }
PTR_VECTOR Children
List of child nodes.
static const unsigned kLowestDefaultScore
int Score
The score of an item resulting from the search algorithm.
void CMP_TREE_NODE::SortNodes ( )

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

Definition at line 78 of file cmp_tree_model.cpp.

References Children, and Compare().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::UpdateSearchString().

79 {
80  std::sort( Children.begin(), Children.end(),
81  []( std::unique_ptr<CMP_TREE_NODE> const& a, std::unique_ptr<CMP_TREE_NODE> const& b )
82  { return Compare( *a, *b ) > 0; } );
83 
84  for( auto& node: Children )
85  {
86  node->SortNodes();
87  }
88 }
PTR_VECTOR Children
List of child nodes.
static int Compare(CMP_TREE_NODE const &aNode1, CMP_TREE_NODE const &aNode2)
Compare two nodes.
virtual void CMP_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 CMP_TREE_NODE_ROOT, CMP_TREE_NODE_LIB, CMP_TREE_NODE_LIB_ID, and CMP_TREE_NODE_UNIT.

Member Data Documentation

wxString CMP_TREE_NODE::Desc
int CMP_TREE_NODE::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 94 of file cmp_tree_model.h.

Referenced by AssignIntrinsicRanks(), CMP_TREE_NODE_UNIT::CMP_TREE_NODE_UNIT(), and Compare().

bool CMP_TREE_NODE::IsRoot

Indicates if the symbol is a root symbol instead of an alias.

Definition at line 108 of file cmp_tree_model.h.

Referenced by CMP_TREE_NODE_LIB_ID::Update().

LIB_ID CMP_TREE_NODE::LibId
wxString CMP_TREE_NODE::MatchName
int CMP_TREE_NODE::Score
wxString CMP_TREE_NODE::SearchText

Descriptive text to search.

Definition at line 102 of file cmp_tree_model.h.

Referenced by CMP_TREE_NODE_LIB_ID::Update(), and CMP_TREE_NODE_LIB_ID::UpdateScore().

bool CMP_TREE_NODE::SearchTextNormalized

Support for lazy normalization.

Definition at line 103 of file cmp_tree_model.h.

Referenced by CMP_TREE_NODE_LIB_ID::Update(), and CMP_TREE_NODE_LIB_ID::UpdateScore().

int CMP_TREE_NODE::Unit

Actual unit, or zero.

Definition at line 107 of file cmp_tree_model.h.

Referenced by CMP_TREE_NODE_UNIT::CMP_TREE_NODE_UNIT(), and CMP_TREE_MODEL_ADAPTER_BASE::ShowPreselect().


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