KiCad PCB EDA Suite
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 <pavlina.chris@gmail.com>
5  * Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
6  * Copyright (C) 2014-2020 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 <memory>
27 #include <wx/string.h>
28 #include <lib_tree_item.h>
29 
30 
32 
33 
76 {
77 public:
84  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) = 0;
85 
89  void ResetScore();
90 
95  void AssignIntrinsicRanks( bool presorted = false );
96 
100  void SortNodes();
101 
106  static int Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2 );
107 
108  LIB_TREE_NODE();
109  virtual ~LIB_TREE_NODE() {}
110 
111  enum TYPE {
113  };
114 
115  typedef std::vector<std::unique_ptr<LIB_TREE_NODE>> PTR_VECTOR;
116 
117  LIB_TREE_NODE* m_Parent; // Parent node or null
118  PTR_VECTOR m_Children; // List of child nodes
119  enum TYPE m_Type; // Node type
120 
127 
128  int m_Score; // The score of an item resulting from the search algorithm.
129  bool m_Pinned; // Item should appear at top when there is no search string
130 
131  wxString m_Name; // Actual name of the part
132  wxString m_Desc; // Description to be displayed
133  wxString m_MatchName; // Normalized name for matching
134  wxString m_SearchText; // Descriptive text to search
135  bool m_Normalized; // Support for lazy normalization.
136 
137 
138  LIB_ID m_LibId; // LIB_ID determined by the parent library nickname and alias name.
139  int m_Unit; // Actual unit, or zero
140  bool m_IsRoot; // Indicates if the symbol is a root symbol instead of an alias.
141 };
142 
143 
148 {
149 public:
154  LIB_TREE_NODE_UNIT( LIB_TREE_NODE_UNIT const& _ ) = delete;
155  void operator=( LIB_TREE_NODE_UNIT const& _ ) = delete;
156 
167  LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem, int aUnit );
168 
169 
173  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override {}
174 };
175 
176 
181 {
182 public:
187  LIB_TREE_NODE_LIB_ID( LIB_TREE_NODE_LIB_ID const& _ ) = delete;
188  void operator=( LIB_TREE_NODE_LIB_ID const& _ ) = delete;
189 
203 
207  void Update( LIB_TREE_ITEM* aItem );
208 
212  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
213 
214 protected:
220  LIB_TREE_NODE_UNIT& AddUnit( LIB_TREE_ITEM* aItem, int aUnit );
221 };
222 
223 
228 {
229 public:
234  LIB_TREE_NODE_LIB( LIB_TREE_NODE_LIB const& _ ) = delete;
235  void operator=( LIB_TREE_NODE_LIB const& _ ) = delete;
236 
244  LIB_TREE_NODE_LIB( LIB_TREE_NODE* aParent, wxString const& aName, wxString const& aDesc );
245 
252 
253  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
254 };
255 
256 
261 {
262 public:
267  LIB_TREE_NODE_ROOT( LIB_TREE_NODE_ROOT const& _ ) = delete;
268  void operator=( LIB_TREE_NODE_ROOT const& _ ) = delete;
269 
274 
278  LIB_TREE_NODE_LIB& AddLib( wxString const& aName, wxString const& aDesc );
279 
280  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
281 };
282 
283 
284 #endif // LIB_TREE_MODEL_H
void operator=(LIB_TREE_NODE_LIB_ID const &_)=delete
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
static int Compare(LIB_TREE_NODE const &aNode1, LIB_TREE_NODE const &aNode2)
Compare two nodes.
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:39
Node type: LIB_ID.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Perform the actual search.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
int m_IntrinsicRank
The rank of the item before any search terms are applied.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher)=0
Update the score for this part.
void operator=(LIB_TREE_NODE_ROOT const &_)=delete
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_UNIT const &_)=delete
Node type: root.
LIB_TREE_NODE * m_Parent
Node type: library.
LIB_TREE_NODE_UNIT & AddUnit(LIB_TREE_ITEM *aItem, int aUnit)
Add a new unit to the component and return it.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
void operator=(LIB_TREE_NODE_LIB const &_)=delete
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
Node type: unit of component.
LIB_TREE_NODE_LIB & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
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 ...
std::vector< std::unique_ptr< LIB_TREE_NODE > > PTR_VECTOR
#define _(s)
Definition: 3d_actions.cpp:33
enum TYPE m_Type
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Do nothing, units just take the parent's score.
LIB_TREE_NODE_ROOT()
Construct the root node.
void Update(LIB_TREE_ITEM *aItem)
Update the node using data from a LIB_ALIAS object.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Update the score for this part.
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) override
Update the score for this part.
virtual ~LIB_TREE_NODE()
PTR_VECTOR m_Children
wxString m_SearchText
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 ...
wxString m_MatchName