KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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_ITEM LIB_TREE_NODE_LIBRARY LIB_TREE_NODE_ROOT LIB_TREE_NODE_UNIT

Public Types

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

Public Member Functions

virtual void UpdateScore (EDA_COMBINED_MATCHER *aMatcher, const wxString &aLib, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter)=0
 Update the score for this part.
 
virtual void ResetScore ()
 Initialize scores recursively.
 
virtual void ForceScore (int aScore)
 
void AssignIntrinsicRanks (bool presorted=false)
 Store intrinsic ranks on all children of this node.
 
void SortNodes (bool aUseScores)
 Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
 
 LIB_TREE_NODE ()
 
virtual ~LIB_TREE_NODE ()
 

Static Public Member Functions

static bool Compare (LIB_TREE_NODE const &aNode1, LIB_TREE_NODE const &aNode2, bool aUseScores)
 Compare two nodes.
 

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.
 
int m_Score
 
bool m_Pinned
 
wxString m_Name
 
wxString m_Desc
 
wxString m_Footprint
 
int m_PinCount
 
std::vector< SEARCH_TERMm_SearchTerms
 
std::map< wxString, wxString > m_Fields
 List of weighted search terms.
 
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:

  • Adapter: LIB_TREE_MODEL_ADAPTER in common/lib_tree_model_adapter.h
  • View:
    • DIALOG_CHOOSE_COMPONENT in eeschema/dialogs/dialog_choose_component.h
    • wxDataViewCtrl

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

Member Enumeration Documentation

◆ TYPE

Enumerator
ROOT 
LIBRARY 
ITEM 
UNIT 
INVALID 

Definition at line 114 of file lib_tree_model.h.

Constructor & Destructor Documentation

◆ LIB_TREE_NODE()

LIB_TREE_NODE::LIB_TREE_NODE ( )

Definition at line 128 of file lib_tree_model.cpp.

◆ ~LIB_TREE_NODE()

virtual LIB_TREE_NODE::~LIB_TREE_NODE ( )
inlinevirtual

Definition at line 112 of file lib_tree_model.h.

Member Function Documentation

◆ AssignIntrinsicRanks()

void LIB_TREE_NODE::AssignIntrinsicRanks ( bool  presorted = false)

◆ Compare()

bool LIB_TREE_NODE::Compare ( LIB_TREE_NODE const &  aNode1,
LIB_TREE_NODE const &  aNode2,
bool  aUseScores 
)
static

Compare two nodes.

Returns true if aNode1 < aNode2.

Definition at line 83 of file lib_tree_model.cpp.

References m_IntrinsicRank, m_Name, m_Pinned, m_Score, and m_Type.

◆ ForceScore()

virtual void LIB_TREE_NODE::ForceScore ( int  aScore)
inlinevirtual

Definition at line 92 of file lib_tree_model.h.

References m_Score.

◆ ResetScore()

void LIB_TREE_NODE::ResetScore ( )
virtual

Initialize scores recursively.

Definition at line 33 of file lib_tree_model.cpp.

References m_Children, and m_Score.

Referenced by LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

◆ SortNodes()

void LIB_TREE_NODE::SortNodes ( bool  aUseScores)

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

Definition at line 70 of file lib_tree_model.cpp.

References m_Children.

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

◆ UpdateScore()

virtual void LIB_TREE_NODE::UpdateScore ( EDA_COMBINED_MATCHER aMatcher,
const wxString &  aLib,
std::function< bool(LIB_TREE_NODE &aNode)> *  aFilter 
)
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_UNIT, LIB_TREE_NODE_ITEM, LIB_TREE_NODE_LIBRARY, and LIB_TREE_NODE_ROOT.

Member Data Documentation

◆ m_Children

◆ m_Desc

◆ m_Fields

std::map<wxString, wxString> LIB_TREE_NODE::m_Fields

◆ m_Footprint

wxString LIB_TREE_NODE::m_Footprint

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

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

◆ m_IsRoot

◆ m_LibId

◆ m_Name

◆ m_Parent

◆ m_PinCount

int LIB_TREE_NODE::m_PinCount

◆ m_Pinned

◆ m_Score

◆ m_SearchTerms

◆ m_Type

◆ m_Unit


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