KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 <eda_pattern_match.h>
30#include <lib_tree_item.h>
31
32
75{
76public:
83 virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) = 0;
84
88 void ResetScore();
89
94 void AssignIntrinsicRanks( bool presorted = false );
95
99 void SortNodes( bool aUseScores );
100
104 static bool Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2,
105 bool aUseScores );
106
108 virtual ~LIB_TREE_NODE() {}
109
110 enum TYPE
111 {
116 INVALID
117 };
118
119 typedef std::vector<std::unique_ptr<LIB_TREE_NODE>> PTR_VECTOR;
120
121 LIB_TREE_NODE* m_Parent; // Parent node or null
122 PTR_VECTOR m_Children; // List of child nodes
123 enum TYPE m_Type; // Node type
124
131
132 int m_Score; // The score of an item resulting from the search algorithm.
133 bool m_Pinned; // Item should appear at top when there is no search string
134
135 wxString m_Name; // Actual name of the part
136 wxString m_Desc; // Description to be displayed
137 wxString m_Footprint; // Footprint ID as a string (ie: the footprint field text)
138
139 std::vector<SEARCH_TERM> m_SearchTerms;
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:41
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(bool aUseScores)
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
static bool Compare(LIB_TREE_NODE const &aNode1, LIB_TREE_NODE const &aNode2, bool aUseScores)
Compare two nodes.
enum TYPE m_Type
std::vector< SEARCH_TERM > m_SearchTerms
std::map< wxString, wxString > m_Fields
List of weighted search terms.
virtual ~LIB_TREE_NODE()
PTR_VECTOR m_Children
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.
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.
#define _(s)
Abstract pattern-matching tool and implementations.