KiCad PCB EDA Suite
lib_tree_model.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2017 Chris Pavlina <[email protected]>
5 * Copyright (C) 2014 Henner Zeller <[email protected]>
6 * Copyright (C) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef LIB_TREE_MODEL_H
23#define LIB_TREE_MODEL_H
24
25#include <vector>
26#include <map>
27#include <memory>
28#include <wx/string.h>
29#include <lib_tree_item.h>
30
31
33
34
77{
78public:
85 virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) = 0;
86
90 void ResetScore();
91
96 void AssignIntrinsicRanks( bool presorted = false );
97
101 void SortNodes();
102
107 static int Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2 );
108
110 virtual ~LIB_TREE_NODE() {}
111
112 enum TYPE {
114 };
115
116 typedef std::vector<std::unique_ptr<LIB_TREE_NODE>> PTR_VECTOR;
117
118 LIB_TREE_NODE* m_Parent; // Parent node or null
119 PTR_VECTOR m_Children; // List of child nodes
120 enum TYPE m_Type; // Node type
121
128
129 int m_Score; // The score of an item resulting from the search algorithm.
130 bool m_Pinned; // Item should appear at top when there is no search string
131
132 wxString m_Name; // Actual name of the part
133 wxString m_Desc; // Description to be displayed
134 wxString m_Footprint; // Footprint ID as a string (ie: the footprint field text)
135 wxString m_MatchName; // Normalized name for matching
136 wxString m_SearchText; // Descriptive text to search
137 bool m_Normalized; // Support for lazy normalization.
138
140 std::map<wxString, wxString> m_Fields;
141
142 LIB_ID m_LibId; // LIB_ID determined by the parent library nickname and alias name.
143 int m_Unit; // Actual unit, or zero
144 bool m_IsRoot; // Indicates if the symbol is a root symbol instead of an alias.
145};
146
147
152{
153public:
159 void operator=( LIB_TREE_NODE_UNIT const& _ ) = delete;
160
171 LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem, int aUnit );
172
173
177 virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) override {}
178};
179
180
185{
186public:
192 void operator=( LIB_TREE_NODE_LIB_ID const& _ ) = delete;
193
207
211 void Update( LIB_TREE_ITEM* aItem );
212
216 virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) override;
217
218protected:
224 LIB_TREE_NODE_UNIT& AddUnit( LIB_TREE_ITEM* aItem, int aUnit );
225};
226
227
232{
233public:
239 void operator=( LIB_TREE_NODE_LIB const& _ ) = delete;
240
248 LIB_TREE_NODE_LIB( LIB_TREE_NODE* aParent, const wxString& aName, const wxString& aDesc );
249
256
257 virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) override;
258};
259
260
265{
266public:
272 void operator=( LIB_TREE_NODE_ROOT const& _ ) = delete;
273
278
282 LIB_TREE_NODE_LIB& AddLib( wxString const& aName, wxString const& aDesc );
283
284 virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) override;
285};
286
287
288#endif // LIB_TREE_MODEL_H
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:40
Node type: LIB_ID.
LIB_TREE_NODE_UNIT & AddUnit(LIB_TREE_ITEM *aItem, int aUnit)
Add a new unit to the component and return it.
void operator=(LIB_TREE_NODE_LIB_ID const &_)=delete
void Update(LIB_TREE_ITEM *aItem)
Update the node using data from a LIB_ALIAS object.
LIB_TREE_NODE_LIB_ID(LIB_TREE_NODE_LIB_ID const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher, const wxString &aLib) override
Perform the actual search.
Node type: library.
LIB_TREE_NODE_LIB_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
void operator=(LIB_TREE_NODE_LIB const &_)=delete
LIB_TREE_NODE_LIB(LIB_TREE_NODE_LIB const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher, const wxString &aLib) override
Update the score for this part.
Node type: root.
void operator=(LIB_TREE_NODE_ROOT const &_)=delete
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher, const wxString &aLib) override
Update the score for this part.
LIB_TREE_NODE_ROOT(LIB_TREE_NODE_ROOT const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
LIB_TREE_NODE_ROOT()
Construct the root node.
LIB_TREE_NODE_LIB & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
Node type: unit of component.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher, const wxString &aLib) override
Do nothing, units just take the parent's score.
void operator=(LIB_TREE_NODE_UNIT const &_)=delete
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 ...
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
enum TYPE m_Type
std::map< wxString, wxString > m_Fields
virtual ~LIB_TREE_NODE()
PTR_VECTOR m_Children
wxString m_SearchText
wxString m_Footprint
LIB_TREE_NODE * m_Parent
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
int m_IntrinsicRank
The rank of the item before any search terms are applied.
static int Compare(LIB_TREE_NODE const &aNode1, LIB_TREE_NODE const &aNode2)
Compare two nodes.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
std::vector< std::unique_ptr< LIB_TREE_NODE > > PTR_VECTOR
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher, const wxString &aLib)=0
Update the score for this part.
wxString m_MatchName
#define _(s)