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
96 void AssignIntrinsicRanks( bool presorted = false );
97
101 void SortNodes( bool aUseScores );
102
106 static bool Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2,
107 bool aUseScores );
108
110 virtual ~LIB_TREE_NODE() {}
111
112 enum TYPE
113 {
118 INVALID
119 };
120
121 typedef std::vector<std::unique_ptr<LIB_TREE_NODE>> PTR_VECTOR;
122
123 LIB_TREE_NODE* m_Parent; // Parent node or null
124 PTR_VECTOR m_Children; // List of child nodes
125 enum TYPE m_Type; // Node type
126
133
134 int m_Score; // The score of an item resulting from the search algorithm.
135 bool m_Pinned; // Item should appear at top when there is no search string
136
137 wxString m_Name; // Actual name of the part
138 wxString m_Desc; // Description to be displayed
139 wxString m_Footprint; // Footprint ID as a string (ie: the footprint field text)
140 int m_PinCount; // Pin count from symbol, or unique pad count from footprint
141
142 std::vector<SEARCH_TERM> m_SearchTerms;
143 std::map<wxString, wxString> m_Fields;
144
145 LIB_ID m_LibId; // LIB_ID determined by the parent library nickname and alias name.
146 int m_Unit; // Actual unit, or zero
147 bool m_IsRoot; // Indicates if the symbol is a root symbol instead of an alias.
148};
149
150
155{
156public:
162 void operator=( LIB_TREE_NODE_UNIT const& _ ) = delete;
163
174 LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem, int aUnit );
175
176 void UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
177 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
178};
179
180
185{
186public:
192 void operator=( LIB_TREE_NODE_ITEM const& _ ) = delete;
193
207
211 void Update( LIB_TREE_ITEM* aItem );
212
216 void UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
217 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
218
219protected:
225 LIB_TREE_NODE_UNIT& AddUnit( LIB_TREE_ITEM* aItem, int aUnit );
226};
227
228
233{
234public:
240 void operator=( LIB_TREE_NODE_LIBRARY const& _ ) = delete;
241
249 LIB_TREE_NODE_LIBRARY( LIB_TREE_NODE* aParent, const wxString& aName, const wxString& aDesc );
250
257
258 void UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
259 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
260};
261
262
267{
268public:
274 void operator=( LIB_TREE_NODE_ROOT const& _ ) = delete;
275
280
284 LIB_TREE_NODE_LIBRARY& AddLib( wxString const& aName, wxString const& aDesc );
285
286 void UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
287 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
288};
289
290
291#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 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.
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
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.