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) 2023 CERN
7 * Copyright (C) 2014-2023 KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef LIB_TREE_MODEL_H
24#define LIB_TREE_MODEL_H
25
26#include <vector>
27#include <map>
28#include <memory>
29#include <wx/string.h>
30#include <eda_pattern_match.h>
31#include <lib_tree_item.h>
32
33
76{
77public:
84 virtual void UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
85 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) = 0;
86
90 virtual void ResetScore();
91
92 virtual void ForceScore( int aScore ) { m_Score = aScore; }
93
98 void AssignIntrinsicRanks( bool presorted = false );
99
103 void SortNodes( bool aUseScores );
104
108 static bool Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2,
109 bool aUseScores );
110
112 virtual ~LIB_TREE_NODE() {}
113
114 enum class TYPE
115 {
116 ROOT,
117 LIBRARY,
118 ITEM,
119 UNIT,
120 INVALID
121 };
122
123 typedef std::vector<std::unique_ptr<LIB_TREE_NODE>> PTR_VECTOR;
124
125 LIB_TREE_NODE* m_Parent; // Parent node or null
126 PTR_VECTOR m_Children; // List of child nodes
127 enum TYPE m_Type; // Node type
128
135
136 int m_Score; // The score of an item resulting from the search algorithm.
137 bool m_Pinned; // Item should appear at top when there is no search string
138
139 wxString m_Name; // Actual name of the part
140 wxString m_Desc; // Description to be displayed
141 wxString m_Footprint; // Footprint ID as a string (ie: the footprint field text)
142 int m_PinCount; // Pin count from symbol, or unique pad count from footprint
143
144 std::vector<SEARCH_TERM> m_SearchTerms;
145 std::map<wxString, wxString> m_Fields;
146
147 LIB_ID m_LibId; // LIB_ID determined by the parent library nickname and alias name.
148 int m_Unit; // Actual unit, or zero
149 bool m_IsRoot; // Indicates if the symbol is a root symbol instead of an alias.
150};
151
152
157{
158public:
164 void operator=( LIB_TREE_NODE_UNIT const& _ ) = delete;
165
176 LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem, int aUnit );
177
178 void UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
179 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
180};
181
182
187{
188public:
194 void operator=( LIB_TREE_NODE_ITEM const& _ ) = delete;
195
209
213 void Update( LIB_TREE_ITEM* aItem );
214
218 void UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
219 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
220
221protected:
227 LIB_TREE_NODE_UNIT& AddUnit( LIB_TREE_ITEM* aItem, int aUnit );
228};
229
230
235{
236public:
242 void operator=( LIB_TREE_NODE_LIBRARY const& _ ) = delete;
243
251 LIB_TREE_NODE_LIBRARY( LIB_TREE_NODE* aParent, const wxString& aName, const wxString& aDesc );
252
259
260 void UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
261 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
262};
263
264
269{
270public:
276 void operator=( LIB_TREE_NODE_ROOT const& _ ) = delete;
277
282
286 LIB_TREE_NODE_LIBRARY& AddLib( wxString const& aName, wxString const& aDesc );
287
291 void RemoveLib( wxString const& aName );
292
296 void Clear();
297
298 void UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
299 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
300};
301
302
303#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.
void UpdateScore(EDA_COMBINED_MATCHER *aMatcher, const wxString &aLib, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) override
Perform the actual search.
LIB_TREE_NODE_ITEM(LIB_TREE_NODE_ITEM const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
void operator=(LIB_TREE_NODE_ITEM const &_)=delete
LIB_TREE_NODE_UNIT & AddUnit(LIB_TREE_ITEM *aItem, int aUnit)
Add a new unit to the component and return it.
void Update(LIB_TREE_ITEM *aItem)
Update the node using data from a LIB_ALIAS object.
Node type: library.
LIB_TREE_NODE_LIBRARY(LIB_TREE_NODE_LIBRARY const &_)=delete
The addresses of CMP_TREE_NODEs are used as unique IDs for the wxDataViewModel, so don't let them be ...
void operator=(LIB_TREE_NODE_LIBRARY const &_)=delete
LIB_TREE_NODE_ITEM & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
void UpdateScore(EDA_COMBINED_MATCHER *aMatcher, const wxString &aLib, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) override
Update the score for this part.
Node type: root.
void operator=(LIB_TREE_NODE_ROOT const &_)=delete
LIB_TREE_NODE_LIBRARY & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
void RemoveLib(wxString const &aName)
Remove a library node from the root.
void UpdateScore(EDA_COMBINED_MATCHER *aMatcher, const wxString &aLib, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) 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.
void Clear()
Clear the tree.
Node type: unit of component.
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 ...
void UpdateScore(EDA_COMBINED_MATCHER *aMatcher, const wxString &aLib, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) override
Update the score for this part.
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
virtual void ForceScore(int aScore)
wxString m_Footprint
LIB_TREE_NODE * m_Parent
virtual void ResetScore()
Initialize scores 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, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter)=0
Update the score for this part.
#define _(s)
Abstract pattern-matching tool and implementations.