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 <wx/string.h>
30#include <eda_pattern_match.h>
31#include <lib_tree_item.h>
32
33
75{
76public:
83 virtual void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
84 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) = 0;
85
89 void RebuildSearchTerms( const std::vector<wxString>& aShownColumns );
90
95 void AssignIntrinsicRanks( const std::vector<wxString>& aShownColumns, bool presorted = false );
96
100 void SortNodes( bool aUseScores );
101
105 static bool Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2,
106 bool aUseScores );
107
109 virtual ~LIB_TREE_NODE() {}
110
111 enum class TYPE
112 {
113 ROOT,
114 LIBRARY,
115 ITEM,
116 UNIT,
117 INVALID
118 };
119
120 typedef std::vector<std::unique_ptr<LIB_TREE_NODE>> PTR_VECTOR;
121
122 LIB_TREE_NODE* m_Parent; // Parent node or null
123 PTR_VECTOR m_Children; // List of child nodes
124 enum TYPE m_Type; // Node type
125
132
133 int m_Score; // The score of an item resulting from the search algorithm.
134 bool m_Pinned; // Item should appear at top when there is no search string
135
136 wxString m_Name; // Actual name of the part
137 wxString m_Desc; // Description to be displayed
138 wxString m_Footprint; // Footprint ID as a string (ie: the footprint field text)
139 int m_PinCount; // Pin count from symbol, or unique pad count from footprint
140
141 std::vector<SEARCH_TERM> m_SearchTerms;
142 std::map<wxString, wxString> m_Fields;
143
144 LIB_ID m_LibId; // LIB_ID determined by the parent library nickname and alias name.
145 int m_Unit; // Actual unit, or zero
146 bool m_IsRoot; // Indicates if the symbol is a root symbol instead of an alias.
147
150
151protected:
152 std::vector<SEARCH_TERM> m_sourceSearchTerms;
153};
154
155
160{
161public:
167 void operator=( LIB_TREE_NODE_UNIT const& _ ) = delete;
168
179 LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem, int aUnit );
180
181 void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
182 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
183};
184
185
190{
191public:
197 void operator=( LIB_TREE_NODE_ITEM const& _ ) = delete;
198
212
216 void Update( LIB_TREE_ITEM* aItem );
217
221 void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
222 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
223
224protected:
230 LIB_TREE_NODE_UNIT& AddUnit( LIB_TREE_ITEM* aItem, int aUnit );
231};
232
233
238{
239public:
245 void operator=( LIB_TREE_NODE_LIBRARY const& _ ) = delete;
246
254 LIB_TREE_NODE_LIBRARY( LIB_TREE_NODE* aParent, const wxString& aName, const wxString& aDesc );
255
262
263 void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
264 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
265};
266
267
272{
273public:
279 void operator=( LIB_TREE_NODE_ROOT const& _ ) = delete;
280
285
289 LIB_TREE_NODE_LIBRARY& AddLib( wxString const& aName, wxString const& aDesc );
290
294 void RemoveGroup( bool aRecentlyUsedGroup, bool aAlreadyPlacedGroup );
295
299 void Clear();
300
301 void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
302 std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) override;
303};
304
305
306#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(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.
Node type: root.
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.
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).
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.
enum TYPE m_Type
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
bool m_IsRecentlyUsedGroup
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.