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_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 Normalized
 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...
 
int VisLen
 Length of the string as shown on screen. 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:

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

Member Enumeration Documentation

◆ TYPE

Enumerator
ROOT 
LIB 
LIBID 
UNIT 
INVALID 

Definition at line 77 of file lib_tree_model.h.

Constructor & Destructor Documentation

◆ LIB_TREE_NODE()

LIB_TREE_NODE::LIB_TREE_NODE ( )

Definition at line 115 of file lib_tree_model.cpp.

116  : Parent( nullptr ),
117  Type( INVALID ),
118  IntrinsicRank( 0 ),
120  Normalized( false ),
121  Unit( 0 ),
122  IsRoot( false )
123 {}
enum TYPE Type
Node type.
bool Normalized
Support for lazy normalization.
LIB_TREE_NODE * Parent
Parent node or null.
int Score
The score of an item resulting from the search algorithm.
static const unsigned kLowestDefaultScore
bool IsRoot
Indicates if the symbol is a root symbol instead of an alias.
int Unit
Actual unit, or zero.
int IntrinsicRank
The rank of the item before any search terms are applied.

◆ ~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 IntrinsicRank member doc for more information.

Definition at line 61 of file lib_tree_model.cpp.

62 {
63  std::vector<LIB_TREE_NODE*> sort_buf;
64 
65  if( presorted )
66  {
67  int max = Children.size() - 1;
68 
69  for( int i = 0; i <= max; ++i )
70  Children[i]->IntrinsicRank = max - i;
71  }
72  else
73  {
74  for( auto const& node: Children )
75  sort_buf.push_back( &*node );
76 
77  std::sort( sort_buf.begin(), sort_buf.end(),
78  []( LIB_TREE_NODE* a, LIB_TREE_NODE* b ) -> bool
79  { return StrNumCmp( a->Name, b->Name, true ) > 0; } );
80 
81  for( int i = 0; i < (int) sort_buf.size(); ++i )
82  sort_buf[i]->IntrinsicRank = i;
83  }
84 }
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Definition: string.cpp:354
PTR_VECTOR Children
List of child nodes.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
wxString Name
Actual name of the part.
int IntrinsicRank
The rank of the item before any search terms are applied.

References Children, IntrinsicRank, 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 100 of file lib_tree_model.cpp.

101 {
102  if( aNode1.Type != aNode2.Type )
103  return 0;
104 
105  if( aNode1.Score != aNode2.Score )
106  return aNode1.Score - aNode2.Score;
107 
108  if( aNode1.Parent != aNode2.Parent )
109  return 0;
110 
111  return aNode1.IntrinsicRank - aNode2.IntrinsicRank;
112 }

References IntrinsicRank, Parent, Score, and Type.

Referenced by SortNodes().

◆ ResetScore()

void LIB_TREE_NODE::ResetScore ( )

Initialize score to kLowestDefaultScore, recursively.

Definition at line 52 of file lib_tree_model.cpp.

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

References Children, kLowestDefaultScore, and 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 87 of file lib_tree_model.cpp.

88 {
89  std::sort( Children.begin(), Children.end(),
90  []( std::unique_ptr<LIB_TREE_NODE>& a, std::unique_ptr<LIB_TREE_NODE>& b )
91  {
92  return Compare( *a, *b ) > 0;
93  } );
94 
95  for( std::unique_ptr<LIB_TREE_NODE>& node: Children )
96  node->SortNodes();
97 }
PTR_VECTOR Children
List of child nodes.
static int Compare(LIB_TREE_NODE const &aNode1, LIB_TREE_NODE const &aNode2)
Compare two nodes.

References Children, and Compare().

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

◆ Children

◆ Desc

wxString LIB_TREE_NODE::Desc

◆ IntrinsicRank

int LIB_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 92 of file lib_tree_model.h.

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

◆ IsRoot

bool LIB_TREE_NODE::IsRoot

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

Definition at line 106 of file lib_tree_model.h.

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

◆ LibId

◆ MatchName

◆ Name

◆ Normalized

bool LIB_TREE_NODE::Normalized

Support for lazy normalization.

Definition at line 101 of file lib_tree_model.h.

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

◆ Parent

◆ Score

int LIB_TREE_NODE::Score

The score of an item resulting from the search algorithm.

Definition at line 95 of file lib_tree_model.h.

Referenced by Compare(), ResetScore(), LIB_TREE_MODEL_ADAPTER::ShowResults(), LIB_TREE_NODE_LIB_ID::UpdateScore(), and LIB_TREE_NODE_LIB::UpdateScore().

◆ SearchText

wxString LIB_TREE_NODE::SearchText

◆ Type

◆ Unit

int LIB_TREE_NODE::Unit

◆ VisLen

int LIB_TREE_NODE::VisLen

Length of the string as shown on screen.

Definition at line 107 of file lib_tree_model.h.


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