KiCad PCB EDA Suite
CMP_TREE_NODE_UNIT Class Reference

Node type: unit of component. More...

#include <cmp_tree_model.h>

Inheritance diagram for CMP_TREE_NODE_UNIT:
CMP_TREE_NODE

Public Types

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

Public Member Functions

 CMP_TREE_NODE_UNIT (CMP_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= (CMP_TREE_NODE_UNIT const &_)=delete
 
 CMP_TREE_NODE_UNIT (CMP_TREE_NODE *aParent, 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 ()
 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 (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...
 
bool InTree
 Flag indicating whether the node is added to the tree. 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...
 
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

Node type: unit of component.

Definition at line 147 of file cmp_tree_model.h.

Member Typedef Documentation

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

Definition at line 83 of file cmp_tree_model.h.

Member Enumeration Documentation

enum CMP_TREE_NODE::TYPE
inherited
Enumerator
ROOT 
LIB 
LIBID 
UNIT 
INVALID 

Definition at line 79 of file cmp_tree_model.h.

Constructor & Destructor Documentation

CMP_TREE_NODE_UNIT::CMP_TREE_NODE_UNIT ( CMP_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.

CMP_TREE_NODE_UNIT::CMP_TREE_NODE_UNIT ( CMP_TREE_NODE aParent,
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
aUnitunit number

Definition at line 115 of file cmp_tree_model.cpp.

References CMP_TREE_NODE::Desc, CMP_TREE_NODE::IntrinsicRank, CMP_TREE_NODE::LibId, CMP_TREE_NODE::MatchName, CMP_TREE_NODE::Name, CMP_TREE_NODE::Parent, LIB_PART::SubReference(), CMP_TREE_NODE::Type, CMP_TREE_NODE::UNIT, and CMP_TREE_NODE::Unit.

116 {
117  Parent = aParent;
118  Type = UNIT;
119 
120  Unit = aUnit;
121  LibId = aParent->LibId;
122 
123  Name = _( "Unit" ) + " " + LIB_PART::SubReference( aUnit, false );
124  Desc = wxEmptyString;
125  MatchName = wxEmptyString;
126 
127  IntrinsicRank = -aUnit;
128 }
wxString Name
Actual name of the part.
wxString Desc
Description to be displayed.
enum TYPE Type
Node type.
LIB_ID LibId
LIB_ID determined by the parent library nickname and alias name.
wxString MatchName
Normalized name for matching.
CMP_TREE_NODE * Parent
Parent node or null.
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Function SubReference.
int IntrinsicRank
The rank of the item before any search terms are applied.
int Unit
Actual unit, or zero.

Member Function Documentation

void CMP_TREE_NODE::AssignIntrinsicRanks ( )
inherited

Store intrinsic ranks on all children of this node.

See IntrinsicRank member doc for more information.

Definition at line 61 of file cmp_tree_model.cpp.

References CMP_TREE_NODE::Children, CMP_TREE_NODE::IntrinsicRank, and CMP_TREE_NODE::MatchName.

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

62 {
63  std::vector<CMP_TREE_NODE*> sort_buf;
64 
65  for( auto const& node: Children )
66  sort_buf.push_back( &*node );
67 
68  std::sort( sort_buf.begin(), sort_buf.end(),
69  []( CMP_TREE_NODE* a, CMP_TREE_NODE* b ) -> bool
70  { return a->MatchName > b->MatchName; } );
71 
72  for( int i = 0; i < (int) sort_buf.size(); ++i )
73  sort_buf[i]->IntrinsicRank = i;
74 }
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.
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 
)
staticinherited

Compare two nodes.

Returns negative if aNode1 < aNode2, zero if aNode1 == aNode2, or positive if aNode1 > aNode2.

Definition at line 90 of file cmp_tree_model.cpp.

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

Referenced by CMP_TREE_NODE::SortNodes().

91 {
92  if( aNode1.Type != aNode2.Type )
93  return 0;
94 
95  if( aNode1.Score != aNode2.Score )
96  return aNode1.Score - aNode2.Score;
97 
98  if( aNode1.Parent != aNode2.Parent )
99  return 0;
100 
101  return aNode1.IntrinsicRank - aNode2.IntrinsicRank;
102 }
void CMP_TREE_NODE_UNIT::operator= ( CMP_TREE_NODE_UNIT const &  _)
delete
void CMP_TREE_NODE::ResetScore ( )
inherited

Initialize score to kLowestDefaultScore, recursively.

Definition at line 52 of file cmp_tree_model.cpp.

References CMP_TREE_NODE::Children, kLowestDefaultScore, and CMP_TREE_NODE::Score.

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::UpdateSearchString().

53 {
54  for( auto& child: Children )
55  child->ResetScore();
56 
58 }
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 ( )
inherited

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

Definition at line 77 of file cmp_tree_model.cpp.

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

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::filterContents().

78 {
79  std::sort( Children.begin(), Children.end(),
80  []( std::unique_ptr<CMP_TREE_NODE> const& a, std::unique_ptr<CMP_TREE_NODE> const& b )
81  { return Compare( *a, *b ) > 0; } );
82 
83  for( auto& node: Children )
84  {
85  node->SortNodes();
86  }
87 }
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_UNIT::UpdateScore ( EDA_COMBINED_MATCHER aMatcher)
inlineoverridevirtual

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

Implements CMP_TREE_NODE.

Definition at line 174 of file cmp_tree_model.h.

174 {}

Member Data Documentation

wxString CMP_TREE_NODE::Desc
inherited

Description to be displayed.

Definition at line 101 of file cmp_tree_model.h.

Referenced by CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID(), CMP_TREE_NODE_UNIT(), and CMP_TREE_MODEL_ADAPTER_BASE::WidthFor().

bool CMP_TREE_NODE::InTree
inherited

Flag indicating whether the node is added to the tree.

Definition at line 88 of file cmp_tree_model.h.

Referenced by CMP_TREE_NODE_LIB::AddAlias(), CMP_TREE_NODE_ROOT::AddLib(), and CMP_TREE_NODE_LIB_ID::AddUnit().

int CMP_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 95 of file cmp_tree_model.h.

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

bool CMP_TREE_NODE::IsRoot
inherited

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

Definition at line 107 of file cmp_tree_model.h.

Referenced by CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID().

LIB_ID CMP_TREE_NODE::LibId
inherited

LIB_ID determined by the parent library nickname and alias name.

Definition at line 105 of file cmp_tree_model.h.

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

wxString CMP_TREE_NODE::MatchName
inherited
int CMP_TREE_NODE::Score
inherited
wxString CMP_TREE_NODE::SearchText
inherited

Descriptive text to search.

Definition at line 103 of file cmp_tree_model.h.

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

int CMP_TREE_NODE::Unit
inherited

Actual unit, or zero.

Definition at line 106 of file cmp_tree_model.h.

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


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