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 The 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 <span>
30#include <wx/string.h>
31#include <eda_pattern_match.h>
32#include <lib_tree_item.h>
33
34
76{
77public:
84 virtual void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
85 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) = 0;
86
90 void RebuildSearchTerms( const std::vector<wxString>& aShownColumns );
91
96 void AssignIntrinsicRanks( const std::vector<wxString>& aShownColumns, 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
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 bool m_IsPower; // Indicates if the symbol is a local or global power symbol
149
152
153protected:
154 std::vector<SEARCH_TERM> m_sourceSearchTerms;
155};
156
157
162{
163public:
169 void operator=( LIB_TREE_NODE_UNIT const& _ ) = delete;
170
181 LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem, int aUnit );
182
183 void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
184 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
185};
186
187
192{
193public:
199 void operator=( LIB_TREE_NODE_ITEM const& _ ) = delete;
200
214
218 void Update( LIB_TREE_ITEM* aItem );
219
223 void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
224 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
225
226protected:
232 LIB_TREE_NODE_UNIT& AddUnit( LIB_TREE_ITEM* aItem, int aUnit );
233};
234
235
240{
241public:
247 void operator=( LIB_TREE_NODE_LIBRARY const& _ ) = delete;
248
256 LIB_TREE_NODE_LIBRARY( LIB_TREE_NODE* aParent, const wxString& aName, const wxString& aDesc );
257
264
265 void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
266 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
267};
268
269
274{
275public:
281 void operator=( LIB_TREE_NODE_ROOT const& _ ) = delete;
282
287
291 LIB_TREE_NODE_LIBRARY& AddLib( wxString const& aName, wxString const& aDesc );
292
296 void RemoveGroup( bool aRecentlyUsedGroup, bool aAlreadyPlacedGroup );
297
301 void Clear();
302
303 void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
304 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
305};
306
307
308#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).
Node type: LIB_ID.
void UpdateScore(const std::vector< std::unique_ptr< EDA_COMBINED_MATCHER > > &aMatchers, 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 UpdateScore(const std::vector< std::unique_ptr< EDA_COMBINED_MATCHER > > &aMatchers, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) override
Update the score for this part.
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 operator=(LIB_TREE_NODE_ROOT const &_)=delete
void RemoveGroup(bool aRecentlyUsedGroup, bool aAlreadyPlacedGroup)
Remove a library node from the root.
LIB_TREE_NODE_LIBRARY & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
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 UpdateScore(const std::vector< std::unique_ptr< EDA_COMBINED_MATCHER > > &aMatchers, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) override
Update the score for this part.
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(const std::vector< std::unique_ptr< EDA_COMBINED_MATCHER > > &aMatchers, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) override
Update the score for this part.
void SortNodes(bool aUseScores)
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
void RebuildSearchTerms(const std::vector< wxString > &aShownColumns)
Rebuild search terms from source search terms and shown fields.
static bool Compare(LIB_TREE_NODE const &aNode1, LIB_TREE_NODE const &aNode2, bool aUseScores)
Compare two nodes.
std::vector< SEARCH_TERM > m_sourceSearchTerms
virtual void UpdateScore(const std::vector< std::unique_ptr< EDA_COMBINED_MATCHER > > &aMatchers, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter)=0
Update the score for this part.
bool m_IsAlreadyPlacedGroup
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
int m_IntrinsicRank
The rank of the item before any search terms are applied.
std::vector< std::unique_ptr< LIB_TREE_NODE > > PTR_VECTOR
void AssignIntrinsicRanks(const std::vector< wxString > &aShownColumns, bool presorted=false)
Store intrinsic ranks on all children of this node.
#define _(s)
Abstract pattern-matching tool and implementations.