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-2018 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 public:
77  enum TYPE {
79  };
80 
81  typedef std::vector<std::unique_ptr<LIB_TREE_NODE>> PTR_VECTOR;
82 
84  PTR_VECTOR Children;
85  enum TYPE Type;
86 
93 
95  int Score;
96 
97  wxString Name;
98  wxString Desc;
99  wxString MatchName;
100  wxString SearchText;
101  bool Normalized;
102 
103 
105  int Unit;
106  bool IsRoot;
107 
114  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) = 0;
115 
119  void ResetScore();
120 
125  void AssignIntrinsicRanks( bool presorted = false );
126 
130  void SortNodes();
131 
136  static int Compare( LIB_TREE_NODE const& aNode1, LIB_TREE_NODE const& aNode2 );
137 
138  LIB_TREE_NODE();
139  virtual ~LIB_TREE_NODE() {}
140 };
141 
142 
147 {
148 
149 public:
154  LIB_TREE_NODE_UNIT( LIB_TREE_NODE_UNIT const& _ ) = delete;
155  void operator=( LIB_TREE_NODE_UNIT const& _ ) = delete;
156 
157 
168  LIB_TREE_NODE_UNIT( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* aItem, int aUnit );
169 
170 
174  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override {}
175 };
176 
177 
182 {
183 public:
188  LIB_TREE_NODE_LIB_ID( LIB_TREE_NODE_LIB_ID const& _ ) = delete;
189  void operator=( LIB_TREE_NODE_LIB_ID const& _ ) = delete;
190 
191 
205 
209  void Update( LIB_TREE_ITEM* aItem );
210 
214  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
215 
216 protected:
222  LIB_TREE_NODE_UNIT& AddUnit( LIB_TREE_ITEM* aItem, int aUnit );
223 };
224 
225 
230 {
231 public:
236  LIB_TREE_NODE_LIB( LIB_TREE_NODE_LIB const& _ ) = delete;
237  void operator=( LIB_TREE_NODE_LIB const& _ ) = delete;
238 
239 
247  LIB_TREE_NODE_LIB( LIB_TREE_NODE* aParent, wxString const& aName, wxString const& aDesc );
248 
254  LIB_TREE_NODE_LIB_ID& AddItem( LIB_TREE_ITEM* aItem );
255 
256  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
257 };
258 
259 
264 {
265 public:
270  LIB_TREE_NODE_ROOT( LIB_TREE_NODE_ROOT const& _ ) = delete;
271  void operator=( LIB_TREE_NODE_ROOT const& _ ) = delete;
272 
277 
281  LIB_TREE_NODE_LIB& AddLib( wxString const& aName, wxString const& aDesc );
282 
283  virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override;
284 };
285 
286 
287 #endif // LIB_TREE_MODEL_H
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
PTR_VECTOR Children
List of child nodes.
enum TYPE Type
Node type.
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
bool Normalized
Support for lazy normalization.
Node type: LIB_ID.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
LIB_TREE_NODE * Parent
Parent node or null.
int Score
The score of an item resulting from the search algorithm.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher)=0
Update the score for this part.
Node type: root.
wxString MatchName
Normalized name for matching.
Node type: library.
LIB_ID LibId
LIB_ID determined by the parent library nickname and alias name.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
Node type: unit of component.
wxString Desc
Description to be displayed.
wxString SearchText
Descriptive text to search.
wxString Name
Actual name of the part.
bool IsRoot
Indicates if the symbol is a root symbol instead of an alias.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
std::vector< std::unique_ptr< LIB_TREE_NODE > > PTR_VECTOR
int Unit
Actual unit, or zero.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Do nothing, units just take the parent&#39;s score.
int IntrinsicRank
The rank of the item before any search terms are applied.
virtual ~LIB_TREE_NODE()