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, const wxString &aLib) 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 bool Compare (LIB_TREE_NODE const &aNode1, LIB_TREE_NODE const &aNode2)
 Compare two nodes. More...
 

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. More...
 
int m_Score
 
bool m_Pinned
 
wxString m_Name
 
wxString m_Desc
 
wxString m_Footprint
 
wxString m_MatchName
 
wxString m_SearchText
 
bool m_Normalized
 
std::map< wxString, wxString > m_Fields
 
LIB_ID m_LibId
 
int m_Unit
 
bool m_IsRoot
 

Detailed Description

Node type: unit of component.

Definition at line 150 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 115 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 111 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 150 of file lib_tree_model.cpp.

151{
152 static void* locale = nullptr;
153 static wxString namePrefix;
154
155 // Fetching translations can take a surprising amount of time when loading libraries,
156 // so only do it when necessary.
157 if( Pgm().GetLocale() != locale )
158 {
159 namePrefix = _( "Unit" );
160 locale = Pgm().GetLocale();
161 }
162
163 m_Parent = aParent;
164 m_Type = UNIT;
165
166 m_Unit = aUnit;
167 m_LibId = aParent->m_LibId;
168
169 m_Name = namePrefix + " " + aItem->GetUnitReference( aUnit );
170
171 if( aItem->HasUnitDisplayName( aUnit ) )
172 {
173 m_Desc = aItem->GetUnitDisplayName( aUnit );
174 }
175 else
176 {
177 m_Desc = wxEmptyString;
178 }
179
180 m_MatchName = wxEmptyString;
181
182 m_IntrinsicRank = -aUnit;
183}
virtual wxString GetUnitReference(int aUnit)
For items with units, return an identifier for unit x.
Definition: lib_tree_item.h:78
virtual bool HasUnitDisplayName(int aUnit)
For items with units, return true if a display name is set for x.
Definition: lib_tree_item.h:88
virtual wxString GetUnitDisplayName(int aUnit)
For items with units, return a display name for unit x.
Definition: lib_tree_item.h:83
enum TYPE m_Type
LIB_TREE_NODE * m_Parent
int m_IntrinsicRank
The rank of the item before any search terms are applied.
wxString m_MatchName
#define _(s)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

References _, LIB_TREE_ITEM::GetUnitDisplayName(), LIB_TREE_ITEM::GetUnitReference(), LIB_TREE_ITEM::HasUnitDisplayName(), LIB_TREE_NODE::m_Desc, LIB_TREE_NODE::m_IntrinsicRank, LIB_TREE_NODE::m_LibId, LIB_TREE_NODE::m_MatchName, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Parent, LIB_TREE_NODE::m_Type, LIB_TREE_NODE::m_Unit, Pgm(), 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 m_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 = m_Children.size() - 1;
69
70 for( int i = 0; i <= max; ++i )
71 m_Children[i]->m_IntrinsicRank = max - i;
72 }
73 else
74 {
75 for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
76 sort_buf.push_back( child.get() );
77
78 std::sort( sort_buf.begin(), sort_buf.end(),
79 []( LIB_TREE_NODE* a, LIB_TREE_NODE* b ) -> bool
80 {
81 return StrNumCmp( a->m_Name, b->m_Name, true ) > 0;
82 } );
83
84 for( int i = 0; i < (int) sort_buf.size(); ++i )
85 sort_buf[i]->m_IntrinsicRank = i;
86 }
87}
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
PTR_VECTOR m_Children

References LIB_TREE_NODE::m_Children, and LIB_TREE_NODE::m_IntrinsicRank.

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), FP_TREE_MODEL_ADAPTER::AddLibraries(), LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks(), LIB_TREE_MODEL_ADAPTER::DoAddLibrary(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync(), FP_TREE_SYNCHRONIZING_ADAPTER::Sync(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary(), and FP_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

◆ Compare()

bool LIB_TREE_NODE::Compare ( LIB_TREE_NODE const &  aNode1,
LIB_TREE_NODE const &  aNode2 
)
staticinherited

Compare two nodes.

Returns true if aNode1 < aNode2.

Definition at line 103 of file lib_tree_model.cpp.

104{
105 if( aNode1.m_Type != aNode2.m_Type )
106 return aNode1.m_Type < aNode2.m_Type;
107
108 // Recently used sorts at top
109 if( aNode1.m_Name.StartsWith( wxT( "-- " ) ) )
110 {
111 if( aNode2.m_Name.StartsWith( wxT( "-- " ) ) )
112 {
113 return aNode1.m_IntrinsicRank > aNode2.m_IntrinsicRank;
114 }
115 else
116 {
117 return true;
118 }
119 }
120 else if( aNode2.m_Name.StartsWith( wxT( "-- " ) ) )
121 {
122 return false;
123 }
124
125 // Pinned nodes go next
126 if( aNode1.m_Pinned && !aNode2.m_Pinned )
127 return true;
128 else if( aNode2.m_Pinned && !aNode1.m_Pinned )
129 return false;
130
131 if( aNode1.m_IntrinsicRank != aNode2.m_IntrinsicRank )
132 return aNode1.m_IntrinsicRank > aNode2.m_IntrinsicRank;
133
134 return reinterpret_cast<const void*>( &aNode1 ) < reinterpret_cast<const void*>( &aNode2 );
135}

References LIB_TREE_NODE::m_IntrinsicRank, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Pinned, and LIB_TREE_NODE::m_Type.

◆ 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( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
56 child->ResetScore();
57
59}
static const unsigned kLowestDefaultScore

References kLowestDefaultScore, LIB_TREE_NODE::m_Children, and LIB_TREE_NODE::m_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 90 of file lib_tree_model.cpp.

91{
92 std::sort( m_Children.begin(), m_Children.end(),
93 []( std::unique_ptr<LIB_TREE_NODE>& a, std::unique_ptr<LIB_TREE_NODE>& b )
94 {
95 return Compare( *a, *b );
96 } );
97
98 for( std::unique_ptr<LIB_TREE_NODE>& node: m_Children )
99 node->SortNodes();
100}

References LIB_TREE_NODE::m_Children.

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

◆ UpdateScore()

virtual void LIB_TREE_NODE_UNIT::UpdateScore ( EDA_COMBINED_MATCHER aMatcher,
const wxString &  aLib 
)
inlineoverridevirtual

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

Implements LIB_TREE_NODE.

Definition at line 176 of file lib_tree_model.h.

176{}

Member Data Documentation

◆ m_Children

◆ m_Desc

◆ m_Fields

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

◆ m_Footprint

wxString LIB_TREE_NODE::m_Footprint
inherited

◆ m_IntrinsicRank

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

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

◆ m_IsRoot

◆ m_LibId

◆ m_MatchName

◆ m_Name

◆ m_Normalized

bool LIB_TREE_NODE::m_Normalized
inherited

◆ m_Parent

◆ m_Pinned

◆ m_Score

◆ m_SearchText

wxString LIB_TREE_NODE::m_SearchText
inherited

◆ m_Type

◆ m_Unit


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