KiCad PCB EDA Suite
LIB_TREE_NODE_UNIT Class Reference

Node type: unit of component. More...

#include <lib_tree_model.h>

Inheritance diagram for LIB_TREE_NODE_UNIT:
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_UNIT (LIB_TREE_NODE_UNIT 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_UNIT const &_)=delete
 
 LIB_TREE_NODE_UNIT (LIB_TREE_NODE *aParent, LIB_TREE_ITEM *aItem, int aUnit)
 Construct a unit node. More...
 
virtual void UpdateScore (EDA_COMBINED_MATCHER &aMatcher) override
 Do nothing, units just take the parent's score. 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_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

Node type: unit of component.

Definition at line 147 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 81 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 77 of file lib_tree_model.h.

Constructor & Destructor Documentation

◆ LIB_TREE_NODE_UNIT() [1/2]

LIB_TREE_NODE_UNIT::LIB_TREE_NODE_UNIT ( LIB_TREE_NODE_UNIT 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_UNIT() [2/2]

LIB_TREE_NODE_UNIT::LIB_TREE_NODE_UNIT ( LIB_TREE_NODE aParent,
LIB_TREE_ITEM aItem,
int  aUnit 
)

Construct a unit node.

The name of the unit will be "Unit %s", where s is aUnit formatted by LIB_PART::SubReference.

Parameters
aParentparent node, should be a CMP_TREE_NODE_ALIAS
aItemparent item
aUnitunit number

Definition at line 128 of file lib_tree_model.cpp.

129 {
130  static void* locale = nullptr;
131  static wxString namePrefix;
132 
133  // Fetching translations can take a surprising amount of time when loading libraries,
134  // so only do it when necessary.
135  if( Pgm().GetLocale() != locale )
136  {
137  namePrefix = _( "Unit" );
138  locale = Pgm().GetLocale();
139  }
140 
141  Parent = aParent;
142  Type = UNIT;
143 
144  Unit = aUnit;
145  LibId = aParent->LibId;
146 
147  Name = namePrefix + " " + aItem->GetUnitReference( aUnit );
148  Desc = wxEmptyString;
149  MatchName = wxEmptyString;
150 
151  IntrinsicRank = -aUnit;
152 }
enum TYPE Type
Node type.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
LIB_TREE_NODE * Parent
Parent node or null.
wxString MatchName
Normalized name for matching.
VTBL_ENTRY wxLocale * GetLocale()
Definition: pgm_base.h:220
LIB_ID LibId
LIB_ID determined by the parent library nickname and alias name.
wxString Desc
Description to be displayed.
wxString Name
Actual name of the part.
int Unit
Actual unit, or zero.
int IntrinsicRank
The rank of the item before any search terms are applied.
virtual wxString GetUnitReference(int aUnit)
For items with units, return an identifier for unit x.
Definition: lib_tree_item.h:64

References LIB_TREE_NODE::Desc, PGM_BASE::GetLocale(), LIB_TREE_ITEM::GetUnitReference(), LIB_TREE_NODE::IntrinsicRank, LIB_TREE_NODE::LibId, LIB_TREE_NODE::MatchName, LIB_TREE_NODE::Name, LIB_TREE_NODE::Parent, Pgm(), LIB_TREE_NODE::Type, LIB_TREE_NODE::UNIT, and LIB_TREE_NODE::Unit.

Member Function Documentation

◆ AssignIntrinsicRanks()

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

Store intrinsic ranks on all children of this node.

See 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 = Children.size() - 1;
69 
70  for( int i = 0; i <= max; ++i )
72  }
73  else
74  {
75  for( auto const& node: 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  { return StrNumCmp( a->Name, b->Name, true ) > 0; } );
81 
82  for( int i = 0; i < (int) sort_buf.size(); ++i )
83  sort_buf[i]->IntrinsicRank = i;
84  }
85 }
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Definition: string.cpp:342
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.
#define max(a, b)
Definition: auxiliary.h:86
size_t i
Definition: json11.cpp:597
int IntrinsicRank
The rank of the item before any search terms are applied.

References LIB_TREE_NODE::Children, i, LIB_TREE_NODE::IntrinsicRank, max, LIB_TREE_NODE::Name, and StrNumCmp().

Referenced by FP_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks(), 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 101 of file lib_tree_model.cpp.

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

References LIB_TREE_NODE::IntrinsicRank, LIB_TREE_NODE::Parent, LIB_TREE_NODE::Score, and LIB_TREE_NODE::Type.

Referenced by LIB_TREE_NODE::SortNodes().

◆ operator=()

void LIB_TREE_NODE_UNIT::operator= ( LIB_TREE_NODE_UNIT 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( auto& child: Children )
56  child->ResetScore();
57 
59 }
PTR_VECTOR Children
List of child nodes.
int Score
The score of an item resulting from the search algorithm.
static const unsigned kLowestDefaultScore

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

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

References LIB_TREE_NODE::Children, and LIB_TREE_NODE::Compare().

Referenced by LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

◆ UpdateScore()

virtual void LIB_TREE_NODE_UNIT::UpdateScore ( EDA_COMBINED_MATCHER aMatcher)
inlineoverridevirtual

Do nothing, units just take the parent's score.

Implements LIB_TREE_NODE.

Definition at line 175 of file lib_tree_model.h.

175 {}

Member Data Documentation

◆ Children

◆ Desc

wxString LIB_TREE_NODE::Desc
inherited

◆ IntrinsicRank

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

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

◆ IsRoot

bool LIB_TREE_NODE::IsRoot
inherited

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

LIB_ID LIB_TREE_NODE::LibId
inherited

◆ MatchName

wxString LIB_TREE_NODE::MatchName
inherited

◆ Name

◆ Normalized

bool LIB_TREE_NODE::Normalized
inherited

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
inherited

The score of an item resulting from the search algorithm.

Definition at line 95 of file lib_tree_model.h.

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

◆ SearchText

wxString LIB_TREE_NODE::SearchText
inherited

◆ Type

◆ Unit

int LIB_TREE_NODE::Unit
inherited

Actual unit, or zero.

Definition at line 105 of file lib_tree_model.h.

Referenced by LIB_TREE_NODE_UNIT(), and LIB_TREE_MODEL_ADAPTER::ShowPreselect().

◆ VisLen

int LIB_TREE_NODE::VisLen
inherited

Length of the string as shown on screen.

Definition at line 107 of file lib_tree_model.h.

Referenced by LIB_TREE_MODEL_ADAPTER::DoAddLibrary().


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